]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/demo/ActiveXWrapper_Acrobat.py
corrected assert even better
[wxWidgets.git] / wxPython / demo / ActiveXWrapper_Acrobat.py
... / ...
CommitLineData
1"""
2<html><body>
3This demo shows how to embed an ActiveX control in a wxPython application, (Win32 only.)
4<p>
5The MakeActiveXClass function dynamically builds a new Class on the fly, that has the
6same signature and semantics as wxWindow. This means that when you call the function
7you get back a new class that you can use just like wxWindow, (set the size and position,
8use in a sizer, etc.) except its contents will be the COM control.
9<p>
10This demo embeds the Adobe Acrobat Reader, and gives you some buttons for opening a PDF
11file, changing pages, etc. that show how to call methods on the COM object. If you don't
12have Acrobat Reader 4.0 installed it won't work.
13</body></html>
14"""
15
16from wxPython.wx import *
17
18if wxPlatform == '__WXMSW__':
19 from wxPython.lib.activexwrapper import MakeActiveXClass
20 import win32com.client.gencache
21
22 try:
23 acrobat = win32com.client.gencache.EnsureModule('{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3)
24 except:
25 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
26
27
28
29#----------------------------------------------------------------------
30
31class TestPanel(wxPanel):
32 def __init__(self, parent, log):
33 wxPanel.__init__(self, parent, -1)
34 self.pdf = None
35
36 sizer = wxBoxSizer(wxVERTICAL)
37 btnSizer = wxBoxSizer(wxHORIZONTAL)
38
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)
42
43 # create an instance of the new class
44 self.pdf = ActiveXWrapper( self, -1, style=wxSUNKEN_BORDER)
45
46 sizer.Add(self.pdf, 1, wxEXPAND)
47
48 btn = wxButton(self, wxNewId(), "Open PDF File")
49 EVT_BUTTON(self, btn.GetId(), self.OnOpenButton)
50 btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
51
52 btn = wxButton(self, wxNewId(), "<-- Previous Page")
53 EVT_BUTTON(self, btn.GetId(), self.OnPrevPageButton)
54 btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
55
56 btn = wxButton(self, wxNewId(), "Next Page -->")
57 EVT_BUTTON(self, btn.GetId(), self.OnNextPageButton)
58 btnSizer.Add(btn, 1, wxEXPAND|wxALL, 5)
59
60
61 btnSizer.Add(50, -1, 2, wxEXPAND)
62 sizer.Add(btnSizer, 0, wxEXPAND)
63
64 self.SetSizer(sizer)
65 self.SetAutoLayout(true)
66
67 def __del__(self):
68 if self.pdf:
69 self.pdf.Cleanup()
70 self.pdf = None
71
72
73
74 def OnOpenButton(self, event):
75 dlg = wxFileDialog(self, wildcard="*.pdf")
76 if dlg.ShowModal() == wxID_OK:
77 wxBeginBusyCursor()
78 self.pdf.LoadFile(dlg.GetPath())
79 wxEndBusyCursor()
80
81 dlg.Destroy()
82
83
84 def OnPrevPageButton(self, event):
85 self.pdf.gotoPreviousPage()
86
87
88 def OnNextPageButton(self, event):
89 self.pdf.gotoNextPage()
90
91
92
93#----------------------------------------------------------------------
94
95def runTest(frame, nb, log):
96 if wxPlatform == '__WXMSW__':
97 win = TestPanel(nb, log)
98 return win
99 else:
100 dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
101 'Sorry', wxOK | wxICON_INFORMATION)
102 dlg.ShowModal()
103 dlg.Destroy()
104
105
106overview = __doc__
107
108#----------------------------------------------------------------------
109
110
111if __name__ == '__main__':
112 class TestFrame(wxFrame):
113 def __init__(self):
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)
118
119 def OnCloseWindow(self, event):
120
121 self.tp.pdf.Cleanup()
122 self.Destroy()
123
124
125 app = wxPySimpleApp()
126 frame = TestFrame()
127 frame.Show(true)
128 app.MainLoop()
129
130
131