Very clever that you build the widget and aplicate the bindings and sizer directly and then return the widget you made on the same “sentence” on the fly … awesome
Very clever that you build the widget and aplicate the bindings and sizer directly and then return the widget you made on the same “sentence” on the fly … awesome
Yeah, I have put together several different versions of the “onWidgetSetup” method where I set up the widget or various widget and/or add them to a sizer. It’s pretty handy for getting rid of a bunch or repetitious stuff, although sometimes I make the method too complex. Still, I think they’re fun exercises.
Yeah, I have put together several different versions of the "onWidgetSetup"
method where I set up the widget or various widget and/or add them to a
sizer. It's pretty handy for getting rid of a bunch or repetitious stuff,
although sometimes I make the method too complex. Still, I think they're fun
exercises.
I have an "addLabeledInput" function that currently accepts 14
different arguments...fortunately almost all of them take sensible
defaults and can thus usually be ignored. Still far cleaner than
repetitively creating and inserting each object and its text label
into a sizer.
Whenever you find yourself using a similar form setup you should be
asking yourself how much of it can be replaced by a function call, or
at the very least, a data-driven loop. E.g.
for label, action in [("Connect to device", self.onConnect), ("Take
image", self.onImage), ("Save image", self.onSave)]:
button = wx.Button(self, label = label)
button.Bind(wx.EVT_BUTTON, action)
sizer.Add(button)
- Mike
-Chris
···
On Fri, Mar 2, 2012 at 11:12 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
I have been using an extended version of this where the buttons need to
be members of self, as the state of the system changes different sets of
controls are visible and or enabled.
for (Name, Label, Action) in [(...)]
button = wx.Button(self, label=Label)
button.Bind(wx.EVT_BUTTON, Action)
sizer.Add(Button)
setattr(self, Name, button)
···
On 02/03/2012 8:13 PM, Chris Weisiger wrote:
On Fri, Mar 2, 2012 at 11:12 AM, Mike Driscoll <kyosohma@gmail.com> wrote:
Yeah, I have put together several different versions of the "onWidgetSetup"
method where I set up the widget or various widget and/or add them to a
sizer. It's pretty handy for getting rid of a bunch or repetitious stuff,
although sometimes I make the method too complex. Still, I think they're fun
exercises.
I have an "addLabeledInput" function that currently accepts 14
different arguments...fortunately almost all of them take sensible
defaults and can thus usually be ignored. Still far cleaner than
repetitively creating and inserting each object and its text label
into a sizer.
Whenever you find yourself using a similar form setup you should be
asking yourself how much of it can be replaced by a function call, or
at the very least, a data-driven loop. E.g.
for label, action in [("Connect to device", self.onConnect), ("Take
image", self.onImage), ("Save image", self.onSave)]:
button = wx.Button(self, label = label)
button.Bind(wx.EVT_BUTTON, action)
sizer.Add(button)