]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/pdfwin.py
1 #----------------------------------------------------------------------
3 # Purpose: A class that allows the use of the Acrobat PSF reader
8 # Created: 22-March-2004
10 # Copyright: (c) 2004 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
16 #----------------------------------------------------------------------
20 def get_acroversion():
21 " Return version of Adobe Acrobat executable or None"
23 if _acroversion
== None:
25 acrosoft
= [r
'SOFTWARE\Adobe\Acrobat Reader\%version%\InstallPath',
26 r
'SOFTWARE\Adobe\Adobe Acrobat\%version%\InstallPath',]
28 for regkey
in acrosoft
:
29 for version
in ('7.0', '6.0', '5.0', '4.0'):
31 path
= _winreg
.QueryValue(_winreg
.HKEY_LOCAL_MACHINE
,
32 regkey
.replace('%version%', version
))
33 _acroversion
= version
39 #----------------------------------------------------------------------
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
50 if get_acroversion() >= '7.0':
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)
57 class PDFWindowError(RuntimeError):
59 RuntimeError.__init
__(self
, "A PDF must be loaded before calling this method.")
62 class PDFWindow(wx
.Panel
):
63 def __init__(self
, *args
, **kw
):
64 wx
.Panel
.__init
__(self
, *args
, **kw
)
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)
73 sizer
.Add(self
.ie
, 1, wx
.EXPAND
)
77 def LoadFile(self
, fileName
):
79 return self
.ie
.Document
.LoadFile(fileName
)
81 self
.ie
.Navigate2(fileName
)
82 return True # can we sense failure at this point?
84 def GetVersions(self
):
86 return self
.ie
.Document
.GetVersions()
88 raise PDFWindowError()
92 return self
.ie
.Document
.Print()
94 raise PDFWindowError()
96 def goBackwardStack(self
):
98 return self
.ie
.Document
.goBackwardStack()
100 raise PDFWindowError()
102 def goForwardStack(self
):
104 return self
.ie
.Document
.goForwardStack()
106 raise PDFWindowError()
108 def gotoFirstPage(self
):
110 return self
.ie
.Document
.gotoFirstPage()
112 raise PDFWindowError()
114 def gotoLastPage(self
):
116 return self
.ie
.Document
.gotoLastPage()
118 raise PDFWindowError()
120 def gotoNextPage(self
):
122 return self
.ie
.Document
.gotoNextPage()
124 raise PDFWindowError()
126 def gotoPreviousPage(self
):
128 return self
.ie
.Document
.gotoPreviousPage()
130 raise PDFWindowError()
134 return self
.ie
.Document
.printAll()
136 raise PDFWindowError()
138 def printAllFit(self
, shrinkToFit
):
140 return self
.ie
.Document
.printAllFit()
142 raise PDFWindowError()
144 def printPages(self
, from_
, to
):
146 return self
.ie
.Document
.printPages()
148 raise PDFWindowError()
150 def printPagesFit(self
, from_
, to
, shrinkToFit
):
152 return self
.ie
.Document
.printPagesFit()
154 raise PDFWindowError()
156 def printWithDialog(self
):
158 return self
.ie
.Document
.printWithDialog()
160 raise PDFWindowError()
162 def setCurrentHighlight(self
, a
, b
, c
, d
):
164 return self
.ie
.Document
.setCurrentHighlight()
166 raise PDFWindowError()
168 def setCurrentHightlight(self
, a
, b
, c
, d
):
170 return self
.ie
.Document
.setCurrentHightlight()
172 raise PDFWindowError()
174 def setCurrentPage(self
, n
):
176 return self
.ie
.Document
.setCurrentPage()
178 raise PDFWindowError()
180 def setLayoutMode(self
, layoutMode
):
182 return self
.ie
.Document
.setLayoutMode()
184 raise PDFWindowError()
186 def setNamedDest(self
, namedDest
):
188 return self
.ie
.Document
.setNamedDest()
190 raise PDFWindowError()
192 def setPageMode(self
, pageMode
):
194 return self
.ie
.Document
.setPageMode()
196 raise PDFWindowError()
198 def setShowScrollbars(self
, On
):
200 return self
.ie
.Document
.setShowScrollbars()
202 raise PDFWindowError()
204 def setShowToolbar(self
, On
):
206 return self
.ie
.Document
.setShowToolbar()
208 raise PDFWindowError()
210 def setView(self
, viewMode
):
212 return self
.ie
.Document
.setView()
214 raise PDFWindowError()
216 def setViewRect(self
, left
, top
, width
, height
):
218 return self
.ie
.Document
.setViewRect()
220 raise PDFWindowError()
222 def setViewScroll(self
, viewMode
, offset
):
224 return self
.ie
.Document
.setViewScroll()
226 raise PDFWindowError()
228 def setZoom(self
, percent
):
230 return self
.ie
.Document
.setZoom()
232 raise PDFWindowError()
234 def setZoomScroll(self
, percent
, left
, top
):
236 return self
.ie
.Document
.setZoomScroll()
238 raise PDFWindowError()
245 clsID
= '{CA8A9780-280D-11CF-A24D-444553540000}'
246 progID
= 'AcroPDF.PDF.1'
249 # Create eventTypes and event binders
250 wxEVT_Error
= wx
.activex
.RegisterActiveXEvent('OnError')
251 wxEVT_Message
= wx
.activex
.RegisterActiveXEvent('OnMessage')
253 EVT_Error
= wx
.PyEventBinder(wxEVT_Error
, 1)
254 EVT_Message
= wx
.PyEventBinder(wxEVT_Message
, 1)
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
)
265 # Methods exported by the ActiveX object
266 def QueryInterface(self
, riid
):
267 return self
.CallAXMethod('QueryInterface', riid
)
270 return self
.CallAXMethod('AddRef')
273 return self
.CallAXMethod('Release')
275 def GetTypeInfoCount(self
):
276 return self
.CallAXMethod('GetTypeInfoCount')
278 def GetTypeInfo(self
, itinfo
, lcid
):
279 return self
.CallAXMethod('GetTypeInfo', itinfo
, lcid
)
281 def GetIDsOfNames(self
, riid
, rgszNames
, cNames
, lcid
):
282 return self
.CallAXMethod('GetIDsOfNames', riid
, rgszNames
, cNames
, lcid
)
284 def Invoke(self
, dispidMember
, riid
, lcid
, wFlags
, pdispparams
):
285 return self
.CallAXMethod('Invoke', dispidMember
, riid
, lcid
, wFlags
, pdispparams
)
287 def LoadFile(self
, fileName
):
288 return self
.CallAXMethod('LoadFile', fileName
)
290 def setShowToolbar(self
, On
):
291 return self
.CallAXMethod('setShowToolbar', On
)
293 def gotoFirstPage(self
):
294 return self
.CallAXMethod('gotoFirstPage')
296 def gotoLastPage(self
):
297 return self
.CallAXMethod('gotoLastPage')
299 def gotoNextPage(self
):
300 return self
.CallAXMethod('gotoNextPage')
302 def gotoPreviousPage(self
):
303 return self
.CallAXMethod('gotoPreviousPage')
305 def setCurrentPage(self
, n
):
306 return self
.CallAXMethod('setCurrentPage', n
)
308 def goForwardStack(self
):
309 return self
.CallAXMethod('goForwardStack')
311 def goBackwardStack(self
):
312 return self
.CallAXMethod('goBackwardStack')
314 def setPageMode(self
, pageMode
):
315 return self
.CallAXMethod('setPageMode', pageMode
)
317 def setLayoutMode(self
, layoutMode
):
318 return self
.CallAXMethod('setLayoutMode', layoutMode
)
320 def setNamedDest(self
, namedDest
):
321 return self
.CallAXMethod('setNamedDest', namedDest
)
324 return self
.CallAXMethod('Print')
326 def printWithDialog(self
):
327 return self
.CallAXMethod('printWithDialog')
329 def setZoom(self
, percent
):
330 return self
.CallAXMethod('setZoom', percent
)
332 def setZoomScroll(self
, percent
, left
, top
):
333 return self
.CallAXMethod('setZoomScroll', percent
, left
, top
)
335 def setView(self
, viewMode
):
336 return self
.CallAXMethod('setView', viewMode
)
338 def setViewScroll(self
, viewMode
, offset
):
339 return self
.CallAXMethod('setViewScroll', viewMode
, offset
)
341 def setViewRect(self
, left
, top
, width
, height
):
342 return self
.CallAXMethod('setViewRect', left
, top
, width
, height
)
344 def printPages(self
, from_
, to
):
345 return self
.CallAXMethod('printPages', from_
, to
)
347 def printPagesFit(self
, from_
, to
, shrinkToFit
):
348 return self
.CallAXMethod('printPagesFit', from_
, to
, shrinkToFit
)
351 return self
.CallAXMethod('printAll')
353 def printAllFit(self
, shrinkToFit
):
354 return self
.CallAXMethod('printAllFit', shrinkToFit
)
356 def setShowScrollbars(self
, On
):
357 return self
.CallAXMethod('setShowScrollbars', On
)
359 def GetVersions(self
):
360 return self
.CallAXMethod('GetVersions')
362 def setCurrentHightlight(self
, a
, b
, c
, d
):
363 return self
.CallAXMethod('setCurrentHightlight', a
, b
, c
, d
)
365 def setCurrentHighlight(self
, a
, b
, c
, d
):
366 return self
.CallAXMethod('setCurrentHighlight', a
, b
, c
, d
)
368 def postMessage(self
, strArray
):
369 return self
.CallAXMethod('postMessage', strArray
)
371 # Getters, Setters and properties
373 return self
.GetAXProp('src')
374 def _set_src(self
, src
):
375 self
.SetAXProp('src', src
)
376 src
= property(_get_src
, _set_src
)
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
)
386 # --------------------
388 # type:string arg:string canGet:True canSet:True
391 # type:VT_VARIANT arg:VT_VARIANT canGet:True canSet:True
397 # --------------------
402 # in:True out:False optional:False type:unsupported type 29
404 # in:False out:True optional:False type:unsupported type 26
416 # in:False out:True optional:False type:int
422 # in:True out:False optional:False type:int
424 # in:True out:False optional:False type:int
426 # in:False out:True optional:False type:unsupported type 26
432 # in:True out:False optional:False type:unsupported type 29
434 # in:True out:False optional:False type:unsupported type 26
436 # in:True out:False optional:False type:int
438 # in:True out:False optional:False type:int
440 # in:False out:True optional:False type:int
446 # in:True out:False optional:False type:int
448 # in:True out:False optional:False type:unsupported type 29
450 # in:True out:False optional:False type:int
452 # in:True out:False optional:False type:int
454 # in:True out:False optional:False type:unsupported type 29
456 # in:False out:True optional:False type:VT_VARIANT
458 # in:False out:True optional:False type:unsupported type 29
460 # in:False out:True optional:False type:int
466 # in:True out:False optional:False type:string
472 # in:True out:False optional:False type:bool
490 # in:True out:False optional:False type:int
502 # in:True out:False optional:False type:string
508 # in:True out:False optional:False type:string
514 # in:True out:False optional:False type:string
526 # in:True out:False optional:False type:double
532 # in:True out:False optional:False type:double
534 # in:True out:False optional:False type:double
536 # in:True out:False optional:False type:double
542 # in:True out:False optional:False type:string
548 # in:True out:False optional:False type:string
550 # in:True out:False optional:False type:double
556 # in:True out:False optional:False type:double
558 # in:True out:False optional:False type:double
560 # in:True out:False optional:False type:double
562 # in:True out:False optional:False type:double
568 # in:True out:False optional:False type:int
570 # in:True out:False optional:False type:int
576 # in:True out:False optional:False type:int
578 # in:True out:False optional:False type:int
580 # in:True out:False optional:False type:bool
589 # in:True out:False optional:False type:bool
595 # in:True out:False optional:False type:bool
598 # retType: VT_VARIANT
600 # setCurrentHightlight
604 # in:True out:False optional:False type:int
606 # in:True out:False optional:False type:int
608 # in:True out:False optional:False type:int
610 # in:True out:False optional:False type:int
612 # setCurrentHighlight
616 # in:True out:False optional:False type:int
618 # in:True out:False optional:False type:int
620 # in:True out:False optional:False type:int
622 # in:True out:False optional:False type:int
628 # in:True out:False optional:False type:VT_VARIANT
634 # --------------------