I have found some interesting things as I examine the code Paul posted: 
http://leafe.com/archives/showMsg/349049

dabo.ui.dTextBox(pan, Height=41, DataSource="self.Form",
DataField="MyProp1", RegID="txt1")

I can change DataSource="self.Form" to DataSource=self and it still works.

so something is figuring out that the string needs to converted to a reference, 
and it seems to understand "self.form".

Now looking at bd2.py - the version that is Paul's UI with my myClass (end of 
message.)

DataSource=myObj works and I get the expected warning:
Dabo Info Log: Tue Apr 24 21:35:00 2007: DataSource '<__main__.myClass object 
at 
0xb7dbfe2c>' does not inherit from dObject. This may result in unsupported 
problems.

DataSource="myObj" does not.  I don't get an error, until I type a value and 
move focus to another object:

Dabo Error Log: Tue Apr 24 21:08:54 2007: Could not bind to 'myObj.MyProp2'
Reason: 'NoneType' object has no attribute 'MyProp2'

This seems odd.  myObj should be created and in scope, so why isn't the 
conversion happening?

I can fix it by adding a reference to myObj to the form:

         frm = MyForm()
+       frm.myObj1 = myObj

and now: DataSource="self.Form.myObj1" works.  (this gives me hope for how to 
use a .cdxml, but I am still exploring.)

Not only does the app work, but I am not getting the "DataSource not dObject" 
warning.  I am not sure if this is a good thing or not.  The only thing I 
changed was how the object was referenced, so I should be getting the same 
warning.

So my main question is why doesn't DataSource="myObj" work?

# bd2.py
# Bind to Data ver 2
# Paul's UI and Carl's myClass

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

class myClass(object):

    def _getMyProp1(self):
      return self._myProp1

    def _setMyProp1(self, val):
      self._myProp1=val

    MyProp1 = property(_getMyProp1, _setMyProp1, None, "My Prop #1")

    def _getMyProp2(self):
      return self._myProp2

    def _setMyProp2(self, val):
      self._myProp2=val

    MyProp2 = property(_getMyProp2, _setMyProp2, None, "My Prop #2")

    def __init__(self):
      self.MyProp1 = 'a'
      self.MyProp2 = 'b'

    def swap(self):
      self.MyProp1, self.MyProp2 = self.MyProp2, self.MyProp1

    def test(self):
      print self.MyProp1, self.MyProp2
      self.swap()
      print self.MyProp1, self.MyProp2


class MyForm(dabo.ui.dForm):
        def initProperties(self):
                self.Caption = "Bind to BO Demo"
                self.Top = 273
                self.Height = 118
                self.Width = 295
                self.Left = 61

        def afterInit(self):
                pan = dabo.ui.dPanel(self)

                dabo.ui.dTextBox(pan, Height=41, DataSource="myObj",
                                DataField="MyProp1", RegID="txt1" )

                dabo.ui.dButton(pan, RegID="butSwap", Caption="Swap")

                dabo.ui.dTextBox(pan, Height=41, DataSource=myObj,
                                DataField="MyProp2", RegID="txt2" )

                hs = pan.Sizer = dabo.ui.dSizer("h")
                hs.append(self.txt1, "expand")
                hs.append(self.butSwap, alignment="Middle")
                hs.append(self.txt2, "expand")

                self.Sizer.append1x(pan)
                self.update()

        def onHit_butSwap(self, evt):
                myObj.swap()
                self.update()

if __name__ == "__main__":
        
        myObj=myClass()
        myObj.test()

        app = dabo.dApp(MainFormClass=None)
        app.setup()
        frm = MyForm()
        frm.show()
        app.start()



Carl K


_______________________________________________
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/dabo-users/[EMAIL PROTECTED]

Reply via email to