I see. So I need to collect the itemID each time an item is added to the
list. That could help me distinguish in which list each item was inserted.
Where is all this documented? I'd like to read more so I can understand how
to most efficiently use the widgets in the UI.
Thanks,
Rich
···
On Sat, 17 Dec 2005, SPE Stani's Python Editor wrote:
No, you can not use GetItemText directly. What you have to do is:
item = list.GetItem(itemId)
text = list.GetItemText(item)
The itemId is returned when you insert the item to the list.
--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
> No, you can not use GetItemText directly. What you have to do is:
> item = list.GetItem(itemId)
> text = list.GetItemText(item)
>
> The itemId is returned when you insert the item to the list.
Stani,
I see. So I need to collect the itemID each time an item is added to the
list. That could help me distinguish in which list each item was inserted.
Where is all this documented? I'd like to read more so I can understand how
to most efficiently use the widgets in the UI.
Well, I learnt the most from the demo and by practice, eg the demo of
the ListCtrl:
items = musicdata.items()
for key, data in items:
index = self.list.InsertImageStringItem(sys.maxint, data[0], self.idx1)
self.list.SetStringItem(index, 1, data[1])
self.list.SetStringItem(index, 2, data[2])
self.list.SetItemData(index, key)
Another reference is the wxWidgets reference (ships with the demo),
with notes about Python:
wxListCtrl::GetItem
wxPython note: The wxPython version of this method takes an integer parameter for the > item ID, an optional integer for the column number, and returns the wxListItem object.
You may not be able to count on the itemIDs being unique between different
controls. However, each ListCtrl you have you should have reference to
somewhere, so you should know what you're working with that way.
Is the List Control covered in the wxWidgets book? The reference docs are
pretty sparse, unfortunately.
-Chris
···
On Friday 16 December 2005 6:25 pm, Rich Shepard wrote:
I see. So I need to collect the itemID each time an item is added to the
list. That could help me distinguish in which list each item was inserted.
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
The itemId is returned when you insert the item to the list.
Stani,
I see. So I need to collect the itemID each time an item is added to the
list. That could help me distinguish in which list each item was inserted.
It is also passed in the event object for the listctrl events, etc. Be careful though, it is essentially just the index of the item in the list, so if items are reordered or removed or new items are inserted then the indexes of existing items can change. If you need to have a unique way of identifying items then that is what the [Get/Set]ItemData methods are for. That value will stick with the list item even when it is moved around the list.
···
On Sat, 17 Dec 2005, SPE Stani's Python Editor wrote:
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
You may not be able to count on the itemIDs being unique between different
controls. However, each ListCtrl you have you should have reference to
somewhere, so you should know what you're working with that way.
I didn't think so, Chris.
Is the List Control covered in the wxWidgets book? The reference docs are
pretty sparse, unfortunately.
Not adequately. That's why I asked here. I looked at the example on the
wiki page, "WriteItYourself," and read the pertinent section of the book
without finding an example of just how to do it.
I'll take Stani's suggestion of looking at the demo file for insight.
Rich
···
On Fri, 16 Dec 2005, Christopher Barker wrote:
--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
What I want to do is write the list contents to a file when the user
presses the "OK" button. The file name is associated with each specific list.
I've looked at the demo, the cookbook, and other resources. There's a lot
of good code on how to set up the list and move items around. I'll try just
writing the contents to a file and see how that comes out.
Thanks,
Rich
···
On Sat, 17 Dec 2005, Robin Dunn wrote:
It is also passed in the event object for the listctrl events, etc. Be
careful though, it is essentially just the index of the item in the list,
so if items are reordered or removed or new items are inserted then the
indexes of existing items can change. If you need to have a unique way of
identifying items then that is what the [Get/Set]ItemData methods are for.
That value will stick with the list item even when it is moved around the
list.
--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
> each ListCtrl you have you should have
> reference to somewhere, so you should know what you're working with that
> way.
I didn't think so, Chris.
huh?
I'll take Stani's suggestion of looking at the demo file for insight.
Always a good idea, I learn the most from samples.
Rich, I think you have tow issues you're dealing with here.
1) How to use the wx.ListCtrl, which I can't help much with, as I haven't
really used it. To bad it's not well documented.
2) Understanding OO,a nd more specifically Python OO. How to pass data back
and forth between different instances of various classes, how to organinse
your data etc. All I can say here is to keep asking questions, and maybe go
back to some of the non-wx Python docs to learn more. I learned the basics of
OO from the "Learning Python" book. "Dive into Python" is good, and you can
read it online or buy it. There are lots of other as well.
I deleted your most recent example code sent to wxPython-users. If you send it
to me again I might be able to make some suggestions
-Chris
···
On Saturday 17 December 2005 11:36 am, Rich Shepard wrote:
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
def OnOK(self, event):
num_items = self.lc.GetItemCount()
fh = open('testcase.in', 'a')
for index in range(num_items):
text = self.lc.GetItemText(index)
fh.write(text)
fh.write('\n')
fh.close
and this works.
On to the next refinements.
Thanks very much,
Rich
···
On Sat, 17 Dec 2005, Robin Dunn wrote:
This is not correct. GetItemText takes the item index (or itemId) just as
GetItem does. You are probably thinking of this:
item = list.GetItem(index)
text = item.GetText()
but, this should work fine too:
text = list.GetItemText(index)
--
Richard B. Shepard, Ph.D. | Author of "Quantifying Environmental
Applied Ecosystem Services, Inc. (TM) | Impact Assessments Using Fuzzy Logic"
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863