File: wx.Printout.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (745 lines) | stat: -rw-r--r-- 25,172 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.Printout:

==========================================================================================================================================
|phoenix_title|  **wx.Printout**
==========================================================================================================================================

This class encapsulates the functionality of printing out an application document.          

A new class must be derived and members overridden to respond to calls such as :meth:`~wx.Printout.OnPrintPage`  and :meth:`~wx.Printout.HasPage`  and to render the print image onto an associated :ref:`wx.DC`. Instances of this class are passed to :meth:`wx.Printer.Print`   or to a :ref:`wx.PrintPreview`  object to initiate printing or previewing. 

Your derived :ref:`wx.Printout`  is responsible for drawing both the preview image and the printed page. If your windows' drawing routines accept an arbitrary DC as an argument, you can re-use those routines within your :ref:`wx.Printout`  subclass to draw the printout image. You may also add additional drawing elements within your :ref:`wx.Printout`  subclass, like headers, footers, and/or page numbers. However, the image on the printed page will often differ from the image drawn on the screen, as will the print preview image :ref:`wx.Printout`  subclass to set the user scale and origin of the associated DC, you can easily use a single drawing routine to draw on your application's windows, to create the print preview image, and to create the printed paper image, and achieve a common appearance to the preview image and the printed page. 







         



.. seealso:: :ref:`Printing Framework Overview <printing framework overview>`, :ref:`wx.PrinterDC`, :ref:`wx.PrintDialog`, :ref:`wx.PageSetupDialog`, :ref:`wx.Printer`, :ref:`wx.PrintPreview`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>Printout</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.Printout_inheritance.png" alt="Inheritance diagram of Printout" usemap="#dummy" class="inheritance"/></center>
   </div>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Object.html" title="wx.Object" alt="" coords="9,5,91,35"/> <area shape="rect" id="node2" href="wx.Printout.html" title="wx.Printout" alt="" coords="5,83,96,112"/> </map> 
   </p>

|


|sub_classes| Known Subclasses
==============================

:ref:`wx.html.HtmlPrintout`, :ref:`wx.richtext.RichTextPrintout`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.Printout.__init__`                                                    Constructor.
:meth:`~wx.Printout.FitThisSizeToPage`                                           Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the page rectangle and the origin is at the top left corner of the page rectangle.
:meth:`~wx.Printout.FitThisSizeToPageMargins`                                    Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the page margins set in the given :ref:`wx.PageSetupDialogData`  object.
:meth:`~wx.Printout.FitThisSizeToPaper`                                          Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the paper and the origin is at the top left corner of the paper.
:meth:`~wx.Printout.GetDC`                                                       Returns the device context associated with the printout (given to the printout at start of printing or previewing).
:meth:`~wx.Printout.GetLogicalPageMarginsRect`                                   Return the rectangle corresponding to the page margins specified by the given :ref:`wx.PageSetupDialogData`  object in the associated :ref:`wx.DC`'s logical coordinates for the current user scale and device origin.
:meth:`~wx.Printout.GetLogicalPageRect`                                          Return the rectangle corresponding to the page in the associated :ref:`wx.DC`  's logical coordinates for the current user scale and device origin.
:meth:`~wx.Printout.GetLogicalPaperRect`                                         Return the rectangle corresponding to the paper in the associated :ref:`wx.DC`  's logical coordinates for the current user scale and device origin.
:meth:`~wx.Printout.GetPPIPrinter`                                               Returns the number of pixels per logical inch of the printer device context.
:meth:`~wx.Printout.GetPPIScreen`                                                Returns the number of pixels per logical inch of the screen device context.
:meth:`~wx.Printout.GetPageInfo`                                                 Called by the framework to obtain information from the application about minimum and maximum page values that the user can select, and the required page range to be printed.
:meth:`~wx.Printout.GetPageSizeMM`                                               Returns the size of the printer page in millimetres.
:meth:`~wx.Printout.GetPageSizePixels`                                           Returns the size of the printer page in pixels, called the page rectangle.
:meth:`~wx.Printout.GetPaperRectPixels`                                          Returns the rectangle that corresponds to the entire paper in pixels, called the paper rectangle.
:meth:`~wx.Printout.GetPreview`                                                  Returns the associated preview object if any.
:meth:`~wx.Printout.GetTitle`                                                    Returns the title of the printout.
:meth:`~wx.Printout.HasPage`                                                     Should be overridden to return ``True`` if the document has this page, or ``False`` if not.
:meth:`~wx.Printout.IsPreview`                                                   Returns ``True`` if the printout is currently being used for previewing.
:meth:`~wx.Printout.MapScreenSizeToDevice`                                       Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that one screen pixel maps to one device pixel on the DC.
:meth:`~wx.Printout.MapScreenSizeToPage`                                         This sets the user scale of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  to the same scale as :meth:`~Printout.MapScreenSizeToPaper`   but sets the logical origin to the top left corner of the page rectangle.
:meth:`~wx.Printout.MapScreenSizeToPageMargins`                                  This sets the user scale of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  to the same scale as :meth:`~Printout.MapScreenSizeToPageMargins`   but sets the logical origin to the top left corner of the page margins specified by the given :ref:`wx.PageSetupDialogData`  object.
:meth:`~wx.Printout.MapScreenSizeToPaper`                                        Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the printed page matches the screen size as closely as possible and the logical origin is in the top left corner of the paper rectangle.
:meth:`~wx.Printout.OffsetLogicalOrigin`                                         Shift the device origin by an amount specified in logical coordinates.
:meth:`~wx.Printout.OnBeginDocument`                                             Called by the framework at the start of document printing.
:meth:`~wx.Printout.OnBeginPrinting`                                             Called by the framework at the start of printing.
:meth:`~wx.Printout.OnEndDocument`                                               Called by the framework at the end of document printing.
:meth:`~wx.Printout.OnEndPrinting`                                               Called by the framework at the end of printing.
:meth:`~wx.Printout.OnPreparePrinting`                                           Called once by the framework before any other demands are made of the :ref:`wx.Printout`  object.
:meth:`~wx.Printout.OnPrintPage`                                                 Called by the framework when a page should be printed.
:meth:`~wx.Printout.SetLogicalOrigin`                                            Set the device origin of the associated :ref:`wx.DC`  so that the current logical point becomes the new logical origin.
================================================================================ ================================================================================


|


|property_summary| Properties Summary
=====================================

================================================================================ ================================================================================
:attr:`~wx.Printout.DC`                                                          See :meth:`~wx.Printout.GetDC`
:attr:`~wx.Printout.LogicalPageRect`                                             See :meth:`~wx.Printout.GetLogicalPageRect`
:attr:`~wx.Printout.LogicalPaperRect`                                            See :meth:`~wx.Printout.GetLogicalPaperRect`
:attr:`~wx.Printout.PaperRectPixels`                                             See :meth:`~wx.Printout.GetPaperRectPixels`
:attr:`~wx.Printout.Preview`                                                     See :meth:`~wx.Printout.GetPreview`
:attr:`~wx.Printout.Title`                                                       See :meth:`~wx.Printout.GetTitle`
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.Printout(Object)

   **Possible constructors**::

       Printout(title="Printout")
       
   
   This class encapsulates the functionality of printing out an
   application document.



   .. method:: __init__(self, title="Printout")

      Constructor.                  

      Pass an optional title argument - the current filename would be a good idea. This will appear in the printing list (at least in MSW)                  


      :param `title`: 
      :type `title`: string







   .. method:: FitThisSizeToPage(self, imageSize)

      Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the page rectangle and the origin is at the top left corner of the page rectangle.                  

      On MSW and Mac, the page rectangle is the printable area of the page. On other platforms and PostScript printing, the page rectangle is the entire paper. 

      Use this if you want your printed image as large as possible, but with the caveat that on some platforms, portions of the image might be cut off at the edges.                  


      :param `imageSize`: 
      :type `imageSize`: wx.Size







   .. method:: FitThisSizeToPageMargins(self, imageSize, pageSetupData)

      Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the page margins set in the given :ref:`wx.PageSetupDialogData`  object.                  

      This function provides the greatest consistency across all platforms because it does not depend on having access to the printable area of the paper. 

                


      :param `imageSize`: 
      :type `imageSize`: wx.Size
      :param `pageSetupData`: 
      :type `pageSetupData`: wx.PageSetupDialogData






      .. note:: 

         On Mac, the native :ref:`wx.PageSetupDialog`  does not let you set the page margins; you'll have to provide your own mechanism, or you can use the Mac-only class MacPageMarginsDialog.   








   .. method:: FitThisSizeToPaper(self, imageSize)

      Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the given image size fits entirely within the paper and the origin is at the top left corner of the paper.                  

      Use this if you're managing your own page margins. 

                


      :param `imageSize`: 
      :type `imageSize`: wx.Size






      .. note:: 

         With most printers, the region around the edges of the paper are not printable so that the edges of the image could be cut off.   








   .. method:: GetDC(self)

      Returns the device context associated with the printout (given to the printout at start of printing or previewing).                  

      The application can use :meth:`GetDC`   to obtain a device context to draw on. 

      This will be a :ref:`wx.PrinterDC`  if printing under Windows or Mac, a :ref:`wx.PostScriptDC`  if printing on other platforms, and a :ref:`wx.MemoryDC`  if previewing.                  

      :rtype: :ref:`wx.DC`








   .. method:: GetLogicalPageMarginsRect(self, pageSetupData)

      Return the rectangle corresponding to the page margins specified by the given :ref:`wx.PageSetupDialogData`  object in the associated :ref:`wx.DC`'s logical coordinates for the current user scale and device origin.                  

      The page margins are specified with respect to the edges of the paper on all platforms.                  


      :param `pageSetupData`: 
      :type `pageSetupData`: wx.PageSetupDialogData




      :rtype: :ref:`wx.Rect`








   .. method:: GetLogicalPageRect(self)

      Return the rectangle corresponding to the page in the associated :ref:`wx.DC`  's logical coordinates for the current user scale and device origin.                  

      On MSW and Mac, this will be the printable area of the paper. On other platforms and PostScript printing, this will be the full paper rectangle.                  

      :rtype: :ref:`wx.Rect`








   .. method:: GetLogicalPaperRect(self)

      Return the rectangle corresponding to the paper in the associated :ref:`wx.DC`  's logical coordinates for the current user scale and device origin.                  

      :rtype: :ref:`wx.Rect`








   .. method:: GetPPIPrinter(self)

      Returns the number of pixels per logical inch of the printer device context.                  

      Dividing the printer ``PPI`` by the screen ``PPI`` can give a suitable scaling factor for drawing text onto the printer. 

      Remember to multiply this by a scaling factor to take the preview DC size into account. Or you can just use the FitThisSizeToXXX() and MapScreenSizeToXXX routines below, which do most of the scaling calculations for you. 

      




   .. method:: GetPPIScreen(self)

      Returns the number of pixels per logical inch of the screen device context.                  

      Dividing the printer ``PPI`` by the screen ``PPI`` can give a suitable scaling factor for drawing text onto the printer. 

      If you are doing your own scaling, remember to multiply this by a scaling factor to take the preview DC size into account. 

      




   .. method:: GetPageInfo(self)

      Called by the framework to obtain information from the application about minimum and maximum page values that the user can select, and the required page range to be printed.                  

      By default this returns (1, 32000) for the page minimum and maximum values, and (1, 1) for the required page range. 

      `minPage`  must be greater than zero and `maxPage`  must be greater than `minPage`.                  

      :rtype: `tuple`







      :returns: 

         ( `minPage`, `maxPage`, `pageFrom`, `pageTo` ) 








   .. method:: GetPageSizeMM(self)

      Returns the size of the printer page in millimetres.                  

      




   .. method:: GetPageSizePixels(self)

      Returns the size of the printer page in pixels, called the page rectangle.                  

      The page rectangle has a top left corner at (0,0) and a bottom right corner at (w,h). These values may not be the same as the values returned from :meth:`wx.DC.GetSize` ; if the printout is being used for previewing, a memory device context is used, which uses a bitmap size reflecting the current preview zoom. The application must take this discrepancy into account if previewing is to be supported.                  

      :rtype: `tuple`







      :returns: 

         ( `w`, `h` ) 








   .. method:: GetPaperRectPixels(self)

      Returns the rectangle that corresponds to the entire paper in pixels, called the paper rectangle.                  

      This distinction between paper rectangle and page rectangle reflects the fact that most printers cannot print all the way to the edge of the paper. The page rectangle is a rectangle whose top left corner is at (0,0) and whose width and height are given by `DC.GetPageSizePixels().` 

      On MSW and Mac, the page rectangle gives the printable area of the paper, while the paper rectangle represents the entire paper, including non-printable borders. Thus, the rectangle returned by `DC.GetPaperRectPixels()` will have a top left corner whose coordinates are small negative numbers and the bottom right corner will have values somewhat larger than the width and height given by `DC.GetPageSizePixels().` 

      On other platforms and for PostScript printing, the paper is treated as if its entire area were printable, so this function will return the same rectangle as the page rectangle.                  

      :rtype: :ref:`wx.Rect`








   .. method:: GetPreview(self)

      Returns the associated preview object if any.                  

      If this printout object is used for previewing, returns the associated :ref:`wx.PrintPreview`. Otherwise returns ``None``. 

      The returned pointer is not owned by the printout and must not be deleted. 

                

      :rtype: :ref:`wx.PrintPreview`







      .. versionadded:: 2.9.1.
      







      .. seealso:: :meth:`IsPreview`   








   .. method:: GetTitle(self)

      Returns the title of the printout.                  

                

      :rtype: `string`







      .. todo:: the python note here was wrong    








   .. method:: HasPage(self, pageNum)

      Should be overridden to return ``True`` if the document has this page, or ``False`` if not.                  

      Returning ``False`` signifies the end of the document. By default, HasPage behaves as if the document has only one page.                  


      :param `pageNum`: 
      :type `pageNum`: int




      :rtype: `bool`








   .. method:: IsPreview(self)

      Returns ``True`` if the printout is currently being used for previewing.                  

                

      :rtype: `bool`







      .. seealso:: :meth:`GetPreview`     








   .. method:: MapScreenSizeToDevice(self)

      Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that one screen pixel maps to one device pixel on the DC.                  

      That is, the user scale is set to (1,1) and the device origin is set to (0,0). 

      Use this if you want to do your own scaling prior to calling :ref:`wx.DC`  drawing calls, for example, if your underlying model is floating-point and you want to achieve maximum drawing precision on high-resolution printers. 

      You can use the GetLogicalXXXRect() routines below to obtain the paper rectangle, page rectangle, or page margins rectangle to perform your own scaling. 

                 



      .. note:: 

         While the underlying drawing model of Mac OS X is floating-point, Widgets's drawing model scales from integer coordinates.   








   .. method:: MapScreenSizeToPage(self)

      This sets the user scale of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  to the same scale as :meth:`MapScreenSizeToPaper`   but sets the logical origin to the top left corner of the page rectangle.                   





   .. method:: MapScreenSizeToPageMargins(self, pageSetupData)

      This sets the user scale of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  to the same scale as :meth:`MapScreenSizeToPageMargins`   but sets the logical origin to the top left corner of the page margins specified by the given :ref:`wx.PageSetupDialogData`  object.                  


      :param `pageSetupData`: 
      :type `pageSetupData`: wx.PageSetupDialogData







   .. method:: MapScreenSizeToPaper(self)

      Set the user scale and device origin of the :ref:`wx.DC`  associated with this :ref:`wx.Printout`  so that the printed page matches the screen size as closely as possible and the logical origin is in the top left corner of the paper rectangle.                  

      That is, a 100-pixel object on screen should appear at the same size on the printed page. (It will, of course, be larger or smaller in the preview image, depending on the zoom factor.) 

      Use this if you want ``WYSIWYG`` behaviour, e.g., in a text editor.                   





   .. method:: OffsetLogicalOrigin(self, xoff, yoff)

      Shift the device origin by an amount specified in logical coordinates.                  


      :param `xoff`: 
      :type `xoff`: int
      :param `yoff`: 
      :type `yoff`: int







   .. method:: OnBeginDocument(self, startPage, endPage)

      Called by the framework at the start of document printing.                  

      Return ``False`` from this function cancels the print job. 

      :meth:`OnBeginDocument`   is called once for every copy printed. 

                


      :param `startPage`: 
      :type `startPage`: int
      :param `endPage`: 
      :type `endPage`: int




      :rtype: `bool`







      .. note:: 

         The base :meth:`OnBeginDocument`   must be called (and the return value checked) from within the overridden function, since it calls :meth:`wx.DC.StartDoc` .   








   .. method:: OnBeginPrinting(self)

      Called by the framework at the start of printing.                  

      :meth:`OnBeginPrinting`   is called once for every print job (regardless of how many copies are being printed).                   





   .. method:: OnEndDocument(self)

      Called by the framework at the end of document printing.                  

      :meth:`OnEndDocument`   is called once for every copy printed. 

                 



      .. note:: 

         The base :meth:`OnEndDocument`   must be called from within the overridden function, since it calls :meth:`wx.DC.EndDoc` .   








   .. method:: OnEndPrinting(self)

      Called by the framework at the end of printing.                  

      OnEndPrinting is called once for every print job (regardless of how many copies are being printed).                   





   .. method:: OnPreparePrinting(self)

      Called once by the framework before any other demands are made of the :ref:`wx.Printout`  object.                  

      This gives the object an opportunity to calculate the number of pages in the document, for example.                   





   .. method:: OnPrintPage(self, pageNum)

      Called by the framework when a page should be printed.                  

      Returning ``False`` cancels the print job.                  


      :param `pageNum`: 
      :type `pageNum`: int




      :rtype: `bool`








   .. method:: SetLogicalOrigin(self, x, y)

      Set the device origin of the associated :ref:`wx.DC`  so that the current logical point becomes the new logical origin.                  


      :param `x`: 
      :type `x`: int
      :param `y`: 
      :type `y`: int







   .. attribute:: DC

      See :meth:`~wx.Printout.GetDC`


   .. attribute:: LogicalPageRect

      See :meth:`~wx.Printout.GetLogicalPageRect`


   .. attribute:: LogicalPaperRect

      See :meth:`~wx.Printout.GetLogicalPaperRect`


   .. attribute:: PaperRectPixels

      See :meth:`~wx.Printout.GetPaperRectPixels`


   .. attribute:: Preview

      See :meth:`~wx.Printout.GetPreview`


   .. attribute:: Title

      See :meth:`~wx.Printout.GetTitle`