johnf wrote:
> On Friday 16 March 2007 22:20, Paul McNett wrote:
>> 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

There's really no reason that we can't move all kinds of stuff like this 
from dForm to dFormMixin so that dDialog would inherit it too.

> 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

Again, "the calling dForm" confuses me. If the dForm is calling the 
dialog, then you certainly have code in the dForm doing something like:

dlg = dabo.ui.dDialog(self, Modal=True, ...)
dlg.show()

So just make it:

dlg = dabo.ui.dDialog(self, Modal=True, ...)
dlg.callingForm = self
dlg.show()

> 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.  

You should always make your dialogs children of some form, so always 
pass the form reference as the first argument, as I did above. That is 
the parent argument, and for forms it can be None or not passed, meaning 
it is a top-level form. And the nice by-product of doing that is that 
you can now find out the "calling form" using 'self.Form' from the 
context of the dialog, and 'self.Form.Form' from the context of an 
object in the dialog.

> 
> 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.

Well, you didn't post all your code, including your getter/setter 
methods and property definition, so I can't say. Nor do I understand 
specifically what "it stopped the app" means (traceback?).

-- 
pkm ~ http://paulmcnett.com


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to