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