John Fabiani wrote:
> On Monday, August 16, 2010 11:12:46 am Jim Byrnes wrote:
>> John Fabiani wrote:
>>> On Monday, August 16, 2010 09:58:34 am Jim Byrnes wrote:
>>>> John Fabiani wrote:
>>>>> On Monday, August 16, 2010 08:44:59 am Jim Byrnes wrote:
>>>>>> I am starting my first Dabo app.  I am putting some info from a Sqlite
>>>>>> database in a dDropdownList.  Then I need to populate some other
>>>>>> controls based on the item selected in the dDropdownList.
>>>>>>
>>>>>> Before I proceeded I wanted to make sure I knew how to get the value
>>>>>> from the dDropdownList so wrote a little test:
>>>>>>
>>>>>> ## *!* ## Dabo Code ID: dDropdownList-dPanel
>>>>>>
>>>>>> def onHit(self, evt):
>>>>>>  item = self.Form.PwordsCategories.Value
>>>>>>  print item
>>>>>>
>>>>>> When I run it I get this:
>>>>>>
>>>>>> Dabo Error Log: Mon Aug 16 10:25:40 2010: Could not bind to
>>>>>> 'categories.Catgegory'
>>>>>> Reason: 'NoneType' object has no attribute 'Catgegory'
>>>>>> WebSites
>>>>>>
>>>>>> OK, WebSites is what I was expecting but what did I do wrong to
>>>>>> generate the Dabo error?
>>>>>>
>>>>>> dDropdownList RegID = PwordsCategories
>>>>>> DataField = Category
>>>>>> DataSource = categories
>>>>>>
>>>>>> Here is the afterInitAll if that's helpful:
>>>>>>
>>>>>> def afterInitAll(self):
>>>>>>  pwordsBiz = self.getBizobj('pwds')
>>>>>>  categories = pwordsBiz.getCategories()
>>>>>>  self.PwordsCategories.Choices = categories
>>>>>>  self.PwordsCategories.ValueMode = 'string'
>>>>>>  
>>>>>>  self.requery()
>>>>>>
>>>>>> Thanks,  Jim
>>>>>
>>>>> Maybe a mis-spellling:-)
>>>>>
>>>>>     'Catgegory'<>    'Category'
>>>>>
>>>>> Johnf
>>>>
>>>> Thanks for catching that.  Getting old I guess, but after I correct that
>>>> and save/run it I get the same results, but Category in the error
>>>> message is spelled correctly now.
>>>>
>>>> Thanks,  Jim
>>>
>>> Maybe you are also setting up the values in the wrong method?  I think it
>>> should be afterInit().  I should have noticed that earlier.  Also you may
>>> have to account for the 'None' value in the list if the requery does not
>>> return anything.
>>>
>>>
>>>
>>> Johnf
>>
>> I commented out the afterInitAll method and put the code:
>>
>> pwordsBiz = self.getBizobj('pwds')
>>      categories = pwordsBiz.getCategories()
>>      self.PwordsCategories.Choices = categories
>>      self.PwordsCategories.ValueMode = 'string'
>>
>>      self.requery()
>>
>> in the afterInit method but that seemed to make it worse.  Nothing from
>> the dDropdownList was printed and I got a long traceback ending with:
>>
>>     File "/tmp/tmpBai5Sx.py", line 260, in afterInit
>>       self.PwordsCategories.Choices = categories
>> AttributeError: 'dForm_62236' object has no attribute 'PwordsCategories'

You were correct, it should be the afterInit.  Another mistake on my 
part.  I had the code in the afterInit in the dForm section of the code 
not the dDropdownList section.  Once I fixed that it ran and produced 
the correct output but the error message was the same.

>> What is this line from the original error message (after correcting the
>> spelling of Category)  telling me:
>>
>> Reason: 'NoneType' object has no attribute 'Category'
>>
>> I've Goolged that before but never really found a explanation I could
>> understand.
>>
>>
>> I'm not sure what you mean about accounting for the 'None' value.
>> However, a value is always returned when I select an item from the
>> dDropdownList.
>>
>> Thanks,  Jim
>
> OK Jim,
> Let's start over!
>
> You need to have a control somewhere on the form.  Something like this will
> work.
>
> #/usr/bin/env python
> import wx
> import dabo
> dabo.settings.dateFormat ="%m/%d/%Y"
>
> import dabo.dEvents as dEvents
> import dabo.dException as dException
>
>
>
> dabo.ui.loadUI('wx')
> from dabo.ui import dKeys as dKeys
>
> class MainForm(dabo.ui.dForm):
>
>
>      def afterInit(self):
>          """Normally the programmer would add code to display the controls
> here.  The programmer could add panels that contain other controls etc. """
>          self.Caption = "Replace with a Window Title"
>          self.Sizer = vs = dabo.ui.dSizer('v')
>
>          choices  = self.getPwordsChoices()
>
>          vs.append(dabo.ui.dDropdownList(self, RegID= 'PwordsCategories',
> Choices = choices))
>
>
>      def getPwordsChoices(self):
>          mylist_of_values = ['<None>',]
>          for val in ['website', 'desktop', 'iphone']:
>              mylist_of_values.append(val)
>
>          return mylist_of_values
>
>
> if __name__ == "__main__":
>      app = dabo.dApp()
>      app.MainFormClass = MainForm
>      app.start()

As I expected yours runs without error.  Looking at your code I see it 
is self contained, ie all in one file.  I'm using the ClassDesigner so I 
have multiple files in Dabo's standard structure.  This must be where I 
am doing something wrong to produce that <NoneType> error.

>
> In this case I have hard coded the value of the dropdown but you of course
> would use the values in your table.  I have also added the '<None>' value to
> the list of available values.  This because if you have not selected a record
> at the time you open the form it will error out on the '<None>' value not
> being in the list.
>

Thanks for the explanation and I have added that to mine.

> Most of the time the "NoneType" is saying the the object does not exist.  I
> think it applies to your error message.

OK, is there anyway to determine what object it is looking for?

> If you are using the ClassDesigner I would do the following to play and learn
> a little more.
>
> I would add the dropdown to the form.  Fillin the choices properties.  Run the
> form.  Use the dShell (control-d to open) and try accessing the value. by
> typing the following (the same is true with my form:
>
> self.RegID.Value  #change the RegID to match what you used in RegID
>

If I do this from dShell Value is correct and no error message is 
displayed.  If I run my program Value is correct but the error message 
appears.

The maddening thing about this is I based my code on the Pycon tutorial 
I completed and which runs fine.  I have opened the corresponding files 
side by side in my editor and still can't see where I went wrong.

Thanks for your efforts,  Jim

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]

Reply via email to