]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/lyxpreview_tools.py
Question environments, from Russ Woodroofe.
[lyx.git] / lib / scripts / lyxpreview_tools.py
index f3077e210107ffd15e7914da2999f4fdd7df6440..73dbc9a1f46cb8bf572869b1a300f2d573fbb9f9 100644 (file)
@@ -1,4 +1,4 @@
-#! /usr/bin/env python -tt
+#! /usr/bin/env python
 
 # file lyxpreview_tools.py
 # This file is part of LyX, the document processor.
@@ -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: