Re: [wxpython-users] wx.ListCtrl Error When Loading Values -- SOLVED
by Rich Shepard other posts by this author
May 9 2008 7:17AM messages near this date
Re: [wxpython-users] wx.ListCtrl Error When Loading Values
|
Re: [wxpython-users] wx.ListCtrl Error When Loading Values
On Thu, 8 May 2008, Tim Roberts wrote:
> Phil answered part of your question, but he didn't address the real issue.
Tim,
So I noticed. :-)
> Your flaw here is assuming that "item" is an index. It's not. Given what
> you are showing there, self.appData.rules is a list that contains exactly
> one thing: a tuple of 5 strings. So, your loop will iterate exactly once,
> and during that iteration, item will be a tuple. A tuple is not a "long",
> hence the error.
Yup. I saw that but didn't read the appropriate code in the book. It turns
out that what works when manually adding a row to the list control (which
becomes a tuple in the database table when saved) does not work when loading
the widget with values retrieved from the database table.
> I suspect you probably wanted to use enumerate(self.appData.rules) here,
> but as Phil pointed out, it's not really needed.
Not quite; see below.
> The other problem is in the 3rd parameter. self.appData.rules contains
> one thing, not 5 things. I can't tell exactly what you meant here, but I
> think you wanted:
>
> for item,strings in enumerate(self.appData.rules):
> idx = self.rulesList.InsertStringItem( sys.maxint, 0, strings[0] )
> self.rulesList.SetStringItem( idx, 1, strings[1] )
> self.rulesList.SetStringItem( idx, 2, strings[2] )
> self.rulesList.SetStringItem( idx, 3, strings[3] )
> self.rulesList.SetStringItem( idx, 4, strings[4] )
This is close to what I had originally written for adding rows to the
list, which doesn't work for displaying saved values. The example for adding
rows on the top of page 398 showed me the solution. Here's my working
function:
def displayValues(self, event):
for item in self.appData.rules:
idx = self.rulesList.InsertStringItem(sys.maxint, item[0])
for col, text in enumerate(item[1:]):
self.rulesList.SetStringItem(idx, col+1, text)
Thanks to both you and Phil,
Rich
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Rich Shepard
Tim Roberts
Rich Shepard
Phil Mayes
Rich Shepard
|