-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadsetcontrolGUI.py
More file actions
1723 lines (1519 loc) · 62.5 KB
/
Copy pathheadsetcontrolGUI.py
File metadata and controls
1723 lines (1519 loc) · 62.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import customtkinter as ctk
import subprocess
import json
import os
import threading
import shlex
import sys
import tkinter as tk
if sys.platform.startswith("linux"):
os.environ.setdefault("TK_APPNAME", "headsetcontrol-gui")
# Ustawienia CustomTkinter
ctk.set_appearance_mode("dark") # Domyślny tryb ciemny
ctk.set_default_color_theme("blue") # Niebieski motyw kolorystyczny
# Słownik tłumaczeń
LANGUAGES = {
"pl": {
"title": "HeadsetControl GUI - Nowoczesny Panel Sterowania",
"settings": "Ustawienia",
"actions": "Akcje",
"device": "Urządzenie (vendorid:productid):",
"sidetone": "Poziom słyszalności:",
"equalizer": "Equalizer (Preset 0-3):",
"equalizer_preset": "Preset equalizera:",
"lights": "Oświetlenie:",
"voice_prompts": "Komunikaty głosowe:",
"voice_prompt": "Komunikaty głosowe:",
"mic_mute": "Wyciszenie mikrofonu:",
"battery": "Bateria:",
"language": "Język:",
"theme": "Motyw:",
"apply": "Zastosuj Ustawienia",
"apply_settings": "Zastosuj ustawienia",
"check_battery": "Sprawdź Baterię",
"on": "Włączone",
"off": "Wyłączone",
"dark": "Ciemny",
"light": "Jasny",
"system": "Systemowy",
"status": "Status:",
"result": "Wynik:",
"ready": "Gotowy",
"error": "Błąd",
"success": "Sukces",
"connecting": "Łączenie...",
"device_not_found": "Nie znaleziono urządzenia",
"command_failed": "Komenda nie powiodła się",
"battery_level": "Poziom baterii",
"settings_applied": "Ustawienia zostały zastosowane",
"about": "O programie",
"version": "Wersja 2.0 - Nowoczesny interfejs 2025",
"light_theme": "Jasny",
"dark_theme": "Ciemny",
"device_profile": "Profil słuchawek:",
"custom_profile": "Własne",
"feature_section_title": "Dostępne funkcje",
"include_setting": "Aktywuj zmianę",
"no_change": "Bez zmian",
"notification_sound": "Dźwięk powiadomień:",
"notification_sound_hint": "ID dźwięku (np. 0-9)",
"inactive_time": "Czas bezczynności (minuty):",
"inactive_time_hint": "0 wyłącza automatyczne usypianie",
"chatmix": "ChatMix:",
"chatmix_hint": "0 = więcej gry, 128 = więcej czatu",
"rotate_to_mute": "Obrót = wycisz:",
"parametric_equalizer": "Equalizer parametryczny:",
"parametric_equalizer_hint": "Format: 300,3.5,1.5,peaking;...",
"microphone_mute_led_brightness": "Jasność LED wyciszenia mikrofonu:",
"microphone_volume": "Głośność mikrofonu:",
"volume_limiter": "Limiter głośności:",
"bluetooth_when_powered_on": "Bluetooth po włączeniu:",
"bluetooth_call_volume": "Głośność połączeń Bluetooth:",
"bluetooth_call_volume_hint": "0 = brak, 1 = średnia, 2 = wysoka",
"equalizer_curve": "Krzywa equalizera:",
"battery_not_supported": "Pomiar baterii nieobsługiwany przez ten profil",
"no_changes_selected": "Brak wybranych zmian do zastosowania",
"invalid_value": "Nieprawidłowa wartość dla {feature}: {detail}",
"value_required": "Wprowadź wartość dla {feature}",
"headsetcontrol_missing": "headsetcontrol nie jest zainstalowany lub dostępny w PATH",
"executing_command": "Wykonuję"
},
"en": {
"title": "HeadsetControl GUI - Modern Control Panel",
"settings": "Settings",
"actions": "Actions",
"device": "Device (vendorid:productid):",
"sidetone": "Sidetone:",
"equalizer": "Equalizer (Preset 0-3):",
"equalizer_preset": "Equalizer preset:",
"lights": "Lights:",
"voice_prompts": "Voice Prompts:",
"voice_prompt": "Voice prompt:",
"mic_mute": "Mic mute:",
"battery": "Battery:",
"language": "Language:",
"theme": "Theme:",
"apply": "Apply Settings",
"apply_settings": "Apply Settings",
"check_battery": "Check Battery",
"on": "On",
"off": "Off",
"dark": "Dark",
"light": "Light",
"system": "System",
"status": "Status:",
"result": "Result:",
"ready": "Ready",
"error": "Error",
"success": "Success",
"connecting": "Connecting...",
"device_not_found": "Device not found",
"command_failed": "Command failed",
"battery_level": "Battery Level",
"settings_applied": "Settings have been applied",
"about": "About",
"version": "Version 2.0 - Modern Interface 2025",
"light_theme": "Light",
"dark_theme": "Dark",
"device_profile": "Headset profile:",
"custom_profile": "Custom",
"feature_section_title": "Available features",
"include_setting": "Enable change",
"no_change": "No change",
"notification_sound": "Notification sound:",
"notification_sound_hint": "Sound ID (e.g. 0-9)",
"inactive_time": "Inactive time (minutes):",
"inactive_time_hint": "0 disables auto sleep",
"chatmix": "ChatMix:",
"chatmix_hint": "0 = more game, 128 = more chat",
"rotate_to_mute": "Rotate to mute:",
"parametric_equalizer": "Parametric equalizer:",
"parametric_equalizer_hint": "Format: 300,3.5,1.5,peaking;...",
"microphone_mute_led_brightness": "Mic mute LED brightness:",
"microphone_volume": "Microphone volume:",
"volume_limiter": "Volume limiter:",
"bluetooth_when_powered_on": "Bluetooth when powered on:",
"bluetooth_call_volume": "Bluetooth call volume:",
"bluetooth_call_volume_hint": "0 = none, 1 = medium, 2 = high",
"equalizer_curve": "Equalizer curve:",
"battery_not_supported": "Battery readings are not supported for this profile",
"no_changes_selected": "No changes selected to apply",
"invalid_value": "Invalid value for {feature}: {detail}",
"value_required": "Enter a value for {feature}",
"headsetcontrol_missing": "headsetcontrol is not installed or available in PATH",
"executing_command": "Executing"
}
}
FEATURE_ORDER = [
"sidetone",
"notification_sound",
"lights",
"inactive_time",
"chatmix",
"voice_prompts",
"rotate_to_mute",
"equalizer_preset",
"equalizer",
"parametric_equalizer",
"microphone_mute_led_brightness",
"microphone_volume",
"volume_limiter",
"bluetooth_when_powered_on",
"bluetooth_call_volume"
]
FEATURE_DEFINITIONS = {
"sidetone": {
"label_key": "sidetone",
"type": "slider",
"flag": "-s",
"min": 0,
"max": 128,
"step": 1
},
"notification_sound": {
"label_key": "notification_sound",
"type": "int",
"flag": "-n",
"min": 0,
"max": 99,
"hint_key": "notification_sound_hint"
},
"lights": {
"label_key": "lights",
"type": "toggle",
"flag": "-l"
},
"inactive_time": {
"label_key": "inactive_time",
"type": "slider",
"flag": "-i",
"min": 0,
"max": 90,
"step": 1,
"hint_key": "inactive_time_hint"
},
"chatmix": {
"label_key": "chatmix",
"type": "slider",
"flag": "-m",
"min": 0,
"max": 128,
"step": 1,
"hint_key": "chatmix_hint"
},
"voice_prompts": {
"label_key": "voice_prompts",
"type": "toggle",
"flag": "-v"
},
"rotate_to_mute": {
"label_key": "rotate_to_mute",
"type": "toggle",
"flag": "-r"
},
"equalizer_preset": {
"label_key": "equalizer_preset",
"type": "choice",
"flag": "-p",
"values": ["0", "1", "2", "3"]
},
"equalizer": {
"label_key": "equalizer_curve",
"type": "text",
"flag": "-e",
"multiline": False
},
"parametric_equalizer": {
"label_key": "parametric_equalizer",
"type": "text",
"flag": "--parametric-equalizer",
"multiline": True,
"allow_newlines": True,
"hint_key": "parametric_equalizer_hint"
},
"microphone_mute_led_brightness": {
"label_key": "microphone_mute_led_brightness",
"type": "slider",
"flag": "--microphone-mute-led-brightness",
"min": 0,
"max": 3,
"step": 1
},
"microphone_volume": {
"label_key": "microphone_volume",
"type": "slider",
"flag": "--microphone-volume",
"min": 0,
"max": 128,
"step": 1
},
"volume_limiter": {
"label_key": "volume_limiter",
"type": "toggle",
"flag": "--volume-limiter"
},
"bluetooth_when_powered_on": {
"label_key": "bluetooth_when_powered_on",
"type": "toggle",
"flag": "--bt-when-powered-on"
},
"bluetooth_call_volume": {
"label_key": "bluetooth_call_volume",
"type": "slider",
"flag": "--bt-call-volume",
"min": 0,
"max": 2,
"step": 1,
"hint_key": "bluetooth_call_volume_hint"
}
}
DEVICE_CAPABILITIES = {
"Audeze Maxwell": [
"sidetone",
"battery",
"inactive_time",
"chatmix",
"voice_prompts",
"equalizer_preset",
"volume_limiter"
],
"Corsair Headset Device": [
"sidetone",
"battery",
"notification_sound",
"lights"
],
"HyperX Cloud Alpha Wireless": [
"sidetone",
"battery",
"inactive_time",
"voice_prompts"
],
"HyperX Cloud Flight Wireless": [
"battery"
],
"HyperX Cloud 3": [
"sidetone"
],
"Logitech G430": [
"sidetone"
],
"Logitech G432/G433": [
"sidetone"
],
"Logitech G533": [
"sidetone",
"battery",
"inactive_time"
],
"Logitech G535": [
"sidetone",
"battery",
"inactive_time"
],
"Logitech G930": [
"sidetone",
"battery"
],
"Logitech G633/G635/G733/G933/G935": [
"sidetone",
"battery",
"lights"
],
"Logitech G PRO Series": [
"sidetone",
"battery",
"inactive_time"
],
"Logitech G PRO X 2": [
"sidetone",
"inactive_time"
],
"Logitech Zone Wired/Zone 750": [
"sidetone",
"voice_prompts",
"rotate_to_mute"
],
"SteelSeries Arctis (1/7X/7P) Wireless": [
"sidetone",
"battery",
"inactive_time"
],
"SteelSeries Arctis (7/Pro)": [
"sidetone",
"battery",
"lights",
"inactive_time",
"chatmix"
],
"SteelSeries Arctis 9": [
"sidetone",
"battery",
"inactive_time",
"chatmix"
],
"SteelSeries Arctis Pro Wireless": [
"sidetone",
"battery",
"inactive_time"
],
"ROCCAT Elo 7.1 Air": [
"lights",
"inactive_time"
],
"ROCCAT Elo 7.1 USB": [
"lights"
],
"SteelSeries Arctis Nova 3": [
"sidetone",
"equalizer_preset",
"equalizer",
"microphone_mute_led_brightness",
"microphone_volume"
],
"SteelSeries Arctis Nova (5/5X)": [
"sidetone",
"battery",
"inactive_time",
"chatmix",
"equalizer_preset",
"equalizer",
"parametric_equalizer",
"microphone_mute_led_brightness",
"microphone_volume",
"volume_limiter"
],
"SteelSeries Arctis Nova 7": [
"sidetone",
"battery",
"inactive_time",
"chatmix",
"equalizer_preset",
"equalizer",
"microphone_mute_led_brightness",
"microphone_volume",
"volume_limiter",
"bluetooth_when_powered_on",
"bluetooth_call_volume"
],
"SteelSeries Arctis 7+": [
"sidetone",
"battery",
"inactive_time",
"chatmix",
"equalizer_preset",
"equalizer"
],
"SteelSeries Arctis Nova Pro Wireless": [
"sidetone",
"battery",
"lights",
"inactive_time",
"equalizer_preset",
"equalizer"
],
"HeadsetControl Test device": [
"sidetone",
"battery",
"notification_sound",
"lights",
"inactive_time",
"chatmix",
"voice_prompts",
"rotate_to_mute",
"equalizer_preset",
"equalizer",
"microphone_mute_led_brightness",
"microphone_volume",
"volume_limiter",
"bluetooth_when_powered_on",
"bluetooth_call_volume"
]
}
class ModernHeadsetControlGUI:
def __init__(self):
self.current_language = "pl"
self._initialize_config_path()
self.saved_feature_states = {}
self._loading_feature_states = False
self.load_config()
# Główne okno
self.root = ctk.CTk()
try:
# Ustaw klasę okna aby środowisko graficzne dopasowało ikonę z pliku .desktop
self.root.wm_class("headsetcontrol-gui")
except Exception:
pass
self.root.title(self.get_text("title"))
self.root.geometry("900x800")
self.root.minsize(900, 700)
self.root.resizable(True, True)
# Ikona okna (jeśli dostępna)
self._icon_image = None
self._set_window_icon()
loaded_profile = getattr(self, "_loaded_profile_key", None)
if loaded_profile not in DEVICE_CAPABILITIES:
loaded_profile = None
# Zmienne dla kontrolek
self.device_var = ctk.StringVar()
self.language_var = ctk.StringVar(value=self.current_language)
self.theme_var = ctk.StringVar(value=ctk.get_appearance_mode())
self.device_profile_var = ctk.StringVar()
self.feature_states = {}
self.profile_display_map = {}
self.selected_profile_key = loaded_profile
self.active_features = []
self.battery_supported = True
self.create_widgets()
self.update_language()
def get_text(self, key):
return LANGUAGES[self.current_language].get(key, key)
def load_config(self):
try:
self._loaded_profile_key = None
if os.path.exists(self.config_file):
with open(self.config_file, 'r') as f:
config = json.load(f)
self.current_language = config.get('language', 'pl')
theme = config.get('theme', 'dark')
ctk.set_appearance_mode(theme)
self._loaded_profile_key = config.get('device_profile')
stored_states = config.get('feature_states', {})
if isinstance(stored_states, dict):
self.saved_feature_states = stored_states
else:
legacy_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "headsetcontrol_config.json")
if os.path.exists(legacy_path):
with open(legacy_path, 'r') as f:
config = json.load(f)
self.current_language = config.get('language', 'pl')
theme = config.get('theme', 'dark')
ctk.set_appearance_mode(theme)
self._loaded_profile_key = config.get('device_profile')
stored_states = config.get('feature_states', {})
if isinstance(stored_states, dict):
self.saved_feature_states = stored_states
# przenieś konfigurację do nowej lokalizacji
try:
self.save_config()
except Exception:
pass
except Exception as e:
print(f"Błąd ładowania konfiguracji: {e}")
def _initialize_config_path(self):
if sys.platform.startswith("win"):
base_dir = os.environ.get("APPDATA")
if not base_dir:
base_dir = os.path.join(os.path.expanduser("~"), "AppData", "Roaming")
config_dir = os.path.join(base_dir, "HeadsetControlGUI")
else:
xdg_dir = os.environ.get("XDG_CONFIG_HOME")
if xdg_dir:
config_dir = os.path.join(xdg_dir, "headsetcontrol-gui")
else:
config_dir = os.path.join(os.path.expanduser("~"), ".config", "headsetcontrol-gui")
try:
os.makedirs(config_dir, exist_ok=True)
except Exception:
fallback = os.path.join(os.path.expanduser("~"), ".headsetcontrol-gui")
os.makedirs(fallback, exist_ok=True)
config_dir = fallback
self.config_dir = config_dir
self.config_file = os.path.join(config_dir, "headsetcontrol_config.json")
def save_config(self):
try:
config = {
'language': self.current_language,
'theme': ctk.get_appearance_mode(),
'device_profile': getattr(self, 'selected_profile_key', None),
'feature_states': getattr(self, 'saved_feature_states', {})
}
os.makedirs(self.config_dir, exist_ok=True)
with open(self.config_file, 'w') as f:
json.dump(config, f, indent=2)
except Exception as e:
print(f"Błąd zapisywania konfiguracji: {e}")
def _set_window_icon(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
ico_path = os.path.join(base_dir, "headsetcontrolGUI.ico")
png_path = os.path.join(base_dir, "headsetcontrolGUI.png")
if os.path.exists(ico_path):
try:
self.root.iconbitmap(ico_path)
return
except Exception:
pass
if os.path.exists(png_path):
try:
self._icon_image = tk.PhotoImage(file=png_path)
self.root.iconphoto(False, self._icon_image)
except Exception as e:
print(f"Nie udało się ustawić ikony okna: {e}")
def _textbox_set_state(self, textbox, state):
if textbox is None:
return
try:
textbox.configure(state=state)
except Exception:
internal = getattr(textbox, "_textbox", None)
if internal is not None:
try:
internal.configure(state=state)
except Exception:
pass
def _textbox_get_value(self, textbox):
if textbox is None:
return ""
try:
return textbox.get("1.0", "end").strip()
except Exception:
internal = getattr(textbox, "_textbox", None)
if internal is not None:
try:
return internal.get("1.0", "end").strip()
except Exception:
pass
return ""
def _profile_state_key(self, profile_key=None):
key = profile_key if profile_key else "__custom__"
return key
def _get_saved_feature_state(self, feature_name, profile_key=None):
profile = self._profile_state_key(profile_key if profile_key is not None else self.selected_profile_key)
return self.saved_feature_states.get(profile, {}).get(feature_name)
def _set_saved_feature_state(self, feature_name, value, profile_key=None):
profile = self._profile_state_key(profile_key if profile_key is not None else self.selected_profile_key)
current_profile_states = self.saved_feature_states.setdefault(profile, {})
if value is None:
if feature_name in current_profile_states:
del current_profile_states[feature_name]
if not current_profile_states:
del self.saved_feature_states[profile]
if not self._loading_feature_states:
self.save_config()
return
if current_profile_states.get(feature_name) == value:
return
current_profile_states[feature_name] = value
if not self._loading_feature_states:
self.save_config()
def _persist_feature_state(self, feature_name):
if self._loading_feature_states:
return
state = self.feature_states.get(feature_name)
if not state:
return
config = state.get("config", {})
control_type = config.get("type")
data = None
if control_type == "slider":
data = {
"include": bool(state["include_var"].get()),
"value": int(state["value_var"].get())
}
elif control_type == "int":
data = {
"include": bool(state["include_var"].get()),
"value": state["entry_var"].get()
}
elif control_type == "toggle":
data = {
"raw_value": state.get("raw_value", "none")
}
elif control_type == "choice":
data = {
"raw_value": state.get("raw_value", "__none__")
}
elif control_type == "text":
include = bool(state["include_var"].get())
textbox_widget = state.get("textbox")
if textbox_widget is not None:
value = self._textbox_get_value(textbox_widget)
else:
entry_var = state.get("entry_var")
value = entry_var.get() if entry_var is not None else ""
data = {
"include": include,
"value": value
}
if data is not None:
self._set_saved_feature_state(feature_name, data)
def _apply_saved_feature_state(self, feature_name, state):
saved = self._get_saved_feature_state(feature_name)
if saved is None:
return
config = state.get("config", {})
control_type = config.get("type")
if control_type == "slider":
include = bool(saved.get("include", False))
value = saved.get("value")
if value is not None:
try:
value = int(value)
except (TypeError, ValueError):
value = config.get("min", 0)
state["value_var"].set(value)
state["slider"].set(value)
state["value_label"].configure(text=str(value))
if include:
state["include_switch"].select()
state["slider"].configure(state="normal")
else:
state["include_switch"].deselect()
state["slider"].configure(state="disabled")
elif control_type == "int":
include = bool(saved.get("include", False))
value = saved.get("value", "")
state["entry_var"].set(value)
if include:
state["include_switch"].select()
state["entry"].configure(state="normal")
else:
state["include_switch"].deselect()
state["entry"].configure(state="disabled")
elif control_type == "toggle":
raw_value = saved.get("raw_value", "none")
state["raw_value"] = raw_value
values = self._toggle_display_values()
mapping = {
"none": values[0],
"on": values[1],
"off": values[2]
}
state["display_var"].set(mapping.get(raw_value, values[0]))
elif control_type == "choice":
raw_value = saved.get("raw_value", "__none__")
state["raw_value"] = raw_value
display = self.get_text("no_change") if raw_value == "__none__" else str(raw_value)
state["display_var"].set(display)
elif control_type == "text":
include = bool(saved.get("include", False))
value = saved.get("value", "")
textbox_widget = state.get("textbox")
if textbox_widget is not None:
self._textbox_set_state(textbox_widget, "normal")
try:
textbox_widget.delete("1.0", "end")
if value:
textbox_widget.insert("1.0", value)
finally:
self._textbox_set_state(textbox_widget, "normal" if include else "disabled")
entry_widget = state.get("entry")
if state.get("entry_var") is not None and entry_widget is not None:
state["entry_var"].set(value)
entry_widget.configure(state="normal" if include else "disabled")
if include:
state["include_switch"].select()
else:
state["include_switch"].deselect()
def create_widgets(self):
# Główny kontener z przewijaniem
self.main_scroll_frame = ctk.CTkScrollableFrame(self.root, corner_radius=0)
self.main_scroll_frame.pack(fill="both", expand=True, padx=20, pady=20)
# Ulepszone bindowanie przewijania - bardziej stabilne
self._setup_mousewheel_binding()
# Prostsze bindowanie przewijania dla Linuxa
self.main_scroll_frame.bind("<Enter>", self._bind_to_mousewheel)
self.main_scroll_frame.bind("<Leave>", self._unbind_from_mousewheel)
# Używaj lokalnej zmiennej dla czytelności poniżej
main_frame = self.main_scroll_frame
# Nagłówek z tytułem
header_frame = ctk.CTkFrame(main_frame, height=80, corner_radius=15)
header_frame.pack(fill="x", padx=10, pady=(10, 20))
header_frame.pack_propagate(False)
self.title_label = ctk.CTkLabel(
header_frame,
text=self.get_text("title"),
font=ctk.CTkFont(size=24, weight="bold")
)
self.title_label.pack(pady=25)
# Panel ustawień języka i motywu
settings_frame = ctk.CTkFrame(main_frame, corner_radius=15)
settings_frame.pack(fill="x", padx=10, pady=(0, 20))
settings_grid = ctk.CTkFrame(settings_frame)
settings_grid.pack(fill="x", padx=20, pady=20)
# Język
self.language_label = ctk.CTkLabel(settings_grid, text=self.get_text("language"),
font=ctk.CTkFont(size=14, weight="bold"))
self.language_label.grid(row=0, column=0, padx=(0, 10), pady=10, sticky="w")
self.language_combo = ctk.CTkComboBox(
settings_grid,
values=["pl", "en"],
variable=self.language_var,
command=self.change_language,
width=120
)
self.language_combo.grid(row=0, column=1, padx=10, pady=10, sticky="w")
# Motyw
self.theme_label = ctk.CTkLabel(settings_grid, text=self.get_text("theme"),
font=ctk.CTkFont(size=14, weight="bold"))
self.theme_label.grid(row=0, column=2, padx=(20, 10), pady=10, sticky="w")
self.theme_combo = ctk.CTkComboBox(
settings_grid,
values=["dark", "light", "system"],
variable=self.theme_var,
command=self.change_theme,
width=120
)
self.theme_combo.grid(row=0, column=3, padx=10, pady=10, sticky="w")
# Główny panel kontroli
control_frame = ctk.CTkFrame(main_frame, corner_radius=15)
control_frame.pack(fill="both", expand=True, padx=10, pady=(0, 20))
# Sekcja urządzenia
device_section = ctk.CTkFrame(control_frame, corner_radius=10)
device_section.pack(fill="x", padx=20, pady=20)
self.device_label = ctk.CTkLabel(device_section, text=self.get_text("device"),
font=ctk.CTkFont(size=14, weight="bold"))
self.device_label.pack(anchor="w", padx=20, pady=(20, 5))
self.device_entry = ctk.CTkEntry(
device_section,
textvariable=self.device_var,
placeholder_text="1038:12ad (opcjonalne)",
height=35,
font=ctk.CTkFont(size=12)
)
self.device_entry.pack(fill="x", padx=20, pady=(0, 20))
# Sekcja profilu urządzenia
profile_frame = ctk.CTkFrame(device_section)
profile_frame.pack(fill="x", padx=20, pady=(0, 20))
self.device_profile_label = ctk.CTkLabel(
profile_frame,
text=self.get_text("device_profile"),
font=ctk.CTkFont(size=14, weight="bold")
)
self.device_profile_label.grid(row=0, column=0, padx=(0, 10), pady=10, sticky="w")
self.device_profile_combo = ctk.CTkComboBox(
profile_frame,
values=[],
variable=self.device_profile_var,
command=self.on_device_profile_change,
width=320
)
self.device_profile_combo.grid(row=0, column=1, padx=10, pady=10, sticky="w")
profile_frame.grid_columnconfigure(1, weight=1)
# Sekcja funkcji dynamicznych
features_section = ctk.CTkFrame(control_frame, corner_radius=10)
features_section.pack(fill="both", expand=True, padx=20, pady=(0, 20))
self.features_section_title = ctk.CTkLabel(
features_section,
text=self.get_text("feature_section_title"),
font=ctk.CTkFont(size=16, weight="bold")
)
self.features_section_title.pack(anchor="w", padx=20, pady=(20, 10))
self.feature_container = ctk.CTkFrame(features_section)
self.feature_container.pack(fill="both", expand=True, padx=10, pady=(0, 20))
# Panel przycisków
buttons_frame = ctk.CTkFrame(control_frame, corner_radius=10)
buttons_frame.pack(fill="x", padx=20, pady=(0, 20))
buttons_container = ctk.CTkFrame(buttons_frame)
buttons_container.pack(pady=20)
self.apply_button = ctk.CTkButton(
buttons_container,
text=self.get_text("apply"),
command=self.apply_settings,
height=45,
width=200,
font=ctk.CTkFont(size=14, weight="bold"),
corner_radius=10
)
self.apply_button.pack(side="left", padx=10)
self.battery_button = ctk.CTkButton(
buttons_container,
text=self.get_text("check_battery"),
command=self.check_battery,
height=45,
width=200,
font=ctk.CTkFont(size=14, weight="bold"),
corner_radius=10,
fg_color=("gray70", "gray30"),
hover_color=("gray60", "gray40")
)
self.battery_button.pack(side="left", padx=10)
# Panel statusu
status_frame = ctk.CTkFrame(main_frame, height=60, corner_radius=15)
status_frame.pack(fill="x", padx=10, pady=(0, 10))
status_frame.pack_propagate(False)
self.status_label = ctk.CTkLabel(
status_frame,
text=f"{self.get_text('status')} {self.get_text('ready')}",
font=ctk.CTkFont(size=12)
)
self.status_label.pack(pady=20)
# Progress bar (ukryty domyślnie)
self.progress_bar = ctk.CTkProgressBar(status_frame, width=400)
self.progress_bar.pack(pady=10)
self.progress_bar.pack_forget()
# Widżet wyników
output_frame = ctk.CTkFrame(main_frame, corner_radius=15)
output_frame.pack(fill="both", expand=True, padx=10, pady=(0, 10))
self.output_label = ctk.CTkLabel(output_frame, text=self.get_text("result"), font=ctk.CTkFont(size=14, weight="bold"))
self.output_label.pack(anchor="w", padx=20, pady=(20, 5))
self.output_text = ctk.CTkTextbox(output_frame, height=140, font=ctk.CTkFont(family="Consolas", size=10), wrap="word")
self.output_text.pack(fill="both", expand=True, padx=20, pady=(0, 20))
self.refresh_device_profile_options()
self.on_device_profile_change(self.device_profile_var.get())
def refresh_device_profile_options(self):
if not hasattr(self, "device_profile_combo"):
return
custom_display = self.get_text("custom_profile")
device_names = list(DEVICE_CAPABILITIES.keys())
values = [custom_display] + device_names
current_display = self._profile_display_from_key(self.selected_profile_key)
if current_display not in values:
current_display = custom_display
self.selected_profile_key = None
self.profile_display_map = {custom_display: None}
for name in device_names:
self.profile_display_map[name] = name
self.device_profile_combo.configure(values=values)
self.device_profile_var.set(current_display)
def _profile_display_from_key(self, profile_key):
if profile_key and profile_key in DEVICE_CAPABILITIES:
return profile_key
return self.get_text("custom_profile")
def on_device_profile_change(self, selection):
if not hasattr(self, "device_profile_combo"):
return
previous_profile = getattr(self, "selected_profile_key", None)
if not selection:
selection = self.device_profile_var.get()
profile_key = self.profile_display_map.get(selection) if selection in self.profile_display_map else None
if profile_key not in DEVICE_CAPABILITIES:
profile_key = None
self.selected_profile_key = profile_key
self.device_profile_var.set(self._profile_display_from_key(profile_key))
self.build_feature_controls()
if profile_key != previous_profile:
self.save_config()
def build_feature_controls(self):
if not hasattr(self, "feature_container"):
return
for child in self.feature_container.winfo_children():
child.destroy()
if self.selected_profile_key is None:
raw_features = ["battery"] + [feature for feature in FEATURE_ORDER if feature in FEATURE_DEFINITIONS]
else:
raw_features = DEVICE_CAPABILITIES.get(self.selected_profile_key, [])
features_sorted = self._sort_features(raw_features)
self.active_features = features_sorted
self.battery_supported = "battery" in features_sorted
if hasattr(self, "battery_button"):
state = "normal" if self.battery_supported else "disabled"
self.battery_button.configure(state=state)
self.feature_states = {}
self._loading_feature_states = True
has_controls = False
try:
for feature in features_sorted:
if feature == "battery":
continue