-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresenter.py
More file actions
25 lines (21 loc) · 864 Bytes
/
presenter.py
File metadata and controls
25 lines (21 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from model import Model, CalculatorException
from view import View
class Presenter:
def __init__(self, view: View, model: Model):
self._view = view
self._model = model
def execute(self):
"""
Function to execute calculator app
"""
# get expression string from view
input_string = self._view.get_input()
self._view.set_output("Результат вычисления")
try:
tokens = self._model.input_tokenize(input_string)
parsed = self._model.sort_machine_algo(tokens)
# print("Reverse Polish Notation: " + " ".join([str(item.t_value) for item in parsed]))
result = self._model.evaluate(parsed)
self._view.set_output(str(result))
except CalculatorException as err:
self._view.display_error(str(err))