Merge lp:~gatesphere/leo-editor/printing into lp:leo-editor

Proposed by Jake Peck
Status: Merged
Merged at revision: 5779
Proposed branch: lp:~gatesphere/leo-editor/printing
Merge into: lp:leo-editor
Diff against target: 514 lines (+351/-18)
4 files modified
leo/config/leoSettings.leo (+22/-9)
leo/core/LeoPyRef.leo (+7/-7)
leo/plugins/leoPluginsRef.leo (+5/-2)
leo/plugins/printing.py (+317/-0)
To merge this branch: bzr merge lp:~gatesphere/leo-editor/printing
Reviewer Review Type Date Requested Status
The Leo editor team Pending
Review via email: mp+163725@code.launchpad.net

Description of the change

Adds a printing plugin that allows printing and print-previewing from the Qt GUI. Offers several printing modes, including single node, marked nodes, and expanded node (filling in all @others, <<sections>>, etc.). All of these are available in two modes - body only, or with headlines.

All unit tests pass.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'leo/config/leoSettings.leo'
--- leo/config/leoSettings.leo 2013-05-13 05:40:49 +0000
+++ leo/config/leoSettings.leo 2013-05-14 14:51:04 +0000
@@ -93,9 +93,9 @@
93<v t="ekr.20041119035704.3"><vh>\@type type-name: base-type = [list of valid values]</vh></v>93<v t="ekr.20041119035704.3"><vh>\@type type-name: base-type = [list of valid values]</vh></v>
94<v t="ekr.20041120155431.2"><vh>\@type type-name: script: script-name</vh></v>94<v t="ekr.20041120155431.2"><vh>\@type type-name: script: script-name</vh></v>
95</v>95</v>
96<v t="ekr.20061011082224"><vh>Candidates for settings in myLeoSettings.leo</vh>96<v t="ekr.20061011082224" a="E"><vh>Candidates for settings in myLeoSettings.leo</vh>
97<v t="ekr.20070224073109.1"><vh>@enabled-plugins</vh></v>97<v t="ekr.20070224073109.1"><vh>@enabled-plugins</vh></v>
98<v t="ekr.20110611092035.16470"><vh>Appearance</vh>98<v t="ekr.20110611092035.16470" a="E"><vh>Appearance</vh>
99<v t="ekr.20111024091133.16701"><vh>@@@int qt-tab-width = 40</vh></v>99<v t="ekr.20111024091133.16701"><vh>@@@int qt-tab-width = 40</vh></v>
100<v t="ekr.20081018053140.12"><vh>@data qt-gui-plugin-style-sheet</vh></v>100<v t="ekr.20081018053140.12"><vh>@data qt-gui-plugin-style-sheet</vh></v>
101<v t="ekr.20081023060109.13"><vh>@int qt-rich-text-zoom-in = 10</vh></v>101<v t="ekr.20081023060109.13"><vh>@int qt-rich-text-zoom-in = 10</vh></v>
@@ -103,7 +103,7 @@
103<v t="ekr.20070604075218"><vh>@bool use_chapter_tabs = True</vh></v>103<v t="ekr.20070604075218"><vh>@bool use_chapter_tabs = True</vh></v>
104<v t="ekr.20070318065601"><vh>@bool use_chapters = True</vh></v>104<v t="ekr.20070318065601"><vh>@bool use_chapters = True</vh></v>
105</v>105</v>
106<v t="ekr.20110611092035.16471"><vh>Colorizer &amp; colors</vh>106<v t="ekr.20110611092035.16471" a="E"><vh>Colorizer &amp; colors</vh>
107<v t="ekr.20060201111002"><vh>@bool use_syntax_coloring = True</vh></v>107<v t="ekr.20060201111002"><vh>@bool use_syntax_coloring = True</vh></v>
108<v t="ekr.20041119034357.67"><vh>@color split_bar_color = LightSteelBlue2</vh></v>108<v t="ekr.20041119034357.67"><vh>@color split_bar_color = LightSteelBlue2</vh></v>
109<v t="ekr.20081018053140.12"></v>109<v t="ekr.20081018053140.12"></v>
@@ -515,7 +515,7 @@
515</v>515</v>
516</v>516</v>
517<v t="ekr.20070224073109.1"></v>517<v t="ekr.20070224073109.1"></v>
518<v t="ekr.20041119034357.1"><vh>@settings</vh>518<v t="ekr.20041119034357.1" a="E"><vh>@settings</vh>
519<v t="ekr.20100904134301.11000"><vh>Abbreviations</vh>519<v t="ekr.20100904134301.11000"><vh>Abbreviations</vh>
520<v t="ekr.20100904134301.11006"><vh>@bool enable-abbreviations = False</vh></v>520<v t="ekr.20100904134301.11006"><vh>@bool enable-abbreviations = False</vh></v>
521<v t="ekr.20100904134301.11002"><vh>@data global-abbreviations</vh></v>521<v t="ekr.20100904134301.11002"><vh>@data global-abbreviations</vh></v>
@@ -527,7 +527,7 @@
527<v t="tbrown.20120821183537.18663"><vh>@string abbreviations-place-start = &lt;|</vh></v>527<v t="tbrown.20120821183537.18663"><vh>@string abbreviations-place-start = &lt;|</vh></v>
528<v t="tbrown.20120821183537.18662"><vh>@string abbreviations-place-end = |&gt;</vh></v>528<v t="tbrown.20120821183537.18662"><vh>@string abbreviations-place-end = |&gt;</vh></v>
529</v>529</v>
530<v t="ekr.20110611092035.16470"></v>530<v t="ekr.20110611092035.16470" a="E"></v>
531<v t="ekr.20110510071925.14588"><vh>Autocompleter</vh>531<v t="ekr.20110510071925.14588"><vh>Autocompleter</vh>
532<v t="ekr.20110512085854.14461"><vh>@bool auto_tab_complete = False</vh></v>532<v t="ekr.20110512085854.14461"><vh>@bool auto_tab_complete = False</vh></v>
533<v t="ekr.20051027175030"><vh>@bool autocomplete-brackets = False</vh></v>533<v t="ekr.20051027175030"><vh>@bool autocomplete-brackets = False</vh></v>
@@ -536,7 +536,7 @@
536<v t="ekr.20110510071925.14590"><vh>@@@bool use_codewise = False</vh></v>536<v t="ekr.20110510071925.14590"><vh>@@@bool use_codewise = False</vh></v>
537<v t="ekr.20110510071925.14589"><vh>@bool use_qcompleter = True</vh></v>537<v t="ekr.20110510071925.14589"><vh>@bool use_qcompleter = True</vh></v>
538</v>538</v>
539<v t="ekr.20110611092035.16471"></v>539<v t="ekr.20110611092035.16471" a="E"></v>
540<v t="ekr.20041119034357.10"><vh>Command options</vh>540<v t="ekr.20041119034357.10"><vh>Command options</vh>
541<v t="ekr.20111115083813.12518"><vh>@bool indent_added_comments = True</vh></v>541<v t="ekr.20111115083813.12518"><vh>@bool indent_added_comments = True</vh></v>
542<v t="ekr.20041119041019.1"><vh>@string remove_sentinels_extension = .txt</vh></v>542<v t="ekr.20041119041019.1"><vh>@string remove_sentinels_extension = .txt</vh></v>
@@ -1389,7 +1389,7 @@
1389<v t="ekr.20110611092035.16492"><vh>Mouse</vh>1389<v t="ekr.20110611092035.16492"><vh>Mouse</vh>
1390<v t="ekr.20080324105006.6"><vh>@bool allow_middle_button_paste = False</vh></v>1390<v t="ekr.20080324105006.6"><vh>@bool allow_middle_button_paste = False</vh></v>
1391</v>1391</v>
1392<v t="ekr.20051123100536"><vh>Plugins</vh>1392<v t="ekr.20051123100536" a="E"><vh>Plugins</vh>
1393<v t="ekr.20041119034357.13"><vh>@bool use_plugins = True</vh></v>1393<v t="ekr.20041119034357.13"><vh>@bool use_plugins = True</vh></v>
1394<v t="ekr.20071113084330"><vh>@bool warn_when_plugins_fail_to_load = True</vh></v>1394<v t="ekr.20071113084330"><vh>@bool warn_when_plugins_fail_to_load = True</vh></v>
1395<v t="ekr.20070224073109.1"></v>1395<v t="ekr.20070224073109.1"></v>
@@ -1453,6 +1453,10 @@
1453<v t="ekr.20060922110220"><vh>@bool opml_write_uAs = True</vh></v>1453<v t="ekr.20060922110220"><vh>@bool opml_write_uAs = True</vh></v>
1454<v t="ekr.20060919171527.2"><vh>@string opml_namespace = leo:com:leo-opml-version-1</vh></v>1454<v t="ekr.20060919171527.2"><vh>@string opml_namespace = leo:com:leo-opml-version-1</vh></v>
1455</v>1455</v>
1456<v t="peckj.20130514082859.5599" a="E"><vh>printing plugin</vh>
1457<v t="peckj.20130514082859.5600"><vh>@string printing-font-size = 12</vh></v>
1458<v t="peckj.20130514082859.5601"><vh>@string printing-font-family = DejaVu Sans Mono</vh></v>
1459</v>
1456<v t="ekr.20081018053140.11"><vh>qtGui plugin</vh>1460<v t="ekr.20081018053140.11"><vh>qtGui plugin</vh>
1457<v t="ekr.20110611092035.16472"><vh>Don't change these unless you know what you are doing</vh>1461<v t="ekr.20110611092035.16472"><vh>Don't change these unless you know what you are doing</vh>
1458<v t="ekr.20081023060109.14"><vh>@bool qt-use-scintilla = False</vh></v>1462<v t="ekr.20081023060109.14"><vh>@bool qt-use-scintilla = False</vh></v>
@@ -1462,7 +1466,7 @@
1462</v>1466</v>
1463</v>1467</v>
1464<v t="ekr.20071213060239"><vh>rst3 plugin</vh>1468<v t="ekr.20071213060239"><vh>rst3 plugin</vh>
1465<v t="ekr.20071213060239.1"><vh>rst3 http options</vh>1469<v t="ekr.20071213060239.1" a="E"><vh>rst3 http options</vh>
1466<v t="ekr.20071213061454"><vh>@bool rst3_clear_http_attributes = False</vh></v>1470<v t="ekr.20071213061454"><vh>@bool rst3_clear_http_attributes = False</vh></v>
1467<v t="ekr.20071213061454.1"><vh>@bool rst3_http_server_support = False</vh></v>1471<v t="ekr.20071213061454.1"><vh>@bool rst3_http_server_support = False</vh></v>
1468<v t="ekr.20071213061454.2"><vh>@string rst3_http_attributename = rst_http_attribute</vh></v>1472<v t="ekr.20071213061454.2"><vh>@string rst3_http_attributename = rst_http_attribute</vh></v>
@@ -1487,7 +1491,7 @@
1487<v t="ekr.20071213061923.2"><vh>@bool rst3_generate_rst = True</vh></v>1491<v t="ekr.20071213061923.2"><vh>@bool rst3_generate_rst = True</vh></v>
1488<v t="ekr.20090430075506.7"><vh>@bool rst3_generate_rst_header_comment = True</vh></v>1492<v t="ekr.20090430075506.7"><vh>@bool rst3_generate_rst_header_comment = True</vh></v>
1489</v>1493</v>
1490<v t="ekr.20071213060514.2"><vh>rst3 formatting options</vh>1494<v t="ekr.20071213060514.2" a="E"><vh>rst3 formatting options</vh>
1491<v t="ekr.20071213061930.1"><vh>@bool rst3_show_headlines = True</vh></v>1495<v t="ekr.20071213061930.1"><vh>@bool rst3_show_headlines = True</vh></v>
1492<v t="ekr.20071213061930.2"><vh>@bool rst3_show_organizer_nodes = True</vh></v>1496<v t="ekr.20071213061930.2"><vh>@bool rst3_show_organizer_nodes = True</vh></v>
1493<v t="ekr.20071213061930.3"><vh>@bool rst3_show_options_nodes = False</vh></v>1497<v t="ekr.20071213061930.3"><vh>@bool rst3_show_options_nodes = False</vh></v>
@@ -4461,6 +4465,7 @@
4461stickynotes.py4465stickynotes.py
4462todo.py4466todo.py
4463viewrendered.py4467viewrendered.py
4468printing.py
44644469
4465# Alphabetical list of all Leo plugins.4470# Alphabetical list of all Leo plugins.
44664471
@@ -9733,6 +9738,14 @@
9733action will be used instead.</t>9738action will be used instead.</t>
9734<t tx="leohag.20081204085551.13"></t>9739<t tx="leohag.20081204085551.13"></t>
9735<t tx="nh910.20110621123823.3423"></t>9740<t tx="nh910.20110621123823.3423"></t>
9741<t tx="peckj.20130514082859.5599"></t>
9742<t tx="peckj.20130514082859.5600">This defines the font size for body text in print outs.
9743
9744Size is in px. Default 12.</t>
9745<t tx="peckj.20130514082859.5601">This determines the font family for print outs. It's highly recommended
9746to choose a monospaced font.
9747
9748Default: DejaVu Sans Mono</t>
9736<t tx="tbrown.20081003103821.1">True: if the same file (basename) occurs more than once in the recent files9749<t tx="tbrown.20081003103821.1">True: if the same file (basename) occurs more than once in the recent files
9737list, i.e. on two different paths it will appear as a submenu with the basename9750list, i.e. on two different paths it will appear as a submenu with the basename
9738as its heading, and the two (or more) paths as its entries. This is easier to9751as its heading, and the two (or more) paths as its entries. This is easier to
97399752
=== modified file 'leo/core/LeoPyRef.leo'
--- leo/core/LeoPyRef.leo 2013-05-01 16:19:39 +0000
+++ leo/core/LeoPyRef.leo 2013-05-14 14:51:04 +0000
@@ -27,8 +27,7 @@
27expanded="ekr.20120329072206.9701,"><vh>@file ../doc/leoProjects.txt</vh></v>27expanded="ekr.20120329072206.9701,"><vh>@file ../doc/leoProjects.txt</vh></v>
28</v>28</v>
29<v t="EKR.20040519090151.2"><vh>To do</vh>29<v t="EKR.20040519090151.2"><vh>To do</vh>
30<v t="ekr.20100119205347.6015"30<v t="ekr.20100119205347.6015"><vh>@file ../doc/leoToDo.txt</vh></v>
31marks="ekr.20111116103733.9818,"><vh>@file ../doc/leoToDo.txt</vh></v>
32</v>31</v>
33<v t="ekr.20031218072017.2406" a="E"><vh>Code</vh>32<v t="ekr.20031218072017.2406" a="E"><vh>Code</vh>
34<v t="ekr.20090802181029.5988"><vh>Version</vh>33<v t="ekr.20090802181029.5988"><vh>Version</vh>
@@ -42,7 +41,7 @@
42<v t="ekr.20120519121124.9919"><vh>@file ../external/leosax.py</vh></v>41<v t="ekr.20120519121124.9919"><vh>@file ../external/leosax.py</vh></v>
43<v t="ekr.20031218072017.2605"><vh>@file runLeo.py </vh></v>42<v t="ekr.20031218072017.2605"><vh>@file runLeo.py </vh></v>
44</v>43</v>
45<v t="ekr.20031218072017.2604" a="E"><vh>Core classes</vh>44<v t="ekr.20031218072017.2604"><vh>Core classes</vh>
46<v t="ekr.20031218072017.2608"><vh>@file leoApp.py</vh></v>45<v t="ekr.20031218072017.2608"><vh>@file leoApp.py</vh></v>
47<v t="ekr.20041005105605.1"><vh>@file leoAtFile.py</vh></v>46<v t="ekr.20041005105605.1"><vh>@file leoAtFile.py</vh></v>
48<v t="ekr.20070227091955.1"><vh>@file leoBridge.py</vh></v>47<v t="ekr.20070227091955.1"><vh>@file leoBridge.py</vh></v>
@@ -51,7 +50,7 @@
51<v t="ekr.20031218072017.2794"><vh>@file leoColor.py</vh></v>50<v t="ekr.20031218072017.2794"><vh>@file leoColor.py</vh></v>
52<v t="ekr.20031218072017.2810"><vh>@file leoCommands.py</vh></v>51<v t="ekr.20031218072017.2810"><vh>@file leoCommands.py</vh></v>
53<v t="ekr.20041117062700"><vh>@file leoConfig.py</vh></v>52<v t="ekr.20041117062700"><vh>@file leoConfig.py</vh></v>
54<v t="ekr.20050710142719" a="E"53<v t="ekr.20050710142719"
55expanded="ekr.20050920084036.13,ekr.20100901080826.6002,ekr.20100901080826.6155,ekr.20050920084036.53,ekr.20071114081313,ekr.20080108092811,"><vh>@file leoEditCommands.py</vh></v>54expanded="ekr.20050920084036.13,ekr.20100901080826.6002,ekr.20100901080826.6155,ekr.20050920084036.53,ekr.20071114081313,ekr.20080108092811,"><vh>@file leoEditCommands.py</vh></v>
56<v t="ekr.20031218072017.3018"><vh>@file leoFileCommands.py</vh></v>55<v t="ekr.20031218072017.3018"><vh>@file leoFileCommands.py</vh></v>
57<v t="ekr.20031218072017.3093" descendentVnodeUnknownAttributes="7d71005506302e31352e3071017d71025808000000616e6e6f7461746571037d710473732e"><vh>@file leoGlobals.py</vh></v>56<v t="ekr.20031218072017.3093" descendentVnodeUnknownAttributes="7d71005506302e31352e3071017d71025808000000616e6e6f7461746571037d710473732e"><vh>@file leoGlobals.py</vh></v>
@@ -78,12 +77,13 @@
78</v>77</v>
79<v t="ekr.20110605121601.17862" a="E"><vh>Qt gui</vh>78<v t="ekr.20110605121601.17862" a="E"><vh>Qt gui</vh>
80<v t="ekr.20110605121601.17863"><vh>@file ../plugins/baseNativeTree.py</vh></v>79<v t="ekr.20110605121601.17863"><vh>@file ../plugins/baseNativeTree.py</vh></v>
81<v t="ekr.20120419093256.10048" a="E"80<v t="ekr.20120419093256.10048"
82expanded="ekr.20110318080425.14389,"><vh>@file ../plugins/free_layout.py</vh></v>81expanded="ekr.20110318080425.14389,"><vh>@file ../plugins/free_layout.py</vh></v>
83<v t="ekr.20110605121601.17954" a="E"82<v t="ekr.20110605121601.17954"
84expanded="tbrown.20120418121002.25711,ekr.20110605121601.17961,ekr.20110605121601.17966,ekr.20110605121601.17969,"><vh>@file ../plugins/nested_splitter.py</vh></v>83expanded="tbrown.20120418121002.25711,ekr.20110605121601.17961,ekr.20110605121601.17966,ekr.20110605121601.17969,"><vh>@file ../plugins/nested_splitter.py</vh></v>
85<v t="ekr.20110605121601.17996"><vh>@file ../plugins/qtframecommands.py</vh></v>84<v t="ekr.20110605121601.17996"><vh>@file ../plugins/qtframecommands.py</vh></v>
86<v t="ekr.20110605121601.18002" a="E"><vh>@file ../plugins/qtGui.py</vh></v>85<v t="ekr.20110605121601.18002" a="E"
86expanded="ekr.20110605121601.18136,ekr.20110605121601.18340,ekr.20110605121601.18342,ekr.20110605121601.18343,ekr.20110605121601.18354,ekr.20110605121601.18361,"><vh>@file ../plugins/qtGui.py</vh></v>
87<v t="ekr.20110605121601.18695"><vh>QDesigner files</vh>87<v t="ekr.20110605121601.18695"><vh>QDesigner files</vh>
88<v t="ekr.20110605121601.18696"><vh>@auto ../test/qtui_generate.py</vh></v>88<v t="ekr.20110605121601.18696"><vh>@auto ../test/qtui_generate.py</vh></v>
89<v t="ekr.20110605121601.18698"><vh>@auto ../plugins/qt_main.py</vh></v>89<v t="ekr.20110605121601.18698"><vh>@auto ../plugins/qt_main.py</vh></v>
9090
=== modified file 'leo/plugins/leoPluginsRef.leo'
--- leo/plugins/leoPluginsRef.leo 2013-04-20 15:05:19 +0000
+++ leo/plugins/leoPluginsRef.leo 2013-05-14 14:51:04 +0000
@@ -58,7 +58,7 @@
58</v>58</v>
59</v>59</v>
60</v>60</v>
61<v t="ekr.20101110150056.9453"><vh> Qt only plugins</vh>61<v t="ekr.20101110150056.9453" a="E"><vh> Qt only plugins</vh>
62<v t="tbrown.20091029123555.5319" descendentVnodeUnknownAttributes="7d71005503302e3571017d710258040000007465737471037d710458050000005f6564697471057d7106580400000074686973710758120000006f6b20686f77206120626f757420746869737108737373732e"><vh>@file attrib_edit.py</vh></v>62<v t="tbrown.20091029123555.5319" descendentVnodeUnknownAttributes="7d71005503302e3571017d710258040000007465737471037d710458050000005f6564697471057d7106580400000074686973710758120000006f6b20686f77206120626f757420746869737108737373732e"><vh>@file attrib_edit.py</vh></v>
63<v t="ville.20090310191936.10"><vh>@file colorize_headlines.py</vh></v>63<v t="ville.20090310191936.10"><vh>@file colorize_headlines.py</vh></v>
64<v t="ekr.20090701111504.5294"><vh>@file contextmenu.py</vh></v>64<v t="ekr.20090701111504.5294"><vh>@file contextmenu.py</vh></v>
@@ -72,7 +72,9 @@
72<v t="tbrown.20100318101414.5990"><vh>@file viewrendered.py</vh></v>72<v t="tbrown.20100318101414.5990"><vh>@file viewrendered.py</vh></v>
73<v t="tbrown.20090206153748.1"><vh>@file graphcanvas.py</vh></v>73<v t="tbrown.20090206153748.1"><vh>@file graphcanvas.py</vh></v>
74<v t="ville.20110403115003.10348"><vh>@file valuespace.py</vh></v>74<v t="ville.20110403115003.10348"><vh>@file valuespace.py</vh></v>
75<v t="ville.20130127035134.3685"><vh>@file internal_ipkernel.py</vh></v>75<v t="ville.20130127035134.3685" a="O"><vh>@file internal_ipkernel.py</vh></v>
76<v t="peckj.20130514093558.4062" a="E"
77expanded="peckj.20130513115943.16249,"><vh>@file printing.py</vh></v>
76<v t="tbrown.20130420091241.44181"><vh>@file screen_capture.py</vh></v>78<v t="tbrown.20130420091241.44181"><vh>@file screen_capture.py</vh></v>
77</v>79</v>
78<v t="ekr.20100103093121.5365"><vh>Auto completion</vh>80<v t="ekr.20100103093121.5365"><vh>Auto completion</vh>
@@ -541,5 +543,6 @@
541<t tx="ekr.20121126102050.10134"></t>543<t tx="ekr.20121126102050.10134"></t>
542<t tx="rogererens.20041130095659">@ It is possible to link to nodes within the same file. However clones might be better.544<t tx="rogererens.20041130095659">@ It is possible to link to nodes within the same file. However clones might be better.
543</t>545</t>
546<t tx="ville.20130127035134.3685"></t>
544</tnodes>547</tnodes>
545</leo_file>548</leo_file>
546549
=== added file 'leo/plugins/printing.py'
--- leo/plugins/printing.py 1970-01-01 00:00:00 +0000
+++ leo/plugins/printing.py 2013-05-14 14:51:04 +0000
@@ -0,0 +1,317 @@
1#@+leo-ver=5-thin
2#@+node:peckj.20130513115943.16246: * @file printing.py
3#@@language python
4#@@tabwidth -4
5
6#@+<< docstring >>
7#@+node:peckj.20130513115943.16252: ** << docstring >>
8'''Supports printing from the Qt GUI.
9
10Jacob M. Peck, 2013
11
12Commands
13========
14
15This plugin supports the following twelve commands:
16
17print-selected-node
18-------------------
19
20Opens up the print dialog to print the selected headline and node.
21
22print-preview-selected-node
23---------------------------
24
25Opens up the print preview dialog to preview the selected headline
26and node.
27
28print-selected-node-body
29------------------------
30
31Opens up the print dialog to print the selected node body.
32
33print-preview-selected-node-body
34--------------------------------
35
36Opens up the print preview dialog to preview the selected node body.
37
38print-expanded-node
39-------------------
40
41Opens up the print dialog to print the expanded contents of the
42selected node, with top-level headline.
43
44print-preview-expanded-node
45---------------------------
46
47Opens up the print preview dialog to preview the expanded contents
48of theselected node, with top-level headline.
49
50print-expanded-node-body
51------------------------
52
53Opens up the print dialog to print the expanded node body.
54
55print-preview-expanded-node-body
56--------------------------------
57
58Opens up the print preview dialog to preview the expanded node
59body.
60
61print-marked-nodes
62------------------
63
64Opens up the print dialog to print all marked nodes in the current
65outline, with headlines.
66
67print-preview-marked-nodes
68--------------------------
69
70Opens up the print preview dialog to preview all marked nodes in \
71the current outline, with headlines.
72
73print-marked-node-bodies
74------------------------
75
76Opens up the print dialog to print the bodies of all marked nodes
77in the current outline.
78
79print-preview-marked-node-bodies
80--------------------------------
81
82Opens up the print preview dialog to preview the bodies of all
83marked nodes in the current outline.
84
85Settings
86========
87
88- ``@string printing-font-family = DejaVu Sans Mono``
89 The font family for printing. A monospaced font is recommended.
90
91- ``@string printing-font-size = 12``
92 The font size for printing bodies, in px. Due to limitations
93 of PyQt, the size of headlines cannot be changed.
94
95'''
96#@-<< docstring >>
97#@+<< version history >>
98#@+node:peckj.20130513115943.16254: ** << version history >>
99#@+at
100#
101# version 0.1 (2013-05-14) - initial release
102#
103#@@c
104#@-<< version history >>
105#@+<< imports >>
106#@+node:peckj.20130513115943.16253: ** << imports >>
107import leo.core.leoGlobals as g
108import leo.plugins.qtGui as qtGui
109from PyQt4 import QtGui
110from PyQt4 import QtCore
111#@-<< imports >>
112
113__version__ = '0.1'
114
115#@+others
116#@+node:peckj.20130513115943.16247: ** init
117def init ():
118
119 if g.app.gui is None:
120 g.app.createQtGui(__file__)
121
122 ok = g.app.gui.guiName().startswith('qt')
123
124 if ok:
125 g.registerHandler(('new','open2'),onCreate)
126 g.plugin_signon(__name__)
127
128 return ok
129#@+node:peckj.20130513115943.16248: ** onCreate
130def onCreate (tag, keys):
131
132 '''Handle the onCreate event in the printing plugin.'''
133
134 c = keys.get('c')
135
136 if c:
137 pc = printingController(c)
138 c.thePrintingController = pc
139
140#@+node:peckj.20130513115943.16249: ** class printingController
141class printingController:
142
143 #@+others
144 #@+node:peckj.20130513115943.16250: *3* __init__
145 def __init__ (self,c):
146 self.c = c
147
148 # gather settings
149 self.font_size = c.config.getString('printing-font-size') or '12'
150 self.font_family = c.config.getString('printing-font-family') or 'DejaVu Sans Mono'
151
152 # initialize
153 self.stylesheet = self.construct_stylesheet()
154
155 # register commands
156 ## selected node
157 c.k.registerCommand('print-selected-node-body',shortcut=None,func=self.print_selected_node_body)
158 c.k.registerCommand('print-preview-selected-node-body',
159 shortcut=None,func=self.print_preview_selected_node_body)
160 c.k.registerCommand('print-selected-node',shortcut=None,func=self.print_selected_node)
161 c.k.registerCommand('print-preview-selected-node',
162 shortcut=None,func=self.print_preview_selected_node)
163 ## expanded node
164 c.k.registerCommand('print-expanded-node-body',shortcut=None,func=self.print_expanded_node_body)
165 c.k.registerCommand('print-preview-expanded-node-body',
166 shortcut=None,func=self.print_preview_expanded_node_body)
167 c.k.registerCommand('print-expanded-node',shortcut=None,func=self.print_expanded_node)
168 c.k.registerCommand('print-preview-expanded-node',
169 shortcut=None,func=self.print_preview_expanded_node)
170 ## marked nodes
171 c.k.registerCommand('print-marked-node-bodies',shortcut=None,func=self.print_marked_node_bodies)
172 c.k.registerCommand('print-preview-marked-node-bodies',
173 shortcut=None,func=self.print_preview_marked_node_bodies)
174 c.k.registerCommand('print-marked-nodes',shortcut=None,func=self.print_marked_nodes)
175 c.k.registerCommand('print-preview-marked-nodes',
176 shortcut=None,func=self.print_preview_marked_nodes)
177
178 #@+node:peckj.20130513115943.22457: *3* helpers
179 #@+node:peckj.20130513115943.22458: *4* construct stylesheet
180 def construct_stylesheet(self):
181 s = 'h1 {font-family: %s}\n' % self.font_family
182 s += 'pre {font-family: %s; font-size: %spx}' % (self.font_family, self.font_size)
183 return s
184 #@+node:peckj.20130513115943.22459: *4* construct document
185 def construct_document(self, text, head=None):
186 doc = QtGui.QTextDocument()
187 doc.setDefaultStyleSheet(self.stylesheet)
188 text = self.sanitize_html(text)
189 if head:
190 head = self.sanitize_html(head)
191 contents = "<h1>%s</h1>\n<pre>%s</pre>" % (head, text)
192 else:
193 contents = "<pre>%s<pre>" % text
194 doc.setHtml(contents)
195 return doc
196 #@+node:peckj.20130514082859.5603: *4* construct complex document
197 def construct_complex_document(self, nodes, heads=False):
198 doc = QtGui.QTextDocument()
199 doc.setDefaultStyleSheet(self.stylesheet)
200 contents = ''
201 for n in nodes:
202 if heads:
203 contents += '<h1>%s</h1>\n' % (self.sanitize_html(n.h))
204 contents += '<pre>%s</pre>\n' % (self.sanitize_html(n.b))
205 doc.setHtml(contents)
206 return doc
207 #@+node:peckj.20130513115943.22661: *4* print dialog
208 def print_doc(self, doc):
209 dialog = QtGui.QPrintDialog()
210 if dialog.exec_() == QtGui.QDialog.Accepted:
211 doc.print_(dialog.printer())
212 #@+node:peckj.20130513115943.22662: *4* print preview dialog
213 def print_preview_doc(self, doc):
214 dialog = QtGui.QPrintPreviewDialog()
215 dialog.paintRequested.connect(doc.print_)
216 dialog.exec_()
217 #@+node:peckj.20130514082859.5604: *4* sanitize html
218 def sanitize_html(self, html):
219 ''' quick and dirty way to make sure html is escaped properly for printing '''
220 return html.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
221 #@+node:peckj.20130514082859.5610: *4* untangle
222 def untangle(self,p):
223 return g.getScript(self.c,p,
224 useSelectedText=False,
225 useSentinels=False)
226 #@+node:peckj.20130513115943.22666: *3* selected node
227 #@+node:peckj.20130513193024.6336: *4* print_selected_node_body
228 def print_selected_node_body (self,event=None):
229 ''' prints the selected node body'''
230
231 doc = self.construct_document(self.c.p.b)
232 self.print_doc(doc)
233 #@+node:peckj.20130513193024.6337: *4* print_preview_selected_node_body
234 def print_preview_selected_node_body (self,event=None):
235 ''' print previews the selected node body'''
236
237 doc = self.construct_document(self.c.p.b)
238 self.print_preview_doc(doc)
239 #@+node:peckj.20130513115943.16251: *4* print_selected_node
240 def print_selected_node (self,event=None):
241 ''' prints the selected node '''
242
243 doc = self.construct_document(self.c.p.b, head=self.c.p.h)
244 self.print_doc(doc)
245 #@+node:peckj.20130513115943.22456: *4* print_preview_selected_node
246 def print_preview_selected_node (self,event=None):
247 ''' prints the selected node '''
248
249 doc = self.construct_document(self.c.p.b, head=self.c.p.h)
250 self.print_preview_doc(doc)
251 #@+node:peckj.20130514082859.5616: *3* expanded selected node
252 #@+node:peckj.20130514082859.5617: *4* print_expanded_node_body
253 def print_expanded_node_body (self,event=None):
254 ''' prints the expanded selected node body '''
255
256 doc = self.construct_document(self.untangle(self.c.p))
257 self.print_doc(doc)
258 #@+node:peckj.20130514082859.5618: *4* print_preview_expanded_node_body
259 def print_preview_expanded_node_body (self,event=None):
260 ''' print previews the expanded selected node body'''
261
262 doc = self.construct_document(self.untangle(self.c.p))
263 self.print_preview_doc(doc)
264 #@+node:peckj.20130514082859.5619: *4* print_expanded_node
265 def print_expanded_node (self,event=None):
266 ''' prints the expanded selected node '''
267
268 p = self.c.p
269 doc = self.construct_document(self.untangle(p), head=p.h)
270 self.print_doc(doc)
271 #@+node:peckj.20130514082859.5620: *4* print_preview_expanded_node
272 def print_preview_expanded_node (self,event=None):
273 ''' prints the expanced selected node '''
274
275 p = self.c.p
276 doc = self.construct_document(self.untangle(p), head=p.h)
277 self.print_preview_doc(doc)
278 #@+node:peckj.20130514082859.5605: *3* marked nodes
279 #@+node:peckj.20130514082859.5606: *4* print_marked_node_bodies
280 def print_marked_node_bodies (self,event=None):
281 ''' prints the marked node bodies'''
282 nodes = []
283 for n in self.c.all_positions():
284 if n.isMarked():
285 nodes.append(n.v)
286 doc = self.construct_complex_document(nodes)
287 self.print_doc(doc)
288 #@+node:peckj.20130514082859.5607: *4* print_preview_marked_node_bodies
289 def print_preview_marked_node_bodies (self,event=None):
290 ''' print previews the marked node bodies'''
291 nodes = []
292 for n in self.c.all_positions():
293 if n.isMarked():
294 nodes.append(n.v)
295 doc = self.construct_complex_document(nodes)
296 self.print_preview_doc(doc)
297 #@+node:peckj.20130514082859.5608: *4* print_marked_nodes
298 def print_marked_nodes (self,event=None):
299 ''' prints the marked nodes'''
300 nodes = []
301 for n in self.c.all_positions():
302 if n.isMarked():
303 nodes.append(n.v)
304 doc = self.construct_complex_document(nodes, heads=True)
305 self.print_doc(doc)
306 #@+node:peckj.20130514082859.5609: *4* print_preview_marked_nodes
307 def print_preview_marked_nodes (self,event=None):
308 ''' print previews the marked nodes'''
309 nodes = []
310 for n in self.c.all_positions():
311 if n.isMarked():
312 nodes.append(n.v)
313 doc = self.construct_complex_document(nodes, heads=True)
314 self.print_preview_doc(doc)
315 #@-others
316#@-others
317#@-leo

Subscribers

People subscribed via source and target branches

to all changes: