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.
16 # 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net)
24 if wx
.Platform
== '__WXMSW__':
25 import wx
.lib
.activexwrapper
as ax
26 import win32com
.client
.gencache
29 acrobat
= win32com
.client
.gencache
.EnsureModule(
30 '{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3
33 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
36 #----------------------------------------------------------------------
38 class TestPanel(wx
.Panel
):
39 def __init__(self
, parent
, log
):
40 wx
.Panel
.__init
__(self
, parent
, -1)
43 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
44 btnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
46 # this function creates a new class that can be used as
47 # a wx.Window, but contains the given ActiveX control.
48 ActiveXWrapper
= ax
.MakeActiveXClass(acrobat
.Pdf
)
50 # create an instance of the new class
51 self
.pdf
= ActiveXWrapper( self
, -1, style
=wx
.SUNKEN_BORDER
)
53 sizer
.Add(self
.pdf
, proportion
=1, flag
=wx
.EXPAND
)
55 btn
= wx
.Button(self
, wx
.NewId(), "Open PDF File")
56 self
.Bind(wx
.EVT_BUTTON
, self
.OnOpenButton
)
57 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
59 btn
= wx
.Button(self
, wx
.NewId(), "<-- Previous Page")
60 self
.Bind(wx
.EVT_BUTTON
, self
.OnPrevPageButton
, id=btn
.GetId())
61 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
63 btn
= wx
.Button(self
, wx
.NewId(), "Next Page -->")
64 self
.Bind(wx
.EVT_BUTTON
, self
.OnNextPageButton
, id=btn
.GetId())
65 btnSizer
.Add(btn
, proportion
=1, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
68 btnSizer
.Add((50,-1), proportion
=2, flag
=wx
.EXPAND
)
69 sizer
.Add(btnSizer
, proportion
=0, flag
=wx
.EXPAND
)
72 self
.SetAutoLayout(True)
74 self
.Bind(wx
.EVT_WINDOW_DESTROY
, self
.OnDestroy
)
77 def OnDestroy(self
, evt
):
84 def OnOpenButton(self
, event
):
85 dlg
= wx
.FileDialog(self
, wildcard
="*.pdf")
87 if dlg
.ShowModal() == wx
.ID_OK
:
89 self
.pdf
.LoadFile(dlg
.GetPath())
95 def OnPrevPageButton(self
, event
):
96 self
.pdf
.gotoPreviousPage()
99 def OnNextPageButton(self
, event
):
100 self
.pdf
.gotoNextPage()
104 #----------------------------------------------------------------------
106 def runTest(frame
, nb
, log
):
107 if wx
.Platform
== '__WXMSW__':
108 win
= TestPanel(nb
, log
)
111 dlg
= wx
.MessageDialog(frame
, 'This demo only works on MSW.',
112 'Sorry', wx
.OK | wx
.ICON_INFORMATION
)
119 #----------------------------------------------------------------------
122 if __name__
== '__main__':
123 class TestFrame(wx
.Frame
):
126 self
, None, -1, "ActiveX test -- Acrobat", size
=(640, 480),
127 style
=wx
.DEFAULT_FRAME_STYLE|wx
.NO_FULL_REPAINT_ON_RESIZE
130 self
.tp
= TestPanel(self
, sys
.stdout
)
133 app
= wx
.PySimpleApp()