11
11
import time
12
12
import threading
13
13
from subprocess import getoutput
14
+ from . import adb_processor
14
15
# initializing a variable containing the path where program executable is stored.
15
16
application_path = ''
16
17
@@ -337,8 +338,107 @@ def closeWindowAndReturnData(self):
337
338
return (self .ipaddr_and_port , self .authcode )
338
339
339
340
341
+ chosen_dev = ''
342
+
343
+ class ChooseADeviceWindow (Toplevel ):
344
+ global getTextJustification , killADBDaemon , requestADBConnection , ipaddr_and_port , authcode , chosen_dev
345
+ def __init__ (self ):
346
+ global chosen_dev
347
+ super ().__init__ ()
348
+ self .wm_attributes ("-topmost" , True )
349
+ # trying to apply some styling as well.
350
+ try :
351
+ set_default_color_theme (f"{ application_path } \\ ..\\ style.json" )
352
+ except Exception as style_json_file_loader_tryone_error :
353
+ print (f"[ERROR]: couldn't read from file 'style.json' in the current directory due to the error:\n { style_json_file_loader_tryone_error } " )
354
+ self .destroy ()
355
+ return # error 299 is for error loading style.json file from current and previous directories.
356
+ def getCurrentAppearanceMode ():
357
+ """
358
+ Gets the current appearance mode to apply to the background of the widgets.
359
+
360
+ Returns a tuple containing the values of text color and background color for widgets.
361
+
362
+ Order goes like that:
363
+
364
+ ```py
365
+ (background_color, text_color)
366
+ ```
367
+ """
368
+ global GetConfig
369
+ try :
370
+ if str (GetConfig ["ProgConfig" ]['appearancemode' ]) == "1" : # 1 is for light mode
371
+ return (None , 'black' )
372
+ elif str (GetConfig ["ProgConfig" ]['appearancemode' ]) == "2" : # 2 is for dark mode
373
+ return ('#333' , "white" )
374
+ else :
375
+ return (None , "black" )
376
+ except Exception as exception_reading_appearance_mode :
377
+ messagebox .showerror ("An ERROR has occured" , f"{ exception_reading_appearance_mode } " )
378
+ return False
379
+ return False
380
+
381
+
382
+ def closeWindowAndReturnChoice ():
383
+ """
384
+ Closes this window and saves the chosen value into the variable `chosen_dev`
385
+ """
386
+ global chosen_dev
387
+ if str (self .devchoosercombobox .get ()) == getCurrentLanguage ().chooser_choose_a_device : # all devices are chosen
388
+ return None
389
+ else :
390
+ _choice = self .devchoosercombobox .get ()
391
+ _choice = _choice .split ("\t " )
392
+ chosen_dev = _choice [0 ]
393
+ print (chosen_dev )
394
+ try :
395
+ self .destroy ()
396
+ except :
397
+ print ("[INFO] window might have been already destroyed" )
398
+ return
399
+
400
+
401
+ self .title (f"{ getCurrentLanguage ().choose_a_device_window_title } " )
402
+ self .appwidth = 605
403
+ self .appheight = 257
404
+ self .spawn_x = (int (self .winfo_screenwidth ()) / 2 ) - (self .appwidth / 2 )
405
+ self .spawn_y = (int (self .winfo_screenheight ()) / 2 ) - (self .appheight / 2 )
406
+ self .geometry (f'{ self .appwidth } x{ self .appheight } +{ int (self .spawn_x )} +{ int (self .spawn_y )} ' ) # spawns in the middle of the screen.
407
+ self .resizable (False , False )
408
+ self .wm_resizable (False , False )
409
+ self .configure (bg = getCurrentAppearanceMode ()[0 ])
410
+ try :
411
+ self .iconbitmap (f"{ application_path } \\ debug.ico" )
412
+ except Exception as errorLoadingIconBitmap :
413
+ print (f"An exception has occured while attempting to load iconbitmap for the 'Connect Phone to PC Window'\n Error details are:\n \n { errorLoadingIconBitmap } " )
414
+ messagebox .showerror ("Error" , f"An exception has occured while attempting to load iconbitmap for 'connectphonetopc' window\n Error details are:\n \n { errorLoadingIconBitmap } " )
415
+ pass
416
+
417
+
418
+
419
+ self .lbl0 = Label (self , text = getCurrentLanguage ().choose_a_usb_debugging_device , font = ("Arial Bold" , 17 ), bg = getCurrentAppearanceMode ()[0 ], fg = getCurrentAppearanceMode ()[1 ], justify = getTextJustification ())
420
+ self .lbl0 .pack (expand = False )
421
+ self .lbl1 = Label (self , text = getCurrentLanguage ().choose_a_device_info , font = ("Arial" , 12 ), bg = getCurrentAppearanceMode ()[0 ], fg = getCurrentAppearanceMode ()[1 ], justify = getTextJustification (), wraplength = 599 )
422
+ self .lbl1 .pack (expand = False )
423
+ self .devchooser_combobox_values = [getCurrentLanguage ().chooser_choose_a_device ]
424
+ _deviceslst :list = adb_processor .listADBDevices ()
425
+ for _dev in _deviceslst :
426
+ self .devchooser_combobox_values .append (_dev )
427
+ self .devchoosercombobox = CTkComboBox (self , width = 450 , values = self .devchooser_combobox_values )
428
+ self .devchoosercombobox .pack (expand = False , pady = 0 , padx = 0 , ipadx = 0 , ipady = 0 , after = self .lbl1 )
429
+ self .continue_btn = CTkButton (self , text = getCurrentLanguage ().continue_connection_window_btn , command = closeWindowAndReturnChoice )
430
+ self .continue_btn .pack (expand = False , pady = 15 , ipadx = 170 , ipady = 5 )
431
+
432
+
433
+ def __str__ (self ):
434
+ return chosen_dev
435
+
436
+
437
+
438
+
340
439
341
440
if __name__ == '__main__' :
342
- # ConnectPhoneToPCViaWiFiWindow().mainloop()
441
+ # ChooseADeviceWindow().mainloop()
442
+ # print(chosen_dev)
343
443
# raise SystemExit(0)
344
444
pass
0 commit comments