[wxpython-users] An event between different widgets
C M
cmpython at gmail.com
Wed Apr 23 12:14:01 PDT 2008
On Wed, Apr 23, 2008 at 2:20 PM, Mark Guagenti <mgenti at gentiweb.com> wrote:
> The easiest way to code it would be:
> self.list = wx.ListCtrl(style=wx.LC_SINGLE_SEL)
> self.Bind(wx.EVT_BUTTON, self.OnDelButton, delBtn)
>
> def OnDelButton(self, event):
> if self.list.SelectedItemCount > 0:
> self.list.DeleteItem(self.list.GetFirstSelected())
> else:
> dlg = wx.MessageDialog(self, "An entry must be selected
> first", "Error", style=wx.OK|wx.ICON_ERROR)
> dlg.ShowModal()
> dlg.Destroy()
>
> On Wed, Apr 23, 2008 at 12:59 PM, Gerard Petersen <lijssies at gp-net.nl> wrote:
> > Hi all,
> >
> > I've been around wx.python for a couple of months now, and gathered quite an
> > application already (mostly sorting out boxsizers ... :-)
> >
> > I want to be able to manage (add/remove/edit) a listctrl with seperate
> > buttons. See image link: http://www.gp-net.nl/userdl/snippet1.jpg
> >
> > I've read a good piece on bind methods and events on the wxpywiki, but I'm a
> > bit lost. When I select an entry in the list, I want to remove it with the
> > button so there needs to be a function for the button-down event but
> > it also is listctrl related. I don't really know where to put the method (or
> > it's trigger) that actually kicks the entry from the list.
> >
> > Any tips, URL's with examples or code snippets are very welcome.
> >
> > Thanx a lot.
> >
> > Regards,
> >
> > Gerard.
The example given is the way to think about it. It is not that you
are passing the event from one widget to another; the way to think
about it is: you have an event from one widget. Then, in the event
handler for that widget, you can do anything, including mucking about
with the state/contents of other widgets by using their (many)
methods. Also, you can also make the event handler simply call
another function which really does the work. This way, if you change
the GUI, you still have the function, and so the GUI is separate from
the logic. So for the above it would be more like (realizing it was
written just to make the point):
def OnDelButton(self, event):
self.delete_listctrl()
def delete_listctrl(self):
if self.list.SelectedItemCount > 0
self.list.DeleteItem(self.list.GetFirstSelected())
else:
dlg = wx.MessageDialog(self, "An entry must be selected
first", "Error",
style=wx.OK|wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
More information about the wxpython-users
mailing list