From 249f874ab84d34b5d5a86aa2d127f39d5e2a4b5a Mon Sep 17 00:00:00 2001 From: sumpfralle Date: Sun, 12 Jun 2011 18:15:34 +0000 Subject: [PATCH] merged r1083 (added GTK for Windows) git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1089 bbaffbd6-741e-11dd-a85d-61de82d9cad9 --- Changelog | 1 + pyinstaller/pycam.spec | 34 ++++++++++++++++++-- share/ui/gtkrc_windows | 68 ++++++++++++++++++++++++++++++++++++++++ src/pycam/Gui/Project.py | 7 +++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 share/ui/gtkrc_windows diff --git a/Changelog b/Changelog index 631ddf90..ffb7b594 100644 --- a/Changelog +++ b/Changelog @@ -3,6 +3,7 @@ Version 0.5.1 - UNRELEASED * 2D projection of multi-layered 2D models * significantly improved performance of 3D visualization * fixed "help" links for Windows users + * added GTK theme with a native look&feel for Windows * improved detection of library locations for Windows package * minor bugs fixed diff --git a/pyinstaller/pycam.spec b/pyinstaller/pycam.spec index c1e9d0ec..d5d02219 100644 --- a/pyinstaller/pycam.spec +++ b/pyinstaller/pycam.spec @@ -26,6 +26,7 @@ else: data = [(os.path.join(UI_DATA_RELATIVE, "pycam-project.ui"), os.path.join(UI_DATA_DIR, "pycam-project.ui"), "DATA"), (os.path.join(UI_DATA_RELATIVE, "menubar.xml"), os.path.join(UI_DATA_DIR, "menubar.xml"), "DATA"), (os.path.join(UI_DATA_RELATIVE, "logo_gui.png"), os.path.join(UI_DATA_DIR, "logo_gui.png"), "DATA"), + (os.path.join(UI_DATA_RELATIVE, "gtkrc_windows"), os.path.join(UI_DATA_DIR, "gtkrc_windows"), "DATA"), ] # sample models @@ -41,13 +42,13 @@ if get_platform() == PLATFORM_WINDOWS: start_dirs = (os.path.join(os.environ["PROGRAMFILES"], "Common files", "Gtk"), os.path.join(os.environ["COMMONPROGRAMFILES"], "Gtk"), r"C:\\") - def find_gtk_pixbuf_dir(dirs): + def find_filename_below_dirs(dirs, filename): for start_dir in dirs: for root, dirs, files in os.walk(start_dir): - if "libpixbufloader-png.dll" in files: + if filename in files: return root return None - gtk_loaders_dir = find_gtk_pixbuf_dir(start_dirs) + gtk_loaders_dir = find_filename_below_dirs(start_dirs, "libpixbufloader-png.dll") if gtk_loaders_dir is None: print >>sys.stderr, "Failed to locate Gtk installation (looking for libpixbufloader-png.dll)" #sys.exit(1) @@ -69,6 +70,33 @@ if get_platform() == PLATFORM_WINDOWS: gtk_pixbuf_config_file = os.path.join(config_dir, config_relative) data.append((config_relative, os.path.join(config_dir, config_relative), "DATA")) + + # look for the GTK theme "MS-Windows" + # the required gtkrc file is loaded during startup + import _winreg + try: + k = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\GTK2-Runtime') + except EnvironmentError: + print "Failed to detect the GTK2 runtime environment - the Windows theme will be missing" + gtkdir = None + else: + gtkdir = str(_winreg.QueryValueEx(k, 'InstallationDirectory')[0]) + + if gtkdir: + # we only need this dll file + wimp_engine_file = "libwimp.dll" + engine_dir = find_filename_below_dirs([gtkdir], wimp_engine_file) + if engine_dir: + if engine_dir.startswith(gtkdir): + relative_engine_dir = engine_dir[len(gtkdir):] + else: + relative_engine_dir = engine_dir + engine_dll = os.path.join(engine_dir, wimp_engine_file) + relative_engine_dll = os.path.join(relative_engine_dir, + wimp_engine_file) + data.append((relative_engine_dll, engine_dll, "BINARY")) + + # somehow we need to add glut32.dll manually def find_glut32(start_dir, filename="glut32.dll"): for root, dirs, files in os.walk(start_dir): diff --git a/share/ui/gtkrc_windows b/share/ui/gtkrc_windows new file mode 100644 index 00000000..f79f72b2 --- /dev/null +++ b/share/ui/gtkrc_windows @@ -0,0 +1,68 @@ +gtk-theme-name = "MS-Windows" + +gtk-icon-sizes = "gtk-menu=13,13:gtk-small-toolbar=16,16:gtk-large-toolbar=24,24:gtk-dnd=32,32" +gtk-toolbar-icon-size = small-toolbar + +# disable images in buttons. i've only seen ugly delphi apps use this feature. +gtk-button-images = 0 + +# enable/disable images in menus. most "stock" microsoft apps don't use these, except sparingly. +# the office apps use them heavily, though. +gtk-menu-images = 1 + +# use the win32 button ordering instead of the GNOME HIG one, where applicable +gtk-alternative-button-order = 1 + +# use the win32 sort indicators direction, as in Explorer +gtk-alternative-sort-arrows = 1 + +# Windows users don't expect the PC Speaker beeping at them when they backspace in an empty textview and stuff like that +gtk-error-bell = 0 + +style "msw-default" +{ + GtkWidget::interior-focus = 1 + GtkOptionMenu::indicator-size = { 9, 5 } + GtkOptionMenu::indicator-spacing = { 7, 5, 2, 2 } + GtkSpinButton::shadow-type = in + + # Owen and I disagree that these should be themable + #GtkUIManager::add-tearoffs = 0 + #GtkComboBox::add-tearoffs = 0 + + GtkComboBox::appears-as-list = 1 + GtkComboBox::focus-on-click = 0 + + GOComboBox::add_tearoffs = 0 + + GtkTreeView::allow-rules = 0 + GtkTreeView::expander-size = 12 + + GtkExpander::expander-size = 12 + + GtkScrolledWindow::scrollbar_spacing = 1 + + GtkSeparatorMenuItem::horizontal-padding = 2 + + engine "wimp" + { + } +} +class "*" style "msw-default" + +binding "ms-windows-tree-view" +{ + bind "Right" { "expand-collapse-cursor-row" (1,1,0) } + bind "Left" { "expand-collapse-cursor-row" (1,0,0) } +} + +class "GtkTreeView" binding "ms-windows-tree-view" + +style "msw-combobox-thickness" = "msw-default" +{ + xthickness = 0 + ythickness = 0 +} + +widget_class "*TreeView*ComboBox*" style "msw-combobox-thickness" +widget_class "*ComboBox*GtkFrame*" style "msw-combobox-thickness" diff --git a/src/pycam/Gui/Project.py b/src/pycam/Gui/Project.py index 9d992f05..5103af15 100755 --- a/src/pycam/Gui/Project.py +++ b/src/pycam/Gui/Project.py @@ -72,6 +72,7 @@ GTKBUILD_FILE = "pycam-project.ui" GTKMENU_FILE = "menubar.xml" +GTKRC_FILE_WINDOWS = os.path.join(UI_SUBDIR, "gtkrc_windows") WINDOW_ICON_FILENAMES = ["logo_%dpx.png" % pixels for pixels in (16, 32, 48, 64, 128)] @@ -345,6 +346,12 @@ def __init__(self, no_dialog=False): if gtk_build_file is None: gtk.main_quit() self.gui.add_from_file(gtk_build_file) + if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS: + gtkrc_file = get_data_file_location(GTKRC_FILE_WINDOWS) + if gtkrc_file: + print "GTKRC: %s" % str(gtkrc_file) + gtk.rc_add_default_file(gtkrc_file) + gtk.rc_reparse_all_for_settings(gtk.settings_get_default(), True) self.window = self.gui.get_object("ProjectWindow") # show stock items on buttons # increase the initial width of the window (due to hidden elements)