Problem locating icons for standalone applications generated by cx_freeze/py2exe
- Dominant language
- Python
- Stars
- 462
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Description
When running traits from a standalone executable, icons are expected to be found inside the executable itself. This is because of the statement
"dirname(getattr( sys.modules.get( module ), '**file**' ))" which is used to get the path to the icon folder. The assumption is that the icons resides in subfolders of the module folder (i.e. 'traitsui\image' and 'traitsui\wx\images').
When generating a standalone executable, it is convenient to have the icons in a folder OUTSIDE the executable file. Thus, the function get_resource_path in 'traits\traitbase.py' has to be modified. The code below is a proposal on how that could be done (see also enthought/pyface#116):
```
def get_resource_path ( level = 2 ):
"""Returns a resource path calculated from the caller's stack.
"""
module = sys._getframe( level ).f_globals.get( '__name__', '__main__' )
if module != '__main__':
# Return the path to the module:
try:
path = dirname(getattr( sys.modules.get( module ), '__file__' ))
except:
# Apparently 'module' is not a registered module...treat it like
# '__main__':
pass
else:
if hasattr(sys, 'frozen'):
app_dir, app_name = os.path.split(sys.executable)
sub_dir = path.replace(sys.executable, '')
path = ''.join(app_dir, sub_dir)
return path
# '__main__' is not a real module, so we need a work around:
for path in [ dirname( sys.argv[0] ), getcwd() ]:
if exists( path ):
break
return path
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.