added functions
parent
7f30a44f6d
commit
2f580678fa
|
|
@ -16,6 +16,9 @@ class AbacusCore:
|
||||||
def get_vars(self):
|
def get_vars(self):
|
||||||
return self._vars
|
return self._vars
|
||||||
|
|
||||||
|
def get_funcs(self):
|
||||||
|
return self._funcs
|
||||||
|
|
||||||
def add_var(self, name, value):
|
def add_var(self, name, value):
|
||||||
self._vars[name] = value
|
self._vars[name] = value
|
||||||
|
|
||||||
|
|
@ -37,7 +40,18 @@ class AbacusCore:
|
||||||
:param input_str:
|
:param input_str:
|
||||||
:return:
|
: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)
|
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 = ''.join(input_str.split()) # entferne alle leerzeichen
|
||||||
input_str = input_str.replace(',', '.')
|
input_str = input_str.replace(',', '.')
|
||||||
if input_str is not None:
|
if input_str is not None:
|
||||||
|
|
@ -80,12 +94,16 @@ class AbacusCore:
|
||||||
if var is not None:
|
if var is not None:
|
||||||
new_input_str += str(var)
|
new_input_str += str(var)
|
||||||
else:
|
else:
|
||||||
raise ValueError()
|
func = self._funcs.get(temp_var)
|
||||||
|
if func:
|
||||||
|
new_input_str += str(func)
|
||||||
|
else:
|
||||||
|
raise NotImplemented()
|
||||||
first_position = None
|
first_position = None
|
||||||
if i == input_str_len - 1:
|
if i == input_str_len - 1:
|
||||||
continue
|
continue
|
||||||
new_input_str += input_str[i]
|
new_input_str += input_str[i]
|
||||||
elif c.isalpha():
|
elif c.isalpha() or c=='_':
|
||||||
if first_position is None:
|
if first_position is None:
|
||||||
first_position = i
|
first_position = i
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ if __name__ == '__main__':
|
||||||
var = input('gib was ein:')
|
var = input('gib was ein:')
|
||||||
if var == 'vars':
|
if var == 'vars':
|
||||||
print(ab.get_vars())
|
print(ab.get_vars())
|
||||||
|
elif var == 'func':
|
||||||
|
print(ab.get_funcs())
|
||||||
elif var == 'res':
|
elif var == 'res':
|
||||||
print(res)
|
print(res)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
54
main.py
54
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
|
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__':
|
if __name__ == "__main__":
|
||||||
while True:
|
ag = AbacusGUI()
|
||||||
var = input('gib was ein:')
|
|
||||||
if var == 'vars':
|
|
||||||
print(ab.get_vars())
|
|
||||||
continue
|
|
||||||
print(ab.parse_input(str(var)))
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue