]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/pdfwin.py
PDA adjustements
[wxWidgets.git] / wxPython / wx / lib / pdfwin.py
CommitLineData
b7c75283
RD
1#----------------------------------------------------------------------
2# Name: wx.lib.pdfwin
3# Purpose: A class that allows the use of the Acrobat PSF reader
4# ActiveX control
5#
6# Author: Robin Dunn
7#
8# Created: 22-March-2004
9# RCS-ID: $Id$
10# Copyright: (c) 2004 by Total Control Software
11# Licence: wxWindows license
12#----------------------------------------------------------------------
b7c75283
RD
13
14import wx
b7c75283 15
e5fb6f92 16#----------------------------------------------------------------------
b7c75283 17
e5fb6f92
RD
18_acroversion = None
19
20def get_acroversion():
21 " Return version of Adobe Acrobat executable or None"
22 global _acroversion
23 if _acroversion == None:
24 import _winreg
25 acrosoft = [r'SOFTWARE\Adobe\Acrobat Reader\%version%\InstallPath',
26 r'SOFTWARE\Adobe\Adobe Acrobat\%version%\InstallPath',]
27
28 for regkey in acrosoft:
29 for version in ('7.0', '6.0', '5.0', '4.0'):
30 try:
31 path = _winreg.QueryValue(_winreg.HKEY_LOCAL_MACHINE,
32 regkey.replace('%version%', version))
33 _acroversion = version
34 break
35 except:
36 continue
37 return _acroversion
b7c75283 38
e5fb6f92 39#----------------------------------------------------------------------
b7c75283 40
e5fb6f92
RD
41# The ActiveX module from Acrobat 7.0 has changed and it seems to now
42# require much more from the container than what our wx.activex module
43# provides. If we try to use it via wx.activex then Acrobat crashes.
44# So instead we will use Internet Explorer (via the win32com modules
45# so we can use better dynamic dispatch) and embed the Acrobat control
46# within that. Acrobat provides the IAcroAXDocShim COM class that is
47# accessible via the IE window's Docuemnt property after a PDF file
48# has been loaded.
49
50if get_acroversion() >= '7.0':
51
52 from wx.lib.activexwrapper import MakeActiveXClass
53 import win32com.client.gencache
54 _browserModule = win32com.client.gencache.EnsureModule(
55 "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
56
57 class PDFWindowError(RuntimeError):
58 def __init__(self):
59 RuntimeError.__init__(self, "A PDF must be loaded before calling this method.")
60
61
62 class PDFWindow(wx.Panel):
63 def __init__(self, *args, **kw):
64 wx.Panel.__init__(self, *args, **kw)
65
66 # Make a new class that derives from the WebBrowser class
67 # in the COM module imported above. This class also
68 # derives from wxWindow and implements the machinery
69 # needed to integrate the two worlds.
70 _WebBrowserClass = MakeActiveXClass(_browserModule.WebBrowser)
71 self.ie = _WebBrowserClass(self, -1)
72 sizer = wx.BoxSizer()
73 sizer.Add(self.ie, 1, wx.EXPAND)
74 self.SetSizer(sizer)
75
76
77 def LoadFile(self, fileName):
78 if self.ie.Document:
79 return self.ie.Document.LoadFile(fileName)
80 else:
81 self.ie.Navigate2(fileName)
82 return True # can we sense failure at this point?
83
84 def GetVersions(self):
85 if self.ie.Document:
86 return self.ie.Document.GetVersions()
87 else:
88 raise PDFWindowError()
89
90 def Print(self):
91 if self.ie.Document:
92 return self.ie.Document.Print()
93 else:
94 raise PDFWindowError()
95
96 def goBackwardStack(self):
97 if self.ie.Document:
98 return self.ie.Document.goBackwardStack()
99 else:
100 raise PDFWindowError()
101
102 def goForwardStack(self):
103 if self.ie.Document:
104 return self.ie.Document.goForwardStack()
105 else:
106 raise PDFWindowError()
107
108 def gotoFirstPage(self):
109 if self.ie.Document:
110 return self.ie.Document.gotoFirstPage()
111 else:
112 raise PDFWindowError()
113
114 def gotoLastPage(self):
115 if self.ie.Document:
116 return self.ie.Document.gotoLastPage()
117 else:
118 raise PDFWindowError()
119
120 def gotoNextPage(self):
121 if self.ie.Document:
122 return self.ie.Document.gotoNextPage()
123 else:
124 raise PDFWindowError()
125
126 def gotoPreviousPage(self):
127 if self.ie.Document:
128 return self.ie.Document.gotoPreviousPage()
129 else:
130 raise PDFWindowError()
131
132 def printAll(self):
133 if self.ie.Document:
134 return self.ie.Document.printAll()
135 else:
136 raise PDFWindowError()
137
138 def printAllFit(self, shrinkToFit):
139 if self.ie.Document:
140 return self.ie.Document.printAllFit()
141 else:
142 raise PDFWindowError()
143
144 def printPages(self, from_, to):
145 if self.ie.Document:
146 return self.ie.Document.printPages()
147 else:
148 raise PDFWindowError()
149
150 def printPagesFit(self, from_, to, shrinkToFit):
151 if self.ie.Document:
152 return self.ie.Document.printPagesFit()
153 else:
154 raise PDFWindowError()
155
156 def printWithDialog(self):
157 if self.ie.Document:
158 return self.ie.Document.printWithDialog()
159 else:
160 raise PDFWindowError()
161
162 def setCurrentHighlight(self, a, b, c, d):
163 if self.ie.Document:
164 return self.ie.Document.setCurrentHighlight()
165 else:
166 raise PDFWindowError()
167
168 def setCurrentHightlight(self, a, b, c, d):
169 if self.ie.Document:
170 return self.ie.Document.setCurrentHightlight()
171 else:
172 raise PDFWindowError()
173
174 def setCurrentPage(self, n):
175 if self.ie.Document:
176 return self.ie.Document.setCurrentPage()
177 else:
178 raise PDFWindowError()
179
180 def setLayoutMode(self, layoutMode):
181 if self.ie.Document:
182 return self.ie.Document.setLayoutMode()
183 else:
184 raise PDFWindowError()
185
186 def setNamedDest(self, namedDest):
187 if self.ie.Document:
188 return self.ie.Document.setNamedDest()
189 else:
190 raise PDFWindowError()
191
192 def setPageMode(self, pageMode):
193 if self.ie.Document:
194 return self.ie.Document.setPageMode()
195 else:
196 raise PDFWindowError()
197
198 def setShowScrollbars(self, On):
199 if self.ie.Document:
200 return self.ie.Document.setShowScrollbars()
201 else:
202 raise PDFWindowError()
203
204 def setShowToolbar(self, On):
205 if self.ie.Document:
206 return self.ie.Document.setShowToolbar()
207 else:
208 raise PDFWindowError()
209
210 def setView(self, viewMode):
211 if self.ie.Document:
212 return self.ie.Document.setView()
213 else:
214 raise PDFWindowError()
215
216 def setViewRect(self, left, top, width, height):
217 if self.ie.Document:
218 return self.ie.Document.setViewRect()
219 else:
220 raise PDFWindowError()
221
222 def setViewScroll(self, viewMode, offset):
223 if self.ie.Document:
224 return self.ie.Document.setViewScroll()
225 else:
226 raise PDFWindowError()
227
228 def setZoom(self, percent):
229 if self.ie.Document:
230 return self.ie.Document.setZoom()
231 else:
232 raise PDFWindowError()
233
234 def setZoomScroll(self, percent, left, top):
235 if self.ie.Document:
236 return self.ie.Document.setZoomScroll()
237 else:
238 raise PDFWindowError()
a7a01418 239
e5fb6f92 240
a7a01418 241
e5fb6f92
RD
242else:
243 import wx.activex
a7a01418 244
e5fb6f92
RD
245 clsID = '{CA8A9780-280D-11CF-A24D-444553540000}'
246 progID = 'AcroPDF.PDF.1'
247
248
249 # Create eventTypes and event binders
250 wxEVT_Error = wx.activex.RegisterActiveXEvent('OnError')
251 wxEVT_Message = wx.activex.RegisterActiveXEvent('OnMessage')
252
253 EVT_Error = wx.PyEventBinder(wxEVT_Error, 1)
254 EVT_Message = wx.PyEventBinder(wxEVT_Message, 1)
255
256
257 # Derive a new class from ActiveXWindow
258 class PDFWindow(wx.activex.ActiveXWindow):
259 def __init__(self, parent, ID=-1, pos=wx.DefaultPosition,
260 size=wx.DefaultSize, style=0, name='PDFWindow'):
261 wx.activex.ActiveXWindow.__init__(self, parent,
262 wx.activex.CLSID('{CA8A9780-280D-11CF-A24D-444553540000}'),
263 ID, pos, size, style, name)
264
265 # Methods exported by the ActiveX object
266 def QueryInterface(self, riid):
267 return self.CallAXMethod('QueryInterface', riid)
a7a01418 268
e5fb6f92
RD
269 def AddRef(self):
270 return self.CallAXMethod('AddRef')
a7a01418 271
e5fb6f92
RD
272 def Release(self):
273 return self.CallAXMethod('Release')
a7a01418 274
e5fb6f92
RD
275 def GetTypeInfoCount(self):
276 return self.CallAXMethod('GetTypeInfoCount')
a7a01418 277
e5fb6f92
RD
278 def GetTypeInfo(self, itinfo, lcid):
279 return self.CallAXMethod('GetTypeInfo', itinfo, lcid)
a7a01418 280
e5fb6f92
RD
281 def GetIDsOfNames(self, riid, rgszNames, cNames, lcid):
282 return self.CallAXMethod('GetIDsOfNames', riid, rgszNames, cNames, lcid)
a7a01418 283
e5fb6f92
RD
284 def Invoke(self, dispidMember, riid, lcid, wFlags, pdispparams):
285 return self.CallAXMethod('Invoke', dispidMember, riid, lcid, wFlags, pdispparams)
a7a01418 286
e5fb6f92
RD
287 def LoadFile(self, fileName):
288 return self.CallAXMethod('LoadFile', fileName)
b7c75283 289
e5fb6f92
RD
290 def setShowToolbar(self, On):
291 return self.CallAXMethod('setShowToolbar', On)
b7c75283 292
e5fb6f92
RD
293 def gotoFirstPage(self):
294 return self.CallAXMethod('gotoFirstPage')
b7c75283 295
e5fb6f92
RD
296 def gotoLastPage(self):
297 return self.CallAXMethod('gotoLastPage')
b7c75283 298
e5fb6f92
RD
299 def gotoNextPage(self):
300 return self.CallAXMethod('gotoNextPage')
b7c75283 301
e5fb6f92
RD
302 def gotoPreviousPage(self):
303 return self.CallAXMethod('gotoPreviousPage')
b7c75283 304
e5fb6f92
RD
305 def setCurrentPage(self, n):
306 return self.CallAXMethod('setCurrentPage', n)
b7c75283 307
e5fb6f92
RD
308 def goForwardStack(self):
309 return self.CallAXMethod('goForwardStack')
b7c75283 310
e5fb6f92
RD
311 def goBackwardStack(self):
312 return self.CallAXMethod('goBackwardStack')
b7c75283 313
e5fb6f92
RD
314 def setPageMode(self, pageMode):
315 return self.CallAXMethod('setPageMode', pageMode)
b7c75283 316
e5fb6f92
RD
317 def setLayoutMode(self, layoutMode):
318 return self.CallAXMethod('setLayoutMode', layoutMode)
b7c75283 319
e5fb6f92
RD
320 def setNamedDest(self, namedDest):
321 return self.CallAXMethod('setNamedDest', namedDest)
b7c75283 322
e5fb6f92
RD
323 def Print(self):
324 return self.CallAXMethod('Print')
b7c75283 325
e5fb6f92
RD
326 def printWithDialog(self):
327 return self.CallAXMethod('printWithDialog')
b7c75283 328
e5fb6f92
RD
329 def setZoom(self, percent):
330 return self.CallAXMethod('setZoom', percent)
b7c75283 331
e5fb6f92
RD
332 def setZoomScroll(self, percent, left, top):
333 return self.CallAXMethod('setZoomScroll', percent, left, top)
b7c75283 334
e5fb6f92
RD
335 def setView(self, viewMode):
336 return self.CallAXMethod('setView', viewMode)
b7c75283 337
e5fb6f92
RD
338 def setViewScroll(self, viewMode, offset):
339 return self.CallAXMethod('setViewScroll', viewMode, offset)
b7c75283 340
e5fb6f92
RD
341 def setViewRect(self, left, top, width, height):
342 return self.CallAXMethod('setViewRect', left, top, width, height)
b7c75283 343
e5fb6f92
RD
344 def printPages(self, from_, to):
345 return self.CallAXMethod('printPages', from_, to)
b7c75283 346
e5fb6f92
RD
347 def printPagesFit(self, from_, to, shrinkToFit):
348 return self.CallAXMethod('printPagesFit', from_, to, shrinkToFit)
b7c75283 349
e5fb6f92
RD
350 def printAll(self):
351 return self.CallAXMethod('printAll')
b7c75283 352
e5fb6f92
RD
353 def printAllFit(self, shrinkToFit):
354 return self.CallAXMethod('printAllFit', shrinkToFit)
b7c75283 355
e5fb6f92
RD
356 def setShowScrollbars(self, On):
357 return self.CallAXMethod('setShowScrollbars', On)
b7c75283 358
e5fb6f92
RD
359 def GetVersions(self):
360 return self.CallAXMethod('GetVersions')
a7a01418 361
e5fb6f92
RD
362 def setCurrentHightlight(self, a, b, c, d):
363 return self.CallAXMethod('setCurrentHightlight', a, b, c, d)
a7a01418 364
e5fb6f92
RD
365 def setCurrentHighlight(self, a, b, c, d):
366 return self.CallAXMethod('setCurrentHighlight', a, b, c, d)
a7a01418 367
e5fb6f92
RD
368 def postMessage(self, strArray):
369 return self.CallAXMethod('postMessage', strArray)
a7a01418 370
e5fb6f92
RD
371 # Getters, Setters and properties
372 def _get_src(self):
373 return self.GetAXProp('src')
374 def _set_src(self, src):
375 self.SetAXProp('src', src)
376 src = property(_get_src, _set_src)
a7a01418 377
e5fb6f92
RD
378 def _get_messageHandler(self):
379 return self.GetAXProp('messageHandler')
380 def _set_messageHandler(self, messageHandler):
381 self.SetAXProp('messageHandler', messageHandler)
382 messagehandler = property(_get_messageHandler, _set_messageHandler)
b7c75283
RD
383
384
385# PROPERTIES
386# --------------------
a7a01418
RD
387# src
388# type:string arg:string canGet:True canSet:True
389#
390# messagehandler
391# type:VT_VARIANT arg:VT_VARIANT canGet:True canSet:True
392#
b7c75283
RD
393#
394#
395#
396# METHODS
397# --------------------
a7a01418
RD
398# QueryInterface
399# retType: VT_VOID
400# params:
401# riid
402# in:True out:False optional:False type:unsupported type 29
403# ppvObj
404# in:False out:True optional:False type:unsupported type 26
405#
406# AddRef
407# retType: int
408#
409# Release
410# retType: int
411#
412# GetTypeInfoCount
413# retType: VT_VOID
414# params:
415# pctinfo
416# in:False out:True optional:False type:int
417#
418# GetTypeInfo
419# retType: VT_VOID
420# params:
421# itinfo
422# in:True out:False optional:False type:int
423# lcid
424# in:True out:False optional:False type:int
425# pptinfo
426# in:False out:True optional:False type:unsupported type 26
427#
428# GetIDsOfNames
429# retType: VT_VOID
430# params:
431# riid
432# in:True out:False optional:False type:unsupported type 29
433# rgszNames
434# in:True out:False optional:False type:unsupported type 26
435# cNames
436# in:True out:False optional:False type:int
437# lcid
438# in:True out:False optional:False type:int
439# rgdispid
440# in:False out:True optional:False type:int
441#
442# Invoke
443# retType: VT_VOID
444# params:
445# dispidMember
446# in:True out:False optional:False type:int
447# riid
448# in:True out:False optional:False type:unsupported type 29
449# lcid
450# in:True out:False optional:False type:int
451# wFlags
452# in:True out:False optional:False type:int
453# pdispparams
454# in:True out:False optional:False type:unsupported type 29
455# pvarResult
456# in:False out:True optional:False type:VT_VARIANT
457# pexcepinfo
458# in:False out:True optional:False type:unsupported type 29
459# puArgErr
460# in:False out:True optional:False type:int
461#
b7c75283
RD
462# LoadFile
463# retType: bool
464# params:
465# fileName
a7a01418 466# in:True out:False optional:False type:string
b7c75283
RD
467#
468# setShowToolbar
469# retType: VT_VOID
470# params:
471# On
a7a01418 472# in:True out:False optional:False type:bool
b7c75283
RD
473#
474# gotoFirstPage
475# retType: VT_VOID
476#
477# gotoLastPage
478# retType: VT_VOID
479#
480# gotoNextPage
481# retType: VT_VOID
482#
483# gotoPreviousPage
484# retType: VT_VOID
485#
486# setCurrentPage
487# retType: VT_VOID
488# params:
489# n
a7a01418 490# in:True out:False optional:False type:int
b7c75283
RD
491#
492# goForwardStack
493# retType: VT_VOID
494#
495# goBackwardStack
496# retType: VT_VOID
497#
498# setPageMode
499# retType: VT_VOID
500# params:
501# pageMode
a7a01418 502# in:True out:False optional:False type:string
b7c75283
RD
503#
504# setLayoutMode
505# retType: VT_VOID
506# params:
507# layoutMode
a7a01418 508# in:True out:False optional:False type:string
b7c75283
RD
509#
510# setNamedDest
511# retType: VT_VOID
512# params:
513# namedDest
a7a01418 514# in:True out:False optional:False type:string
b7c75283
RD
515#
516# Print
517# retType: VT_VOID
518#
519# printWithDialog
520# retType: VT_VOID
521#
522# setZoom
523# retType: VT_VOID
524# params:
525# percent
a7a01418 526# in:True out:False optional:False type:double
b7c75283
RD
527#
528# setZoomScroll
529# retType: VT_VOID
530# params:
531# percent
a7a01418 532# in:True out:False optional:False type:double
b7c75283 533# left
a7a01418 534# in:True out:False optional:False type:double
b7c75283 535# top
a7a01418 536# in:True out:False optional:False type:double
b7c75283
RD
537#
538# setView
539# retType: VT_VOID
540# params:
541# viewMode
a7a01418 542# in:True out:False optional:False type:string
b7c75283
RD
543#
544# setViewScroll
545# retType: VT_VOID
546# params:
547# viewMode
a7a01418 548# in:True out:False optional:False type:string
b7c75283 549# offset
a7a01418 550# in:True out:False optional:False type:double
b7c75283
RD
551#
552# setViewRect
553# retType: VT_VOID
554# params:
555# left
a7a01418 556# in:True out:False optional:False type:double
b7c75283 557# top
a7a01418 558# in:True out:False optional:False type:double
b7c75283 559# width
a7a01418 560# in:True out:False optional:False type:double
b7c75283 561# height
a7a01418 562# in:True out:False optional:False type:double
b7c75283
RD
563#
564# printPages
565# retType: VT_VOID
566# params:
567# from
a7a01418 568# in:True out:False optional:False type:int
b7c75283 569# to
a7a01418 570# in:True out:False optional:False type:int
b7c75283
RD
571#
572# printPagesFit
573# retType: VT_VOID
574# params:
575# from
a7a01418 576# in:True out:False optional:False type:int
b7c75283 577# to
a7a01418 578# in:True out:False optional:False type:int
b7c75283 579# shrinkToFit
a7a01418 580# in:True out:False optional:False type:bool
b7c75283
RD
581#
582# printAll
583# retType: VT_VOID
584#
585# printAllFit
586# retType: VT_VOID
587# params:
588# shrinkToFit
a7a01418 589# in:True out:False optional:False type:bool
b7c75283
RD
590#
591# setShowScrollbars
592# retType: VT_VOID
593# params:
594# On
a7a01418 595# in:True out:False optional:False type:bool
b7c75283 596#
a7a01418
RD
597# GetVersions
598# retType: VT_VARIANT
599#
600# setCurrentHightlight
601# retType: VT_VOID
602# params:
603# a
604# in:True out:False optional:False type:int
605# b
606# in:True out:False optional:False type:int
607# c
608# in:True out:False optional:False type:int
609# d
610# in:True out:False optional:False type:int
611#
612# setCurrentHighlight
613# retType: VT_VOID
614# params:
615# a
616# in:True out:False optional:False type:int
617# b
618# in:True out:False optional:False type:int
619# c
620# in:True out:False optional:False type:int
621# d
622# in:True out:False optional:False type:int
623#
624# postMessage
b7c75283 625# retType: VT_VOID
a7a01418
RD
626# params:
627# strArray
628# in:True out:False optional:False type:VT_VARIANT
b7c75283
RD
629#
630#
631#
632#
633# EVENTS
634# --------------------
a7a01418
RD
635# Error
636# retType: VT_VOID
637#
638# Message
639# retType: VT_VOID
640#
b7c75283
RD
641#
642#
643#