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'
>
> 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()
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.
Most of the time the "NoneType" is saying the the object does not exist. I
think it applies to your error message.
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
Johnf
_______________________________________________
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]