Hi all
I'm using wxDesigner and I'm trying to separate dialogs in various folders and subfolders, creating separate wdr files in each directory.
If I put an image in a control, wxDesigner manages it transforming into a png and putting the png in the subfoder called dialog_wdr. This all works fine since I run the (sub-module) script from within the folder that contains it; but if I try to import and call the dialog from an upper level script, there are no chances to get image mechanism used by wxDesigner to work.
In this case wx.Image("dialog_wdr/pngfile.png"...) doesn't find the png simply because searching in a folder that is not found on the upperlevel script folder.
How can I make the script independant from image location, remembering I cannot touch code generated by wxDesigner?
TIA
Fabio
Robin Dunn wrote:
jfabio wrote:
Hi all
I'm using wxDesigner and I'm trying to separate dialogs in various folders and subfolders, creating separate wdr files in each directory.
If I put an image in a control, wxDesigner manages it transforming into a png and putting the png in the subfoder called dialog_wdr. This all works fine since I run the (sub-module) script from within the folder that contains it; but if I try to import and call the dialog from an upper level script, there are no chances to get image mechanism used by wxDesigner to work.
In this case wx.Image("dialog_wdr/pngfile.png"...) doesn't find the png simply because searching in a folder that is not found on the upperlevel script folder.
How can I make the script independant from image location, remembering I cannot touch code generated by wxDesigner?One way is use os.chdir to change the current working directory to where the relative path will work. Another way is to replace the wxDesigner generated function that loads the images with one that you write that does the Right Thing. Yet another way is to get Robert (the wxDesigner author) to change it such that img2py is used to create a .py file with the images embedded within it, then it won't matter where things are located or what the CWD is as long as you can import the module.
Hi Robin, thanks for your reply
Yes, I've found solution in the chdir way. But this is not applicable in generated code, because wxDesigner doesn't permit to change that piece of code.
Imagine this structure:
maindir
__main__
mainclasses
subdir1
__init__
subdir1classes
subdir1_wdr
subdir2
__init__
subdir2classes
subdir2_wdr
etc.
In this scenario, each subdirXXX wxDesigner classes works fine (note: from the bitmap load point of view) if executed standalone and from appropriate subdir directory; problem come calling these classes from the topwindow: in this case, current dir is the maindir, so bmp material is not found.
The only solution I've found is to put all the subdir_wdr folders in the maindir folder.
This help in that direction, altough I don't like because there is a proliferation of directories at the top level that are relative only to images, and it should be better if each images subdir could stay where it would stay (hoping to use appropriate verbs in my macaronic english
I don't know wath img2py does, I will look for tha func.
Many thanks
Fabio