I have a wx.lib.scrolledpanel.ScrollPanel object with lots of children. The panel has methods for adding and removing items, and then updating the layout.
I am trying to get the same context menu to appear for each child by binding the ContextMenu event to them. The Panel should listen for these events and respond.
The first attepmt failed because I can capture the MenuEvents at the panel without difficulty, but I can’t determine which object was under the mouse when I created the context menu.
The second attempt tried to bind the context menu at the panel level, and failed for pretty much the same reason. It also has the added difficulty that scroll action always fires the context menu.
Has anyone played with this combination? Any advice?
Josh English
cardpaneldemo.py (8.92 KB)
cardpanel.py (8.43 KB)
I am trying to get the same context menu to appear for each child by binding the ContextMenu event to them. The Panel should listen for these events and respond.
The first attepmt failed because I can capture the MenuEvents at the panel without difficulty, but I can’t determine which object was under the mouse when I created the context menu.
The second attempt tried to bind the context menu at the panel level, and failed for pretty much the same reason. It also has the added difficulty that scroll action always fires the context menu.
Has anyone played with this combination? Any advice?
Josh English
I have a wx.lib.scrolledpanel.ScrollPanel object with lots of children. The panel has methods for adding and removing items, and then updating the layout.
Sure, I popup menus everywhere. There are all sorts of tricks to using them effectively since you cant tie an attribute to a menuitem.
Not sure exactly you want but I took a quick skim at it. I uncommented the SampleCard context menu binding and basically everything seems right for the most part.
The debug statements could be a bit more descriptive as this is a bit more than a small sample app to wrap your head around at first glance.
Nice little widget and demo BTW. What is the license on it…? wxWidgets by chance?
There are a few different ways you can keep track of the window(card) clicked on. normally just storing a reference to it somewhere is easy enough.
I would normally do this when creating a popup depending on the specific popup type and desired end result.
You could for example send the evtObj instance to the cardPanel before popping up the menu.
like self.GetCardPanel().SetClickedCard(evtObj), then when the OnCardDelete method is called, the necessary info is already there…
The SetClickedCard would be a method added to CardPanel that simply sets an attribute to the last card clicked instance every time the popup menu pops up.
The GetCardPanel would return the desired Card panel instance or card parent in other words. evtObj would be the card instance sent to cardPanel to be set for possible later use if menu item is clicked on.
or you could toy around with the menu help(I often store stuff for misc items there sometimes if statustext isn’t an issue) such as…
self.Bind(wx.EVT_CONTEXT_MENU, self.OnContext)
def OnContext(self, event):
evtObj = event.GetEventObject() # is a instance of wx.Menu, ex: the popup menu.
evtPos = event.GetPosition()
print("evtObj = %s" % evtObj)
print("evtPos = %s" % evtPos)
menu = wx.Menu()
menu.Append(CP.DELETECARD, "Delete", "%s" % evtObj)
self.PopupMenu(menu)
menu.Destroy()
&
def OnCardDelete(self, event):
evtObj = event.GetEventObject() # is a instance of wx.Menu, ex: the popup menu.
evtId = event.GetId() # what the menu item id was.
print(“evtObj = %s” % evtObj)
print(“evtId = %s” % evtId)
print(“Got Delete Card event from”,
evtObj.FindItemById(evtId).GetHelp())
Hope this helps.
···
On Thursday, May 15, 2014 2:46:35 PM UTC-6, Josh English wrote:
Thanks. This looked good, but I went a little crazy and decided to try custom events.
I did find the method wx.Window.GetPopupMenuSelectionFromUser(), which allows me to get the selected menu ID without firing a menu event. From there I could create a custom event and attach the card to the event.
Custom events also allowed me to send the events from some drawn bitmaps that appear when the mouse enters the card.
I will be releasing it with the wxWidgets licence. I want to finish the full demo first, though. Feature Explosion has occured.
Josh
···
On Thursday, May 15, 2014 9:47:14 PM UTC-7, Metallicow wrote:
self.Bind(wx.EVT_CONTEXT_MENU, self.OnContext)
def OnContext(self, event):
evtObj = event.GetEventObject() # is a instance of wx.Menu, ex: the popup menu.
evtPos = event.GetPosition()
print("evtObj = %s" % evtObj)
print("evtPos = %s" % evtPos)
menu = wx.Menu()
menu.Append(CP.DELETECARD, "Delete", "%s" % evtObj)
self.PopupMenu(menu)
menu.Destroy()
&
def OnCardDelete(self, event):
evtObj = event.GetEventObject() # is a instance of wx.Menu, ex: the popup menu.
evtId = event.GetId() # what the menu item id was.
print(“evtObj = %s” % evtObj)
print(“evtId = %s” % evtId)
print(“Got Delete Card event from”,
evtObj.FindItemById(evtId).GetHelp())
Sure, I popup menus everywhere. There are all sorts of tricks to using them effectively since you cant tie an attribute to a menuitem.
Not sure exactly you want but I took a quick skim at it. I uncommented the SampleCard context menu binding and basically everything seems right for the most part.
The debug statements could be a bit more descriptive as this is a bit more than a small sample app to wrap your head around at first glance.
Nice little widget and demo BTW. What is the license on it…? wxWidgets by chance?
There are a few different ways you can keep track of the window(card) clicked on. normally just storing a reference to it somewhere is easy enough.
I would normally do this when creating a popup depending on the specific popup type and desired end result.
You could for example send the evtObj instance to the cardPanel before popping up the menu.
like self.GetCardPanel().SetClickedCard(evtObj), then when the OnCardDelete method is called, the necessary info is already there…
The SetClickedCard would be a method added to CardPanel that simply sets an attribute to the last card clicked instance every time the popup menu pops up.
The GetCardPanel would return the desired Card panel instance or card parent in other words. evtObj would be the card instance sent to cardPanel to be set for possible later use if menu item is clicked on.
or you could toy around with the menu help(I often store stuff for misc items there sometimes if statustext isn’t an issue) such as…
Hope this helps.
Custom event is the best bet, as you can tweak alot more stuff, but I figure you may have been looking for generally.
As far as Feature Explosion… haha Good to hear.
I did that a bit with all the widgets I am developing(seems to be an ongoing thing that keeps pushing back the initial RELz).
Its nice that users share a lot of their custom creations back with the community.
But a lot of these I have collected over the years are stung out in various places and/or are not in the standard wxPy dist.
I have a handful of my own widgets and mixins, but am looking at adding the rest of the communities contributions(wxWidgets/Python licensed) into my mcow(Meticulously Crafted Optimal Widgets) package (like agw(Advanced Generic Widgets)) probably around when phoenix goes official along with a classic/phoenix wrapper
so that at least there will be a download somewhere with all the stuff some folks may have been missing thoughout the years in a central location whether it makes its way into the official dist or not.
Basically, all the docstrings need sphinx’d(doc generation) and tested on classic/phoenix(make sure they are all cross-platform) and a demo made for them(basic usage samples), etc…
The new phoenix demo and its iterations by everyone is still slowly being plugged away at, so it will come eventually in one shape or form. A bit of work overall… yep.
I think the my ThreeWaySplitter mod and Picture classes suffered the most from Feature Explosion/Tweaks and ShapedBitmapButton from extensive testing and a crazy amount of debugging.
…so yeah, send a linky back when you get closer to finishing it. It is a nice general widget/layout that many folks could use in their projects.
Another user did one recently as a math rendering text ctrl that was a pretty neat general widget that was WIPz.
···
On Saturday, May 17, 2014 1:58:14 PM UTC-6, Josh English wrote:
Thanks. This looked good, but I went a little crazy and decided to try custom events.
I did find the method wx.Window.GetPopupMenuSelectionFromUser(), which allows me to get the selected menu ID without firing a menu event. From there I could create a custom event and attach the card to the event.
Custom events also allowed me to send the events from some drawn bitmaps that appear when the mouse enters the card.
I will be releasing it with the wxWidgets licence. I want to finish the full demo first, though. Feature Explosion has occured.
Josh