]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ActiveXWrapper_Acrobat.py
Script updates
[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 import sys
17 import wx
18
19 if wx.Platform == '__WXMSW__':
20 import wx.lib.activexwrapper as ax
21 import win32com.client.gencache
22
23 try:
24 acrobat = win32com.client.gencache.EnsureModule(
25 '{CA8A9783-280D-11CF-A24D-444553540000}', 0x0, 1, 3
26 )
27 except:
28 raise ImportError("Can't load PDF.OCX, install Acrobat 4.0")
29
30
31 #----------------------------------------------------------------------
32
33 class TestPanel(wx.Panel):
34 def __init__(self, parent, log):
35 wx.Panel.__init__(self, parent, -1)
36 self.pdf = None
37
38 sizer = wx.BoxSizer(wx.VERTICAL)
39 btnSizer = wx.BoxSizer(wx.HORIZONTAL)
40
41 # this function creates a new class that can be used as
42 # a wx.Window, but contains the given ActiveX control.
43 ActiveXWrapper = ax.MakeActiveXClass(acrobat.Pdf)
44
45 # create an instance of the new class
46 self.pdf = ActiveXWrapper( self, -1, style=wx.SUNKEN_BORDER)
47
48 sizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)
49
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)
53
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)
57
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)
61
62
63 btnSizer.Add((50,-1), proportion=2, flag=wx.EXPAND)
64 sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)
65
66 self.SetSizer(sizer)
67 self.SetAutoLayout(True)
68
69 self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
70
71
72 def OnDestroy(self, evt):
73 if self.pdf:
74 self.pdf.Cleanup()
75 self.pdf = None
76
77
78
79 def OnOpenButton(self, event):
80 dlg = wx.FileDialog(self, wildcard="*.pdf")
81
82 if dlg.ShowModal() == wx.ID_OK:
83 wx.BeginBusyCursor()
84 self.pdf.LoadFile(dlg.GetPath())
85 wx.EndBusyCursor()
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
101 def runTest(frame, nb, log):
102 if wx.Platform == '__WXMSW__':
103 win = TestPanel(nb, log)
104 return win
105 else:
106 dlg = wx.MessageDialog(frame, 'This demo only works on MSW.',
107 'Sorry', wx.OK | wx.ICON_INFORMATION)
108 dlg.ShowModal()
109 dlg.Destroy()
110
111
112 overview = __doc__
113
114 #----------------------------------------------------------------------
115
116
117 if __name__ == '__main__':
118 class TestFrame(wx.Frame):
119 def __init__(self):
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
125 self.tp = TestPanel(self, sys.stdout)
126
127
128 app = wx.PySimpleApp()
129 frame = TestFrame()
130 frame.Show(True)
131 app.MainLoop()
132
133