File tree Expand file tree Collapse file tree 2 files changed +24
-28
lines changed
Expand file tree Collapse file tree 2 files changed +24
-28
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ class BaseApi(object):
1212
1313 # status code
1414 OK = 0x00
15- ERROR = 0x01
1615 EXIT = 0x02
1716
1817 # transmission payload
@@ -28,16 +27,10 @@ def emit(self, data):
2827 payload = self .Payload (code = self .OK , data = data , exec = None )
2928 )
3029
31- def error (self , e ):
30+ def exit (self , exec_ = None ):
3231 pub .sendMessage (
3332 self .UPDATE_TOPIC ,
34- payload = self .Payload (code = self .ERROR , data = None , exec = e )
35- )
36-
37- def exit (self ):
38- pub .sendMessage (
39- self .UPDATE_TOPIC ,
40- payload = self .Payload (code = self .EXIT , data = None , exec = None )
33+ payload = self .Payload (code = self .EXIT , data = None , exec = exec_ )
4134 )
4235
4336 def run (self ):
@@ -47,8 +40,8 @@ def __call__(self):
4740 try :
4841 self .run ()
4942 except Exception as e :
50- self .error ( e )
51- finally :
43+ self .exit ( exec_ = e )
44+ else :
5245 self .exit ()
5346
5447
@@ -65,6 +58,8 @@ def run(self):
6558 for data in fw_download_handler .download ():
6659 self .emit (data )
6760
68- def error (self , e ):
69- error_message = '{}\n see log: {}' .format (str (e ), DownloadLogFile .log_file_path )
70- super ().error (Exception (error_message ))
61+ def exit (self , exec_ = None ):
62+ if exec_ is not None :
63+ error_message = '{}\n see log: {}' .format (str (exec_ ), DownloadLogFile .log_file_path )
64+ exec_ = Exception (error_message )
65+ super ().exit (exec_ = exec_ )
Original file line number Diff line number Diff line change @@ -263,21 +263,22 @@ def update_progress(self, payload):
263263 self .bar ["value" ] = payload .data
264264 self .log_stringvar .set ('downloading...' )
265265 self .update ()
266- elif payload .code == DownLoadFWApi .ERROR :
267- messagebox .showerror (
268- title = 'Error' ,
269- message = 'Download Firmware Error!\n {}' .format (str (payload .exec )),
270- master = self
271- )
272266 elif payload .code == DownLoadFWApi .EXIT :
273- self .log_stringvar .set ('download process exited.' )
274- self .fw_file_choose_button .config (state = tk .ACTIVE )
275- self .fw_download_button .config (state = tk .ACTIVE )
276- messagebox .showinfo (
277- title = 'Information' ,
278- message = 'Download Firmware Progress Finished!' ,
279- master = self
280- )
267+ if payload .exec :
268+ messagebox .showerror (
269+ title = 'Error' ,
270+ message = 'Download Firmware Error!\n {}' .format (str (payload .exec )),
271+ master = self
272+ )
273+ else :
274+ self .log_stringvar .set ('download process exited.' )
275+ self .fw_file_choose_button .config (state = tk .ACTIVE )
276+ self .fw_download_button .config (state = tk .ACTIVE )
277+ messagebox .showinfo (
278+ title = 'Information' ,
279+ message = 'Download Firmware Progress Finished!' ,
280+ master = self
281+ )
281282 else :
282283 # nothing
283284 pass
You can’t perform that action at this time.
0 commit comments