From 5fac887acd43cc29db5715adcf45f46b32dec75b Mon Sep 17 00:00:00 2001 From: "N0\\A" Date: Sat, 25 Oct 2025 10:42:41 +0200 Subject: [PATCH] calculator --- SUPERCOPY.py | 8 ++++++ strings/en.json | 5 ++++ strings/personality_en.json | 5 ++++ windows/calculator.py | 52 +++++++++++++++++++++++++++++++++++++ windows/main_window.py | 8 ++++++ 5 files changed, 78 insertions(+) create mode 100644 windows/calculator.py diff --git a/SUPERCOPY.py b/SUPERCOPY.py index a8f29b1..9f35291 100644 --- a/SUPERCOPY.py +++ b/SUPERCOPY.py @@ -6,6 +6,14 @@ files = [ "core/headers.py", "core/updater.py", "core/web_search.py", + "strings/en.json", + "strings/personality_en.json", + "windows/app_launcher.py", + "windows/calculator.py", + "windows/file_search.py", + "windows/main_window.py", + "windows/text_viewer.py", + "windows/web_results.py", "main.py", "README.md", "requirements.txt" diff --git a/strings/en.json b/strings/en.json index 1aae6f4..1d0f4f0 100644 --- a/strings/en.json +++ b/strings/en.json @@ -37,11 +37,16 @@ "copy_button": "Copy to Clipboard", "close_button": "Close" }, + "calculator": { + "title": "Calculator", + "copy_button": "Copy Result" + }, "main_window": { "right_menu": { "launch_app": "Launch App", "search_files": "Search Files", "search_web": "Search Web", + "calculator": "Calculator", "send_menu": "Send", "send_files_submenu": "Send File(s)", "send_text_submenu": "Send Text", diff --git a/strings/personality_en.json b/strings/personality_en.json index fdf85e9..f51e66e 100644 --- a/strings/personality_en.json +++ b/strings/personality_en.json @@ -37,11 +37,16 @@ "copy_button": "Copy", "close_button": "Close" }, + "calculator": { + "title": "Calculator", + "copy_button": "Copy" + }, "main_window": { "right_menu": { "launch_app": "Launch App", "search_files": "Find Files", "search_web": "Search Web", + "calculator": "Calculator", "send_menu": "Send", "send_files_submenu": "Send Files", "send_text_submenu": "Send Message", diff --git a/windows/calculator.py b/windows/calculator.py new file mode 100644 index 0000000..abdc586 --- /dev/null +++ b/windows/calculator.py @@ -0,0 +1,52 @@ +from PySide6 import QtWidgets, QtCore + +class CalculatorDialog(QtWidgets.QDialog): + def __init__(self, strings, parent=None): + super().__init__(parent) + self.strings = strings["calculator"] + self.setWindowTitle(self.strings["title"]) + self.setMinimumWidth(350) + + # Main layout + layout = QtWidgets.QVBoxLayout(self) + + # text box + self.equation_box = QtWidgets.QLineEdit() + self.equation_box.setPlaceholderText("Type a mathematical equation...") + self.equation_box.textChanged.connect(self.update_result) + layout.addWidget(self.equation_box) + + # label + self.result_label = QtWidgets.QLabel() + self.result_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) # type: ignore + self.result_label.setStyleSheet("padding: 5px; border: 1px solid #ccc; border-radius: 4px;") + layout.addWidget(self.result_label) + + # copy button + button_layout = QtWidgets.QHBoxLayout() + button_layout.addStretch() + copy_button = QtWidgets.QPushButton(self.strings.get("copy_button", "Copy")) + copy_button.clicked.connect(self.copy_to_clipboard) + button_layout.addWidget(copy_button) + layout.addLayout(button_layout) + + self.setLayout(layout) + self.equation_box.setFocus() + + def update_result(self, text: str): + if not text.strip(): + self.result_label.setText("") + return + + try: + result = eval(text) + + self.result_label.setText(str(result)) + except Exception: + self.result_label.setText("") + + def copy_to_clipboard(self): + text = self.result_label.text() + if text: + clipboard = QtWidgets.QApplication.clipboard() + clipboard.setText(text) \ No newline at end of file diff --git a/windows/main_window.py b/windows/main_window.py index 86d6847..5104fb1 100644 --- a/windows/main_window.py +++ b/windows/main_window.py @@ -14,6 +14,7 @@ from windows.app_launcher import AppLauncherDialog from windows.file_search import FileSearchResults from windows.web_results import WebSearchResults from windows.text_viewer import TextViewerDialog +from windows.calculator import CalculatorDialog ASSET = Path(__file__).parent.parent / "assets" / "2ktan.png" @@ -97,6 +98,7 @@ class MainWindow(QtWidgets.QMainWindow): right_menu.addAction(s["launch_app"], self.start_app_launcher) right_menu.addAction(s["search_files"], self.start_file_search) right_menu.addAction(s["search_web"], self.start_web_search) + right_menu.addAction(s.get("calculator", "Calculator"), self.start_calculator) right_menu.addSeparator() send_menu_right = right_menu.addMenu(s["send_menu"]) self.send_files_submenu_right = send_menu_right.addMenu(s["send_files_submenu"]) @@ -118,6 +120,7 @@ class MainWindow(QtWidgets.QMainWindow): self.left_menu.addAction(s["launch_app"], self.start_app_launcher) self.left_menu.addAction(s["search_files"], self.start_file_search) self.left_menu.addAction(s["search_web"], self.start_web_search) + self.left_menu.addAction(s.get("calculator", "Calculator"), self.start_calculator) self.left_menu.addSeparator() send_menu_left = self.left_menu.addMenu(s["send_menu"]) self.send_files_submenu_left = send_menu_left.addMenu(s["send_files_submenu"]) @@ -321,6 +324,11 @@ class MainWindow(QtWidgets.QMainWindow): self.app_launcher_dialog.move(QtGui.QCursor.pos()) self.app_launcher_dialog.show() + def start_calculator(self): + self.calculator_dialog = CalculatorDialog(self.strings, self) + self.calculator_dialog.move(QtGui.QCursor.pos()) + self.calculator_dialog.show() + def start_file_search(self): s = self.strings["file_search"] dialog = QtWidgets.QInputDialog(self)