Hello,

if the controls on a form contain a dRadiolist connected to a database
field, and if the corresponding dataset is empty, for example by
applying a filter, then the application crashes with an AttributeError:
'dRadioList' object has no attribute 'Clear'.

Very simple example to demonstrate this:

SQLite database "mytest.db", containing a table "person":

create table person(
  idn integer primary key,
  firstname varchar(20),
  lastname varchar(20) not null,
  gender char(1) not null check(gender in 'F', 'M')
);

insert into person (firstname, lastname, gender) values ('Funkel',
'Friedhelm',
'M');
insert into person (firstname, lastname, gender) values ('Prinz', 'Birgit',
'F');
insert into person (firstname, lastname, gender) values ('Bruchhagen',
'Heribert', 'M');

Application code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sqlite_feldtest.py

import dabo
dabo.ui.loadUI("wx")

class BizPerson(dabo.biz.dBizobj):
        def initProperties(self):
                self.DataSource = "person"
                self.KeyField = "id"
                self.AutoPopulatePK = True
                self.UserSQL = """SELECT id, firstname, lastname, gender FROM 
person"""
                self.DefaultValues["gender"] = "M"
                self.DataStructure = [("id", "I", True, "person", "id"),
                ("firstname", "C", False, "person", "firstname"),
                ("lastname", "C", False, "person", "lastname"),
                ("gender", "C", False, "person", "gender")]
        
class FrmTest(dabo.ui.dForm):
        def afterInit(self):
                self.Sizer = dabo.ui.dSizer("v")
                panel = dabo.ui.dPanel(self)
                self.Sizer.append1x(panel)
                panel.Sizer = dabo.ui.dSizer("v")
                grPerson = dabo.ui.dGrid(panel, ColumnCount=4)
                grPerson.DataSource = "person"
                grPerson.Columns[0].Caption = "ID"
                grPerson.Columns[0].DataField = "id"
                grPerson.Columns[1].Caption = "First name"
                grPerson.Columns[1].DataField = "firstname"
                grPerson.Columns[2].Caption = "Last name"
                grPerson.Columns[2].DataField = "lastname"
                grPerson.Columns[3].Caption = "Gender"
                grPerson.Columns[3].DataField = "gender"
                panel.Sizer.append1x(grPerson)
                hs = dabo.ui.dSizer("h")
                hs.append(dabo.ui.dButton(panel, Caption="Last name 'B..'",
                                          OnHit=self.OnFilterB))
                hs.append(dabo.ui.dButton(panel, Caption="Last name 'C..'",
                                          OnHit=self.OnFilterC))
                hs.append(dabo.ui.dButton(panel, Caption="All", 
OnHit=self.OnNoFilter))
                panel.Sizer.append(hs)
                gs = dabo.ui.dGridSizer(MaxCols=2, HGap=3, VGap=3)
                gs.setColExpand(True, 1)
                gs.append(dabo.ui.dLabel(panel, Caption="First name"), 
halign="right")
                gs.append(dabo.ui.dTextBox(panel, DataSource="person",
                                           DataField="firstname"))
                gs.append(dabo.ui.dLabel(panel, Caption="Last name"), 
halign="right")
                gs.append(dabo.ui.dTextBox(panel, DataSource="person",
                                           DataField="lastname"))
                gs.append(dabo.ui.dLabel(panel, Caption="Gender"), 
halign="right")
                rlGender = dabo.ui.dRadioList(panel, DataSource="person",
                                              DataField="gender",
                                              Orientation="horizontal")
                rlGender.Choices = ["Female", "Male"]
                rlGender.Keys = ["F", "M"]
                rlGender.ValueMode = "Key"
                gs.append(rlGender)
                panel.Sizer.append(gs, 0, "x")
                self.layout()
                
        def afterInitAll(self):
                self.requery()
                
        def applyFilter(self, startchar):
                self.removeFilter()
                try:
                        self.PrimaryBizobj.filter("lastname", startchar, 
"startswith")
                except dabo.dException.NoRecordsException:
                        pass
                self.update()
        
        def OnFilterB(self, evt):
                self.applyFilter("B")

        def OnFilterC(self, evt):
                self.applyFilter("C")

        def OnNoFilter(self, evt):
                self.removeFilters()
                self.update()

        def createBizobjs(self):
                self.Application.addConnectFile("sqlite_feldtest.cnxml")
                self.Connection = 
self.Application.getConnectionByName("SQLite_Leute")
                biz = BizPerson(self.Connection)
                self.addBizobj(biz)

if __name__ == "__main__":
        app = dabo.dApp()
        app.MainFormClass = FrmTest
        app.start()


Clicking on the button "Last name 'C..'":

s...@elend:~/bin/dabo_sib> python sqlite_leute.py

Traceback (most recent call last):

  File
"/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_misc.py", line
1341, in Notify

    self.notify()

  File
"/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line
14653, in Notify

    self.result = self.callable(*self.args, **self.kwargs)

  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dForm.py", line 122, in
__update


    super(BaseForm, self).update()

  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
1242, in
update
    self.raiseEvent(dEvents.Update)
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
947, in
raiseEvent
    super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args,
**kwargs)
  File "/home/sib/svn_src/dabo_trunk/dabo/lib/eventMixin.py", line 93, in
raiseEvent
    bindingFunction(event)
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
1223, in
__onUpdate
    self.update()
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
1242, in
update
    self.raiseEvent(dEvents.Update)
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
947, in
raiseEvent
    super(dPemMixin, self).raiseEvent(eventClass, nativeEvent, *args,
**kwargs)
  File "/home/sib/svn_src/dabo_trunk/dabo/lib/eventMixin.py", line 93, in
raiseEvent
    bindingFunction(event)
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dPemMixin.py", line
1223, in
__onUpdate
    self.update()
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/dDataControlMixinBase.py",
line 97,
in update
    self.__dataUpdate()
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/dDataControlMixinBase.py", line
116, in __dataUpdate
    self.Value = self.getBlankValue()
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dControlItemMixin.py",
line
380, in _setValue
    self.KeyValue = value
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dControlItemMixin.py",
line
235, in _setKeyValue
    self._resetChoices()
  File "/home/sib/svn_src/dabo_trunk/dabo/ui/uiwx/dControlItemMixin.py",
line
109, in _resetChoices
    self.Clear()
AttributeError: 'dRadioList' object has no attribute 'Clear'


And that doesn't look right, does it?

Platform: GTK
Python Version: 2.6 on linux2
Dabo Version: Version 0.9.1; Revision 5075M
UI Version: 2.8.8.1 on wxGTK (gtk2)

Same thing on Windows:

Platform: Win
Python Version: 2.6.1 on win32
Dabo Version: Version 0.9.1; Revision ~5067
UI Version: 2.8.9.2 on wxMSW

Regards
Sibylle

-- 
Sibylle Koczian


_______________________________________________
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