]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ActiveX_PDFWindow.py
Another package name fix
[wxWidgets.git] / wxPython / demo / ActiveX_PDFWindow.py
CommitLineData
b7c75283
RD
1import sys
2import wx
3
4if wx.Platform == '__WXMSW__':
5 from wx.lib.pdfwin import PDFWindow
6
7
8#----------------------------------------------------------------------
9
10class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 wx.Panel.__init__(self, parent, -1)
b7c75283 13
f3768653
RD
14 mainsizer = wx.BoxSizer(wx.HORIZONTAL)
15 leftsizer = wx.BoxSizer(wx.VERTICAL)
b7c75283 16 self.pdf = PDFWindow(self, style=wx.SUNKEN_BORDER)
f3768653
RD
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)
b7c75283
RD
99 self.SetAutoLayout(True)
100
f3768653
RD
101 def OnFirstPageButton(self, event):
102 self.pdf.gotoFirstPage()
103
104 def OnPreviousPageButton(self, event):
105 self.pdf.gotoPreviousPage()
b7c75283 106
f3768653
RD
107 def OnNextPageButton(self, event):
108 self.pdf.gotoNextPage()
b7c75283 109
f3768653
RD
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):
b7c75283 132 dlg = wx.FileDialog(self, wildcard="*.pdf")
b7c75283
RD
133 if dlg.ShowModal() == wx.ID_OK:
134 wx.BeginBusyCursor()
135 self.pdf.LoadFile(dlg.GetPath())
136 wx.EndBusyCursor()
b7c75283
RD
137 dlg.Destroy()
138
f3768653
RD
139 def OnPrintButton(self, event):
140 self.pdf.Print()
b7c75283 141
f3768653
RD
142 def OnPageMode(self, event):
143 astring = event.GetEventObject().GetStringSelection()
144 self.pdf.setPageMode(astring.lower())
b7c75283 145
f3768653
RD
146 def OnLayoutMode(self, event):
147 astring = event.GetEventObject().GetStringSelection()
148 self.pdf.setLayoutMode(astring)
b7c75283 149
f3768653
RD
150 def OnToolbar(self, event):
151 on = event.GetEventObject().GetValue()
152 self.pdf.setShowToolbar(on)
b7c75283 153
f3768653
RD
154 def OnScrollbars(self, event):
155 on = event.GetEventObject().GetValue()
156 self.pdf.setShowScrollbars(on)
b7c75283
RD
157
158#----------------------------------------------------------------------
159
160def runTest(frame, nb, log):
161 if wx.Platform == '__WXMSW__':
162 win = TestPanel(nb, log)
163 return win
164 else:
c4ef95da
RD
165 from Main import MessagePanel
166 win = MessagePanel(nb, 'This demo only works on Microsoft Windows.',
167 'Sorry', wx.ICON_WARNING)
168 return win
b7c75283
RD
169
170
3c8ad70a
RD
171overview = """\
172<html><body>
b7c75283
RD
173<h2>wx.lib.pdfwin.PDFWindow</h2>
174
175The wx.lib.pdfwin.PDFWindow class is another example of using ActiveX
176controls from wxPython using the new wx.activex module. This allows
177you to use an ActiveX control as if it is a wx.Window, you can call
178its methods, set/get properties, and receive events from the ActiveX
179control in a very intuitive way.
180
181<p> Using this class is simpler than ActiveXWrapper, doesn't rely on
182the win32all extensions, and is more "wx\'ish", meaning that it uses
183events 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
186buttons for opening a PDF file, changing pages, etc. that show how to
187call 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
197if __name__ == '__main__':
198 import sys,os
199 import run
200 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
201
202