1- import tkinter
21import logging
32
3+ from PyQt6 .QtCore import QTimer
4+ from PyQt6 .QtWidgets import QApplication
5+
46
57class AccountController :
68 def __init__ (self , ctx ):
79 self .ctx = ctx
810
9- def create_account_from_barcode (self , barcode ):
10- self ._create (barcode = barcode )
11-
1211 def go_to_review_from_barcode (self , barcode ):
13- canvas = self .ctx .window .canvas
14- loading = tkinter .Label (
15- canvas ,
16- text = "Looking up student..." ,
17- bg = "#153246" , fg = "white" , font = ("Arial" , 25 ),
18- )
19- loading .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
20- self .ctx .window .update ()
12+ self .ctx .nav .show_status ("Looking up student..." )
13+ QApplication .processEvents ()
2114
2215 student = self .ctx .sheets .lookup_by_barcode (barcode )
23- loading . destroy ()
16+ self . ctx . nav . hide_status ()
2417
2518 if student is None :
26- error = tkinter .Label (
27- canvas ,
28- text = "Student not found. Please enter your details manually." ,
29- bg = "#153246" , fg = "white" , font = ("Arial" , 20 ),
30- )
31- error .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
32- error .after (3000 , error .destroy )
19+ self .ctx .nav .show_status ("Student not found. Please enter your details manually." )
20+ QTimer .singleShot (3000 , self .ctx .nav .hide_status )
3321 return
3422
3523 self .ctx .nav .go_to_create_account_review (
@@ -39,30 +27,16 @@ def go_to_review_from_barcode(self, barcode):
3927 email = student ["email" ],
4028 )
4129
42- def create_account_from_pid (self , pid ):
43- self ._create (pid = pid )
44-
4530 def go_to_review_from_pid (self , pid ):
46- canvas = self .ctx .window .canvas
47- loading = tkinter .Label (
48- canvas ,
49- text = "Looking up student..." ,
50- bg = "#153246" , fg = "white" , font = ("Arial" , 25 ),
51- )
52- loading .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
53- self .ctx .window .update ()
31+ self .ctx .nav .show_status ("Looking up student..." )
32+ QApplication .processEvents ()
5433
5534 student = self .ctx .sheets .lookup_by_pid (pid )
56- loading . destroy ()
35+ self . ctx . nav . hide_status ()
5736
5837 if student is None :
59- error = tkinter .Label (
60- canvas ,
61- text = "Student not found. Please check your PID." ,
62- bg = "#153246" , fg = "white" , font = ("Arial" , 20 ),
63- )
64- error .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
65- error .after (3000 , error .destroy )
38+ self .ctx .nav .show_status ("Student not found. Please check your PID." )
39+ QTimer .singleShot (3000 , self .ctx .nav .hide_status )
6640 return
6741
6842 self .ctx .nav .go_to_create_account_review (
@@ -79,14 +53,8 @@ def create_account_from_review(self, *, first_name, last_name, email, pid):
7953 self ._create (first_name = first_name , last_name = last_name , email = email )
8054
8155 def _create (self , * , barcode = None , pid = None , first_name = None , last_name = None , email = None ):
82- canvas = self .ctx .window .canvas
83- inProgress = tkinter .Label (
84- canvas ,
85- text = "Account creation in progress!" ,
86- bg = "#153246" , fg = "white" , font = ("Arial" , 25 ),
87- )
88- inProgress .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
89- self .ctx .window .update ()
56+ self .ctx .nav .show_status ("Account creation in progress!" )
57+ QApplication .processEvents ()
9058
9159 result = self .ctx .sheets .create_account (
9260 self .ctx .rfid ,
@@ -96,16 +64,11 @@ def _create(self, *, barcode=None, pid=None, first_name=None, last_name=None, em
9664 last_name = last_name ,
9765 email = email ,
9866 )
99- inProgress . destroy ()
67+ self . ctx . nav . hide_status ()
10068
10169 if result is None :
102- error = tkinter .Label (
103- canvas ,
104- text = "ERROR! Could not create account, please try manually." ,
105- bg = "#153246" , fg = "white" , font = ("Arial" , 20 ),
106- )
107- error .place (relx = 0.5 , rely = 0.87 , anchor = "center" )
108- error .after (3000 , lambda : error .destroy ())
70+ self .ctx .nav .show_status ("ERROR! Could not create account, please try manually." )
71+ QTimer .singleShot (3000 , self .ctx .nav .hide_status )
10972 return
11073
11174 logging .info ("Account creation succeeded" )
0 commit comments