From 2f580678fa87234613eb13144d412a8cda1d31ec Mon Sep 17 00:00:00 2001 From: "a.jurcenko" Date: Tue, 16 Sep 2025 16:08:47 +0200 Subject: [PATCH] added functions --- abacus_core.py | 22 ++++++++++++++++++-- console.py | 2 ++ main.py | 54 ++++++++++++++++++++++++++++++++++++++++++-------- readme.md | 3 +++ 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/abacus_core.py b/abacus_core.py index 1037277..fc94197 100644 --- a/abacus_core.py +++ b/abacus_core.py @@ -16,6 +16,9 @@ class AbacusCore: def get_vars(self): return self._vars + def get_funcs(self): + return self._funcs + def add_var(self, name, value): self._vars[name] = value @@ -37,7 +40,18 @@ class AbacusCore: :param input_str: :return: ''' + if input_str.find(':')>-1: + chunks = input_str.split(':') + if len(chunks) == 2: + self._funcs[chunks[0]] = chunks[1] + else: + return self._with_variable(input_str) + + def _with_variable(self, input_str): input_str, comment = self._get_input_wo_commentar(input_str) + func = self._funcs.get(input_str) + if func: + input_str = func input_str = ''.join(input_str.split()) # entferne alle leerzeichen input_str = input_str.replace(',', '.') if input_str is not None: @@ -80,12 +94,16 @@ class AbacusCore: if var is not None: new_input_str += str(var) else: - raise ValueError() + func = self._funcs.get(temp_var) + if func: + new_input_str += str(func) + else: + raise NotImplemented() first_position = None if i == input_str_len - 1: continue new_input_str += input_str[i] - elif c.isalpha(): + elif c.isalpha() or c=='_': if first_position is None: first_position = i else: diff --git a/console.py b/console.py index 0868066..89f9002 100644 --- a/console.py +++ b/console.py @@ -10,6 +10,8 @@ if __name__ == '__main__': var = input('gib was ein:') if var == 'vars': print(ab.get_vars()) + elif var == 'func': + print(ab.get_funcs()) elif var == 'res': print(res) else: diff --git a/main.py b/main.py index 1236f39..b344a6e 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,51 @@ +import sys + +from PySide6.QtGui import QStandardItemModel, QStandardItem +from PySide6.QtUiTools import QUiLoader +from PySide6.QtWidgets import QApplication, QFileDialog +from PySide6.QtCore import QFile, QIODevice, QModelIndex, QAbstractTableModel from abacus_core import AbacusCore -ab = AbacusCore() + +class AbacusGUI: + + def __init__(self): + self._abacus_core = AbacusCore() + self._step = 0 + self._history = [] + self._app = QApplication(sys.argv) + ui_file_name = "gui.ui" + ui_file = QFile(ui_file_name) + if not ui_file.open(QIODevice.ReadOnly): + print(f"Cannot open {ui_file_name}: {ui_file.errorString()}") + sys.exit(-1) + loader = QUiLoader() + self._window = loader.load(ui_file) + ui_file.close() + if not self._window: + print(loader.errorString()) + sys.exit(-1) + self._window.show() + self._window.but_enter.clicked.connect(self._berechne) + self._window.le_input.returnPressed.connect(self._berechne) + + self._history_model = QStandardItemModel() + self._window.lv_history.setModel(self._history_model) + sys.exit(self._app.exec()) + + def _berechne(self): + self._step += 1 + input_str = self._window.le_input.text() + result = self._abacus_core.parse_input(input_str) + if result: + self._history.append(result) + res_str = str(self._step) + ': ' + result[0]+' '+str(result[3])+' : '+str(result[1])+' = '+str(result[2]) + item = QStandardItem(res_str) + self._history_model.appendRow(item) + res = result[2] + self._window.le_input.setText(str(res)) -if __name__ == '__main__': - while True: - var = input('gib was ein:') - if var == 'vars': - print(ab.get_vars()) - continue - print(ab.parse_input(str(var))) +if __name__ == "__main__": + ag = AbacusGUI() diff --git a/readme.md b/readme.md index 00b32c8..fd69300 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,6 @@ # AbacusNG ## Sinn und Zweck + +## Known Bugs +- Eine ein-zeichen Variable so wie _ oder a funktioniert nicht