Ed Leafe schrieb:
> On May 10, 2009, at 4:09 AM, Sibylle Koczian wrote:
> 
>> I don't think the way to populate the list shown in the wiki is the
>> right way for this case (or is it?). I tried simply to create the
>> dropdown list like this:
>>
>>    dl = dabo.ui.dDropdownList(pn, DataSource="rubrik",
>>                               DataField="rub_name")
>>    dl.ValueMode = "String"
> 
> 
>       The wiki example is primarily designed for foreign key lookups, not  
> for cases like this where you are storing the data directly in the  
> table.
> 
That's what I thought.

>       One requirement of list controls that we inherit from wxPython is  
> that the value must be an item in the list. When you set DataSource  
> and DataField, it tries to set the value of the control, but you  
> haven't populated the Choices yet, so you get the error you reported.
> 
So the Keys and Choices aren't populated automagically by setting
DataSource and DataField, right? Thinking this over: that wouldn't work
for the lookup case, I think.

>       The best way to handle this is to set the DataSource and DataField  
> *after* you have populated the list. So remove those from the  
> constructor code. You can include ValueMode in the constructor; you  
> can also include Choices if you've already determined them. So the  
> optimal code would be:
> 
> chc = <some method to get available choices>
> dl = dabo.ui.dDropdownList(pn, Choices=chc, ValueMode="String")
> dl.DataSource = "rubrik"
> dl.DataField = "rub_name"
> 

I tried this, and now the dDropdownList is filled correctly, I get no
error messages - but the parent-child relation doesn't seem to work: the
grid for the child records always shows the records belonging to the
first parent record.

Bizobj code:

class BizRubrik(dabo.biz.dBizobj):
        def initProperties(self):
                self.DataSource = 'rubrik'
                self.KeyField = 'rub_id'
                self.AutoPopulatePK = True
                self.addFrom('rubrik')
                self.addField('rub_id')
                self.addField('rub_name')
                self.DataStructure = [('rub_id', 'I', True, 'rubrik',
                         'rub_id'),
                        ('rub_name', 'C', False, 'rubrik', 'rub_name')]
                
        def getRubriken(self):
                self.requery()
                ds = self.getDataSet()
                rubnamen = [rec['rub_name'] for rec in ds]
                rubids = [rec['rub_id'] for rec in ds]
                return (rubnamen, rubids)
                        
class BizDinge(dabo.biz.dBizobj):
        def initProperties(self):
                self.DataSource = 'dinge'
                self.KeyField = 'd_id'
                self.LinkField = 'rub_id'
                self.FillLinkFromParent = True
                self.AutoPopulatePK = True
                self.addFrom('dinge')
                self.addField('d_id')
                self.addField('rub_id')
                # ... more fields
                self.addOrderBy('rub_id, sys_id')
                self.DataStructure = [('d_id', 'I', True, 'dinge',
                         'd_id'),
                        ('rub_id', 'I', False, 'dinge', 'rub_id'),
                        # ... more fields
                        ]

Main form code:

# -*- coding: utf-8 -*-
# kurzreise_MF.py

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

class KurzreiseMF(dabo.ui.dForm):
        def initProperties(self):
                self.Caption = "Mitnehmen auf kurze Reisen"
                
        def afterInit(self):
                # ... panel, sizers etc.
                # dDropDownList
                (nn, ids) = self.getRubriken()
                dl = dabo.ui.dDropdownList(pn, Choices=nn, Keys=ids,
                                           ValueMode="Key")
                dl.DataSource = "rubrik"
                dl.DataField = "rub_id"
                hs.append(dl, 1)
                pn.Sizer.append(hs, "x", border=10)
                # dGrid
                grDinge = dabo.ui.dGrid(pn, AlternateRowColoring=True,
                        ColumnCount=5,
                        Editable=True, RegID="grDingeID")
                grDinge.DataSource = "dinge"
                for (sp, (cpt, fld)) in enumerate([("ID", "d_id"), ("",
                        "ding_name"),
                        ("Letztes", "letztein"), ("Erstes", "erstaus"),
                        ("Mit", "stueck")]):
                                grDinge.Columns[sp].Caption = cpt
                                grDinge.Columns[sp].DataField = fld
                                if fld != "ding_name":
                                        grDinge.Columns[sp].Width = 50
                                if fld == "stueck":
                                        grDinge.Columns[sp].Editable =
                                                                  True
                pn.Sizer.append1x(grDinge, border=10)
                
                self.layout()

        def afterInitAll(self):
                self.requery()

        def createBizobjs(self):
                conn = self.Application.getConnectionByName("kurzreise")
                rubbiz = self.Application.biz.BizRubrik(conn)
                self.addBizobj(rubbiz)
                dingbiz = self.Application.biz.BizDinge(conn)
                self.addBizobj(dingbiz)
                rubbiz.addChild(dingbiz)
                
        def getRubriken(self):
                rubbiz = self.getBizobj("rubrik")
                (rubnamen, rubids) = rubbiz.getRubriken()
                rubnamen.insert(0, "<None>")
                rubids.insert(0, 0)
                return (rubnamen, rubids)
        
What do I do wrong here? I have tried "Key" and "Strings" as ValueMode
for the dDropdownList, changing the DataField accordingly, but that
doesn't help.

BTW this is a SQLite database, so I could easily post the definition and
some data, if anybody wants to try it. But I don't think it's anything
special about the table definitions that causes problems.

Thank you for hints,
Sibylle 

-- 
Sibylle Koczian

_______________________________________________
Post Messages to: Dabo-users@leafe.com
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/4a080508.4040...@t-online.de

Reply via email to