]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/pdfwin.py
fixed merge conflict
[wxWidgets.git] / wxPython / wx / lib / pdfwin.py
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 #----------------------------------------------------------------------
13
14 import wx
15
16 #----------------------------------------------------------------------
17
18 _acroversion = None
19
20 def 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
38
39 #----------------------------------------------------------------------
40
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
50 if 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()
239
240
241
242 else:
243 import wx.activex
244
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)
268
269 def AddRef(self):
270 return self.CallAXMethod('AddRef')
271
272 def Release(self):
273 return self.CallAXMethod('Release')
274
275 def GetTypeInfoCount(self):
276 return self.CallAXMethod('GetTypeInfoCount')
277
278 def GetTypeInfo(self, itinfo, lcid):
279 return self.CallAXMethod('GetTypeInfo', itinfo, lcid)
280
281 def GetIDsOfNames(self, riid, rgszNames, cNames, lcid):
282 return self.CallAXMethod('GetIDsOfNames', riid, rgszNames, cNames, lcid)
283
284 def Invoke(self, dispidMember, riid, lcid, wFlags, pdispparams):
285 return self.CallAXMethod('Invoke', dispidMember, riid, lcid, wFlags, pdispparams)
286
287 def LoadFile(self, fileName):
288 return self.CallAXMethod('LoadFile', fileName)
289
290 def setShowToolbar(self, On):
291 return self.CallAXMethod('setShowToolbar', On)
292
293 def gotoFirstPage(self):
294 return self.CallAXMethod('gotoFirstPage')
295
296 def gotoLastPage(self):
297 return self.CallAXMethod('gotoLastPage')
298
299 def gotoNextPage(self):
300 return self.CallAXMethod('gotoNextPage')
301
302 def gotoPreviousPage(self):
303 return self.CallAXMethod('gotoPreviousPage')
304
305 def setCurrentPage(self, n):
306 return self.CallAXMethod('setCurrentPage', n)
307
308 def goForwardStack(self):
309 return self.CallAXMethod('goForwardStack')
310
311 def goBackwardStack(self):
312 return self.CallAXMethod('goBackwardStack')
313
314 def setPageMode(self, pageMode):
315 return self.CallAXMethod('setPageMode', pageMode)
316
317 def setLayoutMode(self, layoutMode):
318 return self.CallAXMethod('setLayoutMode', layoutMode)
319
320 def setNamedDest(self, namedDest):
321 return self.CallAXMethod('setNamedDest', namedDest)
322
323 def Print(self):
324 return self.CallAXMethod('Print')
325
326 def printWithDialog(self):
327 return self.CallAXMethod('printWithDialog')
328
329 def setZoom(self, percent):
330 return self.CallAXMethod('setZoom', percent)
331
332 def setZoomScroll(self, percent, left, top):
333 return self.CallAXMethod('setZoomScroll', percent, left, top)
334
335 def setView(self, viewMode):
336 return self.CallAXMethod('setView', viewMode)
337
338 def setViewScroll(self, viewMode, offset):
339 return self.CallAXMethod('setViewScroll', viewMode, offset)
340
341 def setViewRect(self, left, top, width, height):
342 return self.CallAXMethod('setViewRect', left, top, width, height)
343
344 def printPages(self, from_, to):
345 return self.CallAXMethod('printPages', from_, to)
346
347 def printPagesFit(self, from_, to, shrinkToFit):
348 return self.CallAXMethod('printPagesFit', from_, to, shrinkToFit)
349
350 def printAll(self):
351 return self.CallAXMethod('printAll')
352
353 def printAllFit(self, shrinkToFit):
354 return self.CallAXMethod('printAllFit', shrinkToFit)
355
356 def setShowScrollbars(self, On):
357 return self.CallAXMethod('setShowScrollbars', On)
358
359 def GetVersions(self):
360 return self.CallAXMethod('GetVersions')
361
362 def setCurrentHightlight(self, a, b, c, d):
363 return self.CallAXMethod('setCurrentHightlight', a, b, c, d)
364
365 def setCurrentHighlight(self, a, b, c, d):
366 return self.CallAXMethod('setCurrentHighlight', a, b, c, d)
367
368 def postMessage(self, strArray):
369 return self.CallAXMethod('postMessage', strArray)
370
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)
377
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)
383
384
385 # PROPERTIES
386 # --------------------
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 #
393 #
394 #
395 #
396 # METHODS
397 # --------------------
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 #
462 # LoadFile
463 # retType: bool
464 # params:
465 # fileName
466 # in:True out:False optional:False type:string
467 #
468 # setShowToolbar
469 # retType: VT_VOID
470 # params:
471 # On
472 # in:True out:False optional:False type:bool
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
490 # in:True out:False optional:False type:int
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
502 # in:True out:False optional:False type:string
503 #
504 # setLayoutMode
505 # retType: VT_VOID
506 # params:
507 # layoutMode
508 # in:True out:False optional:False type:string
509 #
510 # setNamedDest
511 # retType: VT_VOID
512 # params:
513 # namedDest
514 # in:True out:False optional:False type:string
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
526 # in:True out:False optional:False type:double
527 #
528 # setZoomScroll
529 # retType: VT_VOID
530 # params:
531 # percent
532 # in:True out:False optional:False type:double
533 # left
534 # in:True out:False optional:False type:double
535 # top
536 # in:True out:False optional:False type:double
537 #
538 # setView
539 # retType: VT_VOID
540 # params:
541 # viewMode
542 # in:True out:False optional:False type:string
543 #
544 # setViewScroll
545 # retType: VT_VOID
546 # params:
547 # viewMode
548 # in:True out:False optional:False type:string
549 # offset
550 # in:True out:False optional:False type:double
551 #
552 # setViewRect
553 # retType: VT_VOID
554 # params:
555 # left
556 # in:True out:False optional:False type:double
557 # top
558 # in:True out:False optional:False type:double
559 # width
560 # in:True out:False optional:False type:double
561 # height
562 # in:True out:False optional:False type:double
563 #
564 # printPages
565 # retType: VT_VOID
566 # params:
567 # from
568 # in:True out:False optional:False type:int
569 # to
570 # in:True out:False optional:False type:int
571 #
572 # printPagesFit
573 # retType: VT_VOID
574 # params:
575 # from
576 # in:True out:False optional:False type:int
577 # to
578 # in:True out:False optional:False type:int
579 # shrinkToFit
580 # in:True out:False optional:False type:bool
581 #
582 # printAll
583 # retType: VT_VOID
584 #
585 # printAllFit
586 # retType: VT_VOID
587 # params:
588 # shrinkToFit
589 # in:True out:False optional:False type:bool
590 #
591 # setShowScrollbars
592 # retType: VT_VOID
593 # params:
594 # On
595 # in:True out:False optional:False type:bool
596 #
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
625 # retType: VT_VOID
626 # params:
627 # strArray
628 # in:True out:False optional:False type:VT_VARIANT
629 #
630 #
631 #
632 #
633 # EVENTS
634 # --------------------
635 # Error
636 # retType: VT_VOID
637 #
638 # Message
639 # retType: VT_VOID
640 #
641 #
642 #
643 #