4 if wx
.Platform
== '__WXMSW__':
5 from wx
.lib
.pdfwin
import PDFWindow
8 #----------------------------------------------------------------------
10 class TestPanel(wx
.Panel
):
11 def __init__(self
, parent
, log
):
12 wx
.Panel
.__init
__(self
, parent
, -1)
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
)
19 box
= wx
.StaticBox(self
, wx
.NewId(), "" )
20 buttonsizer
= wx
.StaticBoxSizer(box
, wx
.HORIZONTAL
)
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
)
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
)
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
)
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
)
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
)
44 tx2
= wx
.StaticText(self
, wx
.NewId(), " Zoom")
45 buttonsizer
.Add(tx2
, proportion
=0, flag
=wx
.ALIGN_CENTER|wx
.ALL
, border
=5)
47 ch1
= wx
.Choice(self
, wx
.NewId(),
48 choices
=["Default", "Fit", "FitH", "FitV",
49 "25%", "50%", "75%", "100%", "125%", "200%", "400%"])
51 buttonsizer
.Add(ch1
, proportion
=0, flag
=wx
.ALIGN_CENTER|wx
.ALL
, border
=5)
52 self
.Bind(wx
.EVT_CHOICE
, self
.OnZoom
, ch1
)
54 leftsizer
.Add(buttonsizer
, proportion
=0)
55 mainsizer
.Add(leftsizer
, proportion
=1, flag
=wx
.GROW|wx
.ALIGN_CENTER_HORIZONTAL|wx
.ALL
, border
=5)
57 box
= wx
.StaticBox(self
, wx
.NewId(), "" )
58 rightsizer
= wx
.StaticBoxSizer(box
, wx
.VERTICAL
)
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
)
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
)
68 tx3
= wx
.StaticText(self
, wx
.NewId(), "Page mode:")
69 rightsizer
.Add(tx3
, proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
71 ch2
= wx
.Choice(self
, wx
.NewId(),size
=[100,-1],
72 choices
=["None", "Bookmarks", "Thumbs"])
74 rightsizer
.Add(ch2
, proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
75 self
.Bind(wx
.EVT_CHOICE
, self
.OnPageMode
, ch2
)
77 tx4
= wx
.StaticText(self
, wx
.NewId(), "Layout mode:")
78 rightsizer
.Add(tx4
, proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
80 ch3
= wx
.Choice(self
, wx
.NewId(),size
=[100,-1],
81 choices
=["DontCare", "SinglePage",
82 "OneColumn", "TwoColumnLeft", "TwoColumnRight" ])
84 rightsizer
.Add(ch3
, proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
85 self
.Bind(wx
.EVT_CHOICE
, self
.OnLayoutMode
, ch3
)
87 cx1
= wx
.CheckBox(self
, wx
.NewId(), "Toolbar")
89 rightsizer
.Add( cx1
,proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
90 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnToolbar
, cx1
)
92 cx2
= wx
.CheckBox(self
, wx
.NewId(), "Scrollbars")
94 rightsizer
.Add( cx2
,proportion
=0, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALL
, border
=5)
95 self
.Bind(wx
.EVT_CHECKBOX
, self
.OnScrollbars
, cx2
)
97 mainsizer
.Add( rightsizer
, proportion
=0, flag
=wx
.ALL
, border
=15)
98 self
.SetSizer(mainsizer
)
99 self
.SetAutoLayout(True)
101 def OnFirstPageButton(self
, event
):
102 self
.pdf
.gotoFirstPage()
104 def OnPreviousPageButton(self
, event
):
105 self
.pdf
.gotoPreviousPage()
107 def OnNextPageButton(self
, event
):
108 self
.pdf
.gotoNextPage()
110 def OnLastPageButton(self
, event
):
111 self
.pdf
.gotoLastPage()
113 def OnGotoPage(self
, event
):
114 npage
= event
.GetEventObject().GetValue()
116 self
.pdf
.setCurrentPage(int(npage
))
120 def OnZoom(self
, event
):
121 astring
= event
.GetEventObject().GetStringSelection()
122 if astring
.startswith('Fit'):
123 self
.pdf
.setView(astring
)
126 percent
= float(astring
.replace('%',''))
127 self
.pdf
.setZoom(percent
)
131 def OnLoadButton(self
, event
):
132 dlg
= wx
.FileDialog(self
, wildcard
="*.pdf")
133 if dlg
.ShowModal() == wx
.ID_OK
:
135 self
.pdf
.LoadFile(dlg
.GetPath())
139 def OnPrintButton(self
, event
):
142 def OnPageMode(self
, event
):
143 astring
= event
.GetEventObject().GetStringSelection()
144 self
.pdf
.setPageMode(astring
.lower())
146 def OnLayoutMode(self
, event
):
147 astring
= event
.GetEventObject().GetStringSelection()
148 self
.pdf
.setLayoutMode(astring
)
150 def OnToolbar(self
, event
):
151 on
= event
.GetEventObject().GetValue()
152 self
.pdf
.setShowToolbar(on
)
154 def OnScrollbars(self
, event
):
155 on
= event
.GetEventObject().GetValue()
156 self
.pdf
.setShowScrollbars(on
)
158 #----------------------------------------------------------------------
160 def runTest(frame
, nb
, log
):
161 if wx
.Platform
== '__WXMSW__':
162 win
= TestPanel(nb
, log
)
165 from Main
import MessagePanel
166 win
= MessagePanel(nb
, 'This demo only works on Microsoft Windows.',
167 'Sorry', wx
.ICON_WARNING
)
173 <h2>wx.lib.pdfwin.PDFWindow</h2>
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.
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.
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.
193 #----------------------------------------------------------------------
197 if __name__
== '__main__':
200 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])