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