2007-09-03 Zsolt Foldvari <zfoldvar@users.sourceforge.net>

* src/docgen/gtkprintpreview.glade: Hide Print button for now.
	* src/docgen/GtkPrint.py: Print dialog comes back after Preview is
	finished. Print settings properly saved and reapplied.



svn: r8924
This commit is contained in:
Zsolt Foldvari 2007-09-03 11:53:57 +00:00
parent 4eb636e565
commit 079fb3358d
3 changed files with 42 additions and 25 deletions

View File

@ -1,3 +1,8 @@
2007-09-03 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/docgen/gtkprintpreview.glade: Hide Print button for now.
* src/docgen/GtkPrint.py: Print dialog comes back after Preview is
finished. Print settings properly saved and reapplied.
2007-09-01 Don Allingham <don@gramps-project.org> 2007-09-01 Don Allingham <don@gramps-project.org>
* src/GrampsDbUtils/_WriteGedcom.py: Fix note level (bug #1204) * src/GrampsDbUtils/_WriteGedcom.py: Fix note level (bug #1204)

View File

@ -1233,6 +1233,9 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self._pages = [] self._pages = []
def close(self): def close(self):
self.run()
def run(self):
"""End the meta document. """End the meta document.
It must be implemented in the subclasses. The idea is that with It must be implemented in the subclasses. The idea is that with
@ -1355,37 +1358,46 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
def rotate_text(self, style, text, x, y, angle): def rotate_text(self, style, text, x, y, angle):
pass pass
# the print settings to remember between print sessions
PRINT_SETTINGS = None
class GtkPrint(CairoDoc): class GtkPrint(CairoDoc):
"""Print document via GtkPrint* interface.
def close(self): Requires Gtk+ 2.10.
page_setup = paperstyle_to_pagesetup(self.paper)
"""
print_operation = gtk.PrintOperation() def run(self):
print_operation.set_default_page_setup(page_setup)
print_operation.connect("begin_print", self.on_begin_print)
print_operation.connect("draw_page", self.on_draw_page)
print_operation.connect("paginate", self.on_paginate)
print_operation.connect("preview", self.on_preview)
self.print_settings = None
self.preview = None
self.do_print(print_operation)
def do_print(self, operation):
"""Run the Gtk Print operation. """Run the Gtk Print operation.
""" """
global PRINT_SETTINGS
# get a page setup from the paper style we have
page_setup = paperstyle_to_pagesetup(self.paper)
# set up a print operation
operation = gtk.PrintOperation()
operation.set_default_page_setup(page_setup)
operation.connect("begin_print", self.on_begin_print)
operation.connect("draw_page", self.on_draw_page)
operation.connect("paginate", self.on_paginate)
operation.connect("preview", self.on_preview)
# set print settings if it was stored previously # set print settings if it was stored previously
if self.print_settings is not None: if PRINT_SETTINGS is not None:
operation.set_print_settings(self.print_settings) operation.set_print_settings(PRINT_SETTINGS)
# run print dialog # run print dialog
res = operation.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None) while True:
self.preview = None
res = operation.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, None)
if self.preview is None:
break
# store print settings if printing was successful # store print settings if printing was successful
if res == gtk.PRINT_OPERATION_RESULT_APPLY: if res == gtk.PRINT_OPERATION_RESULT_APPLY:
self.print_settings = operation.get_print_settings() PRINT_SETTINGS = operation.get_print_settings()
def on_begin_print(self, operation, context): def on_begin_print(self, operation, context):
"""Setup environment for printing. """Setup environment for printing.
@ -1398,8 +1410,8 @@ class GtkPrint(CairoDoc):
self.page_height = context.get_height() self.page_height = context.get_height()
# get all document level elements and beging a new page # get all document level elements and beging a new page
self.elements_to_paginate = self._doc.get_children() self.elements_to_paginate = self._doc.get_children()[:]
self._pages.append(GtkDocDocument()) self._pages = [GtkDocDocument(),]
self.available_height = self.page_height self.available_height = self.page_height
def on_paginate(self, operation, context): def on_paginate(self, operation, context):
@ -1481,7 +1493,7 @@ class GtkPrint(CairoDoc):
context.set_cairo_context(cr, PRINTER_DPI, PRINTER_DPI) context.set_cairo_context(cr, PRINTER_DPI, PRINTER_DPI)
return True return True
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Register the document generator with the GRAMPS plugin system # Register the document generator with the GRAMPS plugin system

View File

@ -53,7 +53,7 @@
<child> <child>
<widget class="GtkToolButton" id="print"> <widget class="GtkToolButton" id="print">
<property name="visible">True</property> <property name="sensitive">False</property>
<property name="tooltip" translatable="yes">Prints the current file</property> <property name="tooltip" translatable="yes">Prints the current file</property>
<property name="stock_id">gtk-print</property> <property name="stock_id">gtk-print</property>
<property name="visible_horizontal">True</property> <property name="visible_horizontal">True</property>