X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Flyxpreview_tools.py;h=73dbc9a1f46cb8bf572869b1a300f2d573fbb9f9;hb=88fa0809788ac231fa9b040ee5fd9883476e4980;hp=272f3158de9b4c2d90324d4bff57f71d532634ce;hpb=f907db6a821148cb04e771f8f0bc11513931f911;p=lyx.git diff --git a/lib/scripts/lyxpreview_tools.py b/lib/scripts/lyxpreview_tools.py index 272f3158de..73dbc9a1f4 100644 --- a/lib/scripts/lyxpreview_tools.py +++ b/lib/scripts/lyxpreview_tools.py @@ -11,7 +11,7 @@ # Paul A. Rubin, rubin@msu.edu. # A repository of the following functions, used by the lyxpreview2xyz scripts. -# copyfileobj, error, find_exe, find_exe_or_terminate, mkstemp, +# copyfileobj, error, find_exe, find_exe_or_terminate, make_texcolor, mkstemp, # run_command, warning import os, re, string, sys, tempfile @@ -43,6 +43,22 @@ def error(message): sys.exit(1) +def make_texcolor(hexcolor, graphics): + # Test that the input string contains 6 hexadecimal chars. + hexcolor_re = re.compile("^[0-9a-fA-F]{6}$") + if not hexcolor_re.match(hexcolor): + error("Cannot convert color '%s'" % hexcolor) + + red = float(string.atoi(hexcolor[0:2], 16)) / 255.0 + green = float(string.atoi(hexcolor[2:4], 16)) / 255.0 + blue = float(string.atoi(hexcolor[4:6], 16)) / 255.0 + + if graphics: + return "%f,%f,%f" % (red, green, blue) + else: + return "rgb %f %f %f" % (red, green, blue) + + def find_exe(candidates, path): for prog in candidates: for directory in path: @@ -52,7 +68,11 @@ def find_exe(candidates, path): full_path = os.path.join(directory, prog) if os.access(full_path, os.X_OK): - return full_path + # The thing is in the PATH already (or we wouldn't + # have found it). Return just the basename to avoid + # problems when the path to the executable contains + # spaces. + return os.path.basename(full_path) return None