3 This demo shows how to embed an ActiveX control in a wxPython application, (Win32 only.)
5 The MakeActiveXClass function dynamically builds a new Class on the fly, that has the
6 same signature and semantics as wxWindow. This means that when you call the function
7 you get back a new class that you can use just like wxWindow, (set the size and position,
8 use in a sizer, etc.) except its contents will be the COM control.
10 This demo embeds the Adobe Acrobat Reader, and gives you some buttons for opening a PDF
11 file, changing pages, etc. that show how to call methods on the COM object. If you don't
12 have Acrobat Reader 4.0 installed it won't work.
19 if wx
.Platform
== '__WXMSW__':
20 import wx
.lib
.activexwrapper
as ax
21 import win32com
.client
.gencache
24 acrobat
= win32com
.client
.gencache
.EnsureModule(
25 '{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3
28 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
31 #----------------------------------------------------------------------
33 class TestPanel(wx
.Panel
):
34 def __init__(self
, parent
, log
):
35 wx
.Panel
.__init
__(self
, parent
, -1)
38 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
39 btnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
41 # this function creates a new class that can be used as
42 # a wx.Window, but contains the given ActiveX control.
43 ActiveXWrapper
= ax
.MakeActiveXClass(acrobat
.Pdf
)
45 # create an instance of the new class
46 self
.pdf
= ActiveXWrapper( self
, -1, style
=wx
.SUNKEN_BORDER
)
48 sizer
.Add(self
.pdf
, proportion
=1, flag
=wx
.EXPAND
)
50 btn
= wx
.Button(self
, wx
.NewId(), "Open PDF File")
51 self
.Bind(wx
.EVT_BUTTON
, self
.OnOpenButton
)
52 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
54 btn
= wx
.Button(self
, wx
.NewId(), "<-- Previous Page")
55 self
.Bind(wx
.EVT_BUTTON
, self
.OnPrevPageButton
, id=btn
.GetId())
56 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
58 btn
= wx
.Button(self
, wx
.NewId(), "Next Page -->")
59 self
.Bind(wx
.EVT_BUTTON
, self
.OnNextPageButton
, id=btn
.GetId())
60 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
63 btnSizer
.Add((50,-1), proportion
=2, flag
=wx
.EXPAND
)
64 sizer
.Add(btnSizer
, proportion
=0, flag
=wx
.EXPAND
)
67 self
.SetAutoLayout(True)
69 self
.Bind(wx
.EVT_WINDOW_DESTROY
, self
.OnDestroy
)
72 def OnDestroy(self
, evt
):
79 def OnOpenButton(self
, event
):
80 dlg
= wx
.FileDialog(self
, wildcard
="*.pdf")
82 if dlg
.ShowModal() == wx
.ID_OK
:
84 self
.pdf
.LoadFile(dlg
.GetPath())
90 def OnPrevPageButton(self
, event
):
91 self
.pdf
.gotoPreviousPage()
94 def OnNextPageButton(self
, event
):
95 self
.pdf
.gotoNextPage()
99 #----------------------------------------------------------------------
101 def runTest(frame
, nb
, log
):
102 if wx
.Platform
== '__WXMSW__':
103 win
= TestPanel(nb
, log
)
106 dlg
= wx
.MessageDialog(frame
, 'This demo only works on MSW.',
107 'Sorry', wx
.OK | wx
.ICON_INFORMATION
)
114 #----------------------------------------------------------------------
117 if __name__
== '__main__':
118 class TestFrame(wx
.Frame
):
121 self
, None, -1, "ActiveX test -- Acrobat", size
=(640, 480),
122 style
=wx
.DEFAULT_FRAME_STYLE|wx
.NO_FULL_REPAINT_ON_RESIZE
125 self
.tp
= TestPanel(self
, sys
.stdout
)
128 app
= wx
.PySimpleApp()