laurent@565: #!/usr/bin/env python laurent@565: # -*- coding: utf-8 -*- laurent@565: laurent@565: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor laurent@565: #based on the plcopen standard. laurent@565: # laurent@565: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD laurent@565: # laurent@565: #See COPYING file for copyrights details. laurent@565: # laurent@565: #This library is free software; you can redistribute it and/or laurent@565: #modify it under the terms of the GNU General Public laurent@565: #License as published by the Free Software Foundation; either laurent@565: #version 2.1 of the License, or (at your option) any later version. laurent@565: # laurent@565: #This library is distributed in the hope that it will be useful, laurent@565: #but WITHOUT ANY WARRANTY; without even the implied warranty of laurent@565: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU laurent@565: #General Public License for more details. laurent@565: # laurent@565: #You should have received a copy of the GNU General Public laurent@565: #License along with this library; if not, write to the Free Software laurent@565: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA laurent@565: laurent@565: import wx, os, subprocess laurent@565: laurent@565: def get_inkscape_path(): laurent@565: """ Return the Inkscape path """ laurent@565: import _winreg laurent@565: svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, laurent@565: 'Software\\Classes\\svgfile\\shell\\Inkscape\\command') laurent@565: svgexepath = svgexepath.replace('"%1"', '') laurent@565: return svgexepath.replace('"', '') laurent@565: laurent@565: def open_win_svg(svgexepath, svgfile): laurent@565: """ Open Inkscape on Windows platform """ laurent@565: popenargs = [svgexepath] laurent@565: if svgfile is not None : laurent@565: popenargs.append(svgfile) laurent@565: subprocess.Popen(popenargs).pid laurent@565: laurent@565: def open_lin_svg(svgexepath, svgfile): laurent@565: """ Open Inkscape on Linux platform """ laurent@565: if os.path.isfile("/usr/bin/inkscape"): laurent@565: os.system("%s %s &"%(svgexepath , svgfile)) laurent@565: laurent@565: def open_svg(svgfile): laurent@565: """ Generic function to open SVG file """ laurent@565: if wx.Platform == '__WXMSW__' : laurent@565: try: Laurent@755: open_win_svg(get_inkscape_path(), svgfile) laurent@565: except: laurent@565: wx.MessageBox("Inkscape is not found or installed !") laurent@565: return None laurent@565: else: laurent@565: svgexepath = os.path.join("/usr/bin","inkscape") laurent@565: if(os.path.isfile(svgexepath)): laurent@565: open_lin_svg(svgexepath, svgfile) laurent@565: else: laurent@565: wx.MessageBox("Inkscape is not found or installed !") laurent@565: return None laurent@565: