Passing params to single instance of wxApp

Sam shendley at email.unc.edu
Mon Mar 24 20:02:14 EST 2003


I want my app to only allow one instance, the problem is that it is
associated with a file type so when another of that file type is
opened I end up with two instances. I used the wxSingleInstanceChecker
to stop this from occuring but I really want to pass the params (i.e.
new filename) to the running app.  Any ideas?  I tried the below
solution but it doesnt work cause the two processes have differnt
instantiations of the object.Thanks in advance guys, I looked through
the demos, manuals, documentation, and the web, and couldnt find a
solution, you all are my last hope.

If anyone is curious this is how I fixed the general single instance
problem
class MyApp(wxApp):
    def __init__(self, params):
        self.params = params
        self.checker = btChecker( self.name)
        self.checker.setOwner(self)
        wxApp.__init__(self)
def main(params):
    print params
    checker = btChecker('PTC- ' + str(wxGetUserId()))
    if checker.IsAnotherRunning():
        checker.alreadyRunning(params)
    else:
        app = MyApp(params)
        app.MainLoop()
    
class btChecker(wxSingleInstanceChecker):
    def __init__(self, str):
        wxSingleInstanceChecker.__init__(self, str)
    def setOwner(self,owner):
        self.owner=owner
    def alreadyRunning(self, params):
        if params != []:
            self.owner.CheckFile(params[0])
        
if __name__ == '__main__':
    main(argv[1:])




More information about the Python-list mailing list