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@1881: andrej@1881: from __future__ import absolute_import andrej@1826: from __future__ import print_function andrej@1732: import os andrej@1732: import wx andrej@1732: Laurent@814: Laurent@814: readerexepath = None andrej@1735: andrej@1736: Laurent@814: def get_acroversion(): Laurent@814: " Return version of Adobe Acrobat executable or None" andrej@2431: from six.moves import winreg andrej@2431: adobesoft = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'Software\Adobe') andrej@2431: for index in range(winreg.QueryInfoKey(adobesoft)[0]): andrej@2431: key = winreg.EnumKey(adobesoft, index) Laurent@814: if "acrobat" in key.lower(): andrej@2431: acrokey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s' % key) andrej@2431: for index in range(winreg.QueryInfoKey(acrokey)[0]): andrej@2431: numver = winreg.EnumKey(acrokey, index) Laurent@814: try: andrej@2431: res = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, 'Software\\Adobe\\%s\\%s\\InstallPath' % (key, numver)) Laurent@814: return res andrej@1780: except Exception: Laurent@814: pass Laurent@814: return None Laurent@814: andrej@1736: andrej@1744: def open_win_pdf(readerexepath, pdffile, pagenum=None): andrej@1743: if pagenum is not None: andrej@1734: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", "/A", "page=%d=OpenActions" % pagenum, '"%s"' % pdffile) Laurent@814: else: andrej@1734: os.spawnl(os.P_DETACH, readerexepath, "AcroRd32.exe", '"%s"' % pdffile) Laurent@814: andrej@1736: andrej@1744: def open_lin_pdf(readerexepath, pdffile, pagenum=None): andrej@1743: if pagenum is None: andrej@1734: os.system("%s -remote DS301 %s &" % (readerexepath, pdffile)) Laurent@814: else: andrej@1826: print("Open pdf %s at page %d" % (pdffile, pagenum)) andrej@1734: os.system("%s -remote DS301 %s %d &" % (readerexepath, pdffile, pagenum)) Laurent@814: andrej@1736: andrej@1744: def open_pdf(pdffile, pagenum=None): andrej@1739: if wx.Platform == '__WXMSW__': Laurent@814: try: Laurent@814: readerpath = get_acroversion() andrej@1780: except Exception: Laurent@814: wx.MessageBox("Acrobat Reader is not found or installed !") Laurent@814: return None andrej@1735: Laurent@814: readerexepath = os.path.join(readerpath, "AcroRd32.exe") andrej@1828: if os.path.isfile(readerexepath): Laurent@814: open_win_pdf(readerexepath, pdffile, pagenum) Laurent@814: else: Laurent@814: return None Laurent@814: else: andrej@1740: readerexepath = os.path.join("/usr/bin", "xpdf") andrej@1828: 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