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)
Related
How do I make a step-by-step GUI Layout with Tkinter Python 3.7? What I mean is that I want to have the user enter some information, press the "NEXT" button and enter some more information, etc. I don't think there's really a feasible way to completely change the layout like this with Tkinter, so I'm hoping there's something I'm missing. How do I do this?
I don't think there's really a feasible way to completely change the layout like this with Tkinter,
That is incorrect. This is trivially easy with Tkinter. Create a function or class for each step. All of the widgets for that step should be inside a single frame.
You then just need to call the first function or class to create the frame. When the user clicks "next", destroy the frame and create the next frame. And so on.
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?
I want to create buttons dynamically
self.ctset = wx.BitmapButton(panel, -1, self.pic1, pos=(10,10), size=(50,50))
self.ctset.Bind(wx.EVT_BUTTON, self.add_ct)
self.ctset.SetDefault()
and the add_ct binding function
def add_ct(self, event):
pos=(10,self.yct)
self.yct+=65
self.new = wx.BitmapButton(self, -1, self.pic1, pos=pos,size=(50,50))
self.new.SetDefault()
print "Cutset"
I don't know where I am going wrong but my dynamically created buttons always seem disabled!
I want to bind a function to the dynamically created buttons that allows me to drag them around. Any ideas would be of great help!
I am pretty new to python and wxpython.
I don't see any code that captures the mouse's coordinates or even any drag-and-drop code. You need to download the wxPython demo package from the wxPython website and look at the ShapedWindow example for catching mouse coordinates. See also this old thread: http://wxpython-users.1045709.n5.nabble.com/Drag-Button-around-a-Panel-td3358640.html
In it you will find someone who is doing something very similar to what you want. I also found the following links which you might find helpful:
Drag button between panels in wxPython
How to move items smoothly in wxPython?
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..
I have a Qt program with many buttons, user-interactable widgets, etc.
At one stage in the program, I would like all the widgets to temporarily 'stop working'; stop behaving to mouse clicks and instead pass the event on to one function.
(This is so the User can select a widget to perform meta operations. Part explanation here: Get variable name of Qt Widget (for use in Stylesheet)? )
The User would pick a widget (to do stuff with) by clicking it, and of course clicking a button must not cause the button's bound function to run.
What is the correct (most abstracted, sensible) method of doing this?
(which doesn't involve too much new code. ie; not subclassing every widget)
Is there anything in Qt designed for this?
So far, I am able to retrieve a list of all the widgets in the program (by calling
QObject.findChildren(QtGui.QWidget)
so the solution can incorporate this.
My current horrible ideas are;
Some how dealing with all the applications events all the time in one
function and not letting through the events when I need the
application to be dormant.
When I need dormancy, make a new transparent widget which recieves
mouse clicks and stretch it over the entire window. Take coordinates
of click and figure out the widget underneath.
Somehow create a new 'shell' instance of the window.
THANKS!
(Sorry for the terrible write-up; in a slight rush)
python 2.7.2
PyQt4
Windows 7
You can intercept events send to specific widgets with QObject::installEventFilter.
graphite answered this one first so give credit where credit is due.
For an actual example in PySide, here's an example you might draw some useful code from:
my_app.py
from KeyPressEater import KeyPressEater
if __name__ == "__main__":
app = QApplication(sys.argv)
eater = KeyPressEater()
app.installEventFilter(eater)
KeyPressEater.py
class KeyPressEater(QObject):
# subclassing for eventFilter
def eventFilter(self, obj, event):
if self.ignore_input:
# swallow events
pass
else:
# bubble events
return QObject.eventFilter(self,obj,event)