4
4
import subprocess
5
5
import time
6
6
7
- #import PySimpleGUI as sg
8
7
import tkinter as tk
9
8
from tkinter import ttk , messagebox
10
9
@@ -142,7 +141,7 @@ def get_numlock_state():
142
141
# Ignore tool not found, just return None
143
142
pass
144
143
145
- def tk_main ():
144
+ def main ():
146
145
devices = find_devs (show = False , verbose = False )
147
146
# print("Found {} devices".format(len(devices)))
148
147
@@ -289,22 +288,8 @@ def update_numlock_state(state_var, refresh_btn=None, toggle_btn=None):
289
288
toggle_btn .config (state = tk .NORMAL )
290
289
state_var .set ("On (Numbers)" if numlock_on else "Off (Arrows)" )
291
290
292
- def main ():
293
- devices = find_devs (show = False , verbose = False )
294
- # print("Found {} devices".format(len(devices)))
295
-
296
- device_checkboxes = []
297
- for dev in devices :
298
- device_info = "{}\n Serial No: {}\n FW Version: {}\n " .format (
299
- dev ['product_string' ],
300
- dev ['serial_number' ],
301
- format_fw_ver (dev ['release_number' ])
302
- )
303
- checkbox = sg .Checkbox (device_info , default = True , key = '-CHECKBOX-{}-' .format (dev ['path' ]), enable_events = True )
304
- device_checkboxes .append ([checkbox ])
305
-
306
-
307
-
291
+ # Keeping until all features are implemented
292
+ def main_sg ():
308
293
# Only in the pyinstaller bundle are the FW update binaries included
309
294
if is_pyinstaller ():
310
295
releases = find_releases ()
@@ -321,82 +306,6 @@ def main():
321
306
else :
322
307
bundled_update = []
323
308
324
-
325
- layout = [
326
- [sg .Text ("Detected Devices" )],
327
- ] + device_checkboxes + [
328
- [sg .HorizontalSeparator ()],
329
-
330
- [sg .Text ("Bootloader" )],
331
- [sg .Button ("Bootloader" , k = '-BOOTLOADER-' )],
332
- [sg .HorizontalSeparator ()],
333
- ] + bundled_update + [
334
- [sg .Text ("Backlight Brightness" )],
335
- # TODO: Get default from device
336
- [sg .Slider ((0 , 255 ), orientation = 'h' , default_value = 120 ,
337
- k = '-BRIGHTNESS-' , enable_events = True )],
338
- #[sg.Button("Enable Breathing", k='-ENABLE-BREATHING-')],
339
- #[sg.Button("Disable Breathing", k='-DISABLE-BREATHING-')],
340
-
341
- [sg .Text ("RGB Color" )],
342
- [
343
- sg .Button ("Red" , k = '-RED-' ),
344
- sg .Button ("Green" , k = '-GREEN-' ),
345
- sg .Button ("Blue" , k = '-BLUE-' ),
346
- sg .Button ("White" , k = '-WHITE-' ),
347
- sg .Button ("Off" , k = '-OFF-' ),
348
- ],
349
-
350
- [sg .Text ("RGB Effect" )],
351
- [sg .Combo (RGB_EFFECTS , k = '-RGB-EFFECT-' , enable_events = True )],
352
- [sg .HorizontalSeparator ()],
353
-
354
- [sg .Text ("OS Numlock Setting" )],
355
- [sg .Text ("State: " ), sg .Text ("" , k = '-NUMLOCK-STATE-' ), sg .Push () ,sg .Button ("Refresh" , k = '-NUMLOCK-REFRESH-' , disabled = True )],
356
- [sg .Button ("Send Numlock Toggle" , k = '-NUMLOCK-TOGGLE-' , disabled = True )],
357
-
358
- [sg .HorizontalSeparator ()],
359
- [
360
- sg .Column ([
361
- [sg .Text ("BIOS Mode" )],
362
- [sg .Button ("Enable" , k = '-BIOS-MODE-ENABLE-' ), sg .Button ("Disable" , k = '-BIOS-MODE-DISABLE-' )],
363
- ]),
364
- sg .VSeperator (),
365
- sg .Column ([
366
- [sg .Text ("Factory Mode" )],
367
- [sg .Button ("Enable" , k = '-FACTORY-MODE-ENABLE-' ), sg .Button ("Disable" , k = '-FACTORY-MODE-DISABLE-' )],
368
- ])
369
- ],
370
-
371
- [sg .HorizontalSeparator ()],
372
- [
373
- sg .Column ([
374
- [sg .Text ("Save/Erase Controls" )],
375
- [sg .Button ("Save" , k = '-SAVE-' ), sg .Button ("Clear EEPROM" , k = '-CLEAR-EEPROM-' )],
376
- [sg .Text (f"Program Version: { PROGRAM_VERSION } " )],
377
- ]),
378
- sg .VSeperator (),
379
- sg .Column ([
380
- [sg .Text ("Registry Controls" )],
381
- [sg .Button ("Enable Selective Suspend" , k = '-ENABLE-SELECTIVESUSPEND-' )],
382
- [sg .Button ("Disable Selective Suspend" , k = '-DISABLE-SELECTIVESUSPEND-' )],
383
- #[sg.Button("Reset Registry", k='-RESET-REGISTRY-')],
384
- ])
385
- ],
386
- ]
387
-
388
- icon_path = None
389
- if os .name == 'nt' :
390
- ICON_NAME = 'logo_cropped_transparent_keyboard_48x48.ico'
391
- icon_path = os .path .join (resource_path (), 'res' , ICON_NAME ) if is_pyinstaller () else os .path .join ('res' , ICON_NAME )
392
- window = sg .Window ("QMK Keyboard Control" , layout , finalize = True , icon = icon_path )
393
-
394
- selected_devices = []
395
-
396
- # Optionally sync brightness between keyboards
397
- # window.start_thread(lambda: backlight_watcher(window, devices), (THREAD_KEY, THREAD_EXITING))
398
- window .start_thread (lambda : periodic_event (window ), (THREAD_KEY , THREAD_EXITING ))
399
-
400
309
while True :
401
310
event , values = window .read ()
402
311
# print('Event', event)
@@ -432,79 +341,12 @@ def main():
432
341
restart_hint ()
433
342
window ['-CHECKBOX-{}-' .format (dev ['path' ])].update (False , disabled = True )
434
343
435
- if event == "-NUMLOCK-TOGGLE-" :
436
- if os .name == 'nt' :
437
- keybd_event (VK_NUMLOCK , 0x3A , 0x1 , 0 )
438
- keybd_event (VK_NUMLOCK , 0x3A , 0x3 , 0 )
439
- else :
440
- out = subprocess .check_output (['numlockx' , 'toggle' ])
441
-
442
- # Run commands on all selected devices
443
- hint_shown = False
444
- for dev in selected_devices :
445
- if event == "-BOOTLOADER-" :
446
- bootloader_jump (dev )
447
- window ['-CHECKBOX-{}-' .format (dev ['path' ])].update (False , disabled = True )
448
- if not hint_shown :
449
- restart_hint ()
450
- hint_shown = True
451
-
452
- if event == "-BIOS-MODE-ENABLE-" :
453
- bios_mode (dev , True )
454
- if event == "-BIOS-MODE-DISABLE-" :
455
- bios_mode (dev , False )
456
-
457
- if event == "-FACTORY-MODE-ENABLE-" :
458
- factory_mode (dev , True )
459
- if event == "-FACTORY-MODE-DISABLE-" :
460
- factory_mode (dev , False )
461
-
462
- if event == '-BRIGHTNESS-' :
463
- set_brightness (dev , int (values ['-BRIGHTNESS-' ]))
464
- set_rgb_brightness (dev , int (values ['-BRIGHTNESS-' ]))
465
-
466
- if event == '-RGB-EFFECT-' :
467
- effect = RGB_EFFECTS .index (values ['-RGB-EFFECT-' ])
468
- set_rgb_u8 (dev , RGB_MATRIX_VALUE_EFFECT , effect )
469
- # TODO: Get effect
470
-
471
- if event == '-RED-' :
472
- set_rgb_color (dev , RED_HUE , 255 )
473
- if event == '-GREEN-' :
474
- set_rgb_color (dev , GREEN_HUE , 255 )
475
- if event == '-BLUE-' :
476
- set_rgb_color (dev , BLUE_HUE , 255 )
477
- if event == '-WHITE-' :
478
- set_rgb_color (dev , None , 0 )
479
- if event == '-OFF-' :
480
- window ['-BRIGHTNESS-' ].Update (0 )
481
- set_rgb_brightness (dev , 0 )
482
-
483
- if event == '-SAVE-' :
484
- save (dev )
485
-
486
- if event == '-CLEAR-EEPROM-' :
487
- eeprom_reset (dev )
488
-
489
- if event == '-RESET-REGISTRY-' :
490
- # TODO: Implement completely deleting the relevant registry entries
491
- pass
492
- if event == '-ENABLE-SELECTIVESUSPEND-' :
493
- selective_suspend_registry (dev ['product_id' ], False , set = True )
494
- if not hint_shown :
495
- replug_hint ()
496
- hint_shown = True
497
-
498
- if event == '-DISABLE-SELECTIVESUSPEND-' :
499
- selective_suspend_registry (dev ['product_id' ], False , set = False )
500
- if not hint_shown :
501
- replug_hint ()
502
- hint_shown = True
503
-
504
- if event == sg .WIN_CLOSED :
505
- break
506
-
507
- window .close ()
344
+ def toggle_numlock ():
345
+ if os .name == 'nt' :
346
+ keybd_event (VK_NUMLOCK , 0x3A , 0x1 , 0 )
347
+ keybd_event (VK_NUMLOCK , 0x3A , 0x3 , 0 )
348
+ else :
349
+ out = subprocess .check_output (['numlockx' , 'toggle' ])
508
350
509
351
510
352
def is_pyinstaller ():
@@ -521,15 +363,7 @@ def resource_path():
521
363
522
364
return base_path
523
365
524
-
525
- THREAD_KEY = '-THREAD-'
526
- THREAD_EXITING = '-THREAD EXITING-'
527
- def periodic_event (window ):
528
- while True :
529
- window .write_event_value ('-PERIODIC-EVENT-' , None )
530
- time .sleep (1 )
531
-
532
-
366
+ # TODO: Possibly use this
533
367
def backlight_watcher (window , devs ):
534
368
prev_brightness = {}
535
369
while True :
0 commit comments