From: Kevin A. <al...@se...> - 2004-09-17 15:51:18
|
On Sep 10, 2004, at 4:18 PM, Kevin Altis wrote: > On Sep 10, 2004, at 12:12 PM, bartek wilczynski wrote: > >> Hi, >> >> When I'm opening a child window, which is a pythonCard Alocated in >> different >> directory, the PythonCard jumps to that directory. As my application >> involves a >> lot of it, it becomes annoying to track "where am I". >> >> Is there any possibility of opening a child window without changing >> the current >> directory ?. >> -- >> greetings >> Bartek > > It could be done, but I'm not sure if it would be consistent since > there is an explicit chdir done for the main background window, and > child windows are just another window that just happen to have a > parent. This could be problematic for the on_initialize handler in > particular if it makes assumptions about the current working directory > being the same as the module directory... Anyway, I can see pro and > con arguments. > > In the meantime, you can just make your own childWindow wrapper > function that you call instead of the one in model.py. You can either > provide the args as shown below or just use *args and *kwargs for the > arg list. > > def childWindow(parent, frameClass, filename=None, rsrc=None): > cwd = os.getcwd() > model.childWindow(parent, frameClass, filename, rsrc) > os.chdir(cwd) > > Also, in case you didn't know, self.application.applicationDirectory > is the directory that contains your main source file in case you ever > need to jump back there or make a relative path change. > I just realized that the code above doesn't actually work, because I didn't return the result, so it should be: def childWindow(parent, frameClass, filename=None, rsrc=None): cwd = os.getcwd() background = model.childWindow(parent, frameClass, filename, rsrc) os.chdir(cwd) return background Assuming that the on_initialize handler in the child window isn't going to need to make references to files in the directory of the child source and resource files. If it does need to make a reference, then you would need to do something like: def childWindow(parent, frameClass, filename=None, rsrc=None): cwd = os.getcwd() wx.CallAfter(os.chdir, cwd) return model.childWindow(parent, frameClass, filename, rsrc) I haven't tested either of the above, but they look correct. ka |