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 from wxPython
.wx
import *
18 if wxPlatform
== '__WXMSW__':
19 from wxPython
.lib
.activexwrapper
import MakeActiveXClass
20 import win32com
.client
.gencache
23 acrobat
= win32com
.client
.gencache
.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
25 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
29 #----------------------------------------------------------------------
31 class TestPanel(wxPanel
):
32 def __init__(self
, parent
, log
):
33 wxPanel
.__init
__(self
, parent
, -1)
36 sizer
= wxBoxSizer(wxVERTICAL
)
37 btnSizer
= wxBoxSizer(wxHORIZONTAL
)
39 # this function creates a new class that can be used as
40 # a wxWindow, but contains the given ActiveX control.
41 ActiveXWrapper
= MakeActiveXClass(acrobat
.Pdf
)
43 # create an instance of the new class
44 self
.pdf
= ActiveXWrapper( self
, -1, style
=wxSUNKEN_BORDER
)
46 sizer
.Add(self
.pdf
, 1, wxEXPAND
)
48 btn
= wxButton(self
, wxNewId(), "Open PDF File")
49 EVT_BUTTON(self
, btn
.GetId(), self
.OnOpenButton
)
50 btnSizer
.Add(btn
, 1, wxEXPAND|wxALL
, 5)
52 btn
= wxButton(self
, wxNewId(), "<-- Previous Page")
53 EVT_BUTTON(self
, btn
.GetId(), self
.OnPrevPageButton
)
54 btnSizer
.Add(btn
, 1, wxEXPAND|wxALL
, 5)
56 btn
= wxButton(self
, wxNewId(), "Next Page -->")
57 EVT_BUTTON(self
, btn
.GetId(), self
.OnNextPageButton
)
58 btnSizer
.Add(btn
, 1, wxEXPAND|wxALL
, 5)
61 btnSizer
.Add(50, -1, 2, wxEXPAND
)
62 sizer
.Add(btnSizer
, 0, wxEXPAND
)
65 self
.SetAutoLayout(true
)
67 EVT_WINDOW_DESTROY(self
, self
.OnDestroy
)
70 def OnDestroy(self
, evt
):
77 def OnOpenButton(self
, event
):
78 dlg
= wxFileDialog(self
, wildcard
="*.pdf")
79 if dlg
.ShowModal() == wxID_OK
:
81 self
.pdf
.LoadFile(dlg
.GetPath())
87 def OnPrevPageButton(self
, event
):
88 self
.pdf
.gotoPreviousPage()
91 def OnNextPageButton(self
, event
):
92 self
.pdf
.gotoNextPage()
96 #----------------------------------------------------------------------
98 def runTest(frame
, nb
, log
):
99 if wxPlatform
== '__WXMSW__':
100 win
= TestPanel(nb
, log
)
103 dlg
= wxMessageDialog(frame
, 'This demo only works on MSW.',
104 'Sorry', wxOK | wxICON_INFORMATION
)
111 #----------------------------------------------------------------------
114 if __name__
== '__main__':
115 class TestFrame(wxFrame
):
117 wxFrame
.__init
__(self
, None, -1, "ActiveX test -- Acrobat", size
=(640, 480),
118 style
=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE
)
119 self
.tp
= TestPanel(self
, sys
.stdout
)
122 app
= wxPySimpleApp()