On Tuesday 16 January 2007 15:28, Ed Leafe wrote:
> On Jan 16, 2007, at 2:05 PM, johnf wrote:
> > OK I'm back where I started. I'm again asking how to call a form
> > class from
> > within form function. But below is the app.
> > import os
> > import inspect
> > import dabo
> > import johnClasses
>
> [snip]
>
> > A function in the form
> > def lookup():
> > new_frm = johnClasses.TestForm()
> > new_frm.showModal()
>
> OK, based on what you wrote, the form that contains this lookup
> function is a cdxml, right? That means that it is separate from the
> program in which you define and run the app.
OK that sort of makes sense. This is sort like
run program
And I am expecting the program to know about my classes. I guess my issue is
why is cdxml separate?
Does that mean my forms (form1.cdxml and form1.cdxml) can't talk to each
other? Does it also mean that each of the forms is independent of the
starting program? Actually, I don't see how to open the second form without
calling it from form1. So I think the two forms can talk to each other
though the call. But does form2 see any of form1 imports?
>
> You simply need to get this whole namespace thing down, and what
> happens when you use the import function. The simple answer to your
> problem would be to add 'import johnClasses' to your cdxml's 'Manage
> Imports' dialog, which will then make the 'johnClasses' name
> available in the form's namespace.
Thanks that fixed the issue I was having of course. It placed the import
statement in the "formName-Code.py" file. I have been reading namespace
stuff for about an hour. Each of the tutorials explains that the use of self
and that imports are available to the program.
So could I have done something like this:
import dabo
import johnClasses
def main():
app = dabo.dApp()
app.johnClasses = johnClasses
Now app has the info and I should be able to call
new_frm = app.johnClasses.TestForm()
new_frm.show()
>
> If I could draw an analogy to VFP, you're thinking of Python's
> import as being similar to SET PROCEDURE TO, in that once it's set,
> it's available everywhere. It's actually closer in scope to VFP's
> #DEFINE statement, which only works in the prg/class in which it is
> declared.
>
that also makes sense.
And I'm not giving up - just not understanding what happening in the code. I
was hoping that seeing hand generated code would help me understand. But
Paul's code worked as I would have expected. It's Dabo's code that does not.
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev