Commit 47aaa319 authored by sumpfralle's avatar sumpfralle

disabled RecentManager for Windows (due to a weird "no stock-icon found" error message)

fixed some more path issues
fixed path handling (local path to URI style) for RecentManager items


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@944 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e1d5e5da
...@@ -51,6 +51,7 @@ import gobject ...@@ -51,6 +51,7 @@ import gobject
import webbrowser import webbrowser
import ConfigParser import ConfigParser
import urllib import urllib
import urlparse
import string import string
import StringIO import StringIO
import pickle import pickle
...@@ -73,12 +74,12 @@ UI_SUBDIR = "ui" ...@@ -73,12 +74,12 @@ UI_SUBDIR = "ui"
FONTS_SUBDIR = "fonts" FONTS_SUBDIR = "fonts"
# necessary for "pyinstaller" # necessary for "pyinstaller"
if "_MEIPASS2" in os.environ: if "_MEIPASS2" in os.environ:
DATA_BASE_DIRS.insert(0, os.environ["_MEIPASS2"]) DATA_BASE_DIRS.insert(0, os.path.normpath(os.environ["_MEIPASS2"]))
# respect an override via an environment setting # respect an override via an environment setting
if DATA_DIR_ENVIRON_KEY in os.environ: if DATA_DIR_ENVIRON_KEY in os.environ:
DATA_BASE_DIRS.insert(0, os.environ[DATA_DIR_ENVIRON_KEY]) DATA_BASE_DIRS.insert(0, os.path.normpath(os.environ[DATA_DIR_ENVIRON_KEY]))
if FONT_DIR_ENVIRON_KEY in os.environ: if FONT_DIR_ENVIRON_KEY in os.environ:
FONT_DIR_OVERRIDE = os.environ[FONT_DIR_ENVIRON_KEY] FONT_DIR_OVERRIDE = os.path.normpath(os.environ[FONT_DIR_ENVIRON_KEY])
else: else:
FONT_DIR_OVERRIDE = None FONT_DIR_OVERRIDE = None
FONT_DIR_FALLBACK = "/usr/share/qcad/fonts" FONT_DIR_FALLBACK = "/usr/share/qcad/fonts"
...@@ -286,14 +287,20 @@ class ProjectGui: ...@@ -286,14 +287,20 @@ class ProjectGui:
# increase the initial width of the window (due to hidden elements) # increase the initial width of the window (due to hidden elements)
self.window.set_default_size(400, -1) self.window.set_default_size(400, -1)
# initialize the RecentManager # initialize the RecentManager
try: if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
self.recent_manager = gtk.RecentManager() # The pyinstaller binary for Windows fails mysteriously when trying
except AttributeError: # to display the stock item.
# GTK 2.12.1 seems to have problems with "RecentManager" on Windows. # Error message: Gtk:ERROR:gtkrecentmanager.c:1942:get_icon_fallback: assertion failed: (retval != NULL)
# Sadly this is the version, that is shipped with the "appunti" GTK
# packages for Windows (April 2010).
# see http://www.daa.com.au/pipermail/pygtk/2009-May/017052.html
self.recent_manager = None self.recent_manager = None
else:
try:
self.recent_manager = gtk.RecentManager()
except AttributeError:
# GTK 2.12.1 seems to have problems with "RecentManager" on
# Windows. Sadly this is the version, that is shipped with the
# "appunti" GTK packages for Windows (April 2010).
# see http://www.daa.com.au/pipermail/pygtk/2009-May/017052.html
self.recent_manager = None
# file loading # file loading
self.last_dirname = None self.last_dirname = None
self.last_task_settings_file = None self.last_task_settings_file = None
...@@ -1010,7 +1017,7 @@ class ProjectGui: ...@@ -1010,7 +1017,7 @@ class ProjectGui:
recent_files_menu.connect("item-activated", recent_files_menu.connect("item-activated",
self.load_recent_model_file) self.load_recent_model_file)
else: else:
self.gui.get_object("OpenRecentModel").hide() self.gui.get_object("OpenRecentModel").set_visible(False)
# load the menubar and connect functions to its items # load the menubar and connect functions to its items
self.menubar = uimanager.get_widget("/MenuBar") self.menubar = uimanager.get_widget("/MenuBar")
window_box = self.gui.get_object("WindowBox") window_box = self.gui.get_object("WindowBox")
...@@ -3717,8 +3724,14 @@ class ProjectGui: ...@@ -3717,8 +3724,14 @@ class ProjectGui:
if os.path.isfile(filename): if os.path.isfile(filename):
# skip this, if the recent manager is not available (e.g. GTK 2.12.1 on Windows) # skip this, if the recent manager is not available (e.g. GTK 2.12.1 on Windows)
if self.recent_manager: if self.recent_manager:
self.recent_manager.add_item("file://%s" \ # Convert the local path to a URI filename style. This is
% str(os.path.abspath(filename))) # specifically necessary under Windows (due to backslashs).
filename_url_local = urllib.pathname2url(
os.path.abspath(filename))
# join the "file:" scheme with the url
filename_url = urlparse.urlunparse(("file", None,
filename_url_local, None, None, None))
self.recent_manager.add_item(filename_url)
# store the directory of the last loaded file # store the directory of the last loaded file
self.last_dirname = os.path.dirname(os.path.abspath(filename)) self.last_dirname = os.path.dirname(os.path.abspath(filename))
......
...@@ -20,13 +20,21 @@ You should have received a copy of the GNU General Public License ...@@ -20,13 +20,21 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
__all__ = [ "iterators", "polynomials", "ProgressCounter", "threading"] __all__ = ["iterators", "polynomials", "ProgressCounter", "threading",
"get_platform", "get_external_program_location", "PLATFORM_WINDOWS",
"PLATFORM_MACOS", "PLATFORM_LINUX", "PLATFORM_UNKNOWN"]
import sys
import os import os
# this is imported below on demand # this is imported below on demand
#import win32com #import win32com
#import win32api #import win32api
PLATFORM_LINUX = 0
PLATFORM_WINDOWS = 1
PLATFORM_MACOS = 2
PLATFORM_UNKNOWN = 3
# setproctitle is (optionally) imported # setproctitle is (optionally) imported
try: try:
from setproctitle import setproctitle from setproctitle import setproctitle
...@@ -35,6 +43,17 @@ except ImportError: ...@@ -35,6 +43,17 @@ except ImportError:
setproctitle = lambda name: None setproctitle = lambda name: None
def get_platform():
if hasattr(sys, "getwindowsversion"):
return PLATFORM_WINDOWS
elif sys.platform == "darwin":
return PLATFORM_MACOS
elif sys.platform.startswith("linux"):
return PLATFORM_LINUX
else:
return PLATFORM_UNKNOWN
def get_external_program_location(key): def get_external_program_location(key):
extensions = ["", ".exe"] extensions = ["", ".exe"]
potential_names = ["%s%s" % (key, ext) for ext in extensions] potential_names = ["%s%s" % (key, ext) for ext in extensions]
......
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