]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ActiveXWrapper_Acrobat.py
mention ShouldInheritColours() change
[wxWidgets.git] / wxPython / demo / ActiveXWrapper_Acrobat.py
1 """
2 <html><body>
3 This demo shows how to embed an ActiveX control in a wxPython application, (Win32 only.)
4 <p>
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.
9 <p>
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.
13 </body></html>
14 """
15
16 from wxPython.wx import *
17
18 if 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
31 class 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 EVT_WINDOW_DESTROY(self, self.OnDestroy)
68
69
70 def OnDestroy(self, evt):
71 if self.pdf:
72 self.pdf.Cleanup()
73 self.pdf = None
74
75
76
77 def OnOpenButton(self, event):
78 dlg = wxFileDialog(self, wildcard="*.pdf")
79 if dlg.ShowModal() == wxID_OK:
80 wxBeginBusyCursor()
81 self.pdf.LoadFile(dlg.GetPath())
82 wxEndBusyCursor()
83
84 dlg.Destroy()
85
86
87 def OnPrevPageButton(self, event):
88 self.pdf.gotoPreviousPage()
89
90
91 def OnNextPageButton(self, event):
92 self.pdf.gotoNextPage()
93
94
95
96 #----------------------------------------------------------------------
97
98 def runTest(frame, nb, log):
99 if wxPlatform == '__WXMSW__':
100 win = TestPanel(nb, log)
101 return win
102 else:
103 dlg = wxMessageDialog(frame, 'This demo only works on MSW.',
104 'Sorry', wxOK | wxICON_INFORMATION)
105 dlg.ShowModal()
106 dlg.Destroy()
107
108
109 overview = __doc__
110
111 #----------------------------------------------------------------------
112
113
114 if __name__ == '__main__':
115 class TestFrame(wxFrame):
116 def __init__(self):
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)
120
121
122 app = wxPySimpleApp()
123 frame = TestFrame()
124 frame.Show(True)
125 app.MainLoop()
126
127
128