[wxPython-users] Some ListCrtl questions
Robin Dunn
robin at alldunn.com
Mon Feb 4 10:50:05 PST 2008
Armando Serrano Lombillo wrote:
> I'm using a ListCtrl in LC_REPORT mode to make a "properties window"
> to edit and view some properties of some objects. (I'm trying to do
> something similar to the properties window you get, for example, in
> the VBA IDE.) My first question is:
>
> 1) Is this a good idea or is there some other control which I'm missing?
You might want to take a look at wxPropertyGrid at
http://wxpropgrid.sourceforge.net/cgi-bin/index
>
> Now I'll explain the problem I'm encountering. I have a properties
> list in all of my objects. Something like myObject.properties =
> [['prop1','val1'],['prop2','val2'],...]. In order to view the
> properties in the ListCtrl, I defined the populate method which gets
> called when an object is selected:
>
> def populate(self, properties):
> self.DeleteAllItems()
> for prop in properties:
> index = self.InsertStringItem(sys.maxint, prop[0])
> self.SetStringItem(index, 1, prop[1])
>
> and it works fine. To edit the properties I used the TextEditMixin
> listctrl mixin (which enables the user to edit the second row but has
> the side effect of also enabling the user to edit the first column
> which I'd prefer wouldn't happen, is this configurable?)
It could probably be done with some tweaks to TextEditMixin, or perhaps
in a class derived from it.
> and I defined
> the following method:
>
> def update_props(self, event):
> for i in range(self.GetItemCount()):
> self.myObject.properties[i][1] = self.GetItem(i, 1).Text
>
> which I binded to EVT_LIST_END_LABEL_EDIT. This doesn't work right and
> I think it is because the item text is still not updated when the
> EVT_LIST_END_LABEL_EDIT is triggered. For example, let's say we have
> 'val1' in a certain item. The user edit's it and changes it to 'val2'.
> But the myObject.properties still has 'val1'. The user now edit's the
> item again to 'val3'. Now myObject.properties get's changed to 'val2'.
> I have looked for another event which is triggered when the value
> really gets changed, but I haven't found any. So my second question:
>
> 2) How do I tackle this?
wx.CallAfter can be used to invoke a function as soon as possible after
the current and pending event handlers have completed. That will give
the widget a chance to write the new values to the data store.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list