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