Paul McNett wrote:
> [EMAIL PROTECTED] wrote:
>> How do we make an AfterInit method “see” a parameter? For example, we want
>> to use and existing class for a lookup and we have a value that we want to
>> start with, how do we pass a parameter the class without messing with the
>
> One of the primary Dabo idioms for this is to make a property in the
> class that represents the parameter, and then pass the property value to
> the class's constructor when instantiating it. Example:
>
> #-- begin test code (copy/paste to a .py file and run it)
>
> import dabo
> dabo.ui.loadUI("wx")
>
> class MyTextBox(dabo.ui.dTextBox):
> def _getMyProp(self):
> return getattr(self, "_myProp", None)
> def _setMyProp(self, val):
> self._myProp = val
> MyProp = property(_getMyProp, _setMyProp)
>
> if __name__ == "__main__":
> app = dabo.dApp()
> app.setup()
> tb = MyTextBox(app.MainForm, MyProp="Test value")
> print tb.MyProp
> app.start()
>
> #-- end test code
johnf wrote:
> Paul using the first option (setting a Property) how can I pass an
object?
> I.e I'd like to pass the calling form to class MyTextBox.
> Actually, any object!
When you say you'd like to pass the calling form to class MyTextBox, it
makes me ask some questions in my mind. First, what does "calling form"
mean in the context of instantiating a MyTextBox instance? I guess the
meat of my question is "What is the situation where the form that is
instantiating your textbox isn't the form the textbox is a child of?"
And I ask that simply because I've never had the need for that. As you
no doubt know, a running instance of any Dabo control can get a
reference to the form it is on using 'self.Form', and thus by
'mytextbox.Form' from whereever the code may live.
And the other main question is, assuming you just want to send any
object as a property argument to your class, I just showed you how to do
that with that test code block (the test string I sent, is after all an
object just like any other object in Python). So my question is "What is
the question?" ;)
--
pkm ~ http://paulmcnett.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users