Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. Laurent@814: # andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # andrej@1571: # See COPYING file for copyrights details. Laurent@814: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. Laurent@814: # andrej@1571: # This program is distributed in the hope that it will be useful, andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. Laurent@814: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Laurent@814: andrej@1881: andrej@1881: from __future__ import absolute_import andrej@1732: import os andrej@1732: import subprocess andrej@1832: import wx Laurent@814: andrej@1736: Laurent@814: def get_inkscape_path(): Laurent@814: """ Return the Inkscape path """ Edouard@2628: if wx.Platform == '__WXMSW__': Edouard@2628: from six.moves import winreg Edouard@2628: try: Edouard@2705: svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, Edouard@2705: 'Software\\Classes\\svgfile\\shell\\Inkscape\\command') Edouard@2628: except OSError: Edouard@2705: try: Edouard@2705: svgexepath = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, Edouard@2705: 'Software\\Classes\\inkscape.svg\\shell\\open\\command') Edouard@2705: except Exception: Edouard@2705: return None Edouard@2705: Edouard@2628: svgexepath = svgexepath.replace('"%1"', '').strip() Edouard@2628: return svgexepath.replace('"', '') Edouard@2628: else: Edouard@2705: # TODO: search for inkscape in $PATH Edouard@2705: svgexepath = os.path.join("/usr/bin", "inkscape") Edouard@2705: if os.path.exists(svgexepath): Edouard@2705: return svgexepath Edouard@2705: return None Laurent@814: andrej@1736: Laurent@814: def open_win_svg(svgexepath, svgfile): Laurent@814: """ Open Inkscape on Windows platform """ Laurent@814: popenargs = [svgexepath] andrej@1739: if svgfile is not None: Laurent@814: popenargs.append(svgfile) andrej@1876: subprocess.Popen(popenargs) Laurent@814: andrej@1736: Laurent@814: def open_lin_svg(svgexepath, svgfile): Laurent@814: """ Open Inkscape on Linux platform """ Laurent@814: if os.path.isfile("/usr/bin/inkscape"): andrej@1739: os.system("%s %s &" % (svgexepath, svgfile)) andrej@1735: andrej@1736: Laurent@814: def open_svg(svgfile): Laurent@814: """ Generic function to open SVG file """ andrej@1739: if wx.Platform == '__WXMSW__': Laurent@814: try: Laurent@814: open_win_svg(get_inkscape_path(), svgfile) andrej@1780: except Exception: Laurent@814: wx.MessageBox("Inkscape is not found or installed !") Laurent@814: return None Laurent@814: else: Edouard@2628: svgexepath=get_inkscape_path() andrej@1828: if os.path.isfile(svgexepath): Laurent@814: open_lin_svg(svgexepath, svgfile) Laurent@814: else: Laurent@814: wx.MessageBox("Inkscape is not found or installed !") Laurent@814: return None