Commit e69391f9 authored by sumpfralle's avatar sumpfralle

added fonts and GTK themes to the binary


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@945 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 47aaa319
# -*- mode: python -*- # -*- mode: python -*-
BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(locals()["spec"]), BASE_DIR = os.path.realpath(os.path.join(os.path.dirname(locals()["spec"]),
os.path.pardir)) os.path.pardir))
UI_DATA_DIR = os.path.join(BASE_DIR, "share", "ui") UI_DATA_RELATIVE = os.path.join("share", "ui")
UI_DATA_DIR = os.path.join(BASE_DIR, UI_DATA_RELATIVE)
data = [("pycam-project.ui", os.path.join(UI_DATA_DIR, "pycam-project.ui"), "DATA"), data = [(os.path.join(UI_DATA_RELATIVE, "pycam-project.ui"), os.path.join(UI_DATA_DIR, "pycam-project.ui"), "DATA"),
("menubar.xml", os.path.join(UI_DATA_DIR, "menubar.xml"), "DATA"), (os.path.join(UI_DATA_RELATIVE, "menubar.xml"), os.path.join(UI_DATA_DIR, "menubar.xml"), "DATA"),
("logo_gui.png", os.path.join(UI_DATA_DIR, "logo_gui.png"), "DATA"), (os.path.join(UI_DATA_RELATIVE, "logo_gui.png"), os.path.join(UI_DATA_DIR, "logo_gui.png"), "DATA"),
] ]
# look for the location of "libpixbufloader-png.dll" (for Windows standalone executable) # look for the location of "libpixbufloader-png.dll" (for Windows standalone executable)
start_dirs = (os.path.join(os.environ["PROGRAMFILES"], "Common files", "Gtk"), start_dirs = (os.path.join(os.environ["PROGRAMFILES"], "Common files", "Gtk"),
os.path.join(os.environ["COMMONPROGRAMFILES"], "Gtk")) os.path.join(os.environ["COMMONPROGRAMFILES"], "Gtk"),
"C:\\")
def find_gtk_pixbuf_dir(dirs): def find_gtk_pixbuf_dir(dirs):
for start_dir in dirs: for start_dir in dirs:
for root, dirs, files in os.walk(start_dir): for root, dirs, files in os.walk(start_dir):
if "libpixbufloader-png.dll" in files: if "libpango-1.0-0.dll" in files:
return root return root
return None return None
gtk_loaders_dir = find_gtk_pixbuf_dir(start_dirs) gtk_loaders_dir = find_gtk_pixbuf_dir(start_dirs)
if gtk_loaders_dir is None: if gtk_loaders_dir is None:
print >>sys.stderr, "Failed to locate Gtk installation (looking for libpixbufloader-png.dll)" print >>sys.stderr, "Failed to locate Gtk installation (looking for libpixbufloader-png.dll)"
sys.exit(1) #sys.exit(1)
gtk_loaders_dir = start_dirs[0]
# configure the pixbufloader (for the Windows standalone executable) # configure the pixbufloader (for the Windows standalone executable)
config_dir = gtk_loaders_dir config_dir = gtk_loaders_dir
config_relative = os.path.join("etc", "gtk-2.0", "gdk-pixbuf.loaders") config_relative = os.path.join("etc", "gtk-2.0", "gdk-pixbuf.loaders")
while not os.path.isfile(os.path.join(config_dir, config_relative)): while not os.path.isfile(os.path.join(config_dir, config_relative)):
config_dir = os.path.dirname(config_dir) new_config_dir = os.path.dirname(config_dir)
if not config_dir: if (not new_config_dir) or (new_config_dir == config_dir):
print >>sys.stderr, "Failed to locate '%s' around '%s'" \ print >>sys.stderr, "Failed to locate '%s' around '%s'" \
% (config_relative, gtk_loaders_dir) % (config_relative, gtk_loaders_dir)
config_dir = None
break
config_dir = new_config_dir
gtk_pixbuf_config_file = os.path.join(config_dir, config_relative) if config_dir:
data.append((config_relative, os.path.join(config_dir, config_relative), "DATA")) gtk_pixbuf_config_file = os.path.join(config_dir, config_relative)
data.append((config_relative, os.path.join(config_dir, config_relative), "DATA"))
# somehow we need to add glut32.dll manually # somehow we need to add glut32.dll manually
more_libs = [] more_libs = []
glut32_dll = os.path.join(config_dir, "bin", "glut32.dll")
more_libs.append((os.path.basename(glut32_dll), glut32_dll, "BINARY")) def find_glut32(start_dir, filename="glut32.dll"):
for root, dirs, files in os.walk(start_dir):
if filename in files:
return os.path.join(root, filename)
return None
glut32_dll = find_glut32(sys.prefix)
if glut32_dll:
more_libs.append((os.path.basename(glut32_dll), glut32_dll, "BINARY"))
more_libs.append(("msjava.dll", "msjava.dll", "BINARY"))
def get_pixbuf_loaders_prefix(gtk_loaders_dir): def get_pixbuf_loaders_prefix(gtk_loaders_dir):
prefix = [] prefix = []
...@@ -46,7 +62,7 @@ def get_pixbuf_loaders_prefix(gtk_loaders_dir): ...@@ -46,7 +62,7 @@ def get_pixbuf_loaders_prefix(gtk_loaders_dir):
prefix.append(path_splits.pop()) prefix.append(path_splits.pop())
if prefix[-1].lower() == "lib": if prefix[-1].lower() == "lib":
prefix.reverse() prefix.reverse()
return "\\".join(prefix) #return "\\".join(prefix)
return os.path.join(*prefix) return os.path.join(*prefix)
else: else:
return None return None
...@@ -54,24 +70,59 @@ def get_pixbuf_loaders_prefix(gtk_loaders_dir): ...@@ -54,24 +70,59 @@ def get_pixbuf_loaders_prefix(gtk_loaders_dir):
gtk_pixbuf_loaders_prefix = get_pixbuf_loaders_prefix(gtk_loaders_dir) gtk_pixbuf_loaders_prefix = get_pixbuf_loaders_prefix(gtk_loaders_dir)
if gtk_pixbuf_loaders_prefix is None: if gtk_pixbuf_loaders_prefix is None:
print >>sys.stderr, "Failed to extract the prefix from '%s'" % gtk_loaders_dir print >>sys.stderr, "Failed to extract the prefix from '%s'" % gtk_loaders_dir
sys.exit(1) gtk_pixbuf_loaders = []
gtk_pixbuf_loaders = Tree(gtk_loaders_dir, prefix=gtk_pixbuf_loaders_prefix) else:
gtk_pixbuf_loaders = Tree(gtk_loaders_dir, prefix=gtk_pixbuf_loaders_prefix)
# import VERSION for the output filename # import VERSION for the output filename
sys.path.insert(0, os.path.join(BASE_DIR, "src")) sys.path.insert(0, os.path.join(BASE_DIR, "src"))
from pycam import VERSION from pycam import VERSION
samples = Tree(os.path.join(BASE_DIR, "samples"), prefix="samples") samples = Tree(os.path.join(BASE_DIR, "samples"), prefix="samples")
fonts = Tree(os.path.join(BASE_DIR, "share", "fonts"), prefix=os.path.join("share", "fonts"))
# First we have to know where gtk is installed, we get this from registry
import _winreg
import msvcrt
try:
k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\GTK2-Runtime')
except EnvironmentError:
print 'You must install the Gtk+ 2.2 Runtime Environment to run this program'
while not msvcrt.kbhit():
pass
sys.exit(1)
else:
gtkdir = str(_winreg.QueryValueEx(k, 'InstallationDirectory')[0])
gtkversion = str(_winreg.QueryValueEx(k, 'BinVersion')[0])
# TODO: fix this hard-coded path
engines_dir = os.path.normpath("C:/Python26/Lib/site-packages/gtk-2.0/runtime/lib/gtk-2.0/2.10.0/engines")
if not os.path.isdir(engines_dir):
print "Failed to locate the engines directory: %s" % str(engines_dir)
sys.exit(1)
#Then we want to go to the directory where the gtkrcfile is located
gtkrc_dir = os.path.join('share', 'themes', 'MS-Windows', 'gtk-2.0')
if not os.path.isdir(gtkrc_dir):
gtkrc_dir = os.path.normpath("C:/Python26/Lib/site-packages/gtk-2.0/runtime/share/themes/MS-Windows/gtk-2.0")
#Add gtkrc file to exe
data.append(('gtkrc', os.path.join(gtkdir, gtkrc_dir, 'gtkrc'), 'DATA'))
#Add libwimp.dll to exe (needed for the MS-Windows theme)
more_libs.append(('libwimp.dll', os.path.join(gtkdir, engines_dir, 'libwimp.dll'), 'BINARY'))
themes = Tree(os.path.join(gtkrc_dir, os.pardir, os.pardir, os.pardir, "icons"),
prefix=os.path.join("share", "icons"))
icon_file = os.path.join(BASE_DIR, "share", "pycam.ico") icon_file = os.path.join(BASE_DIR, "share", "pycam.ico")
a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), os.path.join(BASE_DIR, 'pycam')], a = Analysis([os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), os.path.join(BASE_DIR, 'pycam'), os.path.join(BASE_DIR, "src", "use_gtk.py")],
pathex=[os.path.join(BASE_DIR, "src")], pathex=[os.path.join(BASE_DIR, "src")],
hookspath=[os.path.join(BASE_DIR, "pyinstaller", "hooks")]) hookspath=[os.path.join(BASE_DIR, "pyinstaller", "hooks")])
pyz = PYZ(a.pure) pyz = PYZ(a.pure)
exe = EXE(pyz, data, samples, gtk_pixbuf_loaders, exe = EXE(pyz, data, samples, gtk_pixbuf_loaders, themes, fonts,
a.scripts, a.scripts,
a.binaries + more_libs, a.binaries + more_libs,
a.zipfiles, a.zipfiles,
...@@ -81,6 +132,6 @@ exe = EXE(pyz, data, samples, gtk_pixbuf_loaders, ...@@ -81,6 +132,6 @@ exe = EXE(pyz, data, samples, gtk_pixbuf_loaders,
debug=False, debug=False,
strip=False, strip=False,
upx=True, upx=True,
console=False, console=True,
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment