@@ -147,6 +147,7 @@ def __init__(self):
147147 self .vlm_img : image .Image | None = None
148148 self .vlm_thread_lock = threading .Lock ()
149149 self .vlm_result :str = ''
150+ self .vlm_thread = None
150151 self .page_text = PagedText (self .disp_w , self .disp_h - self .cam .height ())
151152 self .sta = self .Status .IDLE
152153
@@ -250,8 +251,8 @@ def __vlm_thread(self, vlm, img:image.Image, msg: str):
250251
251252 def run_vlm (self , img : image .Image , msg : str ):
252253 self .page_text .clear ()
253- t = threading .Thread (target = self .__vlm_thread , args = [self .vlm , img , msg ], daemon = True )
254- t .start ()
254+ self . vlm_thread = threading .Thread (target = self .__vlm_thread , args = [self .vlm , img , msg ], daemon = True )
255+ self . vlm_thread .start ()
255256 # t.run()
256257
257258 def check_exit (self ):
@@ -289,24 +290,28 @@ def show_ui(self):
289290 exit_img_y = 0
290291 img .draw_image (exit_img_x , exit_img_y , self .exit_img )
291292 self .check_exit ()
292-
293293 # en/zh
294294 size = image .string_size ("ZH" , scale = 2 )
295295 if self .language == 'zh' :
296296 img .draw_string (self .disp_w - size .width (), 0 , "ZH" , image .COLOR_WHITE , scale = 2 )
297297 else :
298298 img .draw_string (self .disp_w - size .width (), 0 , "EN" , image .COLOR_WHITE , scale = 2 )
299-
299+
300300 if self .support_zh :
301- if ts_data [2 ] and self .disp_w - size .width ()* 2 <= ts_data [0 ]<= self .disp_w and 0 <= ts_data [1 ]<= size .height () * 2 :
301+ if ts_data [2 ] and self .disp_w - size .width ()* 4 <= ts_data [0 ]<= self .disp_w and 0 <= ts_data [1 ]<= size .height ()* 4 :
302302 if self .language == 'zh' :
303303 self .language = 'en'
304304 else :
305305 self .language = 'zh'
306+ if self .vlm :
307+ self .vlm .cancel ()
308+ if isinstance (self .vlm_thread , threading .Thread ) and self .vlm_thread .is_alive ():
309+ self .vlm_thread .join ()
310+ self .page_text .clear ()
306311 else :
307312 self .language = 'en'
308- self .disp .show (img )
309313
314+ self .disp .show (img )
310315
311316 def __vlm_on_reply (self , obj , resp ):
312317 print (resp .msg_new )
0 commit comments