Wondering if there's a menu event I can bind to that's related to the currently selected menu item? By menu item I mean the items that show up in a popup menu like New, Open, Save, etc.
Use case: I would like to update a statusbar area of our application with a description of the currently selected menu item.
Any ideas appreciated.
Thank you,
Malcolm
You need to bind to the <<MenuSelect>> event.
There's an <Enter> event that is triggered when the mouse pointer enters a widget's space. Depending on how you're building your menu, you may be able to use it.
See http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm for more
Related
While designing QListWidget and QListTree item's display I would like to keep the amount of information displayed to a minimum
listItem=QtGui.QListWidgetItem()
listItem.setText("Some short info on item")
Instead I would like to implement a overlay window that would be displayed above the listItem user is interested in (similar to ToolTip widget).
It would be great if the user would simply position the mouse over the QListWidget item and being able to display floating "Info on Item" overlay window by pressing some keyboard shortcut. Press shortcut - window is displayed. Press a shortcut again to hide it. Any ideas how to implement this?
Here is the idea:
Set your key-press event to do something like the following:
QtGui.QToolTip.showText(QtGui.QCursor.pos(),"Your long format text...",None)
and either set a flag to toggle on-off with the same key-press, or for another key-press do:
QtGui.QToolTip.hideText()
I have a wxPython app with three listboxes. I'd like to make it so something can only be selected in one of them at a time. I thought I could use an event when the listbox is clicked to deselect the other boxes, but there are no events listed for wx.ListBox at wxpython.org. Is there another way to do this?
I think what you want is EVT_LISTBOX
I am using a SearchCtrl with a dropdown menu and I'm having some trouble with the events. When I click the little arrow next to the search button, the EVT_SEARCHCTRL_SEARCH_BTN is triggered, which is not what I want. I only want the EVT_MENU_RANGE to be triggered after I clicked an item, and not also the EVT_SEARCHCTRL_SEARCH_BTN before i click it.
self.search_ctrl = wx.SearchCtrl(self.panel_1, -1,
style=wx.TE_PROCESS_ENTER)
self.search_menu = wx.Menu()
self.search_items = {"text1":"value1", "text2":"value2"}
for txt in self.search_items:
self.search_menu.Append(-1, txt)
self.search_ctrl.SetMenu(self.search_menu)
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.search, self.search_ctrl)
self.Bind(wx.EVT_MENU_RANGE, self.onSearchMenu)
Although I should probably add id's to the menu bind, this isn't causing the problem. The code works as expected when I comment out the search button bind.
UPDATE
Apparently this isn't a problem, but a 'feature' of the searchctrl. I tried the wxpython demo and the menu also showed up if I just clicked the search button, and not the arrow. It is apparently one button, instead of the two i thought it was.
Is there a way to accomplish my original request? Do i have to manually modify a textctrl, or is there an other solution?
All the examples I've seen suggest you need to specify a range of IDs when you call your menu bind.
Maybe by default it binds to something unexpected... ?
Edit - In light of your update, it seems likely that you're going to need to make a custom control to me..
After creating a simple window/widget layout with Page (page.sourceforge.net)
I found that the listbox curselection() call returns the proper index when releasing Button-1.
When hit, it returns the previous index (the item which we just leave).
Becasue of some timer activities I'd like to get the clicked index at click-time, instead of release-time. Can somebody help me how could I do that? Thank you
Bind to the event <<ListboxSelect>> instead of <1>, this event will fire after the current selection has been updated.
If you genuinely need for the binding to work literally on a press of the mouse button you will have to rearrange the order of the bind tags for the widget.
I am using wxPython to create a taskbar menu. The menu contains some menu items (obviously).
Now I would like to update/change some of these items when a particular item is clicked, while still displaying the menu.
How can I prevent the taskbar menu from disappearing after clicking an item?
The only method I've found that could be useful is wxMenu.UpdateUI(), but that doesn't prevent the menu from disappearing.
Although I never got around to trying it myself, I remember attempting a similar effect with a popup menu & textctrl. You might want to consider trying wx.lib.agw.flatmenu.FlatMenuBar, it provides an event handler OnMenuDismissed(self, event), as well as a few others, which by name appear to be what you need. You would need to create your own OnMenuDismissed() and override the event.