Skip to content

Commit 468fb19

Browse files
committed
changes from Jason Pratt to support running epydoc--don't do stuff on module import
1 parent d4ba21f commit 468fb19

File tree

11 files changed

+433
-413
lines changed

11 files changed

+433
-413
lines changed

direct/src/controls/ControlManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#from PythonUtil import *
55
#from IntervalGlobal import *
66

7-
from otp.avatar import Avatar
7+
#from otp.avatar import Avatar
88
from direct.directnotify import DirectNotifyGlobal
99
#import GhostWalker
1010
#import GravityWalker

direct/src/fsm/FSM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def defaultFilter(self, request, args):
308308
# request) not listed in defaultTransitions and not
309309
# handled by an earlier filter.
310310
if request[0] in string.uppercase:
311-
raise RequestedDenied, request
311+
raise RequestDenied, request
312312

313313
# In either case, we quietly ignore unhandled command
314314
# (lowercase) requests.

direct/src/gui/DirectGuiTest.py

Lines changed: 126 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,136 @@
1-
from direct.showbase.ShowBaseGlobal import *
2-
from DirectGui import *
3-
from whrandom import *
4-
5-
# EXAMPLE CODE
6-
# Load a model
7-
smiley = loader.loadModel('models/misc/smiley')
8-
9-
# Here we specify the button's command
10-
def dummyCmd(index):
11-
print 'Button %d POW!!!!' % index
12-
13-
# Define some commands to bind to enter, exit and click events
14-
def shrink(db):
15-
db['text2_text'] = 'Hi!'
16-
taskMgr.remove('shrink')
17-
taskMgr.remove('expand')
18-
# Get a handle on the geometry for the rollover state
19-
rolloverSmiley = db.component('geom2')
20-
rolloverSmiley.setScale(db.component('geom0').getScale()[0])
21-
rolloverSmiley.lerpScale(.1,.1,.1, 1.0, blendType = 'easeInOut',
22-
task = 'shrink')
23-
24-
def expand(db):
25-
db['text0_text'] = 'Bye!'
26-
taskMgr.remove('shrink')
27-
taskMgr.remove('expand')
28-
db.component('geom0').setScale(db.component('geom2').getScale()[0])
29-
db.component('geom0').lerpScale(1,1,1, 1, blendType = 'easeInOut',
30-
task = 'expand')
31-
db.component('geom2').clearColor()
32-
33-
def ouch(db):
34-
taskMgr.remove('shrink')
35-
taskMgr.remove('expand')
36-
taskMgr.remove('runAway')
37-
db.component('geom0').setScale(db.component('geom2').getScale()[0])
38-
db.component('geom1').setScale(db.component('geom2').getScale()[0])
39-
db['text2_text'] = 'Ouch!'
40-
db['geom2_color'] = Vec4(1,0,0,1)
41-
newX = -1.0 + random() * 2.0
42-
newZ = -1.0 + random() * 2.0
43-
db.lerpPos(Point3(newX, 0, newZ), 1.0, task = 'runAway',
44-
blendType = 'easeOut')
45-
46-
dl = DirectFrame(image = 'models/maps/noise.rgb')
47-
dl.setScale(.5)
48-
49-
# Create a button with a background image, smiley as a geometry element,
50-
# and a text overlay, set a different text for the four button states:
51-
# (normal, press, rollover, and disabled), set scale = .15, and relief raised
52-
dbArray = []
53-
for i in range(10):
54-
db = DirectButton(parent = dl,
1+
2+
if __name__ == "__main__":
3+
from direct.directbase import DirectStart
4+
from DirectGui import *
5+
from whrandom import *
6+
7+
# EXAMPLE CODE
8+
# Load a model
9+
smiley = loader.loadModel('models/misc/smiley')
10+
11+
# Here we specify the button's command
12+
def dummyCmd(index):
13+
print 'Button %d POW!!!!' % index
14+
15+
# Define some commands to bind to enter, exit and click events
16+
def shrink(db):
17+
db['text2_text'] = 'Hi!'
18+
taskMgr.remove('shrink')
19+
taskMgr.remove('expand')
20+
# Get a handle on the geometry for the rollover state
21+
rolloverSmiley = db.component('geom2')
22+
rolloverSmiley.setScale(db.component('geom0').getScale()[0])
23+
rolloverSmiley.lerpScale(.1,.1,.1, 1.0, blendType = 'easeInOut',
24+
task = 'shrink')
25+
26+
def expand(db):
27+
db['text0_text'] = 'Bye!'
28+
taskMgr.remove('shrink')
29+
taskMgr.remove('expand')
30+
db.component('geom0').setScale(db.component('geom2').getScale()[0])
31+
db.component('geom0').lerpScale(1,1,1, 1, blendType = 'easeInOut',
32+
task = 'expand')
33+
db.component('geom2').clearColor()
34+
35+
def ouch(db):
36+
taskMgr.remove('shrink')
37+
taskMgr.remove('expand')
38+
taskMgr.remove('runAway')
39+
db.component('geom0').setScale(db.component('geom2').getScale()[0])
40+
db.component('geom1').setScale(db.component('geom2').getScale()[0])
41+
db['text2_text'] = 'Ouch!'
42+
db['geom2_color'] = Vec4(1,0,0,1)
43+
newX = -1.0 + random() * 2.0
44+
newZ = -1.0 + random() * 2.0
45+
db.lerpPos(Point3(newX, 0, newZ), 1.0, task = 'runAway',
46+
blendType = 'easeOut')
47+
48+
dl = DirectFrame(image = 'models/maps/noise.rgb')
49+
dl.setScale(.5)
50+
51+
# Create a button with a background image, smiley as a geometry element,
52+
# and a text overlay, set a different text for the four button states:
53+
# (normal, press, rollover, and disabled), set scale = .15, and relief raised
54+
dbArray = []
55+
for i in range(10):
56+
db = DirectButton(parent = dl,
57+
image = 'models/maps/noise.rgb',
58+
geom = smiley,
59+
text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
60+
scale = .15, relief = 'raised',
61+
# Here we set an option for a component of the button
62+
geom1_color = Vec4(1,0,0,1),
63+
# Here is an example of a component group option
64+
text_pos = (.6, -.8),
65+
# Set audio characteristics
66+
clickSound = getDefaultClickSound(),
67+
rolloverSound = getDefaultRolloverSound()
68+
)
69+
70+
# You can set component or component group options after a gui item
71+
# has been created
72+
db['text_scale'] = 0.5
73+
db['command'] = lambda i = i: dummyCmd(i)
74+
75+
# Bind the commands
76+
db.bind(ENTER, lambda x, db = db: shrink(db))
77+
db.bind(EXIT, lambda x, db = db: expand(db))
78+
db.bind(B1PRESS, lambda x, db = db: ouch(db))
79+
# Pop up placer when button 2 is pressed
80+
db.bind(B3PRESS, lambda x, db = db: db.place())
81+
82+
dbArray.append(db)
83+
84+
# To get rid of button and clear out hooks call:
85+
# db.destroy()
86+
87+
# DIRECT ENTRY EXAMPLE
88+
def printEntryText(text):
89+
print 'Text:', text
90+
91+
# Here we create an entry, and specify everything up front
92+
# CALL de1.get() and de1.set('new text') to get and set entry contents
93+
de1 = DirectEntry(initialText = 'Hello, how are you?',
5594
image = 'models/maps/noise.rgb',
56-
geom = smiley,
57-
text = ('Hi!', 'Ouch!', 'Bye!', 'ZZZZ!'),
58-
scale = .15, relief = 'raised',
59-
# Here we set an option for a component of the button
60-
geom1_color = Vec4(1,0,0,1),
61-
# Here is an example of a component group option
62-
text_pos = (.6, -.8),
63-
# Set audio characteristics
64-
clickSound = getDefaultClickSound(),
65-
rolloverSound = getDefaultRolloverSound()
95+
image_pos = (4.55, 0, -2.55),
96+
image_scale = (5.5, 1, 4),
97+
command = printEntryText,
98+
pos = (-1.1875, 0, 0.879167),
99+
scale = 0.0707855,
100+
cursorKeys = 1,
66101
)
67102

68-
# You can set component or component group options after a gui item
69-
# has been created
70-
db['text_scale'] = 0.5
71-
db['command'] = lambda i = i: dummyCmd(i)
103+
# DIRECT DIALOG EXAMPLE
104+
def printDialogValue(value):
105+
print 'Value:', value
72106

73-
# Bind the commands
74-
db.bind(ENTER, lambda x, db = db: shrink(db))
75-
db.bind(EXIT, lambda x, db = db: expand(db))
76-
db.bind(B1PRESS, lambda x, db = db: ouch(db))
77-
# Pop up placer when button 2 is pressed
78-
db.bind(B3PRESS, lambda x, db = db: db.place())
107+
simpleDialog = YesNoDialog(text = 'Simple',
108+
command = printDialogValue)
79109

80-
dbArray.append(db)
81-
82-
# To get rid of button and clear out hooks call:
83-
# db.destroy()
84-
85-
# DIRECT ENTRY EXAMPLE
86-
def printEntryText(text):
87-
print 'Text:', text
88-
89-
# Here we create an entry, and specify everything up front
90-
# CALL de1.get() and de1.set('new text') to get and set entry contents
91-
de1 = DirectEntry(initialText = 'Hello, how are you?',
92-
image = 'models/maps/noise.rgb',
93-
image_pos = (4.55, 0, -2.55),
94-
image_scale = (5.5, 1, 4),
95-
command = printEntryText,
96-
pos = (-1.1875, 0, 0.879167),
97-
scale = 0.0707855,
98-
cursorKeys = 1,
99-
)
100-
101-
# DIRECT DIALOG EXAMPLE
102-
def printDialogValue(value):
103-
print 'Value:', value
104-
105-
simpleDialog = YesNoDialog(text = 'Simple',
106-
command = printDialogValue)
107-
108-
customValues = YesNoDialog(text = 'Not Quite So Simple',
109-
buttonValueList = ['Yes', 'No'],
110-
command = printDialogValue)
111-
112-
113-
fancyDialog = YesNoDialog(text = 'Testing Direct Dialog',
114-
geom = smiley,
115-
geom_scale = .1,
116-
geom_pos = (-0.3,0,0),
117-
command = printDialogValue)
110+
customValues = YesNoDialog(text = 'Not Quite So Simple',
111+
buttonValueList = ['Yes', 'No'],
112+
command = printDialogValue)
113+
114+
115+
fancyDialog = YesNoDialog(text = 'Testing Direct Dialog',
116+
geom = smiley,
117+
geom_scale = .1,
118+
geom_pos = (-0.3,0,0),
119+
command = printDialogValue)
118120

119-
customDialog = DirectDialog(text = 'Pick a number',
120-
buttonTextList = map(str, range(10)),
121-
buttonValueList = range(10),
122-
command = printDialogValue)
121+
customDialog = DirectDialog(text = 'Pick a number',
122+
buttonTextList = map(str, range(10)),
123+
buttonValueList = range(10),
124+
command = printDialogValue)
123125

124126

125127

126-
# NOTE: There are some utility functions which help you get size
127-
# of a direct gui widget. These can be used to position and scale an
128-
# image after you've created the entry. scale = (width/2, 1, height/2)
129-
print 'BOUNDS:', de1.getBounds()
130-
print 'WIDTH:', de1.getWidth()
131-
print 'HEIGHT:', de1.getHeight()
132-
print 'CENTER:', de1.getCenter()
128+
# NOTE: There are some utility functions which help you get size
129+
# of a direct gui widget. These can be used to position and scale an
130+
# image after you've created the entry. scale = (width/2, 1, height/2)
131+
print 'BOUNDS:', de1.getBounds()
132+
print 'WIDTH:', de1.getWidth()
133+
print 'HEIGHT:', de1.getHeight()
134+
print 'CENTER:', de1.getCenter()
133135

136+
run()

0 commit comments

Comments
 (0)