Hello All:
This is my first post to this mailing list, but not the first time I created an email. As luck would have it, organizing
my thoughts to write an email usually results in the solution presenting itself to me. Not this time.
I am creating an application in which 'Frame2' is the main application frame with a menu bar, menus and a status bar,
nothing else at present. One of the menus has 3 menu items each of which opens a uniquely named instance of 'Frame4' that
incorporates a ListCtrl item. I have no problem populating the ListCtrl items with data or uniquely labeling and
changing the background colours of the dialogs or selecting data from the ListCtrl's and displaying the selection
(self.key) in a message dialog.
My problem is passing the selected data back to a Frame2 method.This is initiated by a 4th menu item in Frame2 that
attempts to retrieve the data. The three Frame4 dialogs are labeled 'site_dlg', 'plan_dlg' and 'config_dlg'. The
dialogs are not closed, therefore the data should be available, to be passed back. The Frame4 method, getKey(), however
is never called because I get a namespace error.
"NameError: global name 'site_dlg' is not defined"
I'm not sure what I'm doing wrong. This obviously(?) is some sort of namespace error. So I've tried all manner of
renaming the method call such as Frame4.site_dlg.getKey(), but I get the error AttributeError: 'module' object has no
attribute 'site_dlg'.
I am probably doing something very fundamentally wrong, but I cant see it. I hope the code snippets below are sufficient.
Here is the code from module Frame2.py that calls for the creation of one of the Frame4 dialogs (site_dlg)
def OnDataMenuItems0Menu(self, event):
...
a file dialog to select a file
...
if self.filename != '':
try:
# try to close an existing Frame Object
# ignore any errors
# then create a new one
self.DataMenu.Check(id=wxID_FRAME2DATAMENUITEMS0,check=False)
print 'HERE I AM - DataMenuItem0'
site_dlg.Destroy()
finally:
temp_db = wpio.ReadDatabase(self.filename)
input_db = wpio.generic2site_db(temp_db)
# create the list of data to populate the list
self.DataList = [key for key in input_db.keys() if key!= 'Captions']
# ListCtrl Dialog
site_dlg = Frame4.create(None, self.filename, input_type, self.DataList) <<<<<< CALLED HERE
self.DataMenu.Check(id=wxID_FRAME2DATAMENUITEMS0,check=True)
site_dlg.Show(True)
print 'From Frame2 File/Data menu: %s'%(site_dlg.list) <<<<<< NOTICE THAT THIS CALL TO AN OBJECT WORKS
print site_dlg.GetId(), site_dlg.GetLabel()
Here is the Frame2 method that attempts to retrieve the data from the Frame4 dialogs. This is test code at present
def OnDataMenuItems4Menu(self, event):
print 'HERE I AM - DataMenuItem4'
print site_dlg.getKey(), <<<<<<THIS IS THE LINE THAT GENERATES THE NAME ERROR
print plan_dlg.getKey(),
print config_dlg.getKey()
Here is the Frame4 method to return the data that is never successfully called.
def getKey(self):
print 'getkey called'
return self.key
Thanks for any help in advance
···
=============================
Lawrence Gray
lawrence.gray@netcom.ca
PS: after letting this site in my Draft box for a while, I have a solution. I would still like to see what other people may have to offer. My solution is to declare the object 'site_dlg' as global in the the method that creates the Frame4 instances. eg.
def OnDataMenuItems0Menu(self, event):
global site_dlg
...
Everything works but I dont like using global declarations. I hope there is a better solution