Context: My first foray into wxPython (dabbled with Tkinter).
If that means you are not terribly invested in raw wxPython code, you
might want to consider Dabo.
I'm trying to create my own subclass of wx.Choice because I'm creating
more than one wx.Choice. Ideally, I'd like to have a class, where i
pass a choices list to it, so I can have multiple choices, with only a
short piece of code.
So far I have:
class MyChoice(wx.Choice):
def __init__(self, parent, id=-1):
self.ch = wx.Choice(self, -1, (100, 50), choices)
self.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)
and the instantiation:
operator_control = MyChoice (panel,-1, choices=["+", "-"])
So, it throws a wobbly about the choices list and how it's unexpected.
How can I write a simple class so that it accepts the list of choices?
This and a whole lot more in the way of convenience methods has
already been written for you in the dabo.ui module. They call their
subclass of wx.Choice 'dDropdownList', and the code is very simple,
just as you want:
dd = dabo.ui dDropdownList(self, Choices=['+', '-'])
print dd.Choices
-> ['+', '-']
dd.Choices += ['spam', 'eggs']
print dd.Choices
-> ['+', '-', 'spam', 'eggs']
dd.PositionValue = 0
print dd.StringValue
-> '+'
dd.Choices.reverse()
print dd.Choices
-> ['eggs', 'spam', '-', '+']
This works for all list-based controls, not just the wx.Choice subclass.
I worked with wxPython for a couple of year, and always ran into
annoying things such as the way wx.Choice handles
adding/removing/setting its items, or all the steps you have to go
through to display an image from a file at a certain size. I tried
Dabo because someone else on this list was complaining about a problem
I had also run into, and the suggestion to try Dabo was made to them.
So I tried using Dabo for its UI module (I don't use any of the
database stuff), and I was amazed at how much more productive I
became.
wxPython is an amazing product that is well worth the trouble it takes
to to code in it. Dabo gives you all the power and beauty of wxPython
without the annoying stuff.
···
On 1/5/07, Adam Cripps <kabads@gmail.com> wrote:
--
# p.d.