wxpython SearchCtrl two events triggered - python

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..

Related

Moving through panes in AUI managed frame

My wx.Frame derived class is managed by AuiManager. I have several panes in this frame (all are derived from wx.Panel and all have wx.TAB_TRAVERSAL flag set). Pressing TAB key on the keyboard moves focus inside every pane correctly. The problem is, I don't know how to (or even if it is possible) move focus to the next pane. Any ideas about this?
P.S. I've tried googling and reading through wxPython docs, but couldn't find any clue.
I try to be as helpful as I can, given the little information you provided. To shift the focus to another Panel use that Panel's SetFocus() function. (See function description in the link)
Your question also seems to imply that you are interested in the key bindings of focus events. To manage the key bindings to focus events in wxpython, please checkout wx.NavigationKeyEvent. This will allow you to get and set the directions and events resulting from your navigation key inputs.
Last, have you tried pressing the [page down] key for switching panes?

How to add a "remove button" at the right side of the hovering (or each) item of a wx.ComboBox popup

What I want is a mean to remove an item from the combobox without having to add a separate remove button somewhere else. So I want a remove button to appear at the right side on a combobox dropdown item when I hover over my mouse pointer on it. And, it is also OK if all the items have remove button at the right side and do not need hovering.
The images bellow will illustrate what I am saying [...please ignore my mspaint skils]
[combobox with remove button for hovering item]
https://i.imgur.com/kIMtF3G.jpg
[combobox with remove button for each item]
https://i.imgur.com/iyG23vG.jpg
[NOTE: Sorry, I cannot post images directly because it needs at least 10 reputation to post images.]
[I am new to python and wxpython. So please ignore my ignorance if any. And for the same reason any simple code sample will be greatly helpful.]
Regards.
The wx.ComboBox does not have this feature. The wxPython GUI toolkit uses the target platform's native widgets. If those widgets don't support doing it, then neither does wxPython.
However, wxPython does have custom widgets or you could create your own widget to do this sort of thing.
I also think you could use a context-menu for this task. You would need to right-click to make it work. Another method would be to bind to a mouse event and try to figure out where in the widget you are, but I think that method would be error prone.

wxpython event for panel.Show()

I have tried looking through the documentation but not sure which to use.
I am basically looking for an event that is called when the panel containing the event is shown.
My program is split into multiple panels, which the user switches between with buttons. I haven't been able to get the button which switches panels to be able to interact with the combobox, so I've been trying to get it to update when the panel is shown.
class SomePanel(wx.Panel):
... # Panel initilisation/Event listeners
def panelShown(self, event):
# update combobox
Edit: I have found it. Leaving question up in case anyone else needs it.
For anyone with code as weird as mine.
In the SomePanel class:
self.Bind(wx.EVT_SHOW, self.panelShown)

Popup Dialog in Tkinter/Python

I need to add a popup dialog box on my GUI.
So, when ever I hover my mouse over a label, it should be able to show a popup( Like the type we get while hovering over a file in windows).
It should also disappear as soon i move away the mouse.
To start with, I am not even sure which module or class to use. I tried menu, but the results are not what i expected.
I also tried to learn tkCommonDialog, but couldn't understand it properly.
Please Advice!
The little popup window is called a tooltip.
This post may be relevant: http://bytes.com/topic/python/answers/505848-tkinter-button-overrelief
Take a look at the Balloon widget in the Tix package. I think it is just what you are looking for.

Buttons in vizard

I am developing a GUI in Vizard in which i am using radio buttons to select correct options, but I have a problem that I cannot solve.
In every group of radio buttons the 1st button always appears to be selected, but is actually not selected. The only way to select it is by choosing another button and then choosing the 1st button again.
Does anyone know how to solve this? I would like that in the beginning none of the buttons are selected.
I don't know Vizard but radio buttons probably have a method or another way of deselecting them similar to radiobutton.deselect() method of Tkinter. Have you looked at their documentation?
Also someone have done this trick, may be you should try it:
Create another radio button in that group, let it be selected by default and make it invisible
QuestionBox = vizinfo.add("") #Add the vizinfo object
#Create an invisible Radio button to be the default selected one, so that one of the visible ones must be chosen by the user
invisibleRadio = QuestionBox.add(viz.RADIO, 0, "")
invisibleRadio.visible(0) #invisible
source: http://forum.worldviz.com/showthread.php?t=1611

Categories

Resources