diff --git a/abacus_core.py b/abacus_core.py index f108d3f..ae2a203 100644 --- a/abacus_core.py +++ b/abacus_core.py @@ -43,10 +43,14 @@ class AbacusCore: :param input_str: :return: ''' + input_str = input_str.strip() comment = None orig_input_str = input_str if len(input_str) < 1: # leere eingabe wird nicht akzeptiert return + if input_str[0] == '#': # ganze eingabe ist ein kommentar + comment = input_str + return None, None, None, comment chunks = input_str.split('#') if len(chunks) > 1: input_str = chunks[0] @@ -56,6 +60,7 @@ class AbacusCore: raise ValueError('Mehrfachzuweisung wird nicht unterstützt') elif len(chunks) > 1: expression = self._with_variable_another_way(chunks[1]) + chunks[0] = '_'.join(chunks[0].strip().split(' ')) self._vars[chunks[0]] = expression return chunks = input_str.split(':') # gibt es funktionsdefinition? diff --git a/main.py b/main.py index 14b34de..e0a6cbb 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,6 @@ class AbacusGUI: 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: @@ -48,14 +47,20 @@ class AbacusGUI: input_wo_var = str(result[1]) ergebnis = str(result[2]) comment = result[3] - res_str = str(self._step) + '. ' + input_str + ' = ' + ergebnis - # 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)) + if result[0] is not None: + self._step += 1 + res_str = str(self._step) + '> ' + input_str + ' = ' + ergebnis + # 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)) + elif result[3] is not None: + item = QStandardItem(comment) + self._history_model.appendRow(item) + self._window.le_input.setText('') else: self._window.le_input.setText('') self._check_models()