-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (73 loc) · 2.97 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
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import json, glob, random
from hoverable import HoverBehavior
from kivy.uix.image import Image
from kivy.uix.behaviors import ButtonBehavior
from datetime import datetime
from pathlib import Path
Builder.load_file("design.kv")
class LoginScreen(Screen): #class with the same name as the rules in the .kv file
def sign_up(self):
self.manager.current ="sign_up_screen" #switch from the login screen to the sig up screen
def login(self, uname,pword):
with open("users.json") as file:
users = json.load(file)
if uname in users and users[uname]['password'] == pword:
self.manager.current = "loging_screen_success"
else:
self.ids.login_wrong.text="Wrong username or password!"
def forget_password(self):
# self.manager.transition.direction="right"
self.manager.current = "forget_password_screen"
class RootWidget(ScreenManager):
pass
class SignUpScreen(Screen): #any action in the sign up screen it is connected to this class
def add_user(self, uname, pword):
with open("users.json") as file:
users=json.load(file)
users[uname]={'username': uname, 'password': pword,
'created': datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
with open("users.json", 'w') as file:
json.dump(users, file)
self.manager.current ="sign_up_screen_success"
class ForgottenPassword(Screen):
def check_password(self, user):
# self.manager.transition.direction="left"
with open("users.json") as file:
users=json.load(file)
if user in users:
passw = users[user]['password']
self.ids.show_password.text=passw
else:
self.ids.show_password.text="Username invalid"
def forgot_password_back(self):
self.manager.transition.direction="right"
self.manager.current="login_screen"
class SignUpScreenSuccess(Screen):
def login_back(self):
self.manager.transition.direction="right"
self.manager.current="login_screen"
class LoginScreenSuccess(Screen):
def log_out(self):
self.manager.transition.direction="right"
self.manager.current="login_screen"
def get_quote(self, feel):
feel = feel.lower()
available_feeeling = glob.glob("quotes/*txt")
available_feeeling = [Path(filename).stem for filename
in available_feeeling]
if feel in available_feeeling:
with open(f"quotes/{feel}.txt") as file:
quotes = file.readlines()
self.ids.quote.text = random.choice(quotes)
else:
self.ids.quote.text = "Sorry, feeling not supportet yet!"
class ImageButton(ButtonBehavior,HoverBehavior, Image):
pass
class MainApp(App):
def build(self):
return RootWidget()
if __name__ =="__main__":
MainApp().run()