-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
199 lines (154 loc) · 5.64 KB
/
main.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
Window.size = (710, 500)
class ContainerBX(BoxLayout):
size_font = 0
Stopdot = False
all_simbols = []
int_simbols = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
plus_AndOther = ["+", "-", "*", "/"]
plus_AndOtherStop = False
stop_sizeFont = True
def metricsAss(self,
Bin=False, Octal=False,
Hex=False, default=False,
BinTo=False, OctalTo=False,
HexTo=False, defaultTo=False):
if BinTo == True:
try:
txt = str(self.input.text)
main_result = int(txt, 2)
print(main_result)
except:
self.output.text = "Error. Please check your details "
if OctalTo == True:
try:
txt = str(self.input.text)
main_result = int(txt, 8)
print(main_result)
except:
self.output.text = "Error. Please check your details "
if defaultTo == True:
try:
txt = str(self.input.text)
main_result = int(txt)
print(main_result)
except:
self.output.text = "Error. Please check your details "
if HexTo == True:
try:
txt = str(self.input.text)
main_result = int(txt, 16)
print(main_result)
except:
self.output.text = "Error. Please check your details "
if Bin == True:
try:
x = main_result
n = ""
while x > 0:
y = str(x % 2)
n = y + n
x = int(x / 2)
self.output.text = n
except:
self.output.text = "Error. Please check your details "
if Octal == True:
try:
num = int(main_result)
base = 8
newNum = ''
while num > 0:
newNum = str(num % base) + newNum
num //= base
self.output.text = newNum
except:
self.output.text = "Error. Please check your details "
if default == True:
try:
num = int(main_result)
base = 10
newNum = ''
while num > 0:
newNum = str(num % base) + newNum
num //= base
self.output.text = newNum
except:
self.output.text = "Error. Please check your details "
if Hex == True:
try:
num = int(main_result)
base = 16
newNum = ''
while num > 0:
_num = str(num % base)
if _num == "10":
_num = "A"
if _num == "11":
_num = "B"
if _num == "12":
_num = "C"
if _num == "13":
_num = "D"
if _num == "14":
_num = "E"
if _num == "15":
_num = "F"
if _num == "16":
_num = "10"
newNum = _num + newNum
num //= base
self.output.text = newNum
except:
self.output.text = "Error. Please check your details "
def add_numbers(self, numbers, x=1, y=1):
self.all_simbols.append(numbers)
"""Scale font_size"""
# if len(self.display.text) % 9 <= 1 and self.stop_sizeFont == True:
# self.display.font_size -= 5
# self.size_font += 1
# if self.size_font >= 10:
# self.stop_sizeFont = False
# self.s = 1 # stoped write after MinSize
if y == 0:
self.display.text = self.display.text[:-1]
if x == 0:
self.display.font_size = 75
self.stop_sizeFont = True
self.size_font = 0
self.s = 0
if ((self.plus_AndOtherStop != True) or (self.all_simbols[-1] not in self.plus_AndOther)):
self.plus_AndOtherStop = False
if ((self.all_simbols[-1] != ".") or (
self.Stopdot == False and self.display.text != "Error")):
self.display.text += str(numbers)
print(self.all_simbols)
if self.all_simbols[-1] not in self.int_simbols:
if (self.all_simbols[-1] == "."):
self.Stopdot = True
else:
self.Stopdot = False
if self.all_simbols[-1] not in self.int_simbols:
if (self.all_simbols[-1] in self.plus_AndOther):
self.plus_AndOtherStop = True
else:
self.plus_AndOtherStop = False
print(self.all_simbols)
def main_operation(self, calculation, x=0):
try:
self.display.text = str(round((eval(calculation)), 2))
except Exception:
if (x == 1):
self.display.text = ""
x = 0
else:
self.display.text = "Error"
class CalculatorApp(MDApp):
def build(self):
self.theme_cls.primary_palette = "DeepPurple"
self.theme_cls.primary_hue = "400"
self.theme_cls.theme_style = "Dark"
return ContainerBX()
if __name__ == "__main__":
CalculatorApp().run()