After a nice vacation, I am having another crack at Dabo. I am still
struggling with the list box control.
I have a Postgres database with two tables, employees and departments. The
table employees has a foreign key field called department. The table
departments has a primary key which is the department name. To ensure that
an employee can only be part of a valid department, new employees need their
department to be selected from a drop down list from departments.
I have two scripts in ~/time/biz
PublicemployeesBizobj.py which is the basis of the form is:
!/usr/bin/env python
# -*- coding: utf-8 -*-
import dabo
class PublicemployeesBizobj(dabo.biz.dBizobj):
def afterInit(self):
self.DataSource = "public.employees"
self.KeyField = "emp_id"
self.addFrom("public.employees")
self.addField("first_name")
self.addField("surname")
self.addField("emp_id")
self.addField("pwd")
self.addField("department")
self.addField("loginid")
I created PublicdepartmentsBizobj.py for the departments table:
#!/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")
self.addField("primary")
def getNamesAndKeys(self):
"""Return a 2-tuple of lists of the client
names
and their keys.
"""
crs = self.getTempCursor()
crs.execute("""select department
from public.departments
order by department""")
ds = crs.getDataSet()
# Create the lists
names = [rec["department"] for rec in ds]
keys = [rec["department"] for rec in ds]
return (names, keys)
I created the listbox field on my form. I set the DataSource to
public.departments, the DataField to department, the ValueMode to key and
the RegID to department_list. My createBizobjs looks like this:
def createBizobjs(self):
publicemployeesBizobj =
self.Application.biz.PublicemployeesBizobj(self.Connection)
self.addBizobj(publicemployeesBizobj)
publicdepartmentsBizobj =
self.Application.biz.PublicdepartmentsBizobj(self.Connection)
self.addBizobj(publicdepartmentsBizobj)
My afterInitAll looks like this:
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()
After this, I can scroll through the records and make changes and it all
seems great until I try to add a new record. My form stops responding and I
have the following traceback:
dave@Mint-Maya ~/time $ python main.py
/usr/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")
/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dControlItemMixin.py:234:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to
Unicode - interpreting them as being unequal
self.setSelection(self.Keys.index(key))
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_misc.py",
line 1358, in Notify
self.notify()
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py",
line 14767, in Notify
self.result = self.callable(*self.args, **self.kwargs)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/__init__.py", line
317, in ca_func
_func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dForm.py", line 133,
in update
super(BaseForm, self).update()
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1372, in update
self.raiseEvent(dEvents.Update)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1074, in raiseEvent
super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args,
**kwargs)
File "/usr/lib/python2.7/dist-packages/dabo/lib/eventMixin.py", line 81,
in raiseEvent
bindingFunction(event)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1352, in __onUpdate
self.update()
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1372, in update
self.raiseEvent(dEvents.Update)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1074, in raiseEvent
super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args,
**kwargs)
File "/usr/lib/python2.7/dist-packages/dabo/lib/eventMixin.py", line 81,
in raiseEvent
bindingFunction(event)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dPemMixin.py", line
1352, in __onUpdate
self.update()
File "/usr/lib/python2.7/dist-packages/dabo/ui/dDataControlMixinBase.py",
line 119, in update
self.__dataUpdate()
File "/usr/lib/python2.7/dist-packages/dabo/ui/dDataControlMixinBase.py",
line 137, in __dataUpdate
self.Value = src.getFieldVal(self.DataField)
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dControlItemMixin.py",
line 394, in _setValue
self.KeyValue = value
File "/usr/lib/python2.7/dist-packages/dabo/ui/uiwx/dControlItemMixin.py",
line 254, in _setKeyValue
"DataField: '%(dataField)s') to these invalid selections:
%(invalidSelections)s") % locals())
ValueError: Trying to set dDropdownList.Value (DataSource:
'public.employees', DataField: 'department') to these invalid selections:
[u'']
It seems to be choking on a blank department control. I created another
form with the same bizObjs and fields except I used a textbox for the
department. That worked fine for adding a new record.
Any ideas?
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]