Another problem with the API: selecting individual list items. Sizers
need to behave more like lists. Consider deleting an individual sizer
item from a sizer with an event handler:
. . . sizer . . . . . . . . . . . . . . . .
+----------------------------------------+.
This is a panel with a textctrl |.
<DEL> and a delete button |.
Enter stuff: [_foo____________] |.
+----------------------------------------+.
+----------------------------------------+.
(more panels) |.
<DEL> |.
Enter stuff: [________________] |.
+----------------------------------------+.
. . . . . . . . . . . . . . . . . . . . . .
Suppose each panel represents an item in a list L such that the item is
L[i]. You want to update attributes of L[i] based on events.
def OnTextEnter(self, evt):
ctl=evt.GetEventObject()
# find the index of the control in the sizer
sizeritems=self.sizer.GetChildren()
pos=-1
for item in sizeritems:
pos=pos+1
if item.GetWindow()==ctl:
break
answers[pos]=ctl.GetValue()
If the GetChildren/GetWindow API looks unfamiliar to you, that's because
it's undocumented. I discovered it by looking at dir(sizer) and then
dir(sizeritem). (wxSizerItems themselves are also undocumented.) I
shudder to think how hard this would be without the sizeritem API, but
even armed with that knowledge, it's way too hard.
By comparison here's what I tried first. This is obviously incorrect but
I think you can see how I got there mentally:
def OnTextEnter(self, evt):
ctl=evt.GetEventObject()
# find the index of the control in the sizer
pos=self.sizer.GetPosition(ctl)
answers[pos]=ctl.GetValue()
In short, it's a pain in the ass to find out where an item is in the
sizer! Eventually I'm going to want to be able to change the order of the
panels in the sizer; I try not to think too hard about how I'm going to do
that :-).
If we're discussing a new Sizers API, how about adding more list-like
behavior to it so it's trivial to find out where an item is in the sizer.
···
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.