]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ActiveX_PDFWindow.py
reSWIGged
[wxWidgets.git] / wxPython / demo / ActiveX_PDFWindow.py
1 import sys
2 import wx
3
4 if wx.Platform == '__WXMSW__':
5 from wx.lib.pdfwin import PDFWindow
6
7
8 #----------------------------------------------------------------------
9
10 class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 wx.Panel.__init__(self, parent, -1)
13
14 mainsizer = wx.BoxSizer(wx.HORIZONTAL)
15 leftsizer = wx.BoxSizer(wx.VERTICAL)
16 self.pdf = PDFWindow(self, style=wx.SUNKEN_BORDER)
17 leftsizer.Add(self.pdf, proportion=1, flag=wx.EXPAND)
18
19 box = wx.StaticBox(self, wx.NewId(), "" )
20 buttonsizer = wx.StaticBoxSizer(box, wx.HORIZONTAL )
21
22 b1 = wx.Button(self, wx.NewId(), "First")
23 buttonsizer.Add(b1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
24 self.Bind(wx.EVT_BUTTON, self.OnFirstPageButton, b1)
25
26 b2 = wx.Button(self, wx.NewId(), "Previous")
27 buttonsizer.Add(b2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
28 self.Bind(wx.EVT_BUTTON, self.OnPreviousPageButton, b2)
29
30 tx1 = wx.StaticText(self, wx.NewId(), " Go to page" )
31 buttonsizer.Add(tx1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
32 tc1 = wx.TextCtrl(self, wx.NewId(), "0", size=[30,-1])
33 buttonsizer.Add( tc1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
34 self.Bind(wx.EVT_TEXT, self.OnGotoPage, tc1)
35
36 b3 = wx.Button(self, wx.NewId(), "Next")
37 buttonsizer.Add(b3, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
38 self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, b3)
39
40 b4 = wx.Button(self, wx.NewId(), "Last")
41 buttonsizer.Add(b4, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
42 self.Bind(wx.EVT_BUTTON, self.OnLastPageButton, b4)
43
44 tx2 = wx.StaticText(self, wx.NewId(), " Zoom")
45 buttonsizer.Add(tx2, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
46
47 ch1 = wx.Choice(self, wx.NewId(),
48 choices=["Default", "Fit", "FitH", "FitV",
49 "25%", "50%", "75%", "100%", "125%", "200%", "400%"])
50 ch1.SetSelection(0)
51 buttonsizer.Add(ch1, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=5)
52 self.Bind(wx.EVT_CHOICE, self.OnZoom, ch1)
53
54 leftsizer.Add(buttonsizer, proportion=0)
55 mainsizer.Add(leftsizer, proportion=1, flag=wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, border=5)
56
57 box = wx.StaticBox(self, wx.NewId(), "" )
58 rightsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
59
60 b5 = wx.Button(self, wx.NewId(), "Load PDF")
61 rightsizer.Add(b5, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
62 self.Bind(wx.EVT_BUTTON, self.OnLoadButton, b5)
63
64 b6 = wx.Button(self, wx.NewId(), "Print")
65 rightsizer.Add(b6, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
66 self.Bind(wx.EVT_BUTTON, self.OnPrintButton, b6)
67
68 tx3 = wx.StaticText(self, wx.NewId(), "Page mode:")
69 rightsizer.Add(tx3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
70
71 ch2 = wx.Choice(self, wx.NewId(),size=[100,-1],
72 choices=["None", "Bookmarks", "Thumbs"])
73 ch2.SetSelection(0)
74 rightsizer.Add(ch2, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
75 self.Bind(wx.EVT_CHOICE, self.OnPageMode, ch2)
76
77 tx4 = wx.StaticText(self, wx.NewId(), "Layout mode:")
78 rightsizer.Add(tx4, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
79
80 ch3 = wx.Choice(self, wx.NewId(),size=[100,-1],
81 choices=["DontCare", "SinglePage",
82 "OneColumn", "TwoColumnLeft", "TwoColumnRight" ])
83 ch3.SetSelection(0)
84 rightsizer.Add(ch3, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
85 self.Bind(wx.EVT_CHOICE, self.OnLayoutMode, ch3)
86
87 cx1 = wx.CheckBox(self, wx.NewId(), "Toolbar")
88 cx1.SetValue( True )
89 rightsizer.Add( cx1,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
90 self.Bind(wx.EVT_CHECKBOX, self.OnToolbar, cx1)
91
92 cx2 = wx.CheckBox(self, wx.NewId(), "Scrollbars")
93 cx2.SetValue( True )
94 rightsizer.Add( cx2,proportion=0, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
95 self.Bind(wx.EVT_CHECKBOX, self.OnScrollbars, cx2)
96
97 mainsizer.Add( rightsizer, proportion=0, flag=wx.ALL, border=15)
98 self.SetSizer(mainsizer)
99 self.SetAutoLayout(True)
100
101 def OnFirstPageButton(self, event):
102 self.pdf.gotoFirstPage()
103
104 def OnPreviousPageButton(self, event):
105 self.pdf.gotoPreviousPage()
106
107 def OnNextPageButton(self, event):
108 self.pdf.gotoNextPage()
109
110 def OnLastPageButton(self, event):
111 self.pdf.gotoLastPage()
112
113 def OnGotoPage(self, event):
114 npage = event.GetEventObject().GetValue()
115 try:
116 self.pdf.setCurrentPage(int(npage))
117 except ValueError:
118 pass
119
120 def OnZoom(self, event):
121 astring = event.GetEventObject().GetStringSelection()
122 if astring.startswith('Fit'):
123 self.pdf.setView(astring)
124 else:
125 try:
126 percent = float(astring.replace('%',''))
127 self.pdf.setZoom(percent)
128 except ValueError:
129 pass
130
131 def OnLoadButton(self, event):
132 dlg = wx.FileDialog(self, wildcard="*.pdf")
133 if dlg.ShowModal() == wx.ID_OK:
134 wx.BeginBusyCursor()
135 self.pdf.LoadFile(dlg.GetPath())
136 wx.EndBusyCursor()
137 dlg.Destroy()
138
139 def OnPrintButton(self, event):
140 self.pdf.Print()
141
142 def OnPageMode(self, event):
143 astring = event.GetEventObject().GetStringSelection()
144 self.pdf.setPageMode(astring.lower())
145
146 def OnLayoutMode(self, event):
147 astring = event.GetEventObject().GetStringSelection()
148 self.pdf.setLayoutMode(astring)
149
150 def OnToolbar(self, event):
151 on = event.GetEventObject().GetValue()
152 self.pdf.setShowToolbar(on)
153
154 def OnScrollbars(self, event):
155 on = event.GetEventObject().GetValue()
156 self.pdf.setShowScrollbars(on)
157
158 #----------------------------------------------------------------------
159
160 def runTest(frame, nb, log):
161 if wx.Platform == '__WXMSW__':
162 win = TestPanel(nb, log)
163 return win
164 else:
165 from Main import MessagePanel
166 win = MessagePanel(nb, 'This demo only works on Microsoft Windows.',
167 'Sorry', wx.ICON_WARNING)
168 return win
169
170
171 overview = """\
172 <html><body>
173 <h2>wx.lib.pdfwin.PDFWindow</h2>
174
175 The wx.lib.pdfwin.PDFWindow class is another example of using ActiveX
176 controls from wxPython using the new wx.activex module. This allows
177 you to use an ActiveX control as if it is a wx.Window, you can call
178 its methods, set/get properties, and receive events from the ActiveX
179 control in a very intuitive way.
180
181 <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
182 the win32all extensions, and is more "wx\'ish", meaning that it uses
183 events and etc. as would be expected from any other wx window.
184
185 <p> This demo embeds the Adobe Acrobat Reader, and gives you some
186 buttons for opening a PDF file, changing pages, etc. that show how to
187 call methods on the COM object. If you don't have Acrobat Reader 4.0
188 (or greater) installed it won't work.
189
190 </body></html>
191 """
192
193 #----------------------------------------------------------------------
194
195
196
197 if __name__ == '__main__':
198 import sys,os
199 import run
200 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
201
202