Skip to content

Commit 4d33db2

Browse files
mavericklibertyrdb
authored andcommitted
DirectOptionMenu: Fix popup menu reset of the popup marker's pos
Also defines popupMarker_pos and raises an assertion error if #showPopupMenu() is called when no items have been specified. Fixes panda3d#636 Closes panda3d#637
1 parent 16c3ca5 commit 4d33db2

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

direct/src/gui/DirectOptionMenu.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ def __init__(self, parent = None, **kw):
2222
# List of items to display on the popup menu
2323
('items', [], self.setItems),
2424
# 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
2626
('initialitem', None, DGG.INITOPT),
2727
# Amount of padding to place around popup button indicator
2828
('popupMarkerBorder', (.1, .1), None),
29+
# The initial position of the popup marker
30+
('popupMarker_pos', (0, 0, 0), None),
2931
# Background color to use to highlight popup menu items
3032
('highlightColor', (.5, .5, .5, 1), None),
3133
# Extra scale to use on highlight popup menu items
@@ -42,6 +44,8 @@ def __init__(self, parent = None, **kw):
4244
DirectButton.__init__(self, parent)
4345
# Record any user specified frame size
4446
self.initFrameSize = self['frameSize']
47+
# Record any user specified popup marker position
48+
self.initPopupMarkerPos = self['popupMarker_pos']
4549
# Create a small rectangular marker to distinguish this button
4650
# as a popup menu button
4751
self.popupMarker = self.createcomponent(
@@ -168,8 +172,13 @@ def setItems(self):
168172
else:
169173
# Or base it upon largest item
170174
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])
173182
# Adjust popup menu button to fit all items (or use user specified
174183
# frame size
175184
bounds[1] += pmw
@@ -184,6 +193,12 @@ def showPopupMenu(self, event = None):
184193
Adjust popup position if default position puts it outside of
185194
visible screen region
186195
"""
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+
187202
# Show the menu
188203
self.popupMenu.show()
189204
# Make sure its at the right scale

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy