Trying to follow the PyCon tutorial, I am attempting to populate a dropdown
list. The underlying table for the dropdown list contains only one field
which is the primary key. I can't seem to get the list to populate. The
steps I took to achieve this were:
1. I created a script in the /biz directory called
PublicdepartmentsBizobj.py which contains:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dabo
class PublicdepartmentsBizobj(dabo.biz.dBizobj):
def afterinit(self):
self.datasource = "public.departments"
self.keyfield = "department"
self.addfrom("public.departments")
self.addfield("department")
def validateRecord(self):
"""Returning anything other than an empty
string from
this method will prevent the data from being
saved.
"""
ret = ""
# Add your business rules here.
return ret
def getNamesAndKeys(self):
crs = self.getTempCursor()
crs.execute("select department from
public.departments order by department")
ds = crs.getDataSet()
names = [rec["department"] for rec in ds]
keys = [rec["department"] for rec in ds]
return(names, keys)
My createBizobjs() method for the form contains:
def createBizobjs(self):
publicemployeesBizobj =
self.Application.biz.PublicemployeesBizobj(self.Connection)
self.addBizobj(publicemployeesBizobj)
publicdepartmentsBizobj =
self.Application.biz.PublicdepartmentsBizobj(self.Connection)
self.addBizobj(publicdepartmentsBizobj)
I set the DataSource property of my dropdownlist control to
"public.departments". I set the DataField property to "department". The
ValueMode is set to "Key" (I also tried "String"). RegID is set to
"department_list".
The afterInitAll method is as follows:
def afterInitAll(self):
departmentBiz = self.getBizobj("public.departments")
names, keys = departmentBiz.getNamesAndKeys()
self.department_list.Choices = names
self.department_list.Keys = keys
self.department_list.ValueMode = "Key"
self.requery()
I closed the ClassDesigner and updated my main.py to the following:
import dabo
dabo.ui.loadUI("wx")
app = dabo.dApp()
app.MainFormClass = "time_clock.cdxml"
app.start()
The form loads but the dropdown list is empty. Furthermore, the console has
the following output. I am sure I have missed something blatently obvious
but I wil need it pointed out to me.
dave@dave-Mint ~/time $ python main.py
/usr/local/lib/python2.7/dist-packages/dabo/lib/SimpleCrypt.py:52:
UserWarning: WARNING: SimpleCrypt is not secure. Please see
http://wiki.dabodev.com/SimpleCrypt for more information
warnings.warn("WARNING: SimpleCrypt is not secure. Please see
http://wiki.dabodev.com/SimpleCrypt for more information")
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",
line 14636, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )
File "/usr/local/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py",
line 348, in _afterInitAll
self.afterInitAll()
File "/tmp/tmpQOkWFW.py", line 173, in afterInitAll
names, keys = departmentBiz.getNamesAndKeys()
AttributeError: 'NoneType' object has no attribute 'getNamesAndKeys'
Dave Kelly
The Priory Inn
01666 502 251
<http://www.theprioryinn.co.uk/> www.theprioryinn.co.uk
"Dining in a 30 Mile Food Zone"
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
_______________________________________________
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]