|
| 1 | +from kivy.app import App |
| 2 | +from kivy.lang import Builder |
| 3 | +from kivy.uix.screenmanager import ScreenManager, Screen |
| 4 | +import db |
| 5 | + |
| 6 | +global current_user |
| 7 | +current_user = object() |
| 8 | +global kivy_app |
| 9 | +kivy_app = object() |
| 10 | + |
| 11 | + |
| 12 | +class UserData: |
| 13 | + def __init__(self,un =""): |
| 14 | + self.UserName=un |
| 15 | + self.FirstName="" |
| 16 | + self.LastName="" |
| 17 | + self.Email="" |
| 18 | + self.Interests="" |
| 19 | + pass |
| 20 | + |
| 21 | + def update(self,data): |
| 22 | + self.UserName = data[1] |
| 23 | + self.FirstName= data[3] |
| 24 | + self.LastName= data[4] |
| 25 | + self.Email= data[5] |
| 26 | + self.Interests= data[6] |
| 27 | + pass |
| 28 | + |
| 29 | + |
| 30 | + pass |
| 31 | + |
| 32 | +class SplashWindow(Screen): |
| 33 | + |
| 34 | + pass |
| 35 | + |
| 36 | +class LoginWindow(Screen):# |
| 37 | + def login_released(self,usnm, passw): |
| 38 | + print(f"user name = {usnm.text}") |
| 39 | + print(f"password = {passw.text}") |
| 40 | + result = db.un_login(usnm.text,passw.text) |
| 41 | + if result == True: |
| 42 | + |
| 43 | + |
| 44 | + current_user = UserData(usnm.text) |
| 45 | + # clear text fields |
| 46 | + usnm.text ="" |
| 47 | + passw.text ="" |
| 48 | + #set window to profile |
| 49 | + kivy_app.root.current = "profile" |
| 50 | + self.manager.transition.direction = "left" |
| 51 | + pass |
| 52 | + else: |
| 53 | + # give users feedback that they are not able to log in due to invalid credentials |
| 54 | + pass |
| 55 | + |
| 56 | + pass |
| 57 | + |
| 58 | + pass |
| 59 | + |
| 60 | +class ProfileWindow(Screen): |
| 61 | + def display_userdata(self,*args): |
| 62 | + user_profiles = db.profile_get(current_user.UserName) |
| 63 | + assert len(user_profiles) |
| 64 | + |
| 65 | + user_data = user_profiles[0] |
| 66 | + current_user.update(user_data) |
| 67 | + for i in range (len(args)): |
| 68 | + args[i].text = user_data[i + 1] |
| 69 | + pass |
| 70 | + |
| 71 | + |
| 72 | + pass |
| 73 | + pass |
| 74 | + |
| 75 | +class ProfileCreateWindow(Screen): |
| 76 | + def create_profile_released(self,usnm,passw,first_name,last_name,email,interests): |
| 77 | + db.profile_new(usnm.text,passw.text,first_name.text,last_name.text,email.text,interests.text) |
| 78 | + global current_user |
| 79 | + current_user.UserName = usnm.text |
| 80 | + current_user.FirstName = first_name.text |
| 81 | + current_user.LastName = last_name.text |
| 82 | + current_user.Email = email.text |
| 83 | + current_user.Interests = interests.text |
| 84 | + |
| 85 | + |
| 86 | + pass |
| 87 | + |
| 88 | + |
| 89 | + pass |
| 90 | + |
| 91 | +class WindowManager(ScreenManager): |
| 92 | + |
| 93 | + def get_username(self): |
| 94 | + global current_user |
| 95 | + |
| 96 | + return current_user.UserName |
| 97 | + |
| 98 | + def update_username(self,newusername ): |
| 99 | + |
| 100 | + global current_user |
| 101 | + current_user.UserName = newusername |
| 102 | + |
| 103 | + pass |
| 104 | + |
| 105 | + def clear_released(self,* args): |
| 106 | + for element in args: |
| 107 | + element.text = "" |
| 108 | + pass |
| 109 | + pass |
| 110 | + |
| 111 | + |
| 112 | + pass |
| 113 | + |
| 114 | + |
| 115 | +current_user = UserData() |
| 116 | + |
| 117 | +kv = Builder.load_file("my.kv") |
| 118 | + |
| 119 | + |
| 120 | +class MyMainApp(App): |
| 121 | + def build(self): |
| 122 | + return kv |
| 123 | + |
| 124 | +def main(): |
| 125 | + # # Teo: use these lines to manipulate database |
| 126 | + # Database initialization and tests |
| 127 | + db.init() |
| 128 | + # db.un_exists('userNameThatDoesNotExist') |
| 129 | + # db.profile_delete('userNameThatDoesNotExist') |
| 130 | + # db.profile_delete('davidDelSol') |
| 131 | + # db.profile_new( |
| 132 | + # 'davidDelSol', |
| 133 | + # 'encrypted?', |
| 134 | + # 'david', |
| 135 | + # 'aloka', |
| 136 | + # 'test@preform.io', |
| 137 | + # 'salsa,extended intelligence,marathon running in a full suit' |
| 138 | + # ) |
| 139 | + # db.profile_new( |
| 140 | + # 'Python733t', |
| 141 | + # 'encrypted?', |
| 142 | + # 'Doroteo ', |
| 143 | + # 'Bonilla', |
| 144 | + # 'doabonilla@yahoo.com', |
| 145 | + # 'work,school,sleep,repeat' |
| 146 | + # ) |
| 147 | + # db.un_login('davidDelSol', 'encrypted?') |
| 148 | + # db.profile_update('davidDelSol', pw = 'definitelyNotEncripted!') |
| 149 | + # db.un_login('davidDelSol', 'definitelyNotEncripted!') |
| 150 | + # db.un_exists('davidDelSol') |
| 151 | + # db.profile_print(all = True) |
| 152 | + # db.profile_print(['Python733t']) |
| 153 | + # db.profile_print('Python733t') |
| 154 | + pass |
| 155 | + |
| 156 | + |
| 157 | +if __name__ == "__main__": |
| 158 | + kivy_app = MyMainApp() |
| 159 | + |
| 160 | + main() |
| 161 | + kivy_app.run() |
0 commit comments