forked from taburineagle/NeewerLite-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeewerLite-Python.py
3099 lines (2575 loc) · 191 KB
/
NeewerLite-Python.py
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
#############################################################
## NeewerLite-Python
## by Zach Glenwright
#############################################################
## > https://github.com/taburineagle/NeewerLite-Python/ <
#############################################################
## A cross-platform Python script using the bleak and
## PySide2 libraries to control Neewer brand lights via
## Bluetooth on multiple platforms -
## Windows, Linux/Ubuntu, MacOS and RPi
#############################################################
## Based on the NeewerLight project by @keefo (Xu Lian)
## > https://github.com/keefo/NeewerLite <
#############################################################
import os
import sys
import tempfile
import argparse
import platform # used to determine which OS we're using for MAC address/GUID listing
import asyncio
import threading
import time
from datetime import datetime
# IMPORT BLEAK (this is the library that allows the program to communicate with the lights) - THIS IS NECESSARY!
try:
from bleak import BleakScanner, BleakClient
except ModuleNotFoundError as e:
print(" ===== CAN NOT FIND BLEAK LIBRARY =====")
print(" You need the bleak Python package installed to use NeewerLite-Python.")
print(" Bleak is the library that connects the program to Bluetooth devices.")
print(" Please install the Bleak package first before running NeewerLite-Python.")
print()
print(" To install Bleak, run either pip or pip3 from the command line:")
print(" pip install bleak")
print(" pip3 install bleak")
print()
print(" Or visit this website for more information:")
print(" https://pypi.org/project/bleak/")
sys.exit(1) # you can't use the program itself without Bleak, so kill the program if we don't have it
# IMPORT THE WINDOWS LIBRARY (if you don't do this, it will throw an exception on Windows only)
if platform.system() == "Windows": # try to load winrt if we're on Windows
try:
from winrt import _winrt
_winrt.uninit_apartment()
except Exception as e:
pass # if there is an exception to this module loading, you're not on Windows
importError = 0 # whether or not there's an issue loading PySide2 or the GUI file
# IMPORT PYSIDE2 (the GUI libraries)
try:
from PySide2.QtCore import Qt, QItemSelectionModel
from PySide2.QtGui import QLinearGradient, QColor, QKeySequence
from PySide2.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QShortcut, QMessageBox
except Exception as e:
importError = 1 # log that we can't find PySide2
# IMPORT THE GUI ITSELF
try:
from ui_NeewerLightUI import Ui_MainWindow
except Exception as e:
if importError != 1: # if we don't already have a PySide2 issue
importError = 2 # log that we can't find the GUI file - which, if the program is downloaded correctly, shouldn't be an issue
# IMPORT THE HTTP SERVER
try:
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
except Exception as e:
pass # if there are any HTTP errors, don't do anything yet
CCTSlider = -1 # the current slider moved in the CCT window - 1 - Brightness / 2 - Hue / -1 - Both Brightness and Hue
sendValue = [120, 135, 2, 20, 56, 157] # an array to hold the values to be sent to the light - the default is CCT / 5600K / 20%
lastAnimButtonPressed = 1 # which animation button you clicked last - if none, then it defaults to 1 (the police sirens)
lastSelection = [] # the current light selection (this is for snapshot preset entering/leaving buttons)
lastSortingField = -1 # the last field used for sorting purposes
availableLights = [] # the list of Neewer lights currently available to control
# List Subitems (for ^^^^^^):
# [0] - Bleak Scan Object (can use .name / .rssi / .address to get specifics)
# [1] - Bleak Connection (the actual Bluetooth connection to the light itself)
# [2] - Custom Name for Light (string)
# [3] - Last Used Parameters (list)
# [4] - Whether or not to use an Extended CCT Range (boolean)
# [5] - Whether or not to send Brightness and Hue independently for old lights (boolean)
# [6] - Whether or not this light has been manually turned ON/OFF (boolean)
# [7] - The Power and Channel data returned for this light (list)
# Light Preset ***Default*** Settings (for sections below):
# NOTE: The list is 0-based, so the preset itself is +1 from the subitem
# [0] - [CCT mode] - 5600K / 20%
# [1] - [CCT mode] - 3200K / 20%
# [2] - [CCT mode] - 5600K / 0% (lights are on, but set to 0% brightness)
# [3] - [HSI mode] - 0° hue / 100% saturation / 20% intensity (RED)
# [4] - [HSI mode] - 240° hue / 100% saturation / 20% intensity (BLUE)
# [5] - [HSI mode] - 120° hue / 100% saturation / 20% intensity (GREEN)
# [6] - [HSI mode] - 300° hue / 100% saturation / 20% intensity (PURPLE)
# [7] - [HSI mode] - 160° hue / 100% saturation / 20% intensity (CYAN)
# The list of **default** light presets for restoring and checking against
defaultLightPresets = [
[[-1, [5, 20, 56]]],
[[-1, [5, 20, 32]]],
[[-1, [5, 0, 56]]],
[[-1, [4, 20, 0, 100]]],
[[-1, [4, 20, 240, 100]]],
[[-1, [4, 20, 120, 100]]],
[[-1, [4, 20, 300, 100]]],
[[-1, [4, 20, 160, 100]]]
]
# A list of preset mode settings - custom file will overwrite
customLightPresets = [
[[-1, [5, 20, 56]]],
[[-1, [5, 20, 32]]],
[[-1, [5, 0, 56]]],
[[-1, [4, 20, 0, 100]]],
[[-1, [4, 20, 240, 100]]],
[[-1, [4, 20, 120, 100]]],
[[-1, [4, 20, 300, 100]]],
[[-1, [4, 20, 160, 100]]]
]
threadAction = "" # the current action to take from the thread
setLightUUID = "69400002-B5A3-F393-E0A9-E50E24DCCA99" # the UUID to send information to the light
notifyLightUUID = "69400003-B5A3-F393-E0A9-E50E24DCCA99" # the UUID for notify callbacks from the light
receivedData = "" # the data received from the Notify characteristic
# SET FROM THE PREFERENCES FILE ON LAUNCH
findLightsOnStartup = True # whether or not to look for lights when the program starts
autoConnectToLights = True # whether or not to auto-connect to lights after finding them
printDebug = True # show debug messages in the console for all of the program's events
maxNumOfAttempts = 6 # the maximum attempts the program will attempt an action before erroring out
rememberLightsOnExit = False # whether or not to save the currently set light settings (mode/hue/brightness/etc.) when quitting out
rememberPresetsOnExit = True # whether or not to save the custom preset list when quitting out
acceptable_HTTP_IPs = [] # the acceptable IPs for the HTTP server, set on launch by prefs file
customKeys = [] # custom keymappings for keyboard shortcuts, set on launch by the prefs file
whiteListedMACs = [] # whitelisted list of MAC addresses to add to NeewerLite-Python
enableTabsOnLaunch = False # whether or not to enable tabs on startup (even with no lights connected)
lockFile = tempfile.gettempdir() + os.sep + "NeewerLite-Python.lock"
anotherInstance = False # whether or not we're using a new instance (for the Singleton check)
globalPrefsFile = os.path.dirname(os.path.abspath(sys.argv[0])) + os.sep + "NeewerLite-Python.prefs" # the global preferences file for saving/loading
customLightPresetsFile = os.path.dirname(os.path.abspath(sys.argv[0])) + os.sep + "light_prefs" + os.sep + "customLights.prefs"
# FILE LOCKING FOR SINGLE INSTANCE
def singleInstanceLock():
global anotherInstance
try:
lf = os.open(lockFile, os.O_WRONLY | os.O_CREAT | os.O_EXCL) # try to get a file spec to lock the "running" instance
with os.fdopen(lf, 'w') as lockfile:
lockfile.write(str(os.getpid())) # write the PID of the current running process to the temporary lockfile
except IOError: # if we had an error acquiring the file descriptor, the file most likely already exists.
anotherInstance = True
def singleInstanceUnlockandQuit(exitCode):
try:
os.remove(lockFile) # try to delete the lockfile on exit
except FileNotFoundError: # if another process deleted it, then just error out
printDebugString("Lockfile not found in temp directory, so we're going to skip deleting it!")
sys.exit(exitCode) # quit out, with the specified exitCode
def doAnotherInstanceCheck():
if anotherInstance == True: # if we're running a 2nd instance, but we shouldn't be
print("You're already running another instance of NeewerLite-Python.")
print("Please close that copy first before opening a new one.")
print()
print("To force opening a new instance, add --force_instance to the command line.")
sys.exit(1)
try: # try to load the GUI
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setupUi(self) # set up the main UI
self.connectMe() # connect the function handlers to the widgets
if enableTabsOnLaunch == False: # if we're not supposed to enable tabs on launch, then disable them all
self.ColorModeTabWidget.setTabEnabled(0, False) # disable the CCT tab on launch
self.ColorModeTabWidget.setTabEnabled(1, False) # disable the HSI tab on launch
self.ColorModeTabWidget.setTabEnabled(2, False) # disable the SCENE tab on launch
self.ColorModeTabWidget.setTabEnabled(3, False) # disable the LIGHT PREFS tab on launch
self.ColorModeTabWidget.setCurrentIndex(0)
if findLightsOnStartup == True: # if we're set up to find lights on startup, then indicate that
self.statusBar.showMessage("Please wait - searching for Neewer lights...")
else:
self.statusBar.showMessage("Welcome to NeewerLite-Python! Hit the Scan button above to scan for lights.")
if platform.system() == "Darwin": # if we're on MacOS, then change the column text for the 2nd column in the light table
self.lightTable.horizontalHeaderItem(1).setText("Light UUID")
# IF ANY OF THE CUSTOM PRESETS ARE ACTUALLY CUSTOM, THEN MARK THOSE BUTTONS AS CUSTOM
if customLightPresets[0] != defaultLightPresets[0]:
if customLightPresets[0][0][0] == -1: # if the current preset is custom, but a global, mark it that way
self.customPreset_0_Button.markCustom(0)
else: # the current preset is a snapshot preset
self.customPreset_0_Button.markCustom(0, 1)
if customLightPresets[1] != defaultLightPresets[1]:
if customLightPresets[1][0][0] == -1:
self.customPreset_1_Button.markCustom(1)
else:
self.customPreset_1_Button.markCustom(1, 1)
if customLightPresets[2] != defaultLightPresets[2]:
if customLightPresets[2][0][0] == -1:
self.customPreset_2_Button.markCustom(2)
else:
self.customPreset_2_Button.markCustom(2, 1)
if customLightPresets[3] != defaultLightPresets[3]:
if customLightPresets[3][0][0] == -1:
self.customPreset_3_Button.markCustom(3)
else:
self.customPreset_3_Button.markCustom(3, 1)
if customLightPresets[4] != defaultLightPresets[4]:
if customLightPresets[4][0][0] == -1:
self.customPreset_4_Button.markCustom(4)
else:
self.customPreset_4_Button.markCustom(4, 1)
if customLightPresets[5] != defaultLightPresets[5]:
if customLightPresets[5][0][0] == -1:
self.customPreset_5_Button.markCustom(5)
else:
self.customPreset_5_Button.markCustom(5, 1)
if customLightPresets[6] != defaultLightPresets[6]:
if customLightPresets[6][0][0] == -1:
self.customPreset_6_Button.markCustom(6)
else:
self.customPreset_6_Button.markCustom(6, 1)
if customLightPresets[7] != defaultLightPresets[7]:
if customLightPresets[7][0][0] == -1:
self.customPreset_7_Button.markCustom(7)
else:
self.customPreset_7_Button.markCustom(7, 1)
self.show
def connectMe(self):
self.turnOffButton.clicked.connect(self.turnLightOff)
self.turnOnButton.clicked.connect(self.turnLightOn)
self.scanCommandButton.clicked.connect(self.startSelfSearch)
self.tryConnectButton.clicked.connect(self.startConnect)
self.ColorModeTabWidget.currentChanged.connect(self.tabChanged)
self.lightTable.itemSelectionChanged.connect(self.selectionChanged)
# Allow clicking on the headers for sorting purposes
horizHeaders = self.lightTable.horizontalHeader()
horizHeaders.setSectionsClickable(True)
horizHeaders.sectionClicked.connect(self.sortByHeader)
# COMMENTS ARE THE SAME THE ENTIRE WAY DOWN THIS CHAIN
self.customPreset_0_Button.clicked.connect(lambda: self.recallCustomPreset(0)) # when you click a preset
self.customPreset_0_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(0)) # when you right-click a preset
self.customPreset_0_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(0)) # when the mouse enters the widget
self.customPreset_0_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(0, True)) # when the mouse leaves the widget
self.customPreset_1_Button.clicked.connect(lambda: self.recallCustomPreset(1))
self.customPreset_1_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(1))
self.customPreset_1_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(1))
self.customPreset_1_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(1, True))
self.customPreset_2_Button.clicked.connect(lambda: self.recallCustomPreset(2))
self.customPreset_2_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(2))
self.customPreset_2_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(2))
self.customPreset_2_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(2, True))
self.customPreset_3_Button.clicked.connect(lambda: self.recallCustomPreset(3))
self.customPreset_3_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(3))
self.customPreset_3_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(3))
self.customPreset_3_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(3, True))
self.customPreset_4_Button.clicked.connect(lambda: self.recallCustomPreset(4))
self.customPreset_4_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(4))
self.customPreset_4_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(4))
self.customPreset_4_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(4, True))
self.customPreset_5_Button.clicked.connect(lambda: self.recallCustomPreset(5))
self.customPreset_5_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(5))
self.customPreset_5_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(5))
self.customPreset_5_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(5, True))
self.customPreset_6_Button.clicked.connect(lambda: self.recallCustomPreset(6))
self.customPreset_6_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(6))
self.customPreset_6_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(6))
self.customPreset_6_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(6, True))
self.customPreset_7_Button.clicked.connect(lambda: self.recallCustomPreset(7))
self.customPreset_7_Button.rightclicked.connect(lambda: self.saveCustomPresetDialog(7))
self.customPreset_7_Button.enteredWidget.connect(lambda: self.highlightLightsForSnapshotPreset(7))
self.customPreset_7_Button.leftWidget.connect(lambda: self.highlightLightsForSnapshotPreset(7, True))
self.Slider_CCT_Hue.valueChanged.connect(lambda: self.computeValueCCT(2))
self.Slider_CCT_Bright.valueChanged.connect(lambda: self.computeValueCCT(1))
self.Slider_HSI_1_H.valueChanged.connect(self.computeValueHSI)
self.Slider_HSI_2_S.valueChanged.connect(self.computeValueHSI)
self.Slider_HSI_3_L.valueChanged.connect(self.computeValueHSI)
self.Slider_ANM_Brightness.valueChanged.connect(lambda: self.computeValueANM(0))
self.Button_1_police_A.clicked.connect(lambda: self.computeValueANM(1))
self.Button_1_police_B.clicked.connect(lambda: self.computeValueANM(2))
self.Button_1_police_C.clicked.connect(lambda: self.computeValueANM(3))
self.Button_2_party_A.clicked.connect(lambda: self.computeValueANM(4))
self.Button_2_party_B.clicked.connect(lambda: self.computeValueANM(5))
self.Button_2_party_C.clicked.connect(lambda: self.computeValueANM(6))
self.Button_3_lightning_A.clicked.connect(lambda: self.computeValueANM(7))
self.Button_3_lightning_B.clicked.connect(lambda: self.computeValueANM(8))
self.Button_3_lightning_C.clicked.connect(lambda: self.computeValueANM(9))
self.saveLightPrefsButton.clicked.connect(self.checkLightPrefs)
self.resetGlobalPrefsButton.clicked.connect(lambda: self.setupGlobalLightPrefsTab(True))
self.saveGlobalPrefsButton.clicked.connect(self.saveGlobalPrefs)
# SHORTCUT KEYS - MAKE THEM HERE, SET THEIR ASSIGNMENTS BELOW WITH self.setupShortcutKeys()
# IN CASE WE NEED TO CHANGE THEM AFTER CHANGING PREFERENCES
self.SC_turnOffButton = QShortcut(self)
self.SC_turnOnButton = QShortcut(self)
self.SC_scanCommandButton = QShortcut(self)
self.SC_tryConnectButton = QShortcut(self)
self.SC_Tab_CCT = QShortcut(self)
self.SC_Tab_HSI = QShortcut(self)
self.SC_Tab_SCENE = QShortcut(self)
self.SC_Tab_PREFS = QShortcut(self)
# DECREASE/INCREASE BRIGHTNESS REGARDLESS OF WHICH TAB WE'RE ON
self.SC_Dec_Bri_Small = QShortcut(self)
self.SC_Inc_Bri_Small = QShortcut(self)
self.SC_Dec_Bri_Large = QShortcut(self)
self.SC_Inc_Bri_Large = QShortcut(self)
# THE SMALL INCREMENTS *DO* NEED A CUSTOM FUNCTION, BUT ONLY IF WE CHANGE THE
# SHORTCUT ASSIGNMENT TO SOMETHING OTHER THAN THE NORMAL NUMBERS
# THE LARGE INCREMENTS DON'T NEED A CUSTOM FUNCTION
self.SC_Dec_1_Small = QShortcut(self)
self.SC_Inc_1_Small = QShortcut(self)
self.SC_Dec_2_Small = QShortcut(self)
self.SC_Inc_2_Small = QShortcut(self)
self.SC_Dec_3_Small = QShortcut(self)
self.SC_Inc_3_Small = QShortcut(self)
self.SC_Dec_1_Large = QShortcut(self)
self.SC_Inc_1_Large = QShortcut(self)
self.SC_Dec_2_Large = QShortcut(self)
self.SC_Inc_2_Large = QShortcut(self)
self.SC_Dec_3_Large = QShortcut(self)
self.SC_Inc_3_Large = QShortcut(self)
self.setupShortcutKeys() # set up the shortcut keys for the first time
# CONNECT THE KEYS TO THEIR FUNCTIONS
self.SC_turnOffButton.activated.connect(self.turnLightOff)
self.SC_turnOnButton.activated.connect(self.turnLightOn)
self.SC_scanCommandButton.activated.connect(self.startSelfSearch)
self.SC_tryConnectButton.activated.connect(self.startConnect)
self.SC_Tab_CCT.activated.connect(lambda: self.switchToTab(0))
self.SC_Tab_HSI.activated.connect(lambda: self.switchToTab(1))
self.SC_Tab_SCENE.activated.connect(lambda: self.switchToTab(2))
self.SC_Tab_PREFS.activated.connect(lambda: self.switchToTab(3))
# DECREASE/INCREASE BRIGHTNESS REGARDLESS OF WHICH TAB WE'RE ON
self.SC_Dec_Bri_Small.activated.connect(lambda: self.changeSliderValue(0, -1))
self.SC_Inc_Bri_Small.activated.connect(lambda: self.changeSliderValue(0, 1))
self.SC_Dec_Bri_Large.activated.connect(lambda: self.changeSliderValue(0, -5))
self.SC_Inc_Bri_Large.activated.connect(lambda: self.changeSliderValue(0, 5))
# THE SMALL INCREMENTS DO NEED A SPECIAL FUNCTION-
# (see above) - BASICALLY, IF THEY'RE JUST ASSIGNED THE DEFAULT NUMPAD/NUMBER VALUES
# THESE FUNCTIONS DON'T TRIGGER (THE SAME FUNCTIONS ARE HANDLED BY numberShortcuts(n))
# BUT IF THEY ARE CUSTOM, *THEN* THESE TRIGGER INSTEAD, AND THIS FUNCTION ^^^^ JUST DOES
# SCENE SELECTIONS IN SCENE MODE
self.SC_Dec_1_Small.activated.connect(lambda: self.changeSliderValue(1, -1))
self.SC_Inc_1_Small.activated.connect(lambda: self.changeSliderValue(1, 1))
self.SC_Dec_2_Small.activated.connect(lambda: self.changeSliderValue(2, -1))
self.SC_Inc_2_Small.activated.connect(lambda: self.changeSliderValue(2, 1))
self.SC_Dec_3_Small.activated.connect(lambda: self.changeSliderValue(3, -1))
self.SC_Inc_3_Small.activated.connect(lambda: self.changeSliderValue(3, 1))
# THE LARGE INCREMENTS DON'T NEED A CUSTOM FUNCTION
self.SC_Dec_1_Large.activated.connect(lambda: self.changeSliderValue(1, -5))
self.SC_Inc_1_Large.activated.connect(lambda: self.changeSliderValue(1, 5))
self.SC_Dec_2_Large.activated.connect(lambda: self.changeSliderValue(2, -5))
self.SC_Inc_2_Large.activated.connect(lambda: self.changeSliderValue(2, 5))
self.SC_Dec_3_Large.activated.connect(lambda: self.changeSliderValue(3, -5))
self.SC_Inc_3_Large.activated.connect(lambda: self.changeSliderValue(3, 5))
# THE NUMPAD SHORTCUTS ARE SET UP REGARDLESS OF WHAT THE CUSTOM INC/DEC SHORTCUTS ARE
self.SC_Num1 = QShortcut(QKeySequence("1"), self)
self.SC_Num1.activated.connect(lambda: self.numberShortcuts(1))
self.SC_Num2 = QShortcut(QKeySequence("2"), self)
self.SC_Num2.activated.connect(lambda: self.numberShortcuts(2))
self.SC_Num3 = QShortcut(QKeySequence("3"), self)
self.SC_Num3.activated.connect(lambda: self.numberShortcuts(3))
self.SC_Num4 = QShortcut(QKeySequence("4"), self)
self.SC_Num4.activated.connect(lambda: self.numberShortcuts(4))
self.SC_Num5 = QShortcut(QKeySequence("5"), self)
self.SC_Num5.activated.connect(lambda: self.numberShortcuts(5))
self.SC_Num6 = QShortcut(QKeySequence("6"), self)
self.SC_Num6.activated.connect(lambda: self.numberShortcuts(6))
self.SC_Num7 = QShortcut(QKeySequence("7"), self)
self.SC_Num7.activated.connect(lambda: self.numberShortcuts(7))
self.SC_Num8 = QShortcut(QKeySequence("8"), self)
self.SC_Num8.activated.connect(lambda: self.numberShortcuts(8))
self.SC_Num9 = QShortcut(QKeySequence("9"), self)
self.SC_Num9.activated.connect(lambda: self.numberShortcuts(9))
def sortByHeader(self, theHeader):
global availableLights
global lastSortingField
if theHeader < 2: # if we didn't click on the "Linked" or "Status" headers, start processing the sort
sortingList = [] # a copy of the availableLights array
checkForCustomNames = False # whether or not to ask to sort by custom names (if there aren't any custom names, then don't allow)
for a in range(len(availableLights)): # copy the entire availableLights array into a temporary array to process it
if theHeader == 0 and availableLights[a][2] != "": # if the current light has a custom name (and we clicked on Name)
checkForCustomNames = True # then we need to ask what kind of sorting when we sort
sortingList.append([availableLights[a][0], availableLights[a][1], availableLights[a][2], availableLights[a][3], \
availableLights[a][4], availableLights[a][5], availableLights[a][6], availableLights[a][7], \
availableLights[a][0].name, availableLights[a][0].address, availableLights[a][0].rssi])
else: # we clicked on the "Linked" or "Status" headers, which do not allow sorting
sortingField = -1
if theHeader == 0:
sortDlg = QMessageBox(self)
sortDlg.setIcon(QMessageBox.Question)
sortDlg.setWindowTitle("Sort by...")
sortDlg.setText("Which do you want to sort by?")
sortDlg.addButton(" RSSI (Signal Level) ", QMessageBox.ButtonRole.AcceptRole)
sortDlg.addButton(" Type of Light ", QMessageBox.ButtonRole.AcceptRole)
if checkForCustomNames == True: # if we have custom names available, then add that as an option
sortDlg.addButton("Custom Name", QMessageBox.ButtonRole.AcceptRole)
sortDlg.addButton("Cancel", QMessageBox.ButtonRole.RejectRole)
sortDlg.setIcon(QMessageBox.Warning)
clickedButton = sortDlg.exec_()
if clickedButton == 0:
sortingField = 10 # sort by RSSI
elif clickedButton == 1:
sortingField = 8 # sort by type of light
elif clickedButton == 2:
if checkForCustomNames == True: # if the option was available for custom names, this is "custom name"
sortingField = 2
else: # if the option wasn't available, then this is "cancel"
sortingField = -1 # cancel out of sorting - write this!
elif clickedButton == 3: # this option is only available if custom names is accessible - if so, this is "cancel"
sortingField = -1 # cancel out of sorting - write this!
elif theHeader == 1: # sort by MAC Address/GUID
sortingField = 9
if sortingField != -1: # we want to sort
self.lightTable.horizontalHeader().setSortIndicatorShown(True) # show the sorting indicator
if lastSortingField != sortingField: # if we're doing a different kind of sort than the last one
self.lightTable.horizontalHeader().setSortIndicator(theHeader, Qt.SortOrder.AscendingOrder) # force the header to "Ascending" order
if sortingField != 10: # if we're not looking at RSSI
doReverseSort = False # we need an ascending order search
else: # we ARE looking at RSSI
doReverseSort = True # if we're looking at RSSI, then the search order is reversed (as the smaller # is actually the higher value)
else: # if it's the same as before, then take the cue from the last order
if self.lightTable.horizontalHeader().sortIndicatorOrder() == Qt.SortOrder.DescendingOrder:
if sortingField != 10:
doReverseSort = True
else:
doReverseSort = False
elif self.lightTable.horizontalHeader().sortIndicatorOrder() == Qt.SortOrder.AscendingOrder:
if sortingField != 10:
doReverseSort = False
else:
doReverseSort = True
sortedList = sorted(sortingList, key = lambda x: x[sortingField], reverse = doReverseSort) # sort the list
availableLights.clear() # clear the list of available lights
for a in range(len(sortedList)): # rebuild the available lights list from the sorted list
availableLights.append([sortedList[a][0], sortedList[a][1], sortedList[a][2], sortedList[a][3], \
sortedList[a][4], sortedList[a][5], sortedList[a][6], sortedList[a][7]])
self.updateLights(False) # redraw the table with the new light list
lastSortingField = sortingField # keep track of the last field used for sorting, so we know whether or not to switch to ascending
else:
self.lightTable.horizontalHeader().setSortIndicatorShown(False) # hide the sorting indicator
def switchToTab(self, theTab): # SWITCH TO THE REQUESTED TAB **IF IT IS AVAILABLE**
if self.ColorModeTabWidget.isTabEnabled(theTab) == True:
self.ColorModeTabWidget.setCurrentIndex(theTab)
def numberShortcuts(self, theNumber):
# THE KEYS (IF THERE AREN'T CUSTOM ONES SET UP):
# 7 AND 9 ADJUST THE FIRST SLIDER ON A TAB
# 4 AND 6 ADJUST THE SECOND SLIDER ON A TAB
# 1 AND 3 ADJUST THE THIRD SLIDER ON A TAB
# UNLESS WE'RE IN SCENE MODE, THEN THEY JUST SWITCH THE SCENE
if theNumber == 1:
if self.ColorModeTabWidget.currentIndex() == 2: # if we're on the SCENE tab, then the number keys correspond to an animation
self.computeValueANM(1)
else: # if we're not, adjust the slider
if customKeys[16] == "1":
self.changeSliderValue(3, -1) # decrement slider 3
elif theNumber == 2:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(2)
elif theNumber == 3:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(3)
else:
if customKeys[17] == "3":
self.changeSliderValue(3, 1) # increment slider 3
elif theNumber == 4:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(4)
else:
if customKeys[14] == "4":
self.changeSliderValue(2, -1) # decrement slider 2
elif theNumber == 5:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(5)
elif theNumber == 6:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(6)
else:
if customKeys[15] == "6":
self.changeSliderValue(2, 1) # increment slider 2
elif theNumber == 7:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(7)
else:
if customKeys[12] == "7":
self.changeSliderValue(1, -1) # decrement slider 1
elif theNumber == 8:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(8)
elif theNumber == 9:
if self.ColorModeTabWidget.currentIndex() == 2:
self.computeValueANM(9)
else:
if customKeys[13] == "9":
self.changeSliderValue(1, 1) # increment slider 1
def changeSliderValue(self, sliderToChange, changeAmt):
if self.ColorModeTabWidget.currentIndex() == 0: # we have 2 sliders in CCT mode
if sliderToChange == 1:
self.Slider_CCT_Hue.setValue(self.Slider_CCT_Hue.value() + changeAmt)
elif sliderToChange == 2 or sliderToChange == 0:
self.Slider_CCT_Bright.setValue(self.Slider_CCT_Bright.value() + changeAmt)
elif self.ColorModeTabWidget.currentIndex() == 1: # we have 3 sliders in HSI mode
if sliderToChange == 1:
self.Slider_HSI_1_H.setValue(self.Slider_HSI_1_H.value() + changeAmt)
elif sliderToChange == 2:
self.Slider_HSI_2_S.setValue(self.Slider_HSI_2_S.value() + changeAmt)
elif sliderToChange == 3 or sliderToChange == 0:
self.Slider_HSI_3_L.setValue(self.Slider_HSI_3_L.value() + changeAmt)
elif self.ColorModeTabWidget.currentIndex() == 2:
if sliderToChange == 0: # the only "slider" in SCENE mode is the brightness
self.Slider_ANM_Brightness.setValue(self.Slider_ANM_Brightness.value() + changeAmt)
def checkLightTab(self, selectedLight = -1):
if self.ColorModeTabWidget.currentIndex() == 0: # if we're on the CCT tab, do the check
if selectedLight == -1: # if we don't have a light selected
self.setupCCTBounds(56) # restore the bounds to their default of 56(00)K
else:
if availableLights[selectedLight][4] == True: # if we're supposed to be extending the range
if self.Slider_CCT_Hue.maximum() == 56: # if we're set to extend the range, but we're still set to 56(00)K, then change the range
self.setupCCTBounds(85)
else:
if self.Slider_CCT_Hue.maximum() == 85: # if we're set to NOT extend the range, but we're still set to 85(00)K, then reduce the range
self.setupCCTBounds(56)
elif self.ColorModeTabWidget.currentIndex() == 3: # if we're on the Preferences tab instead
if selectedLight != -1: # if there is a specific selected light
self.setupLightPrefsTab(selectedLight) # update the Prefs tab with the information for that selected light
def setupCCTBounds(self, gradientBounds):
self.Slider_CCT_Hue.setMaximum(gradientBounds) # set the max value of the color temperature slider to the new max bounds
gradient = QLinearGradient(0, 0, 532, 31)
# SET GRADIENT OF CCT SLIDER IN CHUNKS OF 5 VALUES BASED ON BOUNDARY
if gradientBounds == 56: # the color temperature boundary is 5600K
gradient.setColorAt(0.0, QColor(255, 187, 120, 255)) # 3200K
gradient.setColorAt(0.25, QColor(255, 204, 153, 255)) # 3800K
gradient.setColorAt(0.50, QColor(255, 217, 182, 255)) # 4400K
gradient.setColorAt(0.75, QColor(255, 228, 206, 255)) # 5000K
gradient.setColorAt(1.0, QColor(255, 238, 227, 255)) # 5600K
else: # the color temperature boundary is 8500K
gradient.setColorAt(0.0, QColor(255, 187, 120, 255)) # 3200K
gradient.setColorAt(0.25, QColor(255, 219, 186, 255)) # 4500K
gradient.setColorAt(0.50, QColor(255, 240, 233, 255)) # 5800K
gradient.setColorAt(0.75, QColor(243, 242, 255, 255)) # 7100K
gradient.setColorAt(1.0, QColor(220, 229, 255, 255)) # 8500K
self.CCT_Temp_Gradient_BG.scene().setBackgroundBrush(gradient) # change the gradient to fit the new boundary
def setupLightPrefsTab(self, selectedLight):
self.customNameTF.setText(availableLights[selectedLight][2]) # set the "custom name" field to the custom name of this light
# IF THE OPTION TO ALLOW WIDER COLOR TEMPERATURES IS ENABLED, THEN ENABLE THAT CHECKBOX
if availableLights[selectedLight][4] == True:
self.widerRangeCheck.setChecked(True)
else:
self.widerRangeCheck.setChecked(False)
# IF THE OPTION TO SEND ONLY CCT MODE IS ENABLED, THEN ENABLE THAT CHECKBOX
if availableLights[selectedLight][5] == True:
self.onlyCCTModeCheck.setChecked(True)
else:
self.onlyCCTModeCheck.setChecked(False)
def setupGlobalLightPrefsTab(self, setDefault=False):
if setDefault == False:
self.findLightsOnStartup_check.setChecked(findLightsOnStartup)
self.autoConnectToLights_check.setChecked(autoConnectToLights)
self.printDebug_check.setChecked(printDebug)
self.rememberLightsOnExit_check.setChecked(rememberLightsOnExit)
self.rememberPresetsOnExit_check.setChecked(rememberPresetsOnExit)
self.maxNumOfAttempts_field.setText(str(maxNumOfAttempts))
self.acceptable_HTTP_IPs_field.setText("\n".join(acceptable_HTTP_IPs))
self.whiteListedMACs_field.setText("\n".join(whiteListedMACs))
self.SC_turnOffButton_field.setKeySequence(customKeys[0])
self.SC_turnOnButton_field.setKeySequence(customKeys[1])
self.SC_scanCommandButton_field.setKeySequence(customKeys[2])
self.SC_tryConnectButton_field.setKeySequence(customKeys[3])
self.SC_Tab_CCT_field.setKeySequence(customKeys[4])
self.SC_Tab_HSI_field.setKeySequence(customKeys[5])
self.SC_Tab_SCENE_field.setKeySequence(customKeys[6])
self.SC_Tab_PREFS_field.setKeySequence(customKeys[7])
self.SC_Dec_Bri_Small_field.setKeySequence(customKeys[8])
self.SC_Inc_Bri_Small_field.setKeySequence(customKeys[9])
self.SC_Dec_Bri_Large_field.setKeySequence(customKeys[10])
self.SC_Inc_Bri_Large_field.setKeySequence(customKeys[11])
self.SC_Dec_1_Small_field.setKeySequence(customKeys[12])
self.SC_Inc_1_Small_field.setKeySequence(customKeys[13])
self.SC_Dec_2_Small_field.setKeySequence(customKeys[14])
self.SC_Inc_2_Small_field.setKeySequence(customKeys[15])
self.SC_Dec_3_Small_field.setKeySequence(customKeys[16])
self.SC_Inc_3_Small_field.setKeySequence(customKeys[17])
self.SC_Dec_1_Large_field.setKeySequence(customKeys[18])
self.SC_Inc_1_Large_field.setKeySequence(customKeys[19])
self.SC_Dec_2_Large_field.setKeySequence(customKeys[20])
self.SC_Inc_2_Large_field.setKeySequence(customKeys[21])
self.SC_Dec_3_Large_field.setKeySequence(customKeys[22])
self.SC_Inc_3_Large_field.setKeySequence(customKeys[23])
else: # if you clicked the RESET button, reset all preference values to their defaults
self.findLightsOnStartup_check.setChecked(True)
self.autoConnectToLights_check.setChecked(True)
self.printDebug_check.setChecked(True)
self.rememberLightsOnExit_check.setChecked(False)
self.rememberPresetsOnExit_check.setChecked(True)
self.maxNumOfAttempts_field.setText("6")
self.acceptable_HTTP_IPs_field.setText("\n".join(["127.0.0.1", "192.168", "10.0.0"]))
self.whiteListedMACs_field.setText("")
self.SC_turnOffButton_field.setKeySequence("Ctrl+PgDown")
self.SC_turnOnButton_field.setKeySequence("Ctrl+PgUp")
self.SC_scanCommandButton_field.setKeySequence("Ctrl+Shift+S")
self.SC_tryConnectButton_field.setKeySequence("Ctrl+Shift+C")
self.SC_Tab_CCT_field.setKeySequence("Alt+1")
self.SC_Tab_HSI_field.setKeySequence("Alt+2")
self.SC_Tab_SCENE_field.setKeySequence("Alt+3")
self.SC_Tab_PREFS_field.setKeySequence("Alt+4")
self.SC_Dec_Bri_Small_field.setKeySequence("/")
self.SC_Inc_Bri_Small_field.setKeySequence("*")
self.SC_Dec_Bri_Large_field.setKeySequence("Ctrl+/")
self.SC_Inc_Bri_Large_field.setKeySequence("Ctrl+*")
self.SC_Dec_1_Small_field.setKeySequence("7")
self.SC_Inc_1_Small_field.setKeySequence("9")
self.SC_Dec_2_Small_field.setKeySequence("4")
self.SC_Inc_2_Small_field.setKeySequence("6")
self.SC_Dec_3_Small_field.setKeySequence("1")
self.SC_Inc_3_Small_field.setKeySequence("3")
self.SC_Dec_1_Large_field.setKeySequence("Ctrl+7")
self.SC_Inc_1_Large_field.setKeySequence("Ctrl+9")
self.SC_Dec_2_Large_field.setKeySequence("Ctrl+4")
self.SC_Inc_2_Large_field.setKeySequence("Ctrl+6")
self.SC_Dec_3_Large_field.setKeySequence("Ctrl+1")
self.SC_Inc_3_Large_field.setKeySequence("Ctrl+3")
def saveGlobalPrefs(self):
# change these global values to the new values in Prefs
global customKeys, autoConnectToLights, printDebug, rememberLightsOnExit, rememberPresetsOnExit, maxNumOfAttempts, acceptable_HTTP_IPs, whiteListedMACs
finalPrefs = [] # list of final prefs to merge together at the end
if not self.findLightsOnStartup_check.isChecked(): # this option is usually on, so only add on false
finalPrefs.append("findLightsOnStartup=0")
if not self.autoConnectToLights_check.isChecked(): # this option is usually on, so only add on false
autoConnectToLights = False
finalPrefs.append("autoConnectToLights=0")
else:
autoConnectToLights = True
if not self.printDebug_check.isChecked(): # this option is usually on, so only add on false
printDebug = False
finalPrefs.append("printDebug=0")
else:
printDebug = True
if self.rememberLightsOnExit_check.isChecked(): # this option is usually off, so only add on true
rememberLightsOnExit = True
finalPrefs.append("rememberLightsOnExit=1")
else:
rememberLightsOnExit = False
if not self.rememberPresetsOnExit_check.isChecked(): # this option is usually on, so only add if false
rememberPresetsOnExit = False
finalPrefs.append("rememberPresetsOnExit=0")
else:
rememberPresetsOnExit = True
if self.maxNumOfAttempts_field.text() != "6": # the default for this option is 6 attempts
maxNumOfAttempts = int(self.maxNumOfAttempts_field.text())
finalPrefs.append("maxNumOfAttempts=" + self.maxNumOfAttempts_field.text())
else:
maxNumOfAttempts = 6
# FIGURE OUT IF THE HTTP IP ADDRESSES HAVE CHANGED
returnedList_HTTP_IPs = self.acceptable_HTTP_IPs_field.toPlainText().split("\n")
if returnedList_HTTP_IPs != ["127.0.0.1", "192.168", "10.0.0"]: # if the list of HTTP IPs have changed
acceptable_HTTP_IPs = returnedList_HTTP_IPs # change the global HTTP IPs available
finalPrefs.append("acceptable_HTTP_IPs=" + ";".join(acceptable_HTTP_IPs)) # add the new ones to the preferences
else:
acceptable_HTTP_IPs = ["127.0.0.1", "192.168", "10.0.0"] # if we reset the IPs, then re-reset the parameter
# ADD WHITELISTED LIGHTS TO PREFERENCES IF THEY EXIST
returnedList_whiteListedMACs = self.whiteListedMACs_field.toPlainText().replace(" ", "").split("\n") # remove spaces and split on newlines
if returnedList_whiteListedMACs[0] != "": # if we have any MAC addresses specified
whiteListedMACs = returnedList_whiteListedMACs # then set the list to the addresses specified
finalPrefs.append("whiteListedMACs=" + ";".join(whiteListedMACs)) # add the new addresses to the preferences
else:
whiteListedMACs = [] # or clear the list
# SET THE NEW KEYBOARD SHORTCUTS TO THE VALUES IN PREFERENCES
customKeys[0] = self.SC_turnOffButton_field.keySequence().toString()
customKeys[1] = self.SC_turnOnButton_field.keySequence().toString()
customKeys[2] = self.SC_scanCommandButton_field.keySequence().toString()
customKeys[3] = self.SC_tryConnectButton_field.keySequence().toString()
customKeys[4] = self.SC_Tab_CCT_field.keySequence().toString()
customKeys[5] = self.SC_Tab_HSI_field.keySequence().toString()
customKeys[6] = self.SC_Tab_SCENE_field.keySequence().toString()
customKeys[7] = self.SC_Tab_PREFS_field.keySequence().toString()
customKeys[8] = self.SC_Dec_Bri_Small_field.keySequence().toString()
customKeys[9] = self.SC_Inc_Bri_Small_field.keySequence().toString()
customKeys[10] = self.SC_Dec_Bri_Large_field.keySequence().toString()
customKeys[11] = self.SC_Inc_Bri_Large_field.keySequence().toString()
customKeys[12] = self.SC_Dec_1_Small_field.keySequence().toString()
customKeys[13] = self.SC_Inc_1_Small_field.keySequence().toString()
customKeys[14] = self.SC_Dec_2_Small_field.keySequence().toString()
customKeys[15] = self.SC_Inc_2_Small_field.keySequence().toString()
customKeys[16] = self.SC_Dec_3_Small_field.keySequence().toString()
customKeys[17] = self.SC_Inc_3_Small_field.keySequence().toString()
customKeys[18] = self.SC_Dec_1_Large_field.keySequence().toString()
customKeys[19] = self.SC_Inc_1_Large_field.keySequence().toString()
customKeys[20] = self.SC_Dec_2_Large_field.keySequence().toString()
customKeys[21] = self.SC_Inc_2_Large_field.keySequence().toString()
customKeys[22] = self.SC_Dec_3_Large_field.keySequence().toString()
customKeys[23] = self.SC_Inc_3_Large_field.keySequence().toString()
self.setupShortcutKeys() # change shortcut key assignments to the new values in prefs
if customKeys[0] != "Ctrl+PgDown":
finalPrefs.append("SC_turnOffButton=" + customKeys[0])
if customKeys[1] != "Ctrl+PgUp":
finalPrefs.append("SC_turnOnButton=" + customKeys[1])
if customKeys[2] != "Ctrl+Shift+S":
finalPrefs.append("SC_scanCommandButton=" + customKeys[2])
if customKeys[3] != "Ctrl+Shift+C":
finalPrefs.append("SC_tryConnectButton=" + customKeys[3])
if customKeys[4] != "Alt+1":
finalPrefs.append("SC_Tab_CCT=" + customKeys[4])
if customKeys[5] != "Alt+2":
finalPrefs.append("SC_Tab_HSI=" + customKeys[5])
if customKeys[6] != "Alt+3":
finalPrefs.append("SC_Tab_SCENE=" + customKeys[6])
if customKeys[7] != "Alt+4":
finalPrefs.append("SC_Tab_PREFS=" + customKeys[7])
if customKeys[8] != "/":
finalPrefs.append("SC_Dec_Bri_Small=" + customKeys[8])
if customKeys[9] != "*":
finalPrefs.append("SC_Inc_Bri_Small=" + customKeys[9])
if customKeys[10] != "Ctrl+/":
finalPrefs.append("SC_Dec_Bri_Large=" + customKeys[10])
if customKeys[11] != "Ctrl+*":
finalPrefs.append("SC_Inc_Bri_Large=" + customKeys[11])
if customKeys[12] != "7":
finalPrefs.append("SC_Dec_1_Small=" + customKeys[12])
if customKeys[13] != "9":
finalPrefs.append("SC_Inc_1_Small=" + customKeys[13])
if customKeys[14] != "4":
finalPrefs.append("SC_Dec_2_Small=" + customKeys[14])
if customKeys[15] != "6":
finalPrefs.append("SC_Inc_2_Small=" + customKeys[15])
if customKeys[16] != "1":
finalPrefs.append("SC_Dec_3_Small=" + customKeys[16])
if customKeys[17] != "3":
finalPrefs.append("SC_Inc_3_Small=" + customKeys[17])
if customKeys[18] != "Ctrl+7":
finalPrefs.append("SC_Dec_1_Large=" + customKeys[18])
if customKeys[19] != "Ctrl+9":
finalPrefs.append("SC_Inc_1_Large=" + customKeys[19])
if customKeys[20] != "Ctrl+4":
finalPrefs.append("SC_Dec_2_Large=" + customKeys[20])
if customKeys[21] != "Ctrl+6":
finalPrefs.append("SC_Inc_2_Large=" + customKeys[21])
if customKeys[22] != "Ctrl+1":
finalPrefs.append("SC_Dec_3_Large=" + customKeys[22])
if customKeys[23] != "Ctrl+3":
finalPrefs.append("SC_Inc_3_Large=" + customKeys[23])
# CARRY "HIDDEN" DEBUGGING OPTIONS TO PREFERENCES FILE
if enableTabsOnLaunch == True:
finalPrefs.append("enableTabsOnLaunch=1")
if len(finalPrefs) > 0: # if we actually have preferences to save...
with open(globalPrefsFile, "w") as prefsFileToWrite:
prefsFileToWrite.write(("\n").join(finalPrefs)) # then write them to the prefs file
# PRINT THIS INFORMATION WHETHER DEBUG OUTPUT IS TURNED ON OR NOT
print("New global preferences saved in " + globalPrefsFile + " - here is the list:")
for a in range(len(finalPrefs)):
print(" > " + finalPrefs[a]) # iterate through the list of preferences and show the new value(s) you set
else: # there are no preferences to save, so clean up the file (if it exists)
print("There are no preferences to save (all preferences are currently set to their default values).")
if os.path.exists(globalPrefsFile): # if a previous preferences file exists
print("Since all preferences are set to their defaults, we are deleting the NeewerLite-Python.prefs file.")
os.remove(globalPrefsFile) # ...delete it!
def setupShortcutKeys(self):
self.SC_turnOffButton.setKey(QKeySequence(customKeys[0]))
self.SC_turnOnButton.setKey(QKeySequence(customKeys[1]))
self.SC_scanCommandButton.setKey(QKeySequence(customKeys[2]))
self.SC_tryConnectButton.setKey(QKeySequence(customKeys[3]))
self.SC_Tab_CCT.setKey(QKeySequence(customKeys[4]))
self.SC_Tab_HSI.setKey(QKeySequence(customKeys[5]))
self.SC_Tab_SCENE.setKey(QKeySequence(customKeys[6]))
self.SC_Tab_PREFS.setKey(QKeySequence(customKeys[7]))
self.SC_Dec_Bri_Small.setKey(QKeySequence(customKeys[8]))
self.SC_Inc_Bri_Small.setKey(QKeySequence(customKeys[9]))
self.SC_Dec_Bri_Large.setKey(QKeySequence(customKeys[10]))
self.SC_Inc_Bri_Large.setKey(QKeySequence(customKeys[11]))
# IF THERE ARE CUSTOM KEYS SET UP FOR THE SMALL INCREMENTS, SET THEM HERE (AS THE NUMPAD KEYS WILL BE TAKEN AWAY IN THAT INSTANCE):
if customKeys[12] != "7":
self.SC_Dec_1_Small.setKey(QKeySequence(customKeys[12]))
else: # if we changed back to default, clear the key assignment if there was one before
self.SC_Dec_1_Small.setKey("")
if customKeys[13] != "9":
self.SC_Inc_1_Small.setKey(QKeySequence(customKeys[13]))
else:
self.SC_Inc_1_Small.setKey("")
if customKeys[14] != "4":
self.SC_Dec_2_Small.setKey(QKeySequence(customKeys[14]))
else:
self.SC_Dec_2_Small.setKey("")
if customKeys[15] != "6":
self.SC_Inc_2_Small.setKey(QKeySequence(customKeys[15]))
else:
self.SC_Inc_2_Small.setKey("")
if customKeys[16] != "1":
self.SC_Dec_3_Small.setKey(QKeySequence(customKeys[16]))
else:
self.SC_Dec_3_Small.setKey("")
if customKeys[17] != "3":
self.SC_Inc_3_Small.setKey(QKeySequence(customKeys[17]))
else:
self.SC_Inc_3_Small.setKey("")
self.SC_Dec_1_Large.setKey(QKeySequence(customKeys[18]))
self.SC_Inc_1_Large.setKey(QKeySequence(customKeys[19]))
self.SC_Dec_2_Large.setKey(QKeySequence(customKeys[20]))
self.SC_Inc_2_Large.setKey(QKeySequence(customKeys[21]))
self.SC_Dec_3_Large.setKey(QKeySequence(customKeys[22]))
self.SC_Inc_3_Large.setKey(QKeySequence(customKeys[23]))
# CHECK TO SEE WHETHER OR NOT TO ENABLE/DISABLE THE "Connect" BUTTON OR CHANGE THE PREFS TAB
def selectionChanged(self):
selectedRows = self.selectedLights() # get the list of currently selected lights
if len(selectedRows) > 0: # if we have a selection
self.tryConnectButton.setEnabled(True) # if we have light(s) selected in the table, then enable the "Connect" button
if len(selectedRows) == 1: # we have exactly one light selected
self.ColorModeTabWidget.setTabEnabled(3, True) # enable the "Preferences" tab for this light
# SWITCH THE TURN ON/OFF BUTTONS ON, AND CHANGE TEXT TO SINGLE BUTTON TEXT
self.turnOffButton.setText("Turn Light Off")
self.turnOffButton.setEnabled(True)
self.turnOnButton.setText("Turn Light On")
self.turnOnButton.setEnabled(True)
self.ColorModeTabWidget.setTabEnabled(0, True)
if availableLights[selectedRows[0]][5] == True: # if this light is CCT only, then disable the HSI and ANM tabs
self.ColorModeTabWidget.setTabEnabled(1, False) # disable the HSI mode tab
self.ColorModeTabWidget.setTabEnabled(2, False) # disable the ANM/SCENE tab
else: # we can use HSI and ANM/SCENE modes, so enable those tabs
self.ColorModeTabWidget.setTabEnabled(1, True) # enable the HSI mode tab
self.ColorModeTabWidget.setTabEnabled(2, True) # enable the ANM/SCENE tab
currentlySelectedRow = selectedRows[0] # get the row index of the 1 selected item
self.checkLightTab(currentlySelectedRow) # if we're on CCT, check to see if this light can use extended values + on Prefs, update Prefs
# RECALL LAST SENT SETTING FOR THIS PARTICULAR LIGHT, IF A SETTING EXISTS
if availableLights[currentlySelectedRow][3] != []: # if the last set parameters aren't empty
if availableLights[currentlySelectedRow][6] != False: # if the light is listed as being turned ON
sendValue = availableLights[currentlySelectedRow][3] # make the current "sendValue" the last set parameter so it doesn't re-send it on re-load
if sendValue[1] == 135: # the last parameter was a CCT mode change
self.setUpGUI(colorMode="CCT",
brightness=sendValue[3],
temp=sendValue[4])
elif sendValue[1] == 134: # the last parameter was a HSI mode change
self.setUpGUI(colorMode="HSI",
hue=sendValue[3] + (256 * sendValue[4]),
sat=sendValue[5],
brightness=sendValue[6])
elif sendValue[1] == 136: # the last parameter was a ANM/SCENE mode change
self.setUpGUI(colorMode="ANM",
brightness=sendValue[3],
scene=sendValue[4])
else:
self.ColorModeTabWidget.setCurrentIndex(0) # switch to the CCT tab if the light is off and there ARE prior parameters
else:
self.ColorModeTabWidget.setCurrentIndex(0) # switch to the CCT tab if there are no prior parameters
else: # we have multiple lights selected
# SWITCH THE TURN ON/OFF BUTTONS ON, AND CHANGE TEXT TO MULTIPLE LIGHTS TEXT
self.turnOffButton.setText("Turn Light(s) Off")
self.turnOffButton.setEnabled(True)
self.turnOnButton.setText("Turn Light(s) On")
self.turnOnButton.setEnabled(True)
self.ColorModeTabWidget.setTabEnabled(0, True)
self.ColorModeTabWidget.setTabEnabled(1, True) # enable the "HSI" mode tab
self.ColorModeTabWidget.setTabEnabled(2, True) # enable the "ANM/SCENE" mode tab
self.ColorModeTabWidget.setTabEnabled(3, False) # disable the "Preferences" tab, as we have multiple lights selected
else: # the selection has been cleared or there are no lights to select
currentTab = self.ColorModeTabWidget.currentIndex() # get the currently selected tab (so when we disable the tabs, we stick on the current one)
self.tryConnectButton.setEnabled(False) # if we have no lights selected, disable the Connect button
# SWITCH THE TURN ON/OFF BUTTONS OFF, AND CHANGE TEXT TO GENERIC TEXT
self.turnOffButton.setText("Turn Light(s) Off")
self.turnOffButton.setEnabled(False)
self.turnOnButton.setText("Turn Light(s) On")
self.turnOnButton.setEnabled(False)
self.ColorModeTabWidget.setTabEnabled(0, False) # disable the "CCT" mode tab
self.ColorModeTabWidget.setTabEnabled(1, False) # disable the "HSI" mode tab
self.ColorModeTabWidget.setTabEnabled(2, False) # disable the "ANM/SCENE" mode tab
self.ColorModeTabWidget.setTabEnabled(3, False) # disable the "Preferences" tab, as we have no lights selected
if currentTab != 3:
self.ColorModeTabWidget.setCurrentIndex(currentTab) # disable the tabs, but don't switch the current one shown
else:
self.ColorModeTabWidget.setCurrentIndex(0) # if we're on Prefs, then switch to the CCT tab
self.checkLightTab() # check to see if we're on the CCT tab - if we are, then restore order
def checkLightPrefs(self): # check the new settings and save the custom file
selectedRows = self.selectedLights() # get the list of currently selected lights
if len(selectedRows) == 1: # if we have 1 selected light - which should never be false, as we can't use Prefs with more than 1
availableLights[selectedRows[0]][2] = self.customNameTF.text() # set this light's custom name to the text box