565
|
1 |
#!/usr/bin/env python
|
|
2 |
# -*- coding: utf-8 -*-
|
|
3 |
|
|
4 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
|
|
5 |
#based on the plcopen standard.
|
|
6 |
#
|
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
|
|
8 |
#
|
|
9 |
#See COPYING file for copyrights details.
|
|
10 |
#
|
|
11 |
#This library is free software; you can redistribute it and/or
|
|
12 |
#modify it under the terms of the GNU General Public
|
|
13 |
#License as published by the Free Software Foundation; either
|
|
14 |
#version 2.1 of the License, or (at your option) any later version.
|
|
15 |
#
|
|
16 |
#This library is distributed in the hope that it will be useful,
|
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 |
#General Public License for more details.
|
|
20 |
#
|
|
21 |
#You should have received a copy of the GNU General Public
|
|
22 |
#License along with this library; if not, write to the Free Software
|
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 |
|
|
25 |
import wx, os, subprocess
|
|
26 |
|
|
27 |
def get_inkscape_path():
|
|
28 |
""" Return the Inkscape path """
|
|
29 |
import _winreg
|
|
30 |
svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
|
|
31 |
'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
|
|
32 |
svgexepath = svgexepath.replace('"%1"', '')
|
|
33 |
return svgexepath.replace('"', '')
|
|
34 |
|
|
35 |
def open_win_svg(svgexepath, svgfile):
|
|
36 |
""" Open Inkscape on Windows platform """
|
|
37 |
popenargs = [svgexepath]
|
|
38 |
if svgfile is not None :
|
|
39 |
popenargs.append(svgfile)
|
|
40 |
subprocess.Popen(popenargs).pid
|
|
41 |
|
|
42 |
def open_lin_svg(svgexepath, svgfile):
|
|
43 |
""" Open Inkscape on Linux platform """
|
|
44 |
if os.path.isfile("/usr/bin/inkscape"):
|
|
45 |
os.system("%s %s &"%(svgexepath , svgfile))
|
|
46 |
|
|
47 |
def open_svg(svgfile):
|
|
48 |
""" Generic function to open SVG file """
|
|
49 |
if wx.Platform == '__WXMSW__' :
|
|
50 |
svgexepath = get_inkscape_path()
|
|
51 |
try:
|
|
52 |
open_win_svg(svgexepath , svgfile)
|
|
53 |
except:
|
|
54 |
wx.MessageBox("Inkscape is not found or installed !")
|
|
55 |
return None
|
|
56 |
else:
|
|
57 |
svgexepath = os.path.join("/usr/bin","inkscape")
|
|
58 |
if(os.path.isfile(svgexepath)):
|
|
59 |
open_lin_svg(svgexepath, svgfile)
|
|
60 |
else:
|
|
61 |
wx.MessageBox("Inkscape is not found or installed !")
|
|
62 |
return None
|
|
63 |
|