[wxPython-dev] 20060712 test build uploaded
David Hughes
dfh at forestfield.co.uk
Fri Jul 14 05:07:59 PDT 2006
Robin Dunn wrote:
> Werner F. Bruhin wrote:
>
>>
>> *ActiveXPdfWindow*
>> Crashes when opening a PDF file (Adobe 7.0.5)
>
>
> Yes, this is the same old problem with Adobe's new ActiveX control =
> that nobody has been able to solve yet. I suppose I should just take =
> this module out of the demo, or else show it by embedding in an IE =
> window instead, which does work. If somebody has time to whip up a =
> patch for this I would appreciate it.
See attached file ActiveX_PDFWindow.py.
Regards,
David Hughes
-------------- next part --------------
import sys
import wx
# Use PDFWindow if Acrobat reader version < 7
# otherwise use IEHtmlWindow - see overview.
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log, acrobat_version):
wx.Panel.__init__(self, parent, -1)
self.acrobat_version =3D acrobat_version
self.pdf =3D None
sizer =3D wx.BoxSizer(wx.VERTICAL)
btnSizer =3D wx.BoxSizer(wx.HORIZONTAL)
if acrobat_version < '7.0':
from wx.lib.pdfwin import PDFWindow
self.pdf =3D PDFWindow(self, style=3Dwx.SUNKEN_BORDER)
else:
from wx.lib.iewin import IEHtmlWindow
self.pdf =3D IEHtmlWindow(self, style=3Dwx.SUNKEN_BORDER)
sizer.Add(self.pdf, proportion=3D1, flag=3Dwx.EXPAND)
btn =3D wx.Button(self, wx.NewId(), "Open PDF File")
self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
btnSizer.Add(btn, proportion=3D1, flag=3Dwx.EXPAND|wx.ALL, border=
=3D5)
if acrobat_version < '7.0':
""" These methods are not available when reader is opened via
IE window - but the reader itself contains page navigation
buttons anyway.
"""
btn =3D wx.Button(self, wx.NewId(), "<-- Previous Page")
self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, btn)
btnSizer.Add(btn, proportion=3D1, flag=3Dwx.EXPAND|wx.ALL, bord=
er=3D5)
btn =3D wx.Button(self, wx.NewId(), "Next Page -->")
self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, btn)
btnSizer.Add(btn, proportion=3D1, flag=3Dwx.EXPAND|wx.ALL, bord=
er=3D5)
btnSizer.Add((50,-1), proportion=3D2, flag=3Dwx.EXPAND)
sizer.Add(btnSizer, proportion=3D0, flag=3Dwx.EXPAND)
self.SetSizer(sizer)
self.SetAutoLayout(True)
def OnOpenButton(self, event):
dlg =3D wx.FileDialog(self, wildcard=3D"*.pdf")
if dlg.ShowModal() =3D=3D wx.ID_OK:
wx.BeginBusyCursor()
if self.acrobat_version < '7.0': =
self.pdf.LoadFile(dlg.GetPath())
else:
self.pdf.Navigate(dlg.GetPath())
wx.EndBusyCursor()
dlg.Destroy()
def OnPrevPageButton(self, event):
self.pdf.gotoPreviousPage()
def OnNextPageButton(self, event):
self.pdf.gotoNextPage()
#--------------------------------------------------------------------------=
--
def get_acroversion():
" Return version of Adobe Acrobat executable or None"
import _winreg
acrosoft =3D [r'SOFTWARE\Adobe\Acrobat Reader\%version%\InstallPath',
r'SOFTWARE\Adobe\Adobe Acrobat\%version%\InstallPath',]
=
for regkey in acrosoft:
for version in ('7.0', '6.0', '5.0', '4.0'):
try:
path =3D _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE, reg=
key.replace('%version%', version))
return version
except:
continue
return None
#--------------------------------------------------------------------------=
--
def runTest(frame, nb, log):
if wx.Platform <> '__WXMSW__':
from Main import MessagePanel
win =3D MessagePanel(nb, 'This demo only works on Microsoft Windows=
.',
'Sorry', wx.ICON_WARNING)
else:
version =3D get_acroversion()
if not version:
from Main import MessagePanel
win =3D MessagePanel(nb, 'Adobe Acrobat reader not found.',
'Sorry', wx.ICON_WARNING)
else:
win =3D TestPanel(nb, log, version)
return win
overview =3D """\
<html><body>
<h2>wx.lib.pdfwin.PDFWindow</h2>
The wx.lib.pdfwin.PDFWindow class is another example of using ActiveX
controls from wxPython using the new wx.activex module. This allows
you to use an ActiveX control as if it is a wx.Window, you can call
its methods, set/get properties, and receive events from the ActiveX
control in a very intuitive way.
<p> Using this class is simpler than ActiveXWrapper, doesn't rely on
the win32all extensions, and is more "wx\'ish", meaning that it uses
events and etc. as would be expected from any other wx window.
<p> This demo embeds the Adobe Acrobat Reader, and gives you some
buttons for opening a PDF file, changing pages, etc. that show how to
call methods on the COM object. If you don't have Acrobat Reader 4.0
(or greater) installed it won't work.
<p> For some reason, Version 7 of the reader causes Python itself to =
crash when it is called directly, but fortunately it can be accessed =
via the Internet Explorer ActiveX control - although with a more =
restricted range of methods. (They also have different names).
</body></html>
"""
#----------------------------------------------------------------------
if __name__ =3D=3D '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
More information about the wxpython-dev
mailing list