Commit a3fb5bec authored by sumpfralle's avatar sumpfralle

use installed qcad fonts if PyCAM's fonts are not found (useful for later...

use installed qcad fonts if PyCAM's fonts are not found (useful for later debian packaging - excluding the font files)
respect a PYCAM_FONT_DIR environment variable for locating font files


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@853 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e41dcffa
...@@ -10,6 +10,8 @@ lower margin (minx, miny, minz) of 10% (for x), 5% (for y) and \-10% (for z). ...@@ -10,6 +10,8 @@ lower margin (minx, miny, minz) of 10% (for x), 5% (for y) and \-10% (for z).
.IP PYCAM_DATA_DIR .IP PYCAM_DATA_DIR
Override the default data directory of PyCAM. This allows Override the default data directory of PyCAM. This allows
you to provide customized logos, menu files or non-default sample files. you to provide customized logos, menu files or non-default sample files.
.IP PYCAM_FONT_DIR
Override the default location of engrave fonts.
.IP PYTHONPATH .IP PYTHONPATH
You may want to define this variable in case that you installed the You may want to define this variable in case that you installed the
\fBPyCAM\fR python package in a non-default location. \fBPyCAM\fR python package in a non-default location.
...@@ -25,3 +27,5 @@ derived from this output. ...@@ -25,3 +27,5 @@ derived from this output.
Take a look at the wiki for more information about PyCAM: Take a look at the wiki for more information about PyCAM:
http://sourceforge.net/apps/mediawiki/pycam/ http://sourceforge.net/apps/mediawiki/pycam/
The website of the PyCAM project: http://pycam.sourceforge.net
...@@ -57,6 +57,7 @@ import os ...@@ -57,6 +57,7 @@ import os
import sys import sys
DATA_DIR_ENVIRON_KEY = "PYCAM_DATA_DIR" DATA_DIR_ENVIRON_KEY = "PYCAM_DATA_DIR"
FONT_DIR_ENVIRON_KEY = "PYCAM_FONT_DIR"
DATA_BASE_DIRS = [os.path.realpath(os.path.join(os.path.dirname(__file__), DATA_BASE_DIRS = [os.path.realpath(os.path.join(os.path.dirname(__file__),
os.pardir, os.pardir, os.pardir, "share")), os.pardir, os.pardir, os.pardir, "share")),
os.path.join(sys.prefix, "share", "pycam")] os.path.join(sys.prefix, "share", "pycam")]
...@@ -68,6 +69,11 @@ if "_MEIPASS2" in os.environ: ...@@ -68,6 +69,11 @@ if "_MEIPASS2" in os.environ:
# 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.environ[DATA_DIR_ENVIRON_KEY])
if FONT_DIR_ENVIRON_KEY in os.environ:
FONT_DIR_OVERRIDE = os.environ[FONT_DIR_ENVIRON_KEY]
else:
FONT_DIR_OVERRIDE = None
FONT_DIR_FALLBACK = "/usr/share/qcad/fonts"
GTKBUILD_FILE = os.path.join(UI_SUBDIR, "pycam-project.ui") GTKBUILD_FILE = os.path.join(UI_SUBDIR, "pycam-project.ui")
GTKMENU_FILE = os.path.join(UI_SUBDIR, "menubar.xml") GTKMENU_FILE = os.path.join(UI_SUBDIR, "menubar.xml")
...@@ -163,12 +169,32 @@ def get_filters_from_list(filter_list, file_filter=True): ...@@ -163,12 +169,32 @@ def get_filters_from_list(filter_list, file_filter=True):
result.append(file_filter) result.append(file_filter)
return result return result
def get_font_files(): def get_font_dir():
if FONT_DIR_OVERRIDE:
if os.path.isdir(FONT_DIR_OVERRIDE):
return FONT_DIR_OVERRIDE
else:
log.warn(("You specified a font dir that does not exist (%s). " \
+ "I will ignore it.") % FONT_DIR_OVERRIDE)
font_dir = get_data_file_location(FONTS_SUBDIR, silent=True) font_dir = get_data_file_location(FONTS_SUBDIR, silent=True)
if font_dir is None: if not font_dir is None:
log.warn("Failed to locate the fonts directory '%s' below '%s'." \ return font_dir
% (FONTS_SUBDIR, DATA_BASE_DIRS)) else:
log.warn(("Failed to locate the fonts directory '%s' below '%s'. " \
+ "Falling back to '%s'.") \
% (FONTS_SUBDIR, DATA_BASE_DIRS, FONT_DIR_FALLBACK))
if os.path.isdir(FONT_DIR_FALLBACK):
return FONT_DIR_FALLBACK
else:
log.warn(("The fallback font directory (%s) does not exist. " \
+ "No fonts will be available.") % FONT_DIR_FALLBACK)
return None
def get_font_files():
font_dir = get_font_dir()
if not font_dir:
return [] return []
log.info("Loading font files from '%s'." % font_dir)
result = [] result = []
files = os.listdir(font_dir) files = os.listdir(font_dir)
for fname in files: for fname in files:
...@@ -1603,7 +1629,7 @@ class ProjectGui: ...@@ -1603,7 +1629,7 @@ class ProjectGui:
self.gui.get_object("FontSelectionBox").pack_start( self.gui.get_object("FontSelectionBox").pack_start(
font_selector, expand=False, fill=False) font_selector, expand=False, fill=False)
sorted_keys = self._fonts.keys() sorted_keys = self._fonts.keys()
sorted_keys.sort() sorted_keys.sort(key=lambda x: x.upper())
for name in sorted_keys: for name in sorted_keys:
font_selector.append_text(name) font_selector.append_text(name)
if sorted_keys: if sorted_keys:
......
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