@@ -22,10 +22,12 @@ def __init__(self, parent = None, **kw):
22
22
# List of items to display on the popup menu
23
23
('items' , [], self .setItems ),
24
24
# Initial item to display on menu button
25
- # Can be an interger index or the same string as the button
25
+ # Can be an integer index or the same string as the button
26
26
('initialitem' , None , DGG .INITOPT ),
27
27
# Amount of padding to place around popup button indicator
28
28
('popupMarkerBorder' , (.1 , .1 ), None ),
29
+ # The initial position of the popup marker
30
+ ('popupMarker_pos' , (0 , 0 , 0 ), None ),
29
31
# Background color to use to highlight popup menu items
30
32
('highlightColor' , (.5 , .5 , .5 , 1 ), None ),
31
33
# Extra scale to use on highlight popup menu items
@@ -42,6 +44,8 @@ def __init__(self, parent = None, **kw):
42
44
DirectButton .__init__ (self , parent )
43
45
# Record any user specified frame size
44
46
self .initFrameSize = self ['frameSize' ]
47
+ # Record any user specified popup marker position
48
+ self .initPopupMarkerPos = self ['popupMarker_pos' ]
45
49
# Create a small rectangular marker to distinguish this button
46
50
# as a popup menu button
47
51
self .popupMarker = self .createcomponent (
@@ -168,8 +172,13 @@ def setItems(self):
168
172
else :
169
173
# Or base it upon largest item
170
174
bounds = [self .minX , self .maxX , self .minZ , self .maxZ ]
171
- pm .setPos (bounds [1 ] + pmw / 2.0 , 0 ,
172
- bounds [2 ] + (bounds [3 ] - bounds [2 ])/ 2.0 )
175
+ if self .initPopupMarkerPos :
176
+ # Use specified position
177
+ pmPos = list (self .initPopupMarkerPos )
178
+ else :
179
+ # Or base the position on the frame size.
180
+ pmPos = [bounds [1 ] + pmw / 2.0 , 0 , bounds [2 ] + (bounds [3 ] - bounds [2 ])/ 2.0 ]
181
+ pm .setPos (pmPos [0 ], pmPos [1 ], pmPos [2 ])
173
182
# Adjust popup menu button to fit all items (or use user specified
174
183
# frame size
175
184
bounds [1 ] += pmw
@@ -184,6 +193,12 @@ def showPopupMenu(self, event = None):
184
193
Adjust popup position if default position puts it outside of
185
194
visible screen region
186
195
"""
196
+
197
+ # Needed attributes (such as minZ) won't be set unless the user has specified
198
+ # items to display. Let's assert that we've given items to work with.
199
+ items = self ['items' ]
200
+ assert items and len (items ) > 0 , 'Cannot show an empty popup menu! You must add items!'
201
+
187
202
# Show the menu
188
203
self .popupMenu .show ()
189
204
# Make sure its at the right scale
0 commit comments