calculator

This commit is contained in:
N0\A
2025-10-25 10:42:41 +02:00
parent fbc84ec20b
commit 5fac887acd
5 changed files with 78 additions and 0 deletions

View File

@@ -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"

View File

@@ -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",

View File

@@ -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",

52
windows/calculator.py Normal file
View File

@@ -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)

View File

@@ -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)