changed logic
parent
b5584bf316
commit
d608d2f077
|
|
@ -43,10 +43,14 @@ class AbacusCore:
|
||||||
:param input_str:
|
:param input_str:
|
||||||
:return:
|
:return:
|
||||||
'''
|
'''
|
||||||
|
input_str = input_str.strip()
|
||||||
comment = None
|
comment = None
|
||||||
orig_input_str = input_str
|
orig_input_str = input_str
|
||||||
if len(input_str) < 1: # leere eingabe wird nicht akzeptiert
|
if len(input_str) < 1: # leere eingabe wird nicht akzeptiert
|
||||||
return
|
return
|
||||||
|
if input_str[0] == '#': # ganze eingabe ist ein kommentar
|
||||||
|
comment = input_str
|
||||||
|
return None, None, None, comment
|
||||||
chunks = input_str.split('#')
|
chunks = input_str.split('#')
|
||||||
if len(chunks) > 1:
|
if len(chunks) > 1:
|
||||||
input_str = chunks[0]
|
input_str = chunks[0]
|
||||||
|
|
@ -56,6 +60,7 @@ class AbacusCore:
|
||||||
raise ValueError('Mehrfachzuweisung wird nicht unterstützt')
|
raise ValueError('Mehrfachzuweisung wird nicht unterstützt')
|
||||||
elif len(chunks) > 1:
|
elif len(chunks) > 1:
|
||||||
expression = self._with_variable_another_way(chunks[1])
|
expression = self._with_variable_another_way(chunks[1])
|
||||||
|
chunks[0] = '_'.join(chunks[0].strip().split(' '))
|
||||||
self._vars[chunks[0]] = expression
|
self._vars[chunks[0]] = expression
|
||||||
return
|
return
|
||||||
chunks = input_str.split(':') # gibt es funktionsdefinition?
|
chunks = input_str.split(':') # gibt es funktionsdefinition?
|
||||||
|
|
|
||||||
9
main.py
9
main.py
|
|
@ -39,7 +39,6 @@ class AbacusGUI:
|
||||||
sys.exit(self._app.exec())
|
sys.exit(self._app.exec())
|
||||||
|
|
||||||
def _berechne(self):
|
def _berechne(self):
|
||||||
self._step += 1
|
|
||||||
input_str = self._window.le_input.text()
|
input_str = self._window.le_input.text()
|
||||||
result = self._abacus_core.parse_input(input_str)
|
result = self._abacus_core.parse_input(input_str)
|
||||||
if result:
|
if result:
|
||||||
|
|
@ -48,7 +47,9 @@ class AbacusGUI:
|
||||||
input_wo_var = str(result[1])
|
input_wo_var = str(result[1])
|
||||||
ergebnis = str(result[2])
|
ergebnis = str(result[2])
|
||||||
comment = result[3]
|
comment = result[3]
|
||||||
res_str = str(self._step) + '. ' + input_str + ' = ' + ergebnis
|
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
|
# res_str = str(self._step) + '. ' + input_str + ' => ' + input_wo_var + ' = ' + ergebnis
|
||||||
if comment:
|
if comment:
|
||||||
res_str += ' ' + comment
|
res_str += ' ' + comment
|
||||||
|
|
@ -56,6 +57,10 @@ class AbacusGUI:
|
||||||
self._history_model.appendRow(item)
|
self._history_model.appendRow(item)
|
||||||
res = result[2]
|
res = result[2]
|
||||||
self._window.le_input.setText(str(res))
|
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:
|
else:
|
||||||
self._window.le_input.setText('')
|
self._window.le_input.setText('')
|
||||||
self._check_models()
|
self._check_models()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue