-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
160 lines (116 loc) · 3.84 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
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
import db_utils as db_u
import os
class RegisterWindow(Screen):
namee = ObjectProperty(None)
email = ObjectProperty(None)
password = ObjectProperty(None)
def submit(self):
if self.namee.text != "" and self.email.text != "" and self.email.text.count("@") == 1 and self.email.text.count(".") > 0:
if self.password != "" :
db_u.add_user(self.email.text, self.password.text, self.namee.text)
sm.current = "login"
else:
erro_form('senha')
else:
erro_form('email')
def login(self):
self.reset()
sm.current = "login"
def reset(self):
self.email.text = ""
self.password.text = ""
self.namee.text = ""
class LoginWindow(Screen):
email = ObjectProperty(None)
password = ObjectProperty(None)
def loginBtn(self):
if db_u.check_credentials(self.email.text, self.password.text):
self.reset()
sm.current = "main"
else:
erro_login()
def createBtn(self):
self.reset()
sm.current = "create"
def reset(self):
self.email.text = ""
self.password.text = ""
def on_enter(self):
pass
class SaveDialog(FloatLayout):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
class UserWindow(Screen):
text_input = ObjectProperty(None)
savefile = ObjectProperty(None)
def dismiss_popup(self):
self._popup.dismiss()
def save_file_on_db(self, img, txt):
insert_report(img, txt)
def save(self, path, filename):
with open(os.path.join(path, filename), 'w') as stream:
stream.write(self.text_input.text)
self.dismiss_popup()
def show_selected(self):
sm.current = 'carregar'
def logout(self):
sm.current = 'login'
class PictureViewer(Screen):
selected = ObjectProperty(None)
cancel = ObjectProperty(None)
def selected(self,filename):
try:
self.ids.image.source = filename[0]
except:
pass
def save_picture(self,filename):
root.ids.foto_escolhida.source = filename[0]
# print(filename[0])
# print('\n')
# print(os.path.abspath(__file__))
def back(self):
sm.current = 'main'
class FormWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
def erro_login():
pop = Popup(title='Erro',
content=Label(text='Senha ou Email incorretos.'),
size_hint=(None, None), size=(400, 400))
pop.open()
def erro_form(string):
if string == 'email':
pop = Popup(title='Email não cadastrado.',
content=Label(text='Please fill in all inputs with valid information.'),
size_hint=(None, None), size=(400, 400))
elif string == 'senha':
pop = Popup(title='Senha incorreta.',
content=Label(text='Please fill in all inputs with valid information.'),
size_hint=(None, None), size=(400, 400))
pop.open()
kv = Builder.load_file("my.kv")
sm = WindowManager()
screens = [
LoginWindow(name="login"),
RegisterWindow(name="create"),
UserWindow(name="main"),
PictureViewer(name="carregar")]
for screen in screens:
sm.add_widget(screen)
sm.current = "login"
class MyMainApp(App):
def build(self):
return sm
if __name__ == "__main__":
MyMainApp().run()