forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectCheckBox.py
More file actions
executable file
·59 lines (46 loc) · 2.13 KB
/
DirectCheckBox.py
File metadata and controls
executable file
·59 lines (46 loc) · 2.13 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
from direct.gui.DirectGui import *
from panda3d.core import *
class DirectCheckBox(DirectButton):
"""
DirectCheckBox(parent) - Create a DirectGuiWidget which responds
to mouse clicks by setting a state of True or False and executes
a callback function if defined.
Uses an image swap rather than a text change to indicate state.
"""
def __init__(self, parent = None, **kw):
optiondefs = (
# Define type of DirectGuiWidget
('pgFunc', PGButton, None),
('numStates', 4, None),
('state', DGG.NORMAL, None),
('relief', DGG.RAISED, None),
('invertedFrames', (1,), None),
# Command to be called on button click
('command', None, None),
('extraArgs', [], None),
# Which mouse buttons can be used to click the button
('commandButtons', (DGG.LMB,), self.setCommandButtons),
# Sounds to be used for button events
('rolloverSound', DGG.getDefaultRolloverSound(), self.setRolloverSound),
('clickSound', DGG.getDefaultClickSound(), self.setClickSound),
# Can only be specified at time of widget contruction
# Do the text/graphics appear to move when the button is clicked
('pressEffect', 1, DGG.INITOPT),
('uncheckedImage', None, None),
('checkedImage', None, None),
('isChecked', False, None),
)
# Merge keyword options with default options
self.defineoptions(kw, optiondefs)
DirectButton.__init__(self,parent)
self.initialiseoptions(DirectCheckBox)
def commandFunc(self, event):
self['isChecked'] = not self['isChecked']
if self['isChecked']:
self['image'] = self['checkedImage']
else:
self['image'] = self['uncheckedImage']
self.setImage()
if self['command']:
# Pass any extra args to command
self['command'](*[self['isChecked']] + self['extraArgs'])