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
)
74 def OnOpenButton(self
, event
):
75 dlg
= wxFileDialog(self
, wildcard
="*.pdf")
76 if dlg
.ShowModal() == wxID_OK
:
78 self
.pdf
.LoadFile(dlg
.GetPath())
84 def OnPrevPageButton(self
, event
):
85 self
.pdf
.gotoPreviousPage()
88 def OnNextPageButton(self
, event
):
89 self
.pdf
.gotoNextPage()
93 #----------------------------------------------------------------------
95 def runTest(frame
, nb
, log
):
96 if wxPlatform
== '__WXMSW__':
97 win
= TestPanel(nb
, log
)
100 dlg
= wxMessageDialog(frame
, 'This demo only works on MSW.',
101 'Sorry', wxOK | wxICON_INFORMATION
)
108 #----------------------------------------------------------------------
111 if __name__
== '__main__':
112 class TestFrame(wxFrame
):
114 wxFrame
.__init
__(self
, None, -1, "ActiveX test -- Acrobat", size
=(640, 480),
115 style
=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE
)
116 self
.tp
= TestPanel(self
, sys
.stdout
)
117 EVT_CLOSE(self
, self
.OnCloseWindow
)
119 def OnCloseWindow(self
, event
):
121 self
.tp
.pdf
.Cleanup()
125 app
= wxPySimpleApp()