ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxpython-users
wxpython-users
Re: [wxpython-users] wx.ListCtrl Error When Loading Values
by Tim Roberts other posts by this author
May 8 2008 6:01PM messages near this date
[wxpython-users] wx.ListCtrl Error When Loading Values | Re: [wxpython-users] wx.ListCtrl Error When Loading Values -- SOLVED
Phil answered part of your question, but he didn't address the real issue.

Rich Shepard wrote:
>  I don't see what's causing the error here:
> 
>  File "/data1/eikos/rulePage.py", line 83, in displayValues
>      self.rulesList.InsertStringItem(item, 0, self.appData.rules[0])
>    File
>  "/usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/_controls.py", 
>  line
>  4698, in InsertStringItem
>      return _controls_.ListCtrl_InsertStringItem(*args, **kwargs)
>  TypeError: in method 'ListCtrl_InsertStringItem', expected argument 2 of
>  type 'long'
> 
>    Here's the code (with the referenced line 83 marked with a hash):
> 
>      def displayValues(self, event):
>        for item in self.appData.rules:
>          self.rulesList.InsertStringItem(item, 0, self.appData.rules[0])
>          #self.rulesList.InsertStringItem(item, 1, self.appData.rules[1])
>          self.rulesList.InsertStringItem(item, 2, self.appData.rules[2])
>          self.rulesList.InsertStringItem(item, 3, self.appData.rules[3])
>          self.rulesList.InsertStringItem(item, 4, self.appData.rules[4])
> 
>    There's only one row in self.appData.rules:
> 
>  [(u'Variety', u'Fish', u'Wildlife', u'WFV2', u'if variety is high then
>  goodness is very increased')]
> 
>    What I read in the wPIA book is that InsertStringItem() -- without 
>  images
>  -- takes the row (here with the 'item' index), the column, and the 
>  string to
>  be inserted. So, I am not seeing what I've done incorrectly.

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.  I suspect you probably wanted to use 
enumerate(self.appData.rules) here, but as Phil pointed out, it's not 
really needed.

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] )

-- 
Tim Roberts, timr@[...].com
Providenza & Boekelheide, Inc.

_______________________________________________
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved