forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValuator.py
More file actions
762 lines (655 loc) · 28 KB
/
Valuator.py
File metadata and controls
762 lines (655 loc) · 28 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
"""Undocumented Module"""
__all__ = ['Valuator', 'ValuatorGroup', 'ValuatorGroupPanel']
from direct.showbase.DirectObject import *
from direct.showbase.TkGlobal import *
from . import WidgetPropertiesDialog
import Pmw
from direct.directtools.DirectUtil import getTkColorString
from panda3d.core import Vec4
import sys
if sys.version_info >= (3, 0):
from tkinter.colorchooser import askcolor
else:
from tkColorChooser import askcolor
VALUATOR_MINI = 'mini'
VALUATOR_FULL = 'full'
class Valuator(Pmw.MegaWidget):
sfBase = 3.0
sfDist = 7
deadband = 5
""" Base class for widgets used to interactively adjust numeric values """
def __init__(self, parent = None, **kw):
#define the megawidget options
INITOPT = Pmw.INITOPT
optiondefs = (
('state', NORMAL, self.setState),
# Widget appearance
('relief', GROOVE, None),
('borderwidth', 2, None),
('text', 'Valuator', self.setLabel),
# Initial and reset values
('value', 0.0, INITOPT),
('resetValue', 0.0, None),
# Behavior
('min', None, None),
('max', None, None),
('resolution', None, None),
('numDigits', 2, self.setEntryFormat),
# Enable/disable popup menu
('fAdjustable', 1, None),
# Actions
('command', None, None),
('commandData', [], None),
('fCommandOnInit', 0, INITOPT),
# Callbacks to execute when updating widget's value
('preCallback', None, None),
('postCallback', None, None),
# Extra data to be passed to callback function, needs to be a list
('callbackData', [], None),
)
self.defineoptions(kw, optiondefs)
# Initialize the superclass
Pmw.MegaWidget.__init__(self, parent)
# Current adjusted (for min/max/resolution) value
self.adjustedValue = self['value']
# Create the components
interior = self.interior()
interior.configure(relief = self['relief'], bd = self['borderwidth'])
# The Valuator
self.createValuator()
# Set valuator callbacks for mouse start/stop
self._valuator['preCallback'] = self._mouseDown
self._valuator['postCallback'] = self._mouseUp
# The Label
if self['text'] is not None:
self._label = self.createcomponent('label', (), None,
Label, (interior,),
text = self['text'],
font = ('MS Sans Serif', 12),
anchor = CENTER)
else:
self._label = None
# The entry
self._entryVal = StringVar()
self._entry = self.createcomponent('entry', (), None,
Entry, (interior,),
justify = RIGHT,
width = 12,
textvariable = self._entryVal)
self._entry.bind('<Return>', self.validateEntryInput)
self._entryBackground = self._entry.cget('background')
# Pack Valuator Widget
self.packValuator()
# Set reset value if none specified
if 'resetValue' not in kw:
self['resetValue'] = self['value']
if self['fAdjustable']:
# The popup menu
self._popupMenu = Menu(interior, tearoff = 0)
self.addValuatorMenuEntries()
self._popupMenu.add_command(label = 'Reset',
command = self.reset)
self._popupMenu.add_command(label = 'Set to Zero',
command = self.zero)
self._popupMenu.add_command(
label = 'Properties...',
command = self._popupPropertiesDialog)
# Add key bindings
if self._label:
self._label.bind(
'<ButtonPress-3>', self._popupValuatorMenu)
self._entry.bind(
'<ButtonPress-3>', self._popupValuatorMenu)
self._valuator._widget.bind(
'<ButtonPress-3>', self._popupValuatorMenu)
# A Dictionary of dictionaries for the popup property dialog
self.propertyDict = {
'state':
{'widget': self,
'type': 'string',
'help': 'Enter state: normal or disabled.'
},
'text':
{'widget': self,
'type': 'string',
'help': 'Enter label text.'
},
'min':
{ 'widget': self,
'type': 'real',
'fNone': 1,
'help': 'Minimum allowable value. Enter None for no minimum.'},
'max':
{ 'widget': self,
'type': 'real',
'fNone': 1,
'help': 'Maximum allowable value. Enter None for no maximum.'},
'numDigits':
{'widget': self,
'type': 'integer',
'help': 'Number of digits after decimal point.'
},
'resolution':
{'widget': self,
'type': 'real',
'fNone': 1,
'help':'Widget resolution. Enter None for no resolution .'
},
'resetValue':
{ 'widget': self,
'type': 'real',
'help': 'Enter value to set widget to on reset.'}
}
# Property list defines the display order of the properties
self.propertyList = [
'state', 'text', 'min', 'max', 'numDigits',
'resolution', 'resetValue']
# Add any valuator specific properties
self.addValuatorPropertiesToDialog()
# Make sure input variables processed
self.fInit = self['fCommandOnInit']
self.initialiseoptions(Valuator)
def set(self, value, fCommand = 1):
"""
Update widget's value by setting valuator, which will in
turn update the entry. fCommand flag (which is passed to the
valuator as commandData, which is then passed in turn to
self.setEntry) controls command execution.
"""
self._valuator['commandData'] = [fCommand]
self._valuator.set(value)
# Restore commandData to 1 so that interaction via valuator widget
# will result in command being executed, otherwise a set with
# commandData == 0 will stick and commands will not be executed
self._valuator['commandData'] = [1]
def get(self):
""" Return current widget value """
return self.adjustedValue
def setEntry(self, value, fCommand = 1):
"""
Update value displayed in entry, fCommand flag controls
command execution
"""
# Clamp value
if self['min'] is not None:
if value < self['min']:
value = self['min']
if self['max'] is not None:
if value > self['max']:
value = self['max']
# Round by resolution
if self['resolution'] is not None:
value = round(value / self['resolution']) * self['resolution']
# Format value and use it to set entry
self._entryVal.set(self.entryFormat % value)
# Update indicator (if any) to reflect new adjusted value
self._valuator.updateIndicator(value)
# Execute command if required
if fCommand and self.fInit and (self['command'] is not None):
self['command'](*[value] + self['commandData'])
# Record adjusted value
self.adjustedValue = value
# Once initialization is finished, allow commands to execute
self.fInit = 1
def setEntryFormat(self):
"""
Change the number of significant digits in entry
"""
# Create new format string
self.entryFormat = "%." + "%df" % self['numDigits']
# Update entry to reflect new format
self.setEntry(self.get())
# Pass info down to valuator to adjust valuator sensitivity
self._valuator['numDigits'] = self['numDigits']
def validateEntryInput(self, event):
""" Check validity of entry and if valid pass along to valuator """
input = self._entryVal.get()
try:
# Reset background
self._entry.configure(background = self._entryBackground)
# Get new value and check validity
newValue = float(input)
# If OK, execute preCallback if one defined
self._preCallback()
# Call set to update valuator
self.set(newValue)
# Execute callback
self._postCallback()
# Update valuator to reflect adjusted value
# Don't execute command
self._valuator.set(self.adjustedValue, 0)
except ValueError:
# Invalid entry, flash background
self._entry.configure(background = 'Pink')
# Callbacks executed on mouse down/up
def _mouseDown(self):
""" Function to execute at start of mouse interaction """
# Execute pre interaction callback
self._preCallback()
def _mouseUp(self):
""" Function to execute at end of mouse interaction """
# Execute post interaction callback
self._postCallback()
# Update valuator to reflect adjusted value
# Don't execute command
self._valuator.set(self.adjustedValue, 0)
# Callback functions
def _preCallback(self):
if self['preCallback']:
self['preCallback'](*self['callbackData'])
def _postCallback(self):
# Exectute post callback if one defined
if self['postCallback']:
self['postCallback'](*self['callbackData'])
def setState(self):
""" Enable/disable widget """
if self['state'] == NORMAL:
self._entry['state'] = NORMAL
self._entry['background'] = self._entryBackground
self._valuator._widget['state'] = NORMAL
elif self['state'] == DISABLED:
self._entry['background'] = 'grey75'
self._entry['state'] = DISABLED
self._valuator._widget['state'] = DISABLED
def setLabel(self):
""" Update label's text """
if self._label:
self._label['text'] = self['text']
def zero(self):
"""
self.zero()
Set valuator to zero
"""
self.set(0.0)
def reset(self):
"""
self.reset()
Reset valuator to reset value
"""
self.set(self['resetValue'])
def mouseReset(self, event):
"""
Reset valuator to resetValue
"""
# If not over any canvas item
#if not self._widget.find_withtag(CURRENT):
self.reset()
# Popup dialog to adjust widget properties
def _popupValuatorMenu(self, event):
self._popupMenu.post(event.widget.winfo_pointerx(),
event.widget.winfo_pointery())
def _popupPropertiesDialog(self):
WidgetPropertiesDialog.WidgetPropertiesDialog(
self.propertyDict,
propertyList = self.propertyList,
title = 'Widget Properties',
parent = self.interior())
def addPropertyToDialog(self, property, pDict):
self.propertyDict[property] = pDict
self.propertyList.append(property)
# Virtual functions to be redefined by subclass
def createValuator(self):
""" Function used by subclass to create valuator geometry """
pass
def packValuator(self):
""" Function used by subclass to pack widget """
pass
def addValuatorMenuEntries(self):
""" Function used by subclass to add menu entries to popup menu """
pass
def addValuatorPropertiesToDialog(self):
""" Function used by subclass to add properties to property dialog """
pass
FLOATER = 'floater'
DIAL = 'dial'
ANGLEDIAL = 'angledial'
SLIDER = 'slider'
class ValuatorGroup(Pmw.MegaWidget):
def __init__(self, parent = None, **kw):
# Default group size
DEFAULT_DIM = 1
# Default value depends on *actual* group size, test for user input
DEFAULT_VALUE = [0.0] * kw.get('dim', DEFAULT_DIM)
DEFAULT_LABELS = ['v[%d]' % x for x in range(kw.get('dim', DEFAULT_DIM))]
#define the megawidget options
INITOPT = Pmw.INITOPT
optiondefs = (
('type', FLOATER, INITOPT),
('dim', DEFAULT_DIM, INITOPT),
('side', TOP, INITOPT),
# A list of initial values, one for each valuator
('value', DEFAULT_VALUE, INITOPT),
('min', None, INITOPT),
('max', None, INITOPT),
('resolution', None, INITOPT),
('numDigits', 2, self._setNumDigits),
# A tuple of labels, one for each valuator
('labels', DEFAULT_LABELS, self._updateLabels),
# The command to be executed when one of the valuators is updated
('command', None, None),
# Callbacks to execute when updating widget's value
('preCallback', None, None),
('postCallback', None, None),
# Extra data to be passed to callback function, needs to be a list
('callbackData', [], None),
)
self.defineoptions(kw, optiondefs)
# Initialize the toplevel widget
Pmw.MegaWidget.__init__(self, parent)
# Create the components
interior = self.interior()
# Get a copy of the initial value (making sure its a list)
self._value = list(self['value'])
# Create the valuators
self._valuatorList = []
for index in range(self['dim']):
# Add a group alias so you can configure the valuators via:
# fg.configure(Valuator_XXX = YYY)
if self['type'] == DIAL:
from . import Dial
valuatorType = Dial.Dial
elif self['type'] == ANGLEDIAL:
from . import Dial
valuatorType = Dial.AngleDial
elif self['type'] == SLIDER:
from . import Slider
valuatorType = Slider.Slider
else:
from . import Floater
valuatorType = Floater.Floater
f = self.createcomponent(
'valuator%d' % index, (), 'valuator', valuatorType,
(interior,), value = self._value[index],
min = self['min'], max = self['max'],
resolution = self['resolution'],
text = self['labels'][index],
command = lambda val, i = index: self._valuatorSetAt(i, val),
preCallback = self._preCallback,
postCallback = self._postCallback,
callbackData = [self],
)
f.pack(side = self['side'], expand = 1, fill = X)
self._valuatorList.append(f)
# Make sure valuators are initialized
self.set(self['value'], fCommand = 0)
# Make sure input variables processed
self.initialiseoptions(ValuatorGroup)
# This is the command is used to set the groups value
def set(self, value, fCommand = 1):
for i in range(self['dim']):
self._value[i] = value[i]
# Update valuator, but don't execute its command
self._valuatorList[i].set(value[i], 0)
if fCommand and (self['command'] is not None):
self['command'](self._value)
def setAt(self, index, value):
# Update valuator and execute its command
self._valuatorList[index].set(value)
# This is the command used by the valuator
def _valuatorSetAt(self, index, value):
self._value[index] = value
if self['command']:
self['command'](self._value)
def get(self):
return self._value
def getAt(self, index):
return self._value[index]
def _setNumDigits(self):
self['valuator_numDigits'] = self['numDigits']
self.formatString = '%0.' + '%df' % self['numDigits']
def _updateLabels(self):
if self['labels']:
for index in range(self['dim']):
self._valuatorList[index]['text'] = self['labels'][index]
def _preCallback(self, valGroup):
# Execute pre callback
if self['preCallback']:
self['preCallback'](*valGroup.get())
def _postCallback(self, valGroup):
# Execute post callback
if self['postCallback']:
self['postCallback'](*valGroup.get())
def __len__(self):
return self['dim']
def __repr__(self):
str = '[' + self.formatString % self._value[0]
for val in self._value[1:]:
str += ', ' + self.formatString % val
str += ']'
return str
class ValuatorGroupPanel(Pmw.MegaToplevel):
def __init__(self, parent = None, **kw):
# Default group size
DEFAULT_DIM = 1
# Default value depends on *actual* group size, test for user input
DEFAULT_VALUE = [0.0] * kw.get('dim', DEFAULT_DIM)
DEFAULT_LABELS = ['v[%d]' % x for x in range(kw.get('dim', DEFAULT_DIM))]
#define the megawidget options
INITOPT = Pmw.INITOPT
optiondefs = (
('type', FLOATER, INITOPT),
('dim', DEFAULT_DIM, INITOPT),
('side', TOP, INITOPT),
('title', 'Valuator Group', None),
# A list of initial values, one for each floater
('value', DEFAULT_VALUE, INITOPT),
('min', None, INITOPT),
('max', None, INITOPT),
('resolution', None, INITOPT),
# A tuple of labels, one for each floater
('labels', DEFAULT_LABELS, self._updateLabels),
('numDigits', 2, self._setNumDigits),
# The command to be executed when one of the floaters is updated
('command', None, self._setCommand),
# Callbacks to execute when updating widget's value
('preCallback', None, self._setPreCallback),
('postCallback', None, self._setPostCallback),
# Extra data to be passed to callback function, needs to be a list
('callbackData', [], self._setCallbackData),
# Destroy or withdraw
('fDestroy', 0, INITOPT)
)
self.defineoptions(kw, optiondefs)
# Initialize the toplevel widget
Pmw.MegaToplevel.__init__(self, parent)
# Create the components
interior = self.interior()
# The Menu Bar
self.balloon = Pmw.Balloon()
menubar = self.createcomponent('menubar', (), None,
Pmw.MenuBar, (interior,),
balloon = self.balloon)
menubar.pack(fill=X)
# ValuatorGroup Menu
menubar.addmenu('Valuator Group', 'Valuator Group Operations')
menubar.addmenuitem(
'Valuator Group', 'command', 'Reset the Valuator Group panel',
label = 'Reset',
command = lambda s = self: s.reset())
if self['fDestroy']:
dismissCommand = self.destroy
else:
dismissCommand = self.withdraw
menubar.addmenuitem(
'Valuator Group', 'command', 'Dismiss Valuator Group panel',
label = 'Dismiss', command = dismissCommand)
menubar.addmenu('Help', 'Valuator Group Help Operations')
self.toggleBalloonVar = IntVar()
self.toggleBalloonVar.set(0)
menubar.addmenuitem('Help', 'checkbutton',
'Toggle balloon help',
label = 'Balloon Help',
variable = self.toggleBalloonVar,
command = self.toggleBalloon)
# Create the valuator group
self.valuatorGroup = self.createcomponent(
'valuatorGroup',
(('valuator', 'valuatorGroup_valuator'),),
None, ValuatorGroup,
(interior,),
type = self['type'],
dim = self['dim'],
value = self['value'],
min = self['min'],
max = self['max'],
resolution = self['resolution'],
labels = self['labels'],
command = self['command'])
self.valuatorGroup.pack(expand = 1, fill = X)
# Make sure input variables processed
self.initialiseoptions(ValuatorGroupPanel)
def toggleBalloon(self):
if self.toggleBalloonVar.get():
self.balloon.configure(state = 'balloon')
else:
self.balloon.configure(state = 'none')
def _updateLabels(self):
self.valuatorGroup['labels'] = self['labels']
def _setNumDigits(self):
self.valuatorGroup['numDigits'] = self['numDigits']
def _setCommand(self):
self.valuatorGroup['command'] = self['command']
def _setPreCallback(self):
self.valuatorGroup['preCallback'] = self['preCallback']
def _setPostCallback(self):
self.valuatorGroup['postCallback'] = self['postCallback']
def _setCallbackData(self):
self.valuatorGroup['callbackData'] = self['callbackData']
def reset(self):
self.set(self['value'])
Pmw.forwardmethods(ValuatorGroupPanel, ValuatorGroup, 'valuatorGroup')
def rgbPanel(nodePath, callback = None, style = 'mini'):
def onRelease(r, g, b, a, nodePath = nodePath):
messenger.send('RGBPanel_setColor', [nodePath, r, g, b, a])
def popupColorPicker():
# Can pass in current color with: color = (255, 0, 0)
color = askcolor(
parent = vgp.interior(),
# Initialize it to current color
initialcolor = tuple(vgp.get()[:3]))[0]
if color:
vgp.set((color[0], color[1], color[2], vgp.getAt(3)))
def printToLog():
c=nodePath.getColor()
print("Vec4(%.3f, %.3f, %.3f, %.3f)"%(c[0], c[1], c[2], c[3]))
# Check init color
if nodePath.hasColor():
initColor = nodePath.getColor() * 255.0
else:
initColor = Vec4(255)
# Create entry scale group
vgp = ValuatorGroupPanel(title = 'RGBA Panel: ' + nodePath.getName(),
dim = 4,
labels = ['R','G','B','A'],
value = [int(initColor[0]),
int(initColor[1]),
int(initColor[2]),
int(initColor[3])],
type = 'slider',
valuator_style = style,
valuator_min = 0,
valuator_max = 255,
valuator_resolution = 1,
# Destroy not withdraw panel on dismiss
fDestroy = 1)
# Update menu button
vgp.component('menubar').component('Valuator Group-button')['text'] = (
'RGBA Panel')
# Set callback
vgp['postCallback'] = onRelease
# Add a print button which will also serve as a color tile
pButton = Button(vgp.interior(), text = 'Print to Log',
bg = getTkColorString(initColor),
command = printToLog)
pButton.pack(expand = 1, fill = BOTH)
# Update menu
menubar = vgp.component('menubar')
menubar.deletemenuitems('Valuator Group', 1, 1)
# Some helper functions
# Clear color
menubar.addmenuitem(
'Valuator Group', 'command',
label='Clear Color', command=lambda: nodePath.clearColor())
# Set Clear Transparency
menubar.addmenuitem(
'Valuator Group', 'command',
label='Set Transparency', command=lambda: nodePath.setTransparency(1))
menubar.addmenuitem(
'Valuator Group', 'command',
label='Clear Transparency', command=lambda: nodePath.clearTransparency())
# System color picker
menubar.addmenuitem(
'Valuator Group', 'command',
label='Popup Color Picker', command=popupColorPicker)
menubar.addmenuitem(
'Valuator Group', 'command',
label='Print to log', command=printToLog)
menubar.addmenuitem(
'Valuator Group', 'command', 'Dismiss Valuator Group panel',
label='Dismiss', command=vgp.destroy)
def setNodePathColor(color):
nodePath.setColor(color[0]/255.0, color[1]/255.0,
color[2]/255.0, color[3]/255.0)
# Update color chip button
pButton['bg'] = getTkColorString(color)
# Execute callback to pass along color info
if callback:
callback(color)
vgp['command'] = setNodePathColor
return vgp
def lightRGBPanel(light, style = 'mini'):
# Color picker for lights
def popupColorPicker():
# Can pass in current color with: color = (255, 0, 0)
color = askcolor(
parent = vgp.interior(),
# Initialize it to current color
initialcolor = tuple(vgp.get()[:3]))[0]
if color:
vgp.set((color[0], color[1], color[2], vgp.getAt(3)))
def printToLog():
n = light.getName()
c=light.getColor()
print(n + (".setColor(Vec4(%.3f, %.3f, %.3f, %.3f))" %
(c[0], c[1], c[2], c[3])))
# Check init color
initColor = light.getColor() * 255.0
# Create entry scale group
vgp = ValuatorGroupPanel(title = 'RGBA Panel: ' + light.getName(),
dim = 4,
labels = ['R','G','B','A'],
value = [int(initColor[0]),
int(initColor[1]),
int(initColor[2]),
int(initColor[3])],
type = 'slider',
valuator_style = style,
valuator_min = 0,
valuator_max = 255,
valuator_resolution = 1,
# Destroy not withdraw panel on dismiss
fDestroy = 1)
# Update menu button
vgp.component('menubar').component('Valuator Group-button')['text'] = (
'Light Control Panel')
# Add a print button which will also serve as a color tile
pButton = Button(vgp.interior(), text = 'Print to Log',
bg = getTkColorString(initColor),
command = printToLog)
pButton.pack(expand = 1, fill = BOTH)
# Update menu
menubar = vgp.component('menubar')
# System color picker
menubar.addmenuitem(
'Valuator Group', 'command',
label='Popup Color Picker', command=popupColorPicker)
menubar.addmenuitem(
'Valuator Group', 'command',
label='Print to log', command=printToLog)
def setLightColor(color):
light.setColor(Vec4(color[0]/255.0, color[1]/255.0,
color[2]/255.0, color[3]/255.0))
# Update color chip button
pButton['bg'] = getTkColorString(color)
vgp['command'] = setLightColor
return vgp