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
Edouard@3111: import wx
andrej@1732: import subprocess
andrej@1736: 
Laurent@814: def get_inkscape_path():
Edouard@3111:     """ Return the Inkscape binary path """
Edouard@3111: 
Edouard@2628:     if wx.Platform == '__WXMSW__':
Edouard@2628:         from six.moves import winreg
Edouard@3111:         inkcmd = None
Edouard@2628:         try:
Edouard@3111:             inkcmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
Edouard@3111:                                            'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
Edouard@2628:         except OSError:
Edouard@3052:             try:
Edouard@3111:                 inkcmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE,
Edouard@3052:                                                'Software\\Classes\\inkscape.svg\\shell\\open\\command')
Edouard@3111:             except OSError:
Edouard@3052:                 return None
Edouard@3052: 
Edouard@3111:         return inkcmd.replace('"%1"', '').strip().replace('"', '')
Edouard@3111: 
Edouard@2628:     else:
Edouard@3111:         try:
Edouard@3111:             return subprocess.check_output("command -v inkscape", shell=True).strip()
Edouard@3111:         except subprocess.CalledProcessError:
Edouard@3111:             return None
andrej@1736: 
Laurent@814: def open_svg(svgfile):
Laurent@814:     """ Generic function to open SVG file """
Edouard@3111:     
Edouard@3111:     inkpath = get_inkscape_path()
Edouard@3111:     if inkpath is None:
Edouard@3111:         wx.MessageBox("Inkscape is not found or installed !")
Laurent@814:     else:
Edouard@3111:         subprocess.Popen([inkpath,svgfile])