forked from sacredsliver/calc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
29 lines (24 loc) · 817 Bytes
/
controller.py
File metadata and controls
29 lines (24 loc) · 817 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
26
27
28
29
import model
import view
def button_click():
value_a = view.get_value()
value_b = view.get_value()
value_o = view.get_opert()
if 'i' in str(value_a) and 'i' in str(value_b):
type_num = model.model_name_kmp
elif view.try_cast(value_a, int) != None and view.try_cast(value_b, int) != None:
type_num = model.model_name_rac
else:
raise Exception('Invalid operands!')
model.init(value_a, value_b, type_num)
if value_o == '*':
result = model.mult()
elif value_o == '/':
result = model.div()
elif value_o == '+':
result = model.sum()
elif value_o == '-':
result = model.sub()
else:
raise Exception('Operation not support!')
view.view_data(result, "result")