docutil/docsvg.py
changeset 1784 64beb9e9c749
parent 1780 c52d1460cea8
child 1801 58ff55053518
equal deleted inserted replaced
1729:31e63e25b4cc 1784:64beb9e9c749
    20 #
    20 #
    21 # You should have received a copy of the GNU General Public License
    21 # You should have received a copy of the GNU General Public License
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import wx, os, subprocess
    25 import wx
       
    26 import os
       
    27 import subprocess
       
    28 
    26 
    29 
    27 def get_inkscape_path():
    30 def get_inkscape_path():
    28     """ Return the Inkscape path """
    31     """ Return the Inkscape path """
    29     import _winreg
    32     import _winreg
    30     svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
    33     svgexepath = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
    31                  'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
    34                                     'Software\\Classes\\svgfile\\shell\\Inkscape\\command')
    32     svgexepath = svgexepath.replace('"%1"', '')
    35     svgexepath = svgexepath.replace('"%1"', '')
    33     return svgexepath.replace('"', '')
    36     return svgexepath.replace('"', '')
       
    37 
    34 
    38 
    35 def open_win_svg(svgexepath, svgfile):
    39 def open_win_svg(svgexepath, svgfile):
    36     """ Open Inkscape on Windows platform """
    40     """ Open Inkscape on Windows platform """
    37     popenargs = [svgexepath]
    41     popenargs = [svgexepath]
    38     if svgfile is not None :
    42     if svgfile is not None:
    39         popenargs.append(svgfile)
    43         popenargs.append(svgfile)
    40     subprocess.Popen(popenargs).pid
    44     subprocess.Popen(popenargs).pid
       
    45 
    41 
    46 
    42 def open_lin_svg(svgexepath, svgfile):
    47 def open_lin_svg(svgexepath, svgfile):
    43     """ Open Inkscape on Linux platform """
    48     """ Open Inkscape on Linux platform """
    44     if os.path.isfile("/usr/bin/inkscape"):
    49     if os.path.isfile("/usr/bin/inkscape"):
    45         os.system("%s %s &"%(svgexepath , svgfile))
    50         os.system("%s %s &" % (svgexepath, svgfile))
    46     
    51 
       
    52 
    47 def open_svg(svgfile):
    53 def open_svg(svgfile):
    48     """ Generic function to open SVG file """
    54     """ Generic function to open SVG file """
    49     if wx.Platform == '__WXMSW__' :
    55     if wx.Platform == '__WXMSW__':
    50         try:
    56         try:
    51             open_win_svg(get_inkscape_path(), svgfile)
    57             open_win_svg(get_inkscape_path(), svgfile)
    52         except:
    58         except Exception:
    53             wx.MessageBox("Inkscape is not found or installed !")
    59             wx.MessageBox("Inkscape is not found or installed !")
    54             return None
    60             return None
    55     else:
    61     else:
    56         svgexepath = os.path.join("/usr/bin","inkscape")
    62         svgexepath = os.path.join("/usr/bin", "inkscape")
    57         if(os.path.isfile(svgexepath)):
    63         if(os.path.isfile(svgexepath)):
    58             open_lin_svg(svgexepath, svgfile)
    64             open_lin_svg(svgexepath, svgfile)
    59         else:
    65         else:
    60             wx.MessageBox("Inkscape is not found or installed !")
    66             wx.MessageBox("Inkscape is not found or installed !")
    61             return None
    67             return None
    62