Added the option to print the currently visible part of the graph.
Triggered by either pressing the key 'p' or the newly added toolbar
button.
TODO: Instead of the key 'p', the sysmtem-default key-combination should
trigger printing (e.g. Ctrl+p).
... | ... |
@@ -1653,8 +1653,42 @@ class DotWidget(gtk.DrawingArea): |
1653 | 1653 |
if event.keyval == gtk.keysyms.q: |
1654 | 1654 |
gtk.main_quit() |
1655 | 1655 |
return True |
1656 |
+ if event.keyval == gtk.keysyms.p: |
|
1657 |
+ self.on_print() |
|
1658 |
+ return True |
|
1656 | 1659 |
return False |
1657 | 1660 |
|
1661 |
+ print_settings = None |
|
1662 |
+ def on_print(self, action=None): |
|
1663 |
+ print_op = gtk.PrintOperation() |
|
1664 |
+ |
|
1665 |
+ if self.print_settings != None: |
|
1666 |
+ print_op.set_print_settings(self.print_settings) |
|
1667 |
+ |
|
1668 |
+ print_op.connect("begin_print", self.begin_print) |
|
1669 |
+ print_op.connect("draw_page", self.draw_page) |
|
1670 |
+ |
|
1671 |
+ res = print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, self.parent.parent) |
|
1672 |
+ |
|
1673 |
+ if res == gtk.PRINT_OPERATION_RESULT_APPLY: |
|
1674 |
+ print_settings = print_op.get_print_settings() |
|
1675 |
+ |
|
1676 |
+ def begin_print(self, operation, context): |
|
1677 |
+ operation.set_n_pages(1) |
|
1678 |
+ #operation.set_support_selection(True) |
|
1679 |
+ #operation.set_has_selection(True) |
|
1680 |
+ return True |
|
1681 |
+ |
|
1682 |
+ def draw_page(self, operation, context, page_nr): |
|
1683 |
+ cr = context.get_cairo_context() |
|
1684 |
+ |
|
1685 |
+ rect = self.get_allocation() |
|
1686 |
+ cr.translate(0.5*rect.width, 0.5*rect.height) |
|
1687 |
+ cr.scale(self.zoom_ratio, self.zoom_ratio) |
|
1688 |
+ cr.translate(-self.x, -self.y) |
|
1689 |
+ |
|
1690 |
+ self.graph.draw(cr, highlight_items=self.highlight) |
|
1691 |
+ |
|
1658 | 1692 |
def get_drag_action(self, event): |
1659 | 1693 |
state = event.state |
1660 | 1694 |
if event.button in (1, 2): # left or middle button |
... | ... |
@@ -1756,6 +1790,7 @@ class DotWindow(gtk.Window): |
1756 | 1790 |
<toolbar name="ToolBar"> |
1757 | 1791 |
<toolitem action="Open"/> |
1758 | 1792 |
<toolitem action="Reload"/> |
1793 |
+ <toolitem action="Print"/> |
|
1759 | 1794 |
<separator/> |
1760 | 1795 |
<toolitem action="ZoomIn"/> |
1761 | 1796 |
<toolitem action="ZoomOut"/> |
... | ... |
@@ -1796,6 +1831,7 @@ class DotWindow(gtk.Window): |
1796 | 1831 |
actiongroup.add_actions(( |
1797 | 1832 |
('Open', gtk.STOCK_OPEN, None, None, None, self.on_open), |
1798 | 1833 |
('Reload', gtk.STOCK_REFRESH, None, None, None, self.on_reload), |
1834 |
+ ('Print', gtk.STOCK_PRINT, None, None, "Prints the currently visible part of the graph", self.widget.on_print), |
|
1799 | 1835 |
('ZoomIn', gtk.STOCK_ZOOM_IN, None, None, None, self.widget.on_zoom_in), |
1800 | 1836 |
('ZoomOut', gtk.STOCK_ZOOM_OUT, None, None, None, self.widget.on_zoom_out), |
1801 | 1837 |
('ZoomFit', gtk.STOCK_ZOOM_FIT, None, None, None, self.widget.on_zoom_fit), |