-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathNeewerLite-Python.py
More file actions
5024 lines (4229 loc) · 307 KB
/
NeewerLite-Python.py
File metadata and controls
5024 lines (4229 loc) · 307 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
#!/usr/bin/python3
#############################################################
## NeewerLite-Python ver. [2025-02-01-BETA]
## 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
############################################################
## Originally based on the NeewerLight project by @keefo
## > https://github.com/keefo/NeewerLite <
############################################################
import os
import sys
import time
import math
import tempfile
import argparse
import asyncio
import threading
import platform # used to determine which OS we're using for MAC address/GUID listing
from datetime import datetime
from subprocess import run, PIPE # used to get MacOS Mac address
from importlib import util as ilu # determining which PySide installation is in place
from importlib import metadata as ilm # determining which version of packages are installed
# Display the version of NeewerLite-Python we're using
print("---------------------------------------------------------")
print(" NeewerLite-Python ver. [2025-02-01-BETA]")
print(" by Zach Glenwright")
print(" > https://github.com/taburineagle/NeewerLite-Python <")
print("---------------------------------------------------------")
print("Checking for bleak and PySide packages...")
if (ilu.find_spec("bleak")) != None: # we have Bleak installed
# IMPORT BLEAK (this is the library that allows the program to communicate with the lights) - THIS IS NECESSARY!
try:
from bleak import BleakScanner, BleakClient
print(f'bleak is installed! Version: {ilm.version("bleak")}')
except ModuleNotFoundError as e:
print("Bleak is installed, but we can't import it! This... should not happen!")
sys.exit(1)
else: # bleak is not installed, so we need to do that...
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
PySideGUI = None # which frontend we're using for the GUI (PySide6 or PySide2)
importError = 0 # whether or not there's an issue loading PySide2 or the GUI file
if (ilu.find_spec("PySide6")) != None: # if PySide6 is available, try to import PySide6
try:
from PySide6.QtCore import QItemSelectionModel
from PySide6.QtGui import QKeySequence, QShortcut
from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QMessageBox
from PySide6.QtCore import QRect, Signal, Qt
from PySide6.QtGui import QFont, QGradient, QLinearGradient, QColor
from PySide6.QtWidgets import QFormLayout, QGridLayout, QKeySequenceEdit, QWidget, QPushButton, QTableWidget, \
QTableWidgetItem, QAbstractScrollArea, QAbstractItemView, QTabWidget, QGraphicsScene, QGraphicsView, QFrame, \
QSlider, QLabel, QLineEdit, QCheckBox, QStatusBar, QScrollArea, QTextEdit, QComboBox
print(f'PySide6 is installed (skipping the PySide2 check!) Version: {ilm.version("PySide6")}')
PySideGUI = "PySide6"
except Exception as e:
print("PySide6 is installed, but couldn't be imported - trying PySide2, if available...")
importError = 1 # log that we can't find PySide6
else:
print("PySide6 isn't installed! Trying PySide2, if available...")
importError = 1 # if PySide6 is installed, but there's an issue importing it, then report an error
if importError == 1:
if ilu.find_spec("PySide2") != None: # if PySide6 couldn't be imported (or there was an issue with it), try PySide2
try:
from PySide2.QtCore import QItemSelectionModel
from PySide2.QtGui import QKeySequence
from PySide2.QtWidgets import QApplication, QMainWindow, QShortcut, QMessageBox
from PySide2.QtCore import QRect, Signal, Qt
from PySide2.QtGui import QFont, QLinearGradient, QColor
from PySide2.QtWidgets import QFormLayout, QGridLayout, QKeySequenceEdit, QWidget, QPushButton, QTableWidget, \
QTableWidgetItem, QAbstractScrollArea, QAbstractItemView, QTabWidget, QGraphicsScene, QGraphicsView, QFrame, \
QSlider, QLabel, QLineEdit, QCheckBox, QStatusBar, QScrollArea, QTextEdit, QComboBox
print(f'PySide2 is installed! Version: {ilm.version("PySide2")}')
importError = 0
PySideGUI = "PySide2"
except Exception as e:
print("PySide2 is installed, but couldn't be imported...")
importError = 1 # log that we can't import PySide2
else:
print(" ===== CAN NOT FIND PYSIDE6 or PYSIDE2 LIBRARIES =====")
print(" You don't have the PySide2 or PySide6 Python libraries installed. If you're only running NeewerLite-Python from")
print(" a command-line (from a Raspberry Pi CLI for instance), or using the HTTP server, you don't need this package.")
print(" If you want to launch NeewerLite-Python with the GUI, you need to install either the PySide2 or PySide6 package.")
print()
print(" To install PySide2, run either pip or pip3 from the command line:")
print(" pip install PySide2")
print(" pip3 install PySide2")
print()
print(" To install PySide6, run either pip or pip3 from the command line:")
print(" pip install PySide6")
print(" pip3 install PySide6")
print()
print(" Visit these websites for more information:")
print(" https://pypi.org/project/PySide2/")
print(" https://pypi.org/project/PySide6/")
importError = 1 # log that we had an issue with importing PySide2
print("---------------------------------------------------------")
# IMPORT THE HTTP SERVER
try:
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import urllib.parse # parsing custom light names in the HTTP server
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, 50, 56, 50] # an array to hold the values to be sent to the light
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] - UpdatedBLEInformation object (replaces Bleak object, but retains information) Object (can use .name / .realname / .address / .rssi / .HWMACaddr 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] - The range of color temperatures to use in CCT mode (list, min, max) <- changed in 0.12
# [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)
# [8] - Whether or not this light uses the new Infinity light protocol (int - 0: no, 1: yes, 2: protocol, but not Infinity light)
# 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, [120, 135, 2, 20, 56, 50]]],
[[-1, [120, 135, 2, 20, 32, 50]]],
[[-1, [120, 135, 2, 0, 56, 50]]],
[[-1, [120, 134, 4, 0, 0, 100, 20]]],
[[-1, [120, 134, 4, 240, 0, 100, 20]]],
[[-1, [120, 134, 4, 120, 0, 100, 20]]],
[[-1, [120, 134, 4, 44, 1, 100, 20]]],
[[-1, [120, 134, 4, 160, 0, 100, 20]]]
]
customLightPresets = defaultLightPresets[:] # copy the default presets to the list for the current session's presets
threadAction = "" # the current action to take from the thread
serverBusy = [False, ""] # whether or not the HTTP server is busy
asyncioEventLoop = None # the current asyncio loop
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 + "light_prefs" + 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
if os.path.exists(lockFile): # the lockfile exists, so we have another instance running
anotherInstance = True
else: # if it doesn't, try to create it
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)
# =======================================================
# = GUI CREATION AND FUNCTIONS AHEAD!
# =======================================================
if PySideGUI != None: # create the GUI if the PySide GUI classes are imported
mainFont = QFont()
mainFont.setBold(True)
if PySideGUI == "PySide2":
mainFont.setWeight(75)
else: # if we're using PySide6, the old "font weight" method is deprecated
mainFont.setWeight(QFont.ExtraBold)
def combinePySideValues(theValues):
# ADDED THIS TO FIX PySide2 VERSIONS < 5.15
# AND THE "can not interpret as integer"
# ERROR WHEN COMBINING ALIGNMENT FLAGS
returnValue = int(theValues[0])
for a in range(1, len(theValues)):
returnValue = returnValue + int(theValues[a])
return returnValue
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
# ============ FONTS, GRADIENTS AND OTHER WINDOW SPECIFICS ============
MainWindow.setFixedSize(590, 670) # the main window should be this size at launch, and no bigger
MainWindow.setWindowTitle("NeewerLite-Python [2025-02-01-BETA] by Zach Glenwright")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
# ============ THE TOP-MOST BUTTONS ============
self.turnOffButton = QPushButton(self.centralwidget)
self.turnOffButton.setGeometry(QRect(10, 4, 150, 22))
self.turnOffButton.setText("Turn Light(s) Off")
self.turnOnButton = QPushButton(self.centralwidget)
self.turnOnButton.setGeometry(QRect(165, 4, 150, 22))
self.turnOnButton.setText("Turn Light(s) On")
self.scanCommandButton = QPushButton(self.centralwidget)
self.scanCommandButton.setGeometry(QRect(416, 4, 81, 22))
self.scanCommandButton.setText("Scan")
self.tryConnectButton = QPushButton(self.centralwidget)
self.tryConnectButton.setGeometry(QRect(500, 4, 81, 22))
self.tryConnectButton.setText("Connect")
self.turnOffButton.setEnabled(False)
self.turnOnButton.setEnabled(False)
self.tryConnectButton.setEnabled(False)
# ============ THE LIGHT TABLE ============
self.lightTable = QTableWidget(self.centralwidget)
self.lightTable.setColumnCount(4)
self.lightTable.setColumnWidth(0, 120)
self.lightTable.setColumnWidth(1, 150)
self.lightTable.setColumnWidth(2, 94)
self.lightTable.setColumnWidth(3, 190)
__QT0 = QTableWidgetItem()
__QT0.setText("Light Name")
self.lightTable.setHorizontalHeaderItem(0, __QT0)
__QT1 = QTableWidgetItem()
__QT1.setText("MAC Address")
self.lightTable.setHorizontalHeaderItem(1, __QT1)
__QT2 = QTableWidgetItem()
__QT2.setText("Linked")
self.lightTable.setHorizontalHeaderItem(2, __QT2)
__QT3 = QTableWidgetItem()
__QT3.setText("Status")
self.lightTable.setHorizontalHeaderItem(3, __QT3)
self.lightTable.setGeometry(QRect(10, 32, 571, 261))
self.lightTable.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.lightTable.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.lightTable.setAlternatingRowColors(True)
self.lightTable.setSelectionBehavior(QAbstractItemView.SelectRows)
self.lightTable.verticalHeader().setStretchLastSection(False)
# ============ THE CUSTOM PRESET BUTTONS ============
self.customPresetButtonsCW = QWidget(self.centralwidget)
self.customPresetButtonsCW.setGeometry(QRect(10, 300, 571, 68))
self.customPresetButtonsLay = QGridLayout(self.customPresetButtonsCW)
self.customPresetButtonsLay.setContentsMargins(0, 0, 0, 0) # ensure this widget spans from the left to the right edge of the light table
self.customPreset_0_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>1</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_0_Button, 1, 1)
self.customPreset_1_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>2</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_1_Button, 1, 2)
self.customPreset_2_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>3</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_2_Button, 1, 3)
self.customPreset_3_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>4</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_3_Button, 1, 4)
self.customPreset_4_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>5</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_4_Button, 1, 5)
self.customPreset_5_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>6</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_5_Button, 1, 6)
self.customPreset_6_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>7</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_6_Button, 1, 7)
self.customPreset_7_Button = customPresetButton(self.centralwidget, text="<strong><font size=+2>8</font></strong><br>PRESET<br>GLOBAL")
self.customPresetButtonsLay.addWidget(self.customPreset_7_Button, 1, 8)
# ============ THE MODE TABS ============
self.ColorModeTabWidget = QTabWidget(self.centralwidget)
self.ColorModeTabWidget.setGeometry(QRect(10, 385, 571, 254))
# === >> MAIN TAB WIDGETS << ===
self.CCT = QWidget()
self.HSI = QWidget()
self.ANM = QWidget()
# ============ SINGLE SLIDER WIDGET DEFINITIONS ============
self.colorTempSlider = parameterWidget(title="Color Temperature", gradient="TEMP",
sliderMin=32, sliderMax=72, sliderVal=56, prefix="00K")
self.brightSlider = parameterWidget(title="Brightness", gradient="BRI")
self.GMSlider = parameterWidget(title="GM Compensation", gradient="GM", sliderOffset=-50, sliderVal=50, prefix="")
self.RGBSlider = parameterWidget(title="Hue", gradient="RGB", sliderMin=0, sliderMax=360, sliderVal=180, prefix="º")
self.colorSatSlider = parameterWidget(title="Saturation", gradient="SAT", sliderVal=100)
# change the saturation gradient when the RGB slider changes
self.RGBSlider.valueChanged.connect(self.colorSatSlider.adjustSatGradient)
self.speedSlider = parameterWidget(title="Speed", gradient="SPEED", sliderMin=0, sliderMax=10, sliderVal=5, prefix="")
self.sparksSlider = parameterWidget(title="Sparks", gradient="SPARKS", sliderMin=0, sliderMax=10, sliderVal=5, prefix="")
# ============ DOUBLE SLIDER WIDGET DEFINITIONS ============
self.brightDoubleSlider = doubleSlider(sliderType="BRI")
self.RGBDoubleSlider = doubleSlider(sliderType="RGB")
self.colorTempDoubleSlider = doubleSlider(sliderType="TEMP")
# ============ FX CHOOSER DEFINITIONS ============
self.effectChooser_Title = QLabel(self.ANM, text="Choose an effect:")
self.effectChooser_Title.setGeometry(QRect(8, 6, 120, 20))
self.effectChooser_Title.setFont(mainFont)
self.effectChooser = QComboBox(self.ANM)
self.effectChooser.setGeometry(QRect(125, 6, 430, 22))
# ============ FX CHOOSER DEFINITIONS ============
self.specialOptionsSection = QWidget(self.ANM)
self.specialOptions_Title = QLabel(self.specialOptionsSection, text="Choose a color option:")
self.specialOptions_Title.setFont(mainFont)
self.specialOptions_Title.setGeometry(0, 0, 250, 20)
self.specialOptionsChooser = QComboBox(self.specialOptionsSection)
self.specialOptionsChooser.setGeometry(QRect(0, 20, self.ColorModeTabWidget.width() - 16, 22))
self.specialOptionsSection.hide()
# =============================================================================
# === >> THE LIGHT PREFS TAB << ===
self.lightPrefs = QWidget()
# CUSTOM NAME FIELD FOR THIS LIGHT
self.customName = QCheckBox(self.lightPrefs)
self.customName.setGeometry(QRect(10, 14, 541, 16))
self.customName.setText("Custom Name for this light:")
self.customName.setFont(mainFont)
self.customNameTF = QLineEdit(self.lightPrefs)
self.customNameTF.setGeometry(QRect(10, 34, 541, 20))
self.customNameTF.setMaxLength(80)
# CUSTOM HSI COLOR TEMPERATURE RANGES FOR THIS LIGHT
self.colorTempRange = QCheckBox(self.lightPrefs)
self.colorTempRange.setGeometry(QRect(10, 82, 541, 16))
self.colorTempRange.setText("Use Custom Color Temperature Range for CCT mode:")
self.colorTempRange.setFont(mainFont)
self.colorTempRange_Min_TF = QLineEdit(self.lightPrefs)
self.colorTempRange_Min_TF.setGeometry(QRect(10, 102, 120, 20))
self.colorTempRange_Min_TF.setMaxLength(80)
self.colorTempRange_Max_TF = QLineEdit(self.lightPrefs)
self.colorTempRange_Max_TF.setGeometry(QRect(160, 102, 120, 20))
self.colorTempRange_Max_TF.setMaxLength(80)
self.colorTempRange_Min_Description = QLabel(self.lightPrefs)
self.colorTempRange_Min_Description.setGeometry(QRect(10, 124, 120, 16))
self.colorTempRange_Min_Description.setAlignment(Qt.AlignCenter)
self.colorTempRange_Min_Description.setText("Minimum")
self.colorTempRange_Min_Description.setFont(mainFont)
self.colorTempRange_Max_Description = QLabel(self.lightPrefs)
self.colorTempRange_Max_Description.setGeometry(QRect(160, 124, 120, 16))
self.colorTempRange_Max_Description.setAlignment(Qt.AlignCenter)
self.colorTempRange_Max_Description.setText("Maximum")
self.colorTempRange_Max_Description.setFont(mainFont)
# WHETHER OR NOT TO ONLY ALLOW CCT MODE FOR THIS LIGHT
self.onlyCCTModeCheck = QCheckBox(self.lightPrefs)
self.onlyCCTModeCheck.setGeometry(QRect(10, 160, 401, 31))
self.onlyCCTModeCheck.setText("This light can only use CCT mode\n(for Neewer lights without HSI mode)")
self.onlyCCTModeCheck.setFont(mainFont)
# SAVE IIITTTTTT!
self.saveLightPrefsButton = QPushButton(self.lightPrefs)
self.saveLightPrefsButton.setGeometry(QRect(416, 170, 141, 23))
self.saveLightPrefsButton.setText("Save Preferences")
# === >> THE GLOBAL PREFS TAB << ===
self.globalPrefs = QScrollArea()
self.globalPrefsCW = QWidget()
self.globalPrefsCW.setMaximumWidth(550) # make sure to resize all contents to fit in the horizontal space of the scrollbar widget
self.globalPrefsLay = QFormLayout(self.globalPrefsCW)
self.globalPrefsLay.setLabelAlignment(Qt.AlignLeft)
self.globalPrefs.setWidget(self.globalPrefsCW)
self.globalPrefs.setWidgetResizable(True)
# MAIN PROGRAM PREFERENCES
self.findLightsOnStartup_check = QCheckBox("Scan for Neewer lights on program launch")
self.autoConnectToLights_check = QCheckBox("Automatically try to link to newly found lights")
self.printDebug_check = QCheckBox("Print debug information to the console")
self.rememberLightsOnExit_check = QCheckBox("Remember the last mode parameters set for lights on exit")
self.rememberPresetsOnExit_check = QCheckBox("Save configuration of custom presets on exit")
self.maxNumOfAttempts_field = QLineEdit()
self.maxNumOfAttempts_field.setFixedWidth(35)
self.acceptable_HTTP_IPs_field = QTextEdit()
self.acceptable_HTTP_IPs_field.setFixedHeight(70)
self.whiteListedMACs_field = QTextEdit()
self.whiteListedMACs_field.setFixedHeight(70)
self.resetGlobalPrefsButton = QPushButton("Reset Preferences to Defaults")
self.saveGlobalPrefsButton = QPushButton("Save Global Preferences")
# THE FIRST SECTION OF KEYBOARD MAPPING SECTION
self.windowButtonsCW = QWidget()
self.windowButtonsLay = QGridLayout(self.windowButtonsCW)
self.SC_turnOffButton_field = singleKeySequenceEditCancel("Ctrl+PgDown")
self.windowButtonsLay.addWidget(QLabel("<strong>Window Top</strong><br>Turn Light(s) Off", alignment=Qt.AlignCenter), 1, 1)
self.windowButtonsLay.addWidget(self.SC_turnOffButton_field, 2, 1)
self.SC_turnOnButton_field = singleKeySequenceEditCancel("Ctrl+PgUp")
self.windowButtonsLay.addWidget(QLabel("<strong>Window Top</strong><br>Turn Light(s) On", alignment=Qt.AlignCenter), 1, 2)
self.windowButtonsLay.addWidget(self.SC_turnOnButton_field, 2, 2)
self.SC_scanCommandButton_field = singleKeySequenceEditCancel("Ctrl+Shift+S")
self.windowButtonsLay.addWidget(QLabel("<strong>Window Top</strong><br>Scan/Re-Scan", alignment=Qt.AlignCenter), 1, 3)
self.windowButtonsLay.addWidget(self.SC_scanCommandButton_field, 2, 3)
self.SC_tryConnectButton_field = singleKeySequenceEditCancel("Ctrl+Shift+C")
self.windowButtonsLay.addWidget(QLabel("<strong>Window Top</strong><br>Connect", alignment=Qt.AlignCenter), 1, 4)
self.windowButtonsLay.addWidget(self.SC_tryConnectButton_field, 2, 4)
# SWITCHING BETWEEN TABS KEYBOARD MAPPING SECTION
self.tabSwitchCW = QWidget()
self.tabSwitchLay = QGridLayout(self.tabSwitchCW)
self.SC_Tab_CCT_field = singleKeySequenceEditCancel("Alt+1")
self.tabSwitchLay.addWidget(QLabel("<strong>Switching Tabs</strong><br>To CCT", alignment=Qt.AlignCenter), 1, 1)
self.tabSwitchLay.addWidget(self.SC_Tab_CCT_field, 2, 1)
self.SC_Tab_HSI_field = singleKeySequenceEditCancel("Alt+2")
self.tabSwitchLay.addWidget(QLabel("<strong>Switching Tabs</strong><br>To HSI", alignment=Qt.AlignCenter), 1, 2)
self.tabSwitchLay.addWidget(self.SC_Tab_HSI_field, 2, 2)
self.SC_Tab_SCENE_field = singleKeySequenceEditCancel("Alt+3")
self.tabSwitchLay.addWidget(QLabel("<strong>Switching Tabs</strong><br>To SCENE", alignment=Qt.AlignCenter), 1, 3)
self.tabSwitchLay.addWidget(self.SC_Tab_SCENE_field, 2, 3)
self.SC_Tab_PREFS_field = singleKeySequenceEditCancel("Alt+4")
self.tabSwitchLay.addWidget(QLabel("<strong>Switching Tabs</strong><br>To Light Prefs", alignment=Qt.AlignCenter), 1, 4)
self.tabSwitchLay.addWidget(self.SC_Tab_PREFS_field, 2, 4)
# BRIGHTNESS ADJUSTMENT KEYBOARD MAPPING SECTION
self.brightnessCW = QWidget()
self.brightnessLay = QGridLayout(self.brightnessCW)
self.SC_Dec_Bri_Small_field = singleKeySequenceEditCancel("/")
self.brightnessLay.addWidget(QLabel("<strong>Brightness</strong><br>Small Decrease", alignment=Qt.AlignCenter), 1, 1)
self.brightnessLay.addWidget(self.SC_Dec_Bri_Small_field, 2, 1)
self.SC_Dec_Bri_Large_field = singleKeySequenceEditCancel("Ctrl+/")
self.brightnessLay.addWidget(QLabel("<strong>Brightness</strong><br>Large Decrease", alignment=Qt.AlignCenter), 1, 2)
self.brightnessLay.addWidget(self.SC_Dec_Bri_Large_field, 2, 2)
self.SC_Inc_Bri_Small_field = singleKeySequenceEditCancel("*")
self.brightnessLay.addWidget(QLabel("<strong>Brightness</strong><br>Small Increase", alignment=Qt.AlignCenter), 1, 3)
self.brightnessLay.addWidget(self.SC_Inc_Bri_Small_field, 2, 3)
self.SC_Inc_Bri_Large_field = singleKeySequenceEditCancel("Ctrl+*")
self.brightnessLay.addWidget(QLabel("<strong>Brightness</strong><br>Large Increase", alignment=Qt.AlignCenter), 1, 4)
self.brightnessLay.addWidget(self.SC_Inc_Bri_Large_field, 2, 4)
# SLIDER ADJUSTMENT KEYBOARD MAPPING SECTIONS
self.sliderAdjustmentCW = QWidget()
self.sliderAdjustmentLay = QGridLayout(self.sliderAdjustmentCW)
self.SC_Dec_1_Small_field = singleKeySequenceEditCancel("7")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 1</strong><br>Small Decrease", alignment=Qt.AlignCenter), 1, 1)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_1_Small_field, 2, 1)
self.SC_Dec_1_Large_field = singleKeySequenceEditCancel("Ctrl+7")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 1</strong><br>Large Decrease", alignment=Qt.AlignCenter), 1, 2)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_1_Large_field, 2, 2)
self.SC_Inc_1_Small_field = singleKeySequenceEditCancel("9")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 1</strong><br>Small Increase", alignment=Qt.AlignCenter), 1, 3)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_1_Small_field, 2, 3)
self.SC_Inc_1_Large_field = singleKeySequenceEditCancel("Ctrl+9")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 1</strong><br>Large Increase", alignment=Qt.AlignCenter), 1, 4)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_1_Large_field, 2, 4)
self.SC_Dec_2_Small_field = singleKeySequenceEditCancel("4")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 2</strong><br>Small Decrease", alignment=Qt.AlignCenter), 3, 1)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_2_Small_field, 4, 1)
self.SC_Dec_2_Large_field = singleKeySequenceEditCancel("Ctrl+4")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 2</strong><br>Large Decrease", alignment=Qt.AlignCenter), 3, 2)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_2_Large_field, 4, 2)
self.SC_Inc_2_Small_field = singleKeySequenceEditCancel("6")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 2</strong><br>Small Increase", alignment=Qt.AlignCenter), 3, 3)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_2_Small_field, 4, 3)
self.SC_Inc_2_Large_field = singleKeySequenceEditCancel("Ctrl+6")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 2</strong><br>Large Increase", alignment=Qt.AlignCenter), 3, 4)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_2_Large_field, 4, 4)
self.SC_Dec_3_Small_field = singleKeySequenceEditCancel("1")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 3</strong><br>Small Decrease", alignment=Qt.AlignCenter), 5, 1)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_3_Small_field, 6, 1)
self.SC_Dec_3_Large_field = singleKeySequenceEditCancel("Ctrl+1")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 3</strong><br>Large Decrease", alignment=Qt.AlignCenter), 5, 2)
self.sliderAdjustmentLay.addWidget(self.SC_Dec_3_Large_field, 6, 2)
self.SC_Inc_3_Small_field = singleKeySequenceEditCancel("3")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 3</strong><br>Small Increase", alignment=Qt.AlignCenter), 5, 3)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_3_Small_field, 6, 3)
self.SC_Inc_3_Large_field = singleKeySequenceEditCancel("Ctrl+3")
self.sliderAdjustmentLay.addWidget(QLabel("<strong>Slider 3</strong><br>Large Increase", alignment=Qt.AlignCenter), 5, 4)
self.sliderAdjustmentLay.addWidget(self.SC_Inc_3_Large_field, 6, 4)
# BOTTOM BUTTONS
self.bottomButtonsCW = QWidget()
self.bottomButtonsLay = QGridLayout(self.bottomButtonsCW)
self.bottomButtonsLay.addWidget(self.resetGlobalPrefsButton, 1, 1)
self.bottomButtonsLay.addWidget(self.saveGlobalPrefsButton, 1, 2)
# FINALLY, IT'S TIME TO BUILD THE PREFERENCES PANE ITSELF
self.globalPrefsLay.addRow(QLabel("<strong><u>Main Program Options</strong></u>", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.findLightsOnStartup_check)
self.globalPrefsLay.addRow(self.autoConnectToLights_check)
self.globalPrefsLay.addRow(self.printDebug_check)
self.globalPrefsLay.addRow(self.rememberLightsOnExit_check)
self.globalPrefsLay.addRow(self.rememberPresetsOnExit_check)
self.globalPrefsLay.addRow("Maximum Number of retries:", self.maxNumOfAttempts_field)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Acceptable IPs to use for the HTTP Server:</strong></u><br><em>Each line below is an IP allows access to NeewerLite-Python's HTTP server.<br>Wildcards for IP addresses can be entered by just leaving that section blank.<br><u>For example:</u><br><strong>192.168.*.*</strong> would be entered as just <strong>192.168.</strong><br><strong>10.0.1.*</strong> is <strong>10.0.1.</strong>", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.acceptable_HTTP_IPs_field)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Whitelisted MAC Addresses/GUIDs</u></strong><br><em>Devices with whitelisted MAC Addresses/GUIDs are added to the<br>list of lights even if their name doesn't contain <strong>Neewer</strong> in it.<br><br>This preference is really only useful if you have compatible lights<br>that don't show up properly due to name mismatches.</em>", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.whiteListedMACs_field)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Custom GUI Keyboard Shortcut Mapping - GUI Buttons</strong></u><br><em>To switch a keyboard shortcut, click on the old shortcut and type a new one in.<br>To reset a shortcut to default, click the X button next to it.</em><br><br>These 4 keyboard shortcuts control the buttons on the top of the window.", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.windowButtonsCW)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Custom GUI Keyboard Shortcut Mapping - Switching Mode Tabs</strong></u><br><em>To switch a keyboard shortcut, click on the old shortcut and type a new one in.<br>To reset a shortcut to default, click the X button next to it.</em><br><br>These 4 keyboard shortcuts switch between<br>the CCT, HSI, SCENE and LIGHT PREFS tabs.", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.tabSwitchCW)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Custom GUI Keyboard Shortcut Mapping - Increase/Decrease Brightness</strong></u><br><em>To switch a keyboard shortcut, click on the old shortcut and type a new one in.<br>To reset a shortcut to default, click the X button next to it.</em><br><br>These 4 keyboard shortcuts adjust the brightness of the selected light(s).", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.brightnessCW)
self.globalPrefsLay.addRow(QLabel("<hr><strong><u>Custom GUI Keyboard Shortcut Mapping - Slider Adjustments</strong></u><br><em>To switch a keyboard shortcut, click on the old shortcut and type a new one in.<br>To reset a shortcut to default, click the X button next to it.</em><br><br>These 12 keyboard shortcuts adjust <em>up to 3 sliders</em> on the currently active tab.", alignment=Qt.AlignCenter))
self.globalPrefsLay.addRow(self.sliderAdjustmentCW)
self.globalPrefsLay.addRow(QLabel("<hr>"))
self.globalPrefsLay.addRow(self.bottomButtonsCW)
# === >> ADD THE TABS TO THE TAB WIDGET << ===
self.ColorModeTabWidget.addTab(self.CCT, "CCT Mode")
self.ColorModeTabWidget.addTab(self.HSI, "HSI Mode")
self.ColorModeTabWidget.addTab(self.ANM, "Scene Mode")
self.ColorModeTabWidget.addTab(self.lightPrefs, "Light Preferences")
self.ColorModeTabWidget.addTab(self.globalPrefs, "Global Preferences")
self.ColorModeTabWidget.setCurrentIndex(0) # make the CCT tab the main tab shown on launch
# ============ THE STATUS BAR AND WINDOW ASSIGNS ============
MainWindow.setCentralWidget(self.centralwidget)
self.statusBar = QStatusBar(MainWindow)
MainWindow.setStatusBar(self.statusBar)
# =======================================================
# = CUSTOM GUI CLASSES
# =======================================================
class parameterWidget(QWidget):
valueChanged = Signal(int) # return the value that's been changed
def __init__(self, **kwargs):
super(parameterWidget, self).__init__()
if 'prefix' in kwargs:
self.thePrefix = kwargs['prefix']
else:
self.thePrefix = "%"
self.widgetTitle = QLabel(self)
self.widgetTitle.setFont(mainFont)
self.widgetTitle.setGeometry(0, 0, 440, 17)
if 'title' in kwargs:
self.widgetTitle.setText(kwargs['title'])
self.bgGradient = QGraphicsView(QGraphicsScene(self), self)
self.bgGradient.setGeometry(0, 20, 552, 24)
self.bgGradient.setFrameShape(QFrame.NoFrame)
self.bgGradient.setFrameShadow(QFrame.Sunken)
self.bgGradient.setAlignment(Qt.Alignment(combinePySideValues([Qt.AlignLeft, Qt.AlignTop])))
self.slider = QSlider(self)
self.slider.setGeometry(0, 25, 552, 16)
self.slider.setStyleSheet("QSlider::groove:horizontal"
"{"
"border: 2px solid transparent;"
"height: 12px;"
"background: transparent;"
"margin: 2px 0;"
"}"
"QSlider::handle:horizontal {"
"background-color: rgba(255, 255, 255, 0.75);"
"opacity:0.3;"
"border: 2px solid #5c5c5c;"
"width: 12px;"
"margin: -2px 0;"
"border-radius: 3px;"
"}")
if 'sliderOffset' in kwargs:
self.sliderOffset = kwargs['sliderOffset']
else:
self.sliderOffset = 0
if 'sliderMin' in kwargs:
self.slider.setMinimum(kwargs['sliderMin'])
else:
self.slider.setMinimum(0)
if 'sliderMax' in kwargs:
self.slider.setMaximum(kwargs['sliderMax'])
else:
self.slider.setMaximum(100)
if 'sliderVal' in kwargs:
self.slider.setValue(kwargs['sliderVal'])
else:
self.slider.setValue(50)
if 'gradient' in kwargs:
self.gradient = kwargs['gradient']
self.bgGradient.setBackgroundBrush(self.renderGradient(self.gradient))
self.slider.setOrientation(Qt.Horizontal)
self.slider.valueChanged.connect(self.sliderValueChanged)
self.minTF = QLabel(self, text=str(self.slider.minimum() + self.sliderOffset) + self.thePrefix)
self.minTF.setGeometry(0, 46, 184, 20)
self.minTF.setAlignment(Qt.AlignLeft)
self.valueTF = QLabel(self, text=str(self.slider.value() + self.sliderOffset) + self.thePrefix)
self.valueTF.setFont(mainFont)
self.valueTF.setGeometry(185, 42, 184, 20)
self.valueTF.setAlignment(Qt.AlignCenter)
self.maxTF = QLabel(self, text=str(self.slider.maximum() + self.sliderOffset) + self.thePrefix)
self.maxTF.setGeometry(370, 46, 184, 20)
self.maxTF.setAlignment(Qt.AlignRight)
def value(self):
return self.slider.value()
def setValue(self, theValue):
self.slider.setValue(int(theValue))
def setRangeText(self, min, max):
self.widgetTitle.setText("Range: " + str(min) + self.thePrefix + "-" + str(max) + self.thePrefix)
def changeSliderRange(self, newRange):
self.slider.setMinimum(newRange[0])
self.slider.setMaximum(newRange[1])
self.minTF.setText(str(newRange[0]) + self.thePrefix)
self.maxTF.setText(str(newRange[1]) + self.thePrefix)
if self.gradient == "TEMP":
self.bgGradient.setBackgroundBrush(self.renderGradient(self.gradient))
def sliderValueChanged(self, changeValue):
self.valueTF.setText(str(changeValue + self.sliderOffset) + self.thePrefix)
self.valueChanged.emit(changeValue)
def adjustSatGradient(self, hue):
self.bgGradient.setBackgroundBrush(self.renderGradient("SAT", hue))
def presentMe(self, parent, posX, posY, halfSize = False):
self.setParent(parent) # move the control to a different tab parent
if halfSize == False: # check all the sizes to make sure they're correct
if self.widgetTitle.geometry() != QRect(0, 0, 440, 17):
self.widgetTitle.setGeometry(0, 0, 440, 17)
if self.bgGradient.geometry() != QRect(0, 20, 552, 24):
self.bgGradient.setGeometry(0, 20, 552, 24)
if self.slider.geometry() != QRect(0, 25, 552, 16):
self.slider.setGeometry(0, 25, 552, 16)
if self.minTF.geometry() != QRect(0, 46, 184, 20):
self.minTF.setGeometry(0, 46, 184, 20)
if self.valueTF.geometry() != QRect(185, 42, 184, 20):
self.valueTF.setGeometry(185, 42, 184, 20)
if self.maxTF.geometry() != QRect(370, 46, 184, 20):
self.maxTF.setGeometry(370, 46, 184, 20)
else:
if self.widgetTitle.geometry() != QRect(0, 0, 216, 17):
self.widgetTitle.setGeometry(0, 0, 216, 17)
if self.bgGradient.geometry() != QRect(0, 20, 272, 24):
self.bgGradient.setGeometry(0, 20, 272, 24)
if self.slider.geometry() != QRect(0, 25, 272, 16):
self.slider.setGeometry(0, 25, 272, 16)
if self.minTF.geometry() != QRect(0, 46, 90, 20):
self.minTF.setGeometry(0, 46, 90, 20)
if self.valueTF.geometry() != QRect(90, 42, 90, 20):
self.valueTF.setGeometry(90, 42, 90, 20)
if self.maxTF.geometry() != QRect(180, 46, 90, 20):
self.maxTF.setGeometry(180, 46, 90, 20)
# finally move the entire control to a position and display it
self.move(posX, posY)
self.show()
def renderGradient(self, gradientType, hue=180):
returnGradient = QLinearGradient(0, 0, 1, 0)
if PySideGUI == "PySide2":
returnGradient.setCoordinateMode(returnGradient.ObjectMode)
else:
returnGradient.setCoordinateMode(QGradient.ObjectMode)
if gradientType == "TEMP": # color temperature gradient (calculate new gradient with new bounds)
min = self.slider.minimum() * 100
max = self.slider.maximum() * 100
rangeStep = (max - min) / 4 # figure out how much in between steps of the gradient
for i in range(5): # fill the gradient with a new set of colors
rgbValues = self.convert_K_to_RGB(min + (rangeStep * i))
returnGradient.setColorAt((0.25 * i), QColor(rgbValues[0], rgbValues[1], rgbValues[2]))
elif gradientType == "BRI": # brightness gradient
returnGradient.setColorAt(0.0, QColor(0, 0, 0, 255)) # Dark
returnGradient.setColorAt(1.0, QColor(255, 255, 255, 255)) # Light
elif gradientType == "GM": # GM adjustment gradient
returnGradient.setColorAt(0.0, QColor(255, 0, 255, 255)) # Full Magenta
returnGradient.setColorAt(0.5, QColor(255, 255, 255, 255)) # White
returnGradient.setColorAt(1.0, QColor(0, 255, 0, 255)) # Full Green
elif gradientType == "RGB": # RGB 360º gradient
returnGradient.setColorAt(0.0, QColor(255, 0, 0, 255))
returnGradient.setColorAt(0.16, QColor(255, 255, 0, 255))
returnGradient.setColorAt(0.33, QColor(0, 255, 0, 255))
returnGradient.setColorAt(0.49, QColor(0, 255, 255, 255))
returnGradient.setColorAt(0.66, QColor(0, 0, 255, 255))
returnGradient.setColorAt(0.83, QColor(255, 0, 255, 255))
returnGradient.setColorAt(1.0, QColor(255, 0, 0, 255))
elif gradientType == "SAT": # color saturation gradient (calculate new gradient with base hue)
returnGradient.setColorAt(0, QColor(255, 255, 255))
newColor = self.convert_HSI_to_RGB(hue / 360)
returnGradient.setColorAt(1, QColor(newColor[0], newColor[1], newColor[2]))
elif gradientType == "SPEED": # speed setting gradient
returnGradient.setColorAt(0.0, QColor(255, 255, 255, 255))
returnGradient.setColorAt(1.0, QColor(0, 0, 255, 255))
elif gradientType == "SPARKS": # sparks setting gradient
returnGradient.setColorAt(0.0, QColor(255, 255, 255, 255))
returnGradient.setColorAt(1.0, QColor(255, 0, 0, 255))
return returnGradient
# CALCULATE THE RGB VALUE OF COLOR TEMPERATURE
def convert_K_to_RGB(self, Ktemp):
# Based on this script: https://gist.github.com/petrklus/b1f427accdf7438606a6
# from @petrklus on GitHub (his source was from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/)
tmp_internal = Ktemp / 100.0
# red
if tmp_internal <= 66:
red = 255
else:
tmp_red = 329.698727446 * math.pow(tmp_internal - 60, -0.1332047592)
if tmp_red < 0:
red = 0
elif tmp_red > 255:
red = 255
else:
red = tmp_red
# green
if tmp_internal <= 66:
tmp_green = 99.4708025861 * math.log(tmp_internal) - 161.1195681661
if tmp_green < 0:
green = 0
elif tmp_green > 255:
green = 255
else:
green = tmp_green
else:
tmp_green = 288.1221695283 * math.pow(tmp_internal - 60, -0.0755148492)
if tmp_green < 0:
green = 0
elif tmp_green > 255:
green = 255
else:
green = tmp_green
# blue
if tmp_internal >= 66:
blue = 255
elif tmp_internal <= 19:
blue = 0
else:
tmp_blue = 138.5177312231 * math.log(tmp_internal - 10) - 305.0447927307
if tmp_blue < 0:
blue = 0
elif tmp_blue > 255:
blue = 255
else:
blue = tmp_blue
return int(red), int(green), int(blue) # return the integer value for each part of the RGB values for this step
def convert_HSI_to_RGB(self, h, s = 1, v = 1):
# Taken from this StackOverflow page, which is an articulation of the colorsys code to
# convert HSV values (not HSI, but close, as I'm keeping S and V locked to 1) to RGB:
# https://stackoverflow.com/posts/26856771/revisions
if s == 0.0: v*=255; return (v, v, v)
i = int(h*6.) # XXX assume int() truncates!
f = (h*6.)-i; p,q,t = int(255*(v*(1.-s))), int(255*(v*(1.-s*f))), int(255*(v*(1.-s*(1.-f)))); v*=255; i%=6
if i == 0: return (v, t, p)
if i == 1: return (q, v, p)
if i == 2: return (p, v, t)
if i == 3: return (p, q, v)
if i == 4: return (t, p, v)
if i == 5: return (v, p, q)
class doubleSlider(QWidget):
valueChanged = Signal(int, int) # return left value, right value
def __init__(self, **kwargs):
super(doubleSlider, self).__init__()
if 'sliderType' in kwargs:
self.sliderType = kwargs['sliderType']
else:
self.sliderType = "RGB"
if self.sliderType == "RGB":
self.leftSlider = parameterWidget(title="Hue Limits", gradient="RGB", sliderMin=0, sliderVal=0, sliderMax=360, prefix="º")
self.rightSlider = parameterWidget(title="Range: 0º-360º", gradient="RGB", sliderMin=0, sliderVal=360, sliderMax=360, prefix="º")
elif self.sliderType == "BRI":
self.leftSlider = parameterWidget(title="Brightness Limits", gradient="BRI", sliderMin=0, sliderVal=0, sliderMax=100, prefix="%")
self.rightSlider = parameterWidget(title="Range: 0%-100%", gradient="BRI", sliderMin=0, sliderVal=100, sliderMax=100, prefix="%")
elif self.sliderType == "TEMP":
self.leftSlider = parameterWidget(title="Color Temperature Limits", gradient="TEMP", sliderMin=32, sliderVal=32, sliderMax=72, prefix="00K")
self.rightSlider = parameterWidget(title="Range: 3200K-5600K", gradient="TEMP", sliderMin=32, sliderVal=72, sliderMax=72, prefix="00K")
self.leftSlider.valueChanged.connect(self.doubleSliderValueChanged)
self.rightSlider.valueChanged.connect(self.doubleSliderValueChanged)
self.leftSlider.presentMe(self, 0, 0, True)
self.rightSlider.presentMe(self, 282, 0, True)
def doubleSliderValueChanged(self):
leftSliderValue = self.leftSlider.value()
rightSliderValue = self.rightSlider.value()
if leftSliderValue > rightSliderValue:
self.rightSlider.setValue(leftSliderValue)
if rightSliderValue < leftSliderValue:
self.leftSlider.setValue(rightSliderValue)
self.rightSlider.setRangeText(leftSliderValue, rightSliderValue)
self.valueChanged.emit(leftSliderValue, rightSliderValue)
def changeSliderRange(self, newRange):
self.leftSlider.changeSliderRange(newRange)
self.rightSlider.changeSliderRange(newRange)
def value(self):
return([self.leftSlider.value(), self.rightSlider.value()])
def setValue(self, theSlider, theValue):
if theSlider == "left":
self.leftSlider.setValue(theValue)
elif theSlider == "right":
self.rightSlider.setValue(theValue)
def presentMe(self, parent, posX, posY):
self.setParent(parent)
self.move(posX, posY)
self.show()
class customPresetButton(QLabel):
clicked = Signal() # signal sent when you click on the button
rightclicked = Signal() # signal sent when you right-click on the button
enteredWidget = Signal() # signal sent when the mouse enters the button
leftWidget = Signal() # signal sent when the mouse leaves the button
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if platform.system() == "Windows": # Windows font
customPresetFont = QFont("Calibri")
customPresetFont.setPointSize(10.5)
self.setFont(customPresetFont)
elif platform.system() == "Linux": # Linux (Ubuntu) font
customPresetFont = QFont()
customPresetFont.setPointSize(10.5)
self.setFont(customPresetFont)
else: # fallback font
customPresetFont = QFont()
customPresetFont.setPointSize(12)
self.setFont(customPresetFont)
self.setAlignment(Qt.AlignCenter)
self.setTextFormat(Qt.TextFormat.RichText)
self.setText(kwargs['text'])
self.setStyleSheet("customPresetButton"
"{"
"border: 1px solid grey; background-color: #a5cbf7;"
"}"
"customPresetButton::hover"
"{"
"background-color: #a5e3f7;"
"}")
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.clicked.emit()
elif event.button() == Qt.RightButton:
self.rightclicked.emit()
def enterEvent(self, event):
self.enteredWidget.emit()
def leaveEvent(self, event):
self.leftWidget.emit()
def markCustom(self, presetNum, isSnap = 0):
if isSnap == 0: # we're using a global preset
self.setText("<strong><font size=+2>" + str(presetNum + 1) + "</font></strong><br>CUSTOM<br>GLOBAL")
self.setStyleSheet("customPresetButton"
"{"
"border: 1px solid grey; background-color: #7188ff;"
"}"
"customPresetButton::hover"
"{"
"background-color: #70b0ff;"
"}")
elif isSnap >= 1: # we're using a snapshot preset
self.setText("<strong><font size=+2>" + str(presetNum + 1) + "</font></strong><br>CUSTOM<br>SNAP")
self.setStyleSheet("customPresetButton"
"{"
"border: 1px solid grey; background-color: #71e993;"
"}"
"customPresetButton::hover"
"{"