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 """
Laurent@814:     import _winreg
andrej@1801:     try:
andrej@1801:         svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
andrej@1801:                                         'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
andrej@1872:     except OSError:
andrej@1801:         svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
andrej@1801:                                         'Software\\Classes\\inkscape.svg\\shell\\open\\command')
Laurent@814:     svgexepath = svgexepath.replace('"%1"', '')
Laurent@814:     return svgexepath.replace('"', '')
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:
andrej@1740:         svgexepath = os.path.join("/usr/bin", "inkscape")
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