Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: andrej@1571: # This file is part of Beremiz, a Integrated Development Environment for andrej@1571: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. Laurent@814: # andrej@1571: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Laurent@814: # andrej@1571: # See COPYING file for copyrights details. Laurent@814: # andrej@1571: # This program is free software; you can redistribute it and/or andrej@1571: # modify it under the terms of the GNU General Public License andrej@1571: # as published by the Free Software Foundation; either version 2 andrej@1571: # of the License, or (at your option) any later version. Laurent@814: # andrej@1571: # This program is distributed in the hope that it will be useful, andrej@1571: # but WITHOUT ANY WARRANTY; without even the implied warranty of andrej@1571: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrej@1571: # GNU General Public License for more details. Laurent@814: # andrej@1571: # You should have received a copy of the GNU General Public License andrej@1571: # along with this program; if not, write to the Free Software andrej@1571: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Laurent@814: andrej@1732: import os andrej@1732: import wx andrej@1732: Laurent@814: Laurent@814: readerexepath = None Laurent@814: Laurent@814: def get_acroversion(): Laurent@814: " Return version of Adobe Acrobat executable or None" Laurent@814: import _winreg Laurent@814: adobesoft = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe') Laurent@814: for index in range(_winreg.QueryInfoKey(adobesoft)[0]): Laurent@814: key = _winreg.EnumKey(adobesoft, index) Laurent@814: if "acrobat" in key.lower(): Laurent@814: acrokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key) Laurent@814: for index in range(_winreg.QueryInfoKey(acrokey)[0]): Laurent@814: numver = _winreg.EnumKey(acrokey, index) Laurent@814: try: Laurent@814: res = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver)) Laurent@814: return res Laurent@814: except: Laurent@814: pass Laurent@814: return None Laurent@814: Laurent@814: def open_win_pdf(readerexepath, pdffile, pagenum = None): Laurent@814: if pagenum != None : Laurent@814: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", "/A", "page=%d=OpenActions" % pagenum, '"%s"'%pdffile) Laurent@814: else: Laurent@814: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"'%pdffile) Laurent@814: Laurent@814: def open_lin_pdf(readerexepath, pdffile, pagenum = None): Laurent@814: if pagenum == None : Laurent@814: os.system("%s -remote DS301 %s &"%(readerexepath, pdffile)) Laurent@814: else: ewald@1572: print "Open pdf %s at page %d"%(pdffile, pagenum) Laurent@814: os.system("%s -remote DS301 %s %d &"%(readerexepath, pdffile, pagenum)) Laurent@814: Laurent@814: def open_pdf(pdffile, pagenum = None): Laurent@814: if wx.Platform == '__WXMSW__' : Laurent@814: try: Laurent@814: readerpath = get_acroversion() Laurent@814: except: Laurent@814: wx.MessageBox("Acrobat Reader is not found or installed !") Laurent@814: return None Laurent@814: Laurent@814: readerexepath = os.path.join(readerpath, "AcroRd32.exe") Laurent@814: if(os.path.isfile(readerexepath)): Laurent@814: open_win_pdf(readerexepath, pdffile, pagenum) Laurent@814: else: Laurent@814: return None Laurent@814: else: Laurent@814: readerexepath = os.path.join("/usr/bin","xpdf") Laurent@814: if(os.path.isfile(readerexepath)): Laurent@814: open_lin_pdf(readerexepath, pdffile, pagenum) Laurent@814: else: Laurent@814: wx.MessageBox("xpdf is not found or installed !") Laurent@814: return None