11from PySide6 .QtCore import QThread , Signal
22
3- from utils .logger import logger
3+ from utils .logger import LogLevel , logger
44
55
66class ExampleThread (QThread ):
@@ -13,15 +13,17 @@ def __init__(self, firstInput: str, secondInput: str | None = None):
1313 self .firstInput = firstInput
1414 self .secondInput = secondInput
1515
16- def output (self , text : str , level = " INFO" ):
17- logger .log (level , text )
18- self .outputSignal .emit (text , level )
16+ def output (self , text : str , level : LogLevel = LogLevel . INFO ):
17+ logger .log (level . value , text )
18+ self .outputSignal .emit (text , level . value )
1919
2020 def run (self ):
21- inputs = self .__dict__ .copy ()
22- logger .info (f"Starting example thread with input parameters: { inputs } " )
23- self .output ("..." )
24- with logger .catch ():
21+ try :
22+ inputs = self .__dict__ .copy ()
23+ logger .info (
24+ f"Starting example thread with input parameters: { inputs } "
25+ )
26+ self .output ("..." )
2527 self .output ("Your first input was: " + self .firstInput )
2628 self .output (
2729 "If you entered text in the second input it will be shown here after 3 seconds"
@@ -30,7 +32,12 @@ def run(self):
3032 try :
3133 raise Exception ("This is an example error after 1.5 seconds" )
3234 except Exception as e :
33- self .output (str (e ), " ERROR" )
35+ self .output (str (e ), LogLevel . ERROR )
3436 self .msleep (1500 )
3537 if self .secondInput :
3638 self .output ("Your second input was: " + self .secondInput )
39+ except Exception as error :
40+ self .output (
41+ f"An unexpected error occurred: { f'{ error } ' .split (';' )[0 ][9 :]} " ,
42+ LogLevel .ERROR ,
43+ )
0 commit comments