sharing variables between two wxpython tabs
I have asked this question but it was not very well formulated.
persistence of objects in python
As a newbie to both python, and GUI programming
I have a large project which contains a number of python files. File a.py defines a class called fobject I am using python 2.5
File b.py and c.py have classes called BProject and CProject which have an object of fobject as parameter. These are pages in wx python based program.
I have included using import CProject (defined in c.py) in b.py. I have a list in CProject which I fill using wx python GUI. Next I call a function BRun defined in BProject which internally calls a CRun Function in CProject ie. in c.py.
开发者_如何学PythonIn this CRun I want to manipulate the list but list is always empty at this time. Why is this so?
What should I do given the constraint is I can't change anything a.py in which fobject is defined ?
file : c.py
def Instance(fObject):
return test_page_CProject(fObject)
class CProject(object):
def __init__(self, fObject):
self.fObj = fObject
self.IntList = []
##snip
def OnIntSelectBtnPress(self,parent):
print ":self.IntList"
print self.IntList
self.listBoxIntSelect.InsertItems(self.IntList,0)
print self.IntList
def OnIntRun(self):
IntLModeList = self.IntListIntMode
#snip
file b.py
def Instance(fObject):
return BProject(fObject)
class BProject(object):
def __init__(self, fObject):
self.FObj = fObject
#snip
Object = __import__('CProject')
#snip
self.intObject = Object.Instance(self.FObj)
self.intObject.OnIntRun()
When CPython.OnIntRun is called the self.IntList is empty when it should'nt be
I'm not following this very well, but normally you need to pass the data in when you instantiate the class. Otherwise, you can use PubSub to pass the information between classes or you could create a simple local web server that each tab checks periodically for new data and updates itself.
If your fObject maintains the references to bProject and cProject, couldn't you write a send_to_c(msg)
function in your fObject, that you could call from your bProject (and vice versa)?
精彩评论