diff --git a/abacus_core.py b/abacus_core.py index fc94197..47a3429 100644 --- a/abacus_core.py +++ b/abacus_core.py @@ -40,10 +40,18 @@ class AbacusCore: :param input_str: :return: ''' + if len(input_str) < 1: + return if input_str.find(':')>-1: - chunks = input_str.split(':') - if len(chunks) == 2: - self._funcs[chunks[0]] = chunks[1] + chunks = input_str.split('#') + comment = None + if len(chunks) > 1: + comment = chunks[1] + input_str = chunks[0] + inp_chunks = input_str.split(':') + if len(inp_chunks) == 2: + self._funcs[inp_chunks[0]] = inp_chunks[1] + return inp_chunks[0], inp_chunks[1], 0, comment else: return self._with_variable(input_str) @@ -77,7 +85,7 @@ class AbacusCore: first_position = None new_input_str = '' operators = ['+', '-', '/', '*'] - delimiters = ['(', ')', '[', ']', ';'] + delimiters = ['(', ')', '[', ']', ';', ' '] op_del = operators + delimiters if input_str[0] in operators: input_str = 'result' + input_str diff --git a/gui.ui b/gui.ui index e945d08..01420fb 100644 --- a/gui.ui +++ b/gui.ui @@ -6,22 +6,119 @@ 0 0 - 506 - 623 + 735 + 770 AbacusNG - + - + - + + + + + Verlauf + + + + + + + - + + + + + Variablen + + + + + + + + + QAbstractItemView::SelectionMode::SingleSelection + + + QListView::ResizeMode::Adjust + + + + + + + + + Neu + + + + + + + Bearbeiten + + + + + + + Löschen + + + + + + + + + + + Funktionen + + + + + + + + + + + + + + Neu + + + + + + + Bearbeiten + + + + + + + Löschnen + + + + + + + + @@ -46,12 +143,51 @@ 0 0 - 506 - 33 + 735 + 24 + + + Datei + + + + + + + + + + + + + + Neu + + + + + Speichern + + + + + Speichern unter + + + + + Drucken + + + + + Beenden + + diff --git a/main.py b/main.py index b344a6e..afb1efd 100644 --- a/main.py +++ b/main.py @@ -28,9 +28,14 @@ class AbacusGUI: 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) + self._var_model = QStandardItemModel() + self._func_model = QStandardItemModel() + self._window.lv_variable.setModel(self._var_model) + self._window.lv_func.setModel(self._func_model) + # self._window.actionExit.clicked.connect(self._berechne) + self._check_models() sys.exit(self._app.exec()) def _berechne(self): @@ -39,11 +44,30 @@ class AbacusGUI: 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]) + input_str = result[0] + input_wo_var = str(result[1]) + ergebnis = str(result[2]) + comment = result[3] + res_str = str(self._step) + '. ' + input_str + ' => ' + input_wo_var + ' = ' + ergebnis + if comment: + res_str += ' ' + comment item = QStandardItem(res_str) self._history_model.appendRow(item) res = result[2] self._window.le_input.setText(str(res)) + else: + self._window.le_input.setText('') + self._check_models() + + def _check_models(self): + self._var_model.clear() + self._func_model.clear() + for k, v in self._abacus_core.get_vars().items(): + item = QStandardItem(k+' = '+str(v)) + self._var_model.appendRow(item) + for k, v in self._abacus_core.get_funcs().items(): + item = QStandardItem(k+' = '+str(v)) + self._func_model.appendRow(item) if __name__ == "__main__": diff --git a/readme.md b/readme.md index fd69300..b563ba7 100644 --- a/readme.md +++ b/readme.md @@ -4,3 +4,4 @@ ## Known Bugs - Eine ein-zeichen Variable so wie _ oder a funktioniert nicht +- rückgabewert einer funktion lässt sich nicht einer variablen zuweisen