On Friday 16 March 2007 22:20, Paul McNett wrote:
> 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?" ;)
Good questions! I'll provide an example:
I sub-class a dialog (MyDialog). I do this because I need a modal form. I
add several objects (textboxes, grid,buttons).
As you are aware notifyUser() is not a method of dialog. Who would have
expected that a dialog would need notifyUser. But I need a way to notify
the user of some action. I could recreate some sort of dialog within my code
but then I have a calling "dForm" that has notifyUser. But how do I make a
reference to the calling "dForm"? I could say
callingForm = self.Parent. But what happens if later I move "MyDialog" in
the call stack? Maybe if I had passed a reference to MyDialog like "self" I
wouldn't worry.
Or I could:
ModalD=MyDialog()
ModalD.CallingForm = self
ModalD.show()
Now following your example I would.
ModalD=MyDialog(CallingForm = self)
# the above allows "self" to be used in the afterInit.
ModalD.show()
But this did not work. "self" is an object and it stopped the app. So I
either don't know how to create the setter/getter methods or I can't
pass "self". I think it is setter/getter methods.
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users