/
main.py
79 lines (58 loc) · 2.18 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
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.behaviors import TouchRippleButtonBehavior, ButtonBehavior
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.metrics import sp, dp
import re
class Clav(TouchRippleButtonBehavior, Label):
def __init__(self, **kwargs):
super(Clav, self).__init__(**kwargs)
self.font_size = sp(48)
self.markup = True
def click_add(self, wid, *args):
if self.text == "c":
self.parent.parent.parent.parent.operation_obj.text = ""
self.parent.parent.parent.parent.result_obj.text = ""
self.text = "."
else:
wid.text += self.text
class MainWidget(BoxLayout):
operation_obj = ObjectProperty()
result_obj = ObjectProperty()
# clavier = ObjectProperty()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.orientation = "vertical"
# def get_result(self, pattern, *args):
# regex = re.compile(r'(^\d*|\.\d*)\+|-|/|\*(\d*|\.\d*$)')
# if regex.match(pattern):
# self.result_obj.text = str(eval(self.operation_obj.text))
# pass
def click_equal(self, *args):
if "x" not in self.operation_obj.text:
self.result_obj.text = str(round(eval(self.operation_obj.text), 10))
else:
self.new_operation_obj = self.operation_obj.text.replace("x", "*")
self.result_obj.text = str(round(eval(self.new_operation_obj), 10))
for child in self.ids.grid.children:
if child.text == ".":
child.color = (236/255, 137/255, 116/255, 1)
child.text = "c"
class Calculator(App):
def advanced_function(self, *args):
pass
def supprim(self, wid, *args):
l = list(wid.text)
if l:
l.pop()
ch = "".join(l)
wid.text = ch
pass
def build(self):
return MainWidget()
if __name__ == "__main__":
from kivy.config import Config
Config.set("graphics", "width", 380)
Config.set("graphics", "height", 750)
Calculator().run()