December 2nd, 2010, 09:32 AM
wxPython using xrc
i have an assignment and i would like to know, if it is possible to perform the folowing :
my task is to create a GUI window, and i would like to generate the gui by using the XRC files.
in my gui i represent different versions of a specific product, the sceleton of each build is ident but the difference is in the checked parameters of each version.
i gut a suggestion that i will create a form for every version exists and when a speccific version is "called" i'll just upload the form from the xrc file.
THE BIG PROBLEM IS: that while the program is running NEW version can be created.
if there is a new version I NEED a NEW FORM/WINDOW, and after a new version is created i also need to save the new configuration in the xrc file.
IS IT POSSIBLE and if the question is yes the HOW can i do it?
thank you all in advance
December 7th, 2010, 08:10 PM
Re: wxPython using xrc
I would think it would be possible..
A python program could theoretically detect the presence of a new xrc resource file, and basically restart itself when it did. Windows, Mac and Linux each have methods for notifying a running program that a particular file or directory of files has changed on disk. I'm pretty sure Python has a way of harnessing it, I'd have to research it, but I'd start by google'ing "Python iNotify". At the very worst, you'd have to create a separate thread that was just using os (the module os) stuff to check for a new version of the xrc file every second or something, that could add a message to the wxPython message queue when it detected a new version. Then a handler could be set up to handle that message, and quit the wxPython part of the program, so that it could be restarted using the new version of the xrc file.
There are a number of possible ways for a python program to basically restart itself (and reload an xrc) after it has quit. One is by having the main program launch a child process, and wait for the child process to exit, and then just restart that process if it exited with a particular exit status code. Another way is to have a launching module that wraps a main module, and reimport that main module. For example, import a mainframe module, and call mainframe.launch() in a loop that checks the result to see if it should keep looping. Then the launch() function would call app.MainLoop(), and return False if the program should actually exit. Something like that.
As an alternative to fully restarting the whole UI, a wxPython itself may have an iNotify api that can raise a wxPython message/event when a particular file as changed. It may also have a way of loading an xrc interface into a particular window (for example the main window). That would probably be the best way to do it, just hook up the inotify event to a function that clears the main window (of all children, etc) and loads an xrc-defined interface into it. I'm not sure if wxPython has those capabilities, but I wouldn't be at all surprised to find that it did, and it shouldn't be too hard to find out, just google wxPython iNotify, and wxPython XRC window.
Hope that helps, have fun. =)
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!