Fix bug #7657: Detect inkscape from the configure script

On Windows, if inkscape is not found in the PATH, search for it
in the registry and store its full path in lyxrc.defaults.
This commit is contained in:
Enrico Forestieri 2015-11-02 23:46:14 +01:00
parent f3c3e1bccd
commit f8bfc8405e
2 changed files with 43 additions and 15 deletions

View File

@ -229,7 +229,7 @@ def checkProg(description, progs, rc_entry = [], path = [], not_found = ''):
for searching but the whole string is used to replace for searching but the whole string is used to replace
%% for a rc_entry. So, feel free to add '$$i' etc for programs. %% for a rc_entry. So, feel free to add '$$i' etc for programs.
path: additional pathes path: additional paths (will be prepended to the program name)
rc_entry: entry to outfile, can be rc_entry: entry to outfile, can be
1. emtpy: no rc entry will be added 1. emtpy: no rc entry will be added
@ -278,6 +278,8 @@ def checkProg(description, progs, rc_entry = [], path = [], not_found = ''):
ac_prog = ac_prog.replace(ac_word, r'%s -jar \"%s\"' % (java, os.path.join(ac_dir, ac_word))) ac_prog = ac_prog.replace(ac_word, r'%s -jar \"%s\"' % (java, os.path.join(ac_dir, ac_word)))
elif ac_word.endswith('.pl'): elif ac_word.endswith('.pl'):
ac_prog = ac_prog.replace(ac_word, r'%s -w \"%s\"' % (perl, os.path.join(ac_dir, ac_word))) ac_prog = ac_prog.replace(ac_word, r'%s -w \"%s\"' % (perl, os.path.join(ac_dir, ac_word)))
elif ac_dir in additional_path:
ac_prog = ac_prog.replace(ac_word, r'\"%s\"' % (os.path.join(ac_dir, ac_word)))
# write rc entries for this command # write rc entries for this command
if len(rc_entry) == 1: if len(rc_entry) == 1:
addToRC(rc_entry[0].replace('%%', ac_prog)) addToRC(rc_entry[0].replace('%%', ac_prog))
@ -337,6 +339,8 @@ def checkProgAlternatives(description, progs, rc_entry = [], alt_rc_entry = [],
ac_prog = ac_prog.replace(ac_word, r'%s -jar \"%s\"' % (java, os.path.join(ac_dir, ac_word))) ac_prog = ac_prog.replace(ac_word, r'%s -jar \"%s\"' % (java, os.path.join(ac_dir, ac_word)))
elif ac_word.endswith('.pl'): elif ac_word.endswith('.pl'):
ac_prog = ac_prog.replace(ac_word, r'%s -w \"%s\"' % (perl, os.path.join(ac_dir, ac_word))) ac_prog = ac_prog.replace(ac_word, r'%s -w \"%s\"' % (perl, os.path.join(ac_dir, ac_word)))
elif ac_dir in additional_path:
ac_prog = ac_prog.replace(ac_word, r'\"%s\"' % (os.path.join(ac_dir, ac_word)))
# write rc entries for this command # write rc entries for this command
if found_prime == False: if found_prime == False:
if len(rc_entry) == 1: if len(rc_entry) == 1:
@ -468,6 +472,23 @@ def checkDTLtools():
dtl_tools = False dtl_tools = False
return dtl_tools return dtl_tools
def checkInkscape():
''' Check whether Inkscape is available and return the full path (Windows only) '''
if os.name != 'nt':
return 'inkscape'
import _winreg
aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_CLASSES_ROOT)
try:
aKey = _winreg.OpenKey(aReg, r"inkscape.svg\DefaultIcon")
val = _winreg.QueryValueEx(aKey, "")
return str(val[0]).split('"')[1].replace('.exe', '')
except EnvironmentError:
try:
aKey = _winreg.OpenKey(aReg, r"Applications\inkscape.exe\shell\open\command")
val = _winreg.QueryValueEx(aKey, "")
return str(val[0]).split('"')[1].replace('.exe', '')
except EnvironmentError:
return 'inkscape'
def checkLatex(dtl_tools): def checkLatex(dtl_tools):
''' Check latex, return lyx_check_config ''' ''' Check latex, return lyx_check_config '''
@ -583,8 +604,9 @@ def checkFormatEntries(dtl_tools):
checkViewerEditor('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'], checkViewerEditor('a FEN viewer and editor', ['xboard -lpf $$i -mode EditPosition'],
rc_entry = [r'\Format fen fen FEN "" "%%" "%%" "" ""']) rc_entry = [r'\Format fen fen FEN "" "%%" "%%" "" ""'])
# #
checkViewerEditor('a SVG viewer and editor', ['inkscape'], checkViewerEditor('a SVG viewer and editor', [inkscape_name],
rc_entry = [r'\Format svg "svg, svgz" SVG "" "%%" "%%" "vector,zipped=native" "image/svg+xml"']) rc_entry = [r'\Format svg "svg, svgz" SVG "" "%%" "%%" "vector,zipped=native" "image/svg+xml"'],
path = [inkscape_path])
# #
imageformats = r'''\Format bmp bmp BMP "" "%s" "%s" "" "image/x-bmp" imageformats = r'''\Format bmp bmp BMP "" "%s" "%s" "" "image/x-bmp"
\Format gif gif GIF "" "%s" "%s" "" "image/gif" \Format gif gif GIF "" "%s" "%s" "" "image/gif"
@ -972,14 +994,17 @@ def checkConverterEntries():
checkProg('an OpenDocument -> EPS converter', ['libreoffice -headless -nologo -convert-to eps $$i', 'unoconv -f eps --stdout $$i > $$o'], checkProg('an OpenDocument -> EPS converter', ['libreoffice -headless -nologo -convert-to eps $$i', 'unoconv -f eps --stdout $$i > $$o'],
rc_entry = [ r'\converter odg eps2 "%%" ""']) rc_entry = [ r'\converter odg eps2 "%%" ""'])
# Only define a converter to pdf6 for graphics # Only define a converter to pdf6 for graphics
checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', 'inkscape --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'], checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
rc_entry = [ r'\converter svg pdf6 "%%" ""']) rc_entry = [ r'\converter svg pdf6 "%%" ""'],
path = ['', inkscape_path])
# #
checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', 'inkscape --file=$$i --export-area-drawing --without-gui --export-eps=$$o'], checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_name + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
rc_entry = [ r'\converter svg eps "%%" ""']) rc_entry = [ r'\converter svg eps "%%" ""'],
path = ['', inkscape_path])
# #
checkProg('a SVG -> PNG converter', ['rsvg-convert -f png -o $$o $$i', 'inkscape --without-gui --file=$$i --export-png=$$o'], checkProg('a SVG -> PNG converter', ['rsvg-convert -f png -o $$o $$i', inkscape_name + ' --without-gui --file=$$i --export-png=$$o'],
rc_entry = [ r'\converter svg png "%%" ""']) rc_entry = [ r'\converter svg png "%%" ""'],
path = ['', inkscape_path])
# #
# gnumeric/xls/ods to tex # gnumeric/xls/ods to tex
@ -1564,6 +1589,7 @@ Format %i
# check java and perl before any checkProg that may require them # check java and perl before any checkProg that may require them
java = checkProg('a java interpreter', ['java'])[1] java = checkProg('a java interpreter', ['java'])[1]
perl = checkProg('a perl interpreter', ['perl'])[1] perl = checkProg('a perl interpreter', ['perl'])[1]
(inkscape_path, inkscape_name) = os.path.split(checkInkscape())
checkFormatEntries(dtl_tools) checkFormatEntries(dtl_tools)
checkConverterEntries() checkConverterEntries()
(chk_docbook, bool_docbook, docbook_cmd) = checkDocBook() (chk_docbook, bool_docbook, docbook_cmd) = checkDocBook()

View File

@ -1055,16 +1055,18 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
} }
case RC_VIEWER_ALTERNATIVES: { case RC_VIEWER_ALTERNATIVES: {
string format, command; string format, command;
lexrc >> format; if ((lexrc >> format) && lexrc.next(true)) {
lexrc >> command; command = lexrc.getString();
viewer_alternatives[format].insert(command); viewer_alternatives[format].insert(command);
}
break; break;
} }
case RC_EDITOR_ALTERNATIVES: { case RC_EDITOR_ALTERNATIVES: {
string format, command; string format, command;
lexrc >> format; if ((lexrc >> format) && lexrc.next(true)) {
lexrc >> command; command = lexrc.getString();
editor_alternatives[format].insert(command); editor_alternatives[format].insert(command);
}
break; break;
} }