Paul McNett wrote:
> johnf wrote:
>> On Tuesday 16 January 2007 11:35, Paul McNett wrote:
>>> johnf wrote:
>>>> import dabo
>>>> import johnsClasses
>>>>
>>>> Then within a form I could say something like
>>>> new_frm = johnsClasses.MydialogClass() #if this wrong say so please
>>>> new_frm.show()
>>>>
>>>> I was sure I was right - but it does not work.  I'm missing something or
>>>> coding something wrong.
>>> johnsClasses is a name in the main module's namespace. It exists only in
>>> that namespace. You need to explicitly import it into any other modules,
>>> for instance your form.
>>>
>>> I don't know how the imports for the cdxml files work, if there's one
>>> place where you can put them, but in any case it will work to just put
>>> an 'import johnsClasses' inside the form method where you want to
>>> instantiate that dialog.
>>
>> So then the proper place is to import in the "afterInitAll"  for each and 
>> every form?  That seems wrong to me.  I'm back to where is my universal way 
>> to get my classes into the app.  
> 
> Python imports into namespaces.
> 
>> I'm still looking for "set classlib additive" and have access from any form. 
>>  
>> So if I do place an import statement into each form will I end up with multi 
>> copies of myclass in memory or just one?  As I currently understand it 
>> python 
>> checks to see if the module is in memory and uses it.  Is that right?   
> 
> Python doesn't reexecute already-imported modules, so that is right.
> 
>> OK maybe I need to hand code this.  So would one you please provide a simple 
>> hand coded example that opens a form, then calls a form from an event or 
>> form 
>> function.  The form does not need to be anything special - just a textbox 
>> with a button to call the second form.
> 
> #-- Here it is all in one file:
> 
> import dabo
> 
> dabo.ui.loadUI("wx")
> 
> class MyTestDialog(dabo.ui.dDialog):
>       pass
> 
> class MyMainForm(dabo.ui.dForm):
>       def afterInit(self):
>               self.addObject(dabo.ui.dButton, Caption="Hit Me", 
> OnHit=self.onButtonHit)
> 
>       def onButtonHit(self, evt):
>               dlg = MyTestDialog()
>               dlg.show()
>               dlg.release()
> 
> 
> if __name__ == "__main__":
>       app = dabo.dApp(MainFormClass=MyMainForm)
>       app.start()
> 
> ## - end example one.
> 
> 
> In the following example, we split MyTestDialog and MyMainForm into 
> their own files, so there are 3 files (main.py, MyTestDialog.py, and 
> MyMainForm.py)
> 
> ##- Begin main.py
> import dabo
> import MyMainForm
> app = dabo.dApp(MainFormClass=MyMainForm.MyMainForm)
> app.start()
> ##- End main.py
> 
> ##- Begin MyTestDialog.py
> import dabo
> 
> dabo.ui.loadUI("wx")
> 
> class MyTestDialog(dabo.ui.dDialog):
>       pass
> 
> ## - End MyTestDialog.py
> 
> ## - Begin MyMainForm.py
> import dabo
> import MyTestDialog
> 
> dabo.ui.loadUI("wx")
> 
> 
> class MyMainForm(dabo.ui.dForm):
>       def afterInit(self):
>               self.addObject(dabo.ui.dButton, Caption="Hit Me", 
> OnHit=self.onButtonHit)
> 
>       def onButtonHit(self, evt):
>               dlg = MyTestDialog.MyTestDialog()
>               dlg.show()
>               dlg.release()
> 
> ##- End MyMainForm.py
> 
> Notice how each file needed to import stuff that may have been imported 
> already in another of the files.
> 
>> Added question:  Is there a utility that converts cdxml files to python 
>> wxPthon code and allows me to save the code to a file?
> 
> Not that I know of.
> 

last I checked the code that executes a .cdxml file did it by creating a 
temp.py 
  and executing that.  so you can grab the temp.py (or whatever it is called) I 
think there is even a flag to prevent it from being deleted.

Carl K

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

Reply via email to