]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ActiveXWrapper_Acrobat.py
Add --with-sdl to the build doc and RPM spec
[wxWidgets.git] / wxPython / demo / ActiveXWrapper_Acrobat.py
CommitLineData
f6bcfd97
BP
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
8fa876ca
RD
16import sys
17import wx
18
19if wx.Platform == '__WXMSW__':
20 import wx.lib.activexwrapper as ax
21 import win32com.client.gencache
f6bcfd97
BP
22
23 try:
8fa876ca
RD
24 acrobat = win32com.client.gencache.EnsureModule(
25 '{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3
26 )
f6bcfd97
BP
27 except:
28 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
29
30
f6bcfd97
BP
31#----------------------------------------------------------------------
32
8fa876ca 33class TestPanel(wx.Panel):
f3d9dc1d 34 def __init__(self, parent, log):
8fa876ca 35 wx.Panel.__init__(self, parent, -1)
f6bcfd97
BP
36 self.pdf = None
37
8fa876ca
RD
38 sizer = wx.BoxSizer(wx.VERTICAL)
39 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
f6bcfd97
BP
40
41 # this function creates a new class that can be used as
8fa876ca
RD
42 # a wx.Window, but contains the given ActiveX control.
43 ActiveXWrapper = ax.MakeActiveXClass(acrobat.Pdf)
f6bcfd97
BP
44
45 # create an instance of the new class
8fa876ca 46 self.pdf = ActiveXWrapper( self, -1, style=wx.SUNKEN_BORDER)
f6bcfd97 47
8fa876ca 48 sizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)
f6bcfd97 49
8fa876ca
RD
50 btn = wx.Button(self, wx.NewId(), "Open PDF File")
51 self.Bind(wx.EVT_BUTTON, self.OnOpenButton)
52 btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
f6bcfd97 53
8fa876ca
RD
54 btn = wx.Button(self, wx.NewId(), "<-- Previous Page")
55 self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, id=btn.GetId())
56 btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
f6bcfd97 57
8fa876ca
RD
58 btn = wx.Button(self, wx.NewId(), "Next Page -->")
59 self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, id=btn.GetId())
60 btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
f6bcfd97
BP
61
62
8fa876ca
RD
63 btnSizer.Add((50,-1), proportion=2, flag=wx.EXPAND)
64 sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)
f6bcfd97
BP
65
66 self.SetSizer(sizer)
1e4a197e 67 self.SetAutoLayout(True)
f6bcfd97 68
8fa876ca 69 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
63b6646e
RD
70
71
72 def OnDestroy(self, evt):
f6bcfd97
BP
73 if self.pdf:
74 self.pdf.Cleanup()
75 self.pdf = None
76
77
78
79 def OnOpenButton(self, event):
8fa876ca
RD
80 dlg = wx.FileDialog(self, wildcard="*.pdf")
81
82 if dlg.ShowModal() == wx.ID_OK:
83 wx.BeginBusyCursor()
f6bcfd97 84 self.pdf.LoadFile(dlg.GetPath())
8fa876ca 85 wx.EndBusyCursor()
f6bcfd97
BP
86
87 dlg.Destroy()
88
89
90 def OnPrevPageButton(self, event):
91 self.pdf.gotoPreviousPage()
92
93
94 def OnNextPageButton(self, event):
95 self.pdf.gotoNextPage()
96
97
98
99#----------------------------------------------------------------------
100
101def runTest(frame, nb, log):
8fa876ca 102 if wx.Platform == '__WXMSW__':
f3d9dc1d 103 win = TestPanel(nb, log)
f6bcfd97
BP
104 return win
105 else:
8fa876ca
RD
106 dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
107 'Sorry', wx.OK | wx.ICON_INFORMATION)
f6bcfd97
BP
108 dlg.ShowModal()
109 dlg.Destroy()
110
111
112overview = __doc__
113
114#----------------------------------------------------------------------
115
116
117if __name__ == '__main__':
8fa876ca 118 class TestFrame(wx.Frame):
f6bcfd97 119 def __init__(self):
8fa876ca
RD
120 wx.Frame.__init__(
121 self, None, -1, "ActiveX test -- Acrobat", size=(640, 480),
122 style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE
123 )
124
f6bcfd97 125 self.tp = TestPanel(self, sys.stdout)
f6bcfd97
BP
126
127
8fa876ca 128 app = wx.PySimpleApp()
f6bcfd97 129 frame = TestFrame()
1e4a197e 130 frame.Show(True)
f6bcfd97
BP
131 app.MainLoop()
132
133