· 6 years ago · Sep 24, 2019, 12:02 PM
1import wx
2#from databases import Database
3import sqlite3
4import wx.lib.agw.aquabutton as AB
5import wx.lib.agw.gradientbutton as GB
6
7#NA PANELIMA SU GUMBOVI DISABLEANI (UMJESTO TEXTBOXOVA SU STAVLJENI ZBOG FERESH FUNKCIJE KOJU NISMO IMPLEMENTIRALI)
8#mogu se svaki put hideati svi gumbi, ali nema potrebe zbog pasivnosti, i za tekst..
9#pocetna NE ODLOGIRAVA, vise korisnika u istoj app,mogu napraviti i da odlogira
10
11
12#funkcija za stvaranje baze podataka
13def databaseFunction():
14 global c
15 global dic
16 global connector
17 global odsjeci
18 #stvaranje connectora, cursora i povezivanje i stvaranje baze
19 connector = sqlite3.connect('example.db')
20 c= connector.cursor()
21 #IF NOT EXISTS osigurava da se nova baza ne stvara svaki put pri pokretanju programa, create index osigurava jedinstvenost korisničkog imena (nema duplih unosa)
22 c.execute('''CREATE TABLE IF NOT EXISTS DatabaseInCabinet(password INTEGER, username VARCHAR(100), titula VARCHAR(100), name VARCHAR(100), role INTEGER, odsjek VARCHAR(100), status VARCHAR(50))''')
23 c.execute("CREATE UNIQUE INDEX IF NOT EXISTS index_part_name ON DatabaseInCabinet(username)")
24
25 values = [
26 {"username": "bb1024", "password": 9221, "name": "Boris Bandurina", "titula": "izv.prof.dr.sc","role":1,"odsjek":"Odsjek za informatologiju","status":"P"},
27 {"username": "sft3321", "password": 8754, "name": "Sanjica Faletar Tanacaković", "titula": "prof.dr.sc","role":1,"odsjek":"Odsjek za informatologiju","status":"P"},
28 {"username": "dh3123", "password": 4322, "name": "Damir Hasenay", "titula": "prof.dr.sc","role":1,"odsjek":"Odsjek za informatologiju","status":"P"},
29 {"username": "kf0918", "password": 2985, "name": "Kristina Feldvari", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za informatologiju","status":"P"},
30
31 {"username": "dv5076", "password": 4331, "name": "Danica Vladić", "titula": "prof.dr.sc","role":1,"odsjek":"Odsjek za psihologiju","status":"N"},
32 {"username": "as1111", "password": 1001, "name": "Ana Šobot", "titula": "izv.prof.dr.sc","role":1,"odsjek":"Odsjek za psihologiju","status":"P"},
33 {"username": "is2131", "password": 5479, "name": "Ivan Skorupan", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za psihologiju","status":"N"},
34 {"username": "pb7651", "password": 2008, "name": "Petar Bubica", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za psihologiju","status":"P"},
35
36 {"username": "df9129", "password": 2048, "name": "Dora Franjić", "titula": "izv.prof.dr.sc","role":1,"odsjek":"Odsjek za pedagogiju","status":"P"},
37 {"username": "fd0201", "password": 1604, "name": "Filip Dutina", "titula": "prof.dr.sc","role":1,"odsjek":"Odsjek za pedagogiju","status":"N"},
38 {"username": "ea0402", "password": 1805, "name": "Ena Aničić", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za pedagogiju","status":"P"},
39 {"username": "ik1405", "password": 1307, "name": "Ivana Kurelja", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za pedagogiju","status":"P"},
40
41 {"username": "ds2303", "password": 1806, "name": "Danijel Strbad", "titula": "izv.prof.dr.sc","role":1,"odsjek":"Odsjek za povijest","status":"N"},
42 {"username": "kg1811", "password": 2309, "name": "Karla Gale", "titula": "prof.dr.sc","role":1,"odsjek":"Odsjek za povijest","status":"P"},
43 {"username": "pg1412", "password": 1995, "name": "Patricia Gale", "titula": "izv.prof.dr.sc","role":1,"odsjek":"Odsjek za povijest","status":"P"},
44 {"username": "iv2712", "password": 1609, "name": "Ivana Vladić", "titula": "doc.dr.sc","role":1,"odsjek":"Odsjek za povijest","status":"P"},
45
46 {"username": "ft4865", "password": 1234, "name": "Filip Todorić", "titula": "student","role":0,"odsjek":"FFOS","status":"P"},
47 {"username": "ds3190", "password": 9909, "name": "Dora Šegvić", "titula": "student","role":0,"odsjek":"FFOS","status":"P"},
48 {"username": "ac6191", "password": 8808, "name": "Antonela Čepčar", "titula": "student","role":0,"odsjek":"FFOS","status":"P"},]
49 #unošenje podataka u bazu podataka (IGNORE) za svako pokretanje programa
50 c.executemany("INSERT OR IGNORE INTO DatabaseInCabinet(username, password, name, titula,role,odsjek,status) VALUES (:username, :password, :name, :titula,:role,:odsjek,:status)",values)
51 dic = {"bb1024": ["P01","P02","P03","P04"], "ds2303": ["P01"],"sft3321":["P01","P02","P03","P04"],"dh3123":["P01","P02","P03"],"kf0918":["P01","P02","P03","P04"],
52 "dv5076":["P01","P02"],"as1111":["P01","P03","P04"],"is2131":["P01","P02","P03","P04","P05","P06"],"pb7651":["P01","P02","P03","P04"],
53 "df9129":["P01","P02","P03","P04"],"fd0201":["P01","P02","P03","P04"],"ea0402":["P01","P02","P03","P04"],"ik1405":["P01","P02","P03","P04"],
54 "kg1811": ["P01","P02","P03","P04"], "pg1412":["P01","P02","P03","P04"],"iv2712":["P01","P02","P03","P04"]} #grupe kojima profesor predaje
55
56 #c.execute("UPDATE DatabaseInCabinet SET name = ? WHERE username = ?", ("Sanjica Faletar","sft3321"))
57 #connector.commit() - samo prvo prezime
58
59 odsjeci = ["Odsjek za informatologiju", "Odsjek za psihologiju", "Odsjek za pedagogiju", "Odsjek za povijest"] #lista odsjeka
60#zadnji panel, ime profesora i aktivnost (kada je logiran student)
61class APanel(wx.Panel):
62
63 def __init__(self,parent):
64 wx.Panel.__init__(self,parent,pos=(0,0),size=(2000,2000))
65 self.frame = parent
66
67 def ShowActivity(self,status,name,user):
68 #postavljanje gumbova
69 name_button = GB.GradientButton(self, bitmap=None,pos=(90,30),size=(200,50),label=name)
70 name_button.SetTopStartColour((105,105,105))
71 name_button.SetTopEndColour((105,105,105))
72 name_button.SetBottomStartColour((105,105,105))
73 name_button.SetBottomEndColour((105,105,105))
74 name_button.Disable()
75 back_button = GB.GradientButton(self, bitmap=None,pos=(165,300),label="Back")
76 back_button.Bind(wx.EVT_BUTTON,self.backP)
77 poc_button = GB.GradientButton(self, bitmap=None,pos=(5,5),size=(50,30),label="Početna")
78 poc_button.Bind(wx.EVT_BUTTON,self.pocetna)
79 logout_button = GB.GradientButton(self, bitmap=None,pos=(300,300),label="Log out")
80 logout_button.Bind(wx.EVT_BUTTON,lambda event: self.logout(event,user))
81 activity = status[0][0]
82 #postavljanje aktivnosti
83 if activity == "A":
84 a_button = GB.GradientButton(self, bitmap=None,pos=(90,150),size=(200,50),label="AKTIVAN(U KABINETU)")
85 a_button.SetTopStartColour((127,255,0))
86 a_button.SetTopEndColour((127,255,0))
87 a_button.SetBottomStartColour((127,255,0))
88 a_button.SetBottomEndColour((127,255,0))
89 a_button.Disable()
90 elif activity == "P":
91 a_button = GB.GradientButton(self, bitmap=None,pos=(90,150),size=(200,50),label="NEAKTIVAN (NIJE U KABINETU)")
92 a_button.SetTopStartColour((139,0,0))
93 a_button.SetTopEndColour((139,0,0))
94 a_button.SetBottomStartColour((139,0,0))
95 a_button.SetBottomEndColour((139,0,0))
96 a_button.Disable()
97 else:
98 a_button = GB.GradientButton(self, bitmap=None,pos=(90,150),size=(200,50),label="NE KORISTI APLIKACIJU")
99 a_button.SetTopStartColour((255,255,0))
100 a_button.SetTopEndColour((255,255,0))
101 a_button.SetBottomStartColour((255,255,0))
102 a_button.SetBottomEndColour((255,255,0))
103 a_button.Disable()
104
105
106 #funkcija za nazad
107 def backP(self,event):
108 self.frame.panel_fifth.Hide()
109 for i in l_buttons:
110 i.Show()
111 self.frame.panel_four.Show()
112 self.Layout()
113 #funkcija za početnu
114 def pocetna(self,event):
115 self.frame.panel_fifth.Hide()
116 self.frame.panel.Show()
117 self.Layout()
118 #log out
119 def logout(self,event,username):
120 c.execute("UPDATE DatabaseInCabinet SET status = ? WHERE username = ?",("P",username))
121 connector.commit()
122 self.frame.panel_fifth.Hide()
123 self.frame.panel.Show()
124 self.Layout()
125
126
127#panel za odsjeke
128class PanelOdsjek(wx.Panel):
129 def __init__(self,parent):
130 wx.Panel.__init__(self,parent,pos=(0,0),size=(2000,2000))
131 self.frame = parent
132
133 def addToOdsjek(self,odsjek):
134 global l_buttons
135 self.Refresh()
136 odsjek_button = GB.GradientButton(self, bitmap=None,pos=(120,30),size=(150,50),label=odsjek)
137 odsjek_button.SetTopStartColour((105,105,105))
138 odsjek_button.SetTopEndColour((105,105,105))
139 odsjek_button.SetBottomStartColour((105,105,105))
140 odsjek_button.SetBottomEndColour((105,105,105))
141 odsjek_button.Disable()
142 back_button = GB.GradientButton(self, bitmap=None,pos=(165,300),label="Back")
143 back_button.Bind(wx.EVT_BUTTON,self.back)
144 poc_button = GB.GradientButton(self, bitmap=None,pos=(5,5),size=(50,30),label="Početna")
145 poc_button.Bind(wx.EVT_BUTTON,self.pocetna)
146 c.execute("SELECT titula,name,username,status FROM DatabaseInCabinet WHERE odsjek = ?",(odsjek,))
147 fetched = c.fetchall()
148 #ovo bi se moglo ubaciti u funkciju
149 x=0
150 y=-100
151 brojac=0
152 l_buttons=[]
153 #postavljanje profesora na odsjecima
154 for i in range(len(fetched)):
155 if i%2==0 and i!=0:
156 x=0
157 if brojac%2==0:
158 y+=100
159 prof_info = GB.GradientButton(self, bitmap=None,pos=(13+x,100+y),size=(180,50),label=fetched[i][0]+ " " + fetched[i][1],align=wx.CENTER)
160 if fetched[i][3]=="A":
161 prof_info.SetForegroundColour((76,187,23))
162 elif fetched[i][3]=="P":
163 prof_info.SetForegroundColour((255,0,0))
164 else:
165 prof_info.SetForegroundColour((255,255,0))
166
167 l_buttons.append(prof_info)
168 x+=183
169 brojac+=1
170 for j in range(len(l_buttons)):
171 string = fetched[j][0]+ " " + fetched[j][1]
172 self.bindButtonsProf(l_buttons[j],string,fetched[j][2])
173
174 def back(self,event):
175 self.frame.panel_three.Show()
176 for i in l_buttons:
177 i.Hide()
178 self.frame.panel_four.Hide()
179 self.Layout()
180
181 def bindButtonsProf(self,button,string,user):
182 button.Bind(wx.EVT_BUTTON,lambda event: self.ActivityProf(event,string,user))
183
184 def ActivityProf(self,event,string,user):
185 c.execute("SELECT status FROM DatabaseInCabinet WHERE username = ?",(user,))
186 fetched_status = c.fetchall()
187 self.frame.panel_four.Hide()
188 for i in l_buttons:
189 i.Hide()
190 self.frame.panel_fifth.Show()
191 self.Layout()
192 self.frame.panel_fifth.ShowActivity(fetched_status,string,user)
193 def pocetna(self,event):
194 self.frame.panel.Show()
195 for i in l_buttons:
196 i.Hide()
197 self.frame.panel_four.Hide()
198 self.Layout()
199
200
201
202
203
204
205
206# application for Professors/Students
207class MyPanelStudent(wx.Panel):
208
209 def __init__(self,parent):
210 wx.Panel.__init__(self,parent,pos=(0,0),size=(2000,2000))
211 self.frame = parent
212 def addToSPanel(self,value):
213 status_p = wx.StaticBox(self,-1)
214 sSizer = wx.StaticBoxSizer(status_p,wx.VERTICAL)
215 s1 = wx.BoxSizer(wx.HORIZONTAL)
216 text_g = wx.StaticText(self,-1,"Odsjeci:",pos=(150,30),size=(60,20),style=wx.ALIGN_CENTRE_HORIZONTAL)
217 s1.Add(text_g,0,wx.ALL | wx.CENTER, 100)
218 text_g.SetBackgroundColour((192,192,192))
219 poc_button = GB.GradientButton(self, bitmap=None,pos=(5,5),size=(50,30),label="Početna")
220 poc_button.Bind(wx.EVT_BUTTON,self.pocetna)
221 back_button = GB.GradientButton(self, bitmap=None,pos=(150,300),label="Log out")
222
223 x=0
224 y=-100
225 brojac = 0
226 l = []
227 for i in range(len(odsjeci)):
228 if i%2==0 and i!=0:
229 x=0
230 if brojac%2==0:
231 y+=100
232 odsjek_info = GB.GradientButton(self, bitmap=None,pos=(33+x,100+y),size=(150,50),label=odsjeci[i])
233 l.append(odsjek_info)
234 x+=183
235 brojac+=1
236
237 for j in range(len(l)):
238 self.bindButtons(l[j],odsjeci[j])
239 back_button.Bind(wx.EVT_BUTTON,lambda event: self.backMainS(event,value))
240
241
242 def backMainS(self,event,value):
243 c.execute("UPDATE DatabaseInCabinet SET status = ? WHERE username = ?",("P",value))
244 connector.commit()
245 self.frame.panel_three.Hide()
246 self.frame.panel.Show()
247 self.Layout()
248 def pocetna(self,event):
249 self.frame.panel_three.Hide()
250 self.frame.panel.Show()
251 self.Layout()
252
253 def bindButtons(self,button,odsjek):
254 button.Bind(wx.EVT_BUTTON,lambda event: self.listaProfOdsjek(event,odsjek))
255
256 def listaProfOdsjek(self,event,odsjek):
257 self.frame.panel_three.Hide()
258 self.frame.panel_four.Show()
259 self.Layout()
260 self.frame.panel_four.addToOdsjek(odsjek)
261#panel za prof sucelje
262class MyPanel(wx.Panel):
263 def __init__(self,parent):
264 wx.Panel.__init__(self,parent,pos=(0,0),size=(2000,2000))
265 self.frame = parent
266
267 def addToPanel(self,status,name,value,titula):
268 string = titula + " " + name + " - " + "aktivnost" + " :"
269 status_p = wx.StaticBox(self,-1,'Name')
270 sSizer = wx.StaticBoxSizer(status_p,wx.VERTICAL)
271 s1 = wx.BoxSizer(wx.HORIZONTAL)
272 #Može i text, static text, itd..
273 ac_button = GB.GradientButton(self, bitmap=None,pos=(100,100),size=(200,50),label="AKTIVAN(U KABINETU)")
274 ac_button.SetTopStartColour((127,255,0))
275 ac_button.SetTopEndColour((127,255,0))
276 ac_button.SetBottomStartColour((127,255,0))
277 ac_button.SetBottomEndColour((127,255,0))
278 ac_button.Disable()
279 ac_button = GB.GradientButton(self, bitmap=None,pos=(40,40),size=(300,50),label=string)
280 ac_button.SetTopStartColour((169,169,169))
281 ac_button.SetTopEndColour((169,169,169))
282 ac_button.SetBottomStartColour((169,169,169))
283 ac_button.SetBottomEndColour((169,169,169))
284 ac_button.Disable()
285 poc_button = GB.GradientButton(self, bitmap=None,pos=(5,5),size=(50,30),label="Početna")
286 poc_button.Bind(wx.EVT_BUTTON,self.pocetna)
287 #text_name = wx.StaticText(self,-1,string,pos=(40,40),size=(150,50),style=wx.ALIGN_CENTRE_HORIZONTAL)
288 #s1.Add(text_name,0,wx.ALL | wx.CENTER, 100)
289 text_g = wx.StaticText(self,-1,"Grupe :",pos=(50,170),size=(60,20),style=wx.ALIGN_CENTRE_HORIZONTAL)
290 s1.Add(text_g,0,wx.ALL | wx.CENTER, 100)
291
292 back_button = GB.GradientButton(self, bitmap=None,pos=(165,280),label="Log out")
293 self.SetBackgroundColour((211,211,211))
294
295 #back_button = wx.Button(self,label='Back',pos=(165, 280),size=(50,25))
296 back_button.Bind(wx.EVT_BUTTON,lambda event: self.backMain(event,value))
297
298 string_for_g = ""
299 for i in dic[value]:
300 string_for_g+=i + " "
301 text_ctrl_groups = wx.TextCtrl(self,value=string_for_g,pos=(60, 200),style=wx.TE_READONLY | wx.TE_MULTILINE,name="Groups",size=(100,40))
302 s1.Add(text_ctrl_groups,0,wx.ALL | wx.CENTER | wx.EXPAND, 100)
303
304 def backMain(self,event,value):
305 c.execute("UPDATE DatabaseInCabinet SET status =? WHERE username = ?",("P",value))
306 connector.commit()
307 self.frame.panel_two.Hide()
308 self.frame.panel.Show()
309 self.Layout()
310
311 def pocetna(self,event):
312 self.frame.panel_two.Hide()
313 self.frame.panel.Show()
314 self.Layout()
315
316
317
318
319class MainPanel(wx.Panel):
320 def __init__(self,parent):
321 wx.Panel.__init__(self,parent)
322 #self.frame = parent
323
324
325class MyApp(wx.Frame):
326
327 def __init__(self):
328 super().__init__(parent=None, title='InCabinet',style=wx.DEFAULT_DIALOG_STYLE | wx.MINIMIZE_BOX)
329 #panel = wx.Panel(self)
330
331 sizer = wx.BoxSizer()
332 self.SetSizer(sizer)
333
334 panel = MainPanel(self)
335 panel.SetBackgroundColour((211,211,211))
336 self.panel = panel
337 sizer.Add(self.panel, 1, wx.EXPAND)
338 self.panel_two = MyPanel(self)
339 self.panel_two.SetBackgroundColour((211,211,211))
340 sizer.Add(self.panel_two, 1, wx.EXPAND)
341 self.panel_two.Hide()
342 self.panel_three = MyPanelStudent(self)
343 self.panel_three.SetBackgroundColour((211,211,211))
344 sizer.Add(self.panel_three, 1, wx.EXPAND)
345 self.panel_three.Hide()
346 self.panel_four = PanelOdsjek(self)
347 self.panel_four.SetBackgroundColour((211,211,211))
348 sizer.Add(self.panel_four, 1, wx.EXPAND)
349 self.panel_four.Hide()
350 self.panel_fifth = APanel(self)
351 self.panel_fifth.SetBackgroundColour((211,211,211))
352 sizer.Add(self.panel_fifth, 1, wx.EXPAND)
353 self.panel_fifth.Hide()
354 self.SetSize((400, 400))
355 self.Centre()
356
357 self.text_ctrl_usernamefield = wx.TextCtrl(panel, pos=(140, 100))
358 self.text_ctrl_passwordfield = wx.TextCtrl(panel, pos=(140, 150),style=wx.TE_PASSWORD)
359 self.text_ctrl_usernamefield.SetBackgroundColour((229,229,229))
360 self.text_ctrl_passwordfield.SetBackgroundColour((229,229,229))
361
362 my_btn_student = GB.GradientButton(panel, label='Login student', pos=(150, 200))
363 my_btn_student.Bind(wx.EVT_BUTTON, self.on_press_student)
364
365 my_btn_prof = GB.GradientButton(panel, label='Login professor', pos=(142, 250))
366 my_btn_prof.Bind(wx.EVT_BUTTON, self.on_press)
367
368 close_btn = GB.GradientButton(panel, label='Kraj', pos=(320, 320), size=(50,30))
369 close_btn.Bind(wx.EVT_BUTTON, self.close)
370
371
372 username_text = wx.StaticText(panel, -1, label="Username:", pos=(80,105), style = wx.ALIGN_CENTER)
373 password_text = wx.StaticText(panel, -1, label="Password:", pos=(80,155), style = wx.ALIGN_CENTER)
374
375 self.Show()
376
377 def newPanel(self):
378 self.panel_two.Show()
379 #self.panel_three.Hide()
380 self.panel.Hide()
381 self.Layout()
382
383 def newSPanel(self):
384 self.panel_three.Show()
385 #self.panel_two.Hide()
386 self.panel.Hide()
387 self.Layout()
388 def close(self,event):
389 self.Close()
390
391 def on_press(self, event):
392 value = self.text_ctrl_usernamefield.GetValue()
393 second_value = self.text_ctrl_passwordfield.GetValue()
394 self.text_ctrl_usernamefield.Clear()
395 self.text_ctrl_passwordfield.Clear()
396 if not (value and second_value):
397 msg = wx.MessageBox(message="Try again",
398 caption='You did not enter anything',
399 style=wx.OK | wx.ICON_INFORMATION)
400 else:
401 c.execute("SELECT username FROM DatabaseInCabinet WHERE username = ? AND password = ? AND role = ?",(value,second_value,1))
402 if len(c.fetchall())>0:
403 c.execute("UPDATE DatabaseInCabinet SET status = ? WHERE username = ?",("A",value))
404 connector.commit()
405 c.execute("SELECT username,name,titula FROM DatabaseInCabinet WHERE username = ?",(value,))
406 lista = c.fetchall()
407 name = lista[0][1]
408 titula = lista[0][2]
409 self.newPanel()
410 self.panel_two.addToPanel("AKTIVAN (U KABINETU)",name,value,titula)
411 else:
412 msg = wx.MessageBox(message="Try again",
413 caption='Wrong arguments - Username/Password not correct',
414 style=wx.OK | wx.ICON_INFORMATION)
415
416
417 def on_press_student(self, event):
418 value = self.text_ctrl_usernamefield.GetValue()
419 second_value = self.text_ctrl_passwordfield.GetValue()
420 self.text_ctrl_usernamefield.Clear()
421 self.text_ctrl_passwordfield.Clear()
422 if not (value and second_value):
423 msg = wx.MessageBox(message="Try again",
424 caption='You did not enter all information',
425 style=wx.OK | wx.ICON_INFORMATION)
426
427 else:
428 c.execute("SELECT username FROM DatabaseInCabinet WHERE username = ? AND password = ? AND role = ?",(value,second_value,0))
429 if len(c.fetchall())>0:
430 c.execute("UPDATE DatabaseInCabinet SET status = ? WHERE username = ?",("A",value))
431 connector.commit()
432 self.newSPanel()
433 self.panel_three.addToSPanel(value)
434 else:
435 msg = wx.MessageBox(message="Try again",
436 caption='Wrong arguments - Username/Password not correct',
437 style=wx.OK | wx.ICON_INFORMATION)
438
439
440#Main funkcija - u njoj se kreira baza podataka, stvara Frame i otvara se aplikacija
441def main():
442 databaseFunction();
443 app = wx.App()
444 frame = MyApp()
445 app.MainLoop()
446if __name__ == '__main__':
447 main()