814
|
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
|
|
26 |
|
|
27 |
readerexepath = None
|
|
28 |
|
|
29 |
def get_acroversion():
|
|
30 |
" Return version of Adobe Acrobat executable or None"
|
|
31 |
import _winreg
|
|
32 |
adobesoft = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe')
|
|
33 |
for index in range(_winreg.QueryInfoKey(adobesoft)[0]):
|
|
34 |
key = _winreg.EnumKey(adobesoft, index)
|
|
35 |
if "acrobat" in key.lower():
|
|
36 |
acrokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key)
|
|
37 |
for index in range(_winreg.QueryInfoKey(acrokey)[0]):
|
|
38 |
numver = _winreg.EnumKey(acrokey, index)
|
|
39 |
try:
|
|
40 |
res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver))
|
|
41 |
return res
|
|
42 |
except:
|
|
43 |
pass
|
|
44 |
return None
|
|
45 |
|
|
46 |
def open_win_pdf(readerexepath, pdffile, pagenum = None):
|
|
47 |
if pagenum != None :
|
|
48 |
os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", "/A", "page=%d=OpenActions" % pagenum, '"%s"'%pdffile)
|
|
49 |
else:
|
|
50 |
os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%pdffile)
|
|
51 |
|
|
52 |
def open_lin_pdf(readerexepath, pdffile, pagenum = None):
|
|
53 |
if pagenum == None :
|
|
54 |
os.system("%s -remote DS301 %s &"%(readerexepath, pdffile))
|
|
55 |
else:
|
|
56 |
print "Open pdf %s at page %d"%(pdffile, pagenum)
|
|
57 |
os.system("%s -remote DS301 %s %d &"%(readerexepath, pdffile, pagenum))
|
|
58 |
|
|
59 |
def open_pdf(pdffile, pagenum = None):
|
|
60 |
if wx.Platform == '__WXMSW__' :
|
|
61 |
try:
|
|
62 |
readerpath = get_acroversion()
|
|
63 |
except:
|
|
64 |
wx.MessageBox("Acrobat Reader is not found or installed !")
|
|
65 |
return None
|
|
66 |
|
|
67 |
readerexepath = os.path.join(readerpath, "AcroRd32.exe")
|
|
68 |
if(os.path.isfile(readerexepath)):
|
|
69 |
open_win_pdf(readerexepath, pdffile, pagenum)
|
|
70 |
else:
|
|
71 |
return None
|
|
72 |
else:
|
|
73 |
readerexepath = os.path.join("/usr/bin","xpdf")
|
|
74 |
if(os.path.isfile(readerexepath)):
|
|
75 |
open_lin_pdf(readerexepath, pdffile, pagenum)
|
|
76 |
else:
|
|
77 |
wx.MessageBox("xpdf is not found or installed !")
|
|
78 |
return None
|