remember metric & custom paper size, issue #1481

svn: r9782
This commit is contained in:
Stéphane Charette 2008-01-12 11:37:21 +00:00
parent 7c37b80716
commit 219a325c43
9 changed files with 196 additions and 55 deletions

View File

@ -1,3 +1,15 @@
2008-01-12 Stéphane Charette <stephanecharette@gmail.com>
* src/Config/_GrampsConfigKeys.py:
* src/ReportBase/_PaperMenu.py:
* src/ReportBase/_GraphvizReportDialog.py:
* src/ReportBase/_DocReportDialog.py:
* src/ReportBase/_BareReportDialog.py:
* src/ReportBase/_ReportOptions.py:
remember if the paper options should be metric, and remember the
custom paper sizes (issues #1481)
* src/plugins/GVFamilyLines.py: small code cleanup
* src/plugins/GVRelGraph.py: implement post_init()
2008-01-11 Stéphane Charette <stephanecharette@gmail.com>
* src/ReportBase/_BareReportDialog.py: allow scroll arrows on the
notebook if there are too many tabs to display

View File

@ -115,6 +115,7 @@ PPREFIX = ('preferences', 'pprefix', 2)
SPREFIX = ('preferences', 'sprefix', 2)
GOUTPUT_PREFERENCE = ('preferences', 'goutput-preference', 2)
OUTPUT_PREFERENCE = ('preferences', 'output-preference', 2)
PAPER_METRIC = ('preferences', 'paper-metric', 1)
PAPER_PREFERENCE = ('preferences', 'paper-preference', 2)
RECENT_FILE = ('paths', 'recent-file', 2)
RECENT_IMPORT_DIR = ('paths', 'recent-import-dir', 2)
@ -232,6 +233,7 @@ default_value = {
SPREFIX : 'S%04d',
GOUTPUT_PREFERENCE : 'No default format',
OUTPUT_PREFERENCE : 'No default format',
PAPER_METRIC : 0,
PAPER_PREFERENCE : 'Letter',
RECENT_FILE : '',
RECENT_IMPORT_DIR : '',

View File

@ -178,9 +178,11 @@ class DocReportDialog(ReportDialog):
self.target_fileentry.set_filename(spath)
def setup_report_options_frame(self):
self.paper_frame = PaperFrame(self.options.handler.get_paper_name(),
self.paper_frame = PaperFrame(self.options.handler.get_paper_metric(),
self.options.handler.get_paper_name(),
self.options.handler.get_orientation(),
self.options.handler.get_margins(),
self.options.handler.get_custom_paper_size()
)
self.setup_html_frame()
ReportDialog.setup_report_options_frame(self)
@ -292,9 +294,11 @@ class DocReportDialog(ReportDialog):
self.parse_style_frame()
self.parse_html_frame()
self.options.handler.set_paper_metric(self.paper_frame.get_paper_metric())
self.options.handler.set_paper_name(self.paper_frame.get_paper_name())
self.options.handler.set_orientation(self.paper_frame.get_orientation())
self.options.handler.set_margins(self.paper_frame.get_paper_margins())
self.options.handler.set_custom_paper_size(self.paper_frame.get_custom_paper_size())
self.parse_user_options()

View File

@ -885,9 +885,11 @@ class GraphvizReportDialog(ReportDialog):
self.paper_label = gtk.Label('<b>%s</b>'%_("Paper Options"))
self.paper_label.set_use_markup(True)
self.paper_frame = PaperFrame(self.options.handler.get_paper_name(),
self.paper_frame = PaperFrame(self.options.handler.get_paper_metric(),
self.options.handler.get_paper_name(),
self.options.handler.get_orientation(),
self.options.handler.get_margins()
self.options.handler.get_margins(),
self.options.handler.get_custom_paper_size()
)
self.notebook.insert_page(self.paper_frame,self.paper_label,0)
self.paper_frame.show_all()
@ -945,9 +947,11 @@ class GraphvizReportDialog(ReportDialog):
self.parse_format_frame()
self.parse_user_options()
self.options.handler.set_paper_metric(self.paper_frame.get_paper_metric())
self.options.handler.set_paper_name(self.paper_frame.get_paper_name())
self.options.handler.set_orientation(self.paper_frame.get_orientation())
self.options.handler.set_margins(self.paper_frame.get_paper_margins())
self.options.handler.set_custom_paper_size(self.paper_frame.get_custom_paper_size())
# Create the output document.
self.make_document()

View File

@ -142,8 +142,8 @@ class OrientationComboBox(gtk.ComboBox):
#-------------------------------------------------------------------------
class PaperFrame(gtk.HBox):
"""PaperFrame provides all the entry necessary to specify a paper style. """
def __init__(self,default_name,default_orientation,
margins=[2.54,2.54,2.54,2.54]):
def __init__(self,default_metric,default_name,default_orientation,
margins=[2.54,2.54,2.54,2.54], custom=[29.7,21.0]):
gtk.HBox.__init__(self)
glade_file = os.path.join(const.GLADE_DIR, "paper_settings.glade")
glade_xml = gtk.glade.XML(glade_file, "paper_table", "gramps")
@ -162,6 +162,7 @@ class PaperFrame(gtk.HBox):
# insert custom widgets
self.papersize_menu = PaperComboBox(default_name)
self.orientation_menu = OrientationComboBox(default_orientation)
self.metric.set_active(default_metric)
# connect all widgets
format_table = glade_xml.get_widget('format_table')
@ -178,6 +179,8 @@ class PaperFrame(gtk.HBox):
self.paper_unit = 'cm'
self.paper_unit_multiplier = 1.0
self.pwidth.set_text("%.2f" % custom[0])
self.pheight.set_text("%.2f" % custom[1])
self.lmargin.set_text("%.2f" % margins[0])
self.rmargin.set_text("%.2f" % margins[1])
self.tmargin.set_text("%.2f" % margins[2])
@ -186,6 +189,7 @@ class PaperFrame(gtk.HBox):
self.paper_table.show_all()
self.add(self.paper_table)
self.units_changed(self.metric)
self.size_changed(None)
def size_changed(self, obj):
@ -249,7 +253,6 @@ class PaperFrame(gtk.HBox):
"""
papersize, papername = self.papersize_menu.get_value()
# FIXME it is wrong to use translatable text in comparison.
# How can we distinguish custom size though?
if papername == _('Custom Size'):
@ -291,6 +294,16 @@ class PaperFrame(gtk.HBox):
return paper_margins
def get_custom_paper_size(self):
width = float(self.pwidth.get_text() ) * self.paper_unit_multiplier
height = float(self.pheight.get_text()) * self.paper_unit_multiplier
paper_size = []
paper_size.append(max(width, 1.0))
paper_size.append(max(height, 1.0))
return paper_size
def get_paper_style(self):
paper_size, paper_name = self.get_paper_size()
paper_orientation = self.orientation_menu.get_value()
@ -301,6 +314,9 @@ class PaperFrame(gtk.HBox):
*paper_margins)
return pstyle
def get_paper_metric(self):
return self.metric.get_active()
def get_paper_name(self):
paper_size, paper_name = self.get_paper_size()
return paper_name

View File

@ -70,8 +70,10 @@ class OptionList(_Options.OptionList):
def __init__(self):
_Options.OptionList.__init__(self)
self.style_name = None
self.paper_metric = None
self.paper_name = None
self.orientation = None
self.custom_paper_size = [29.7, 21.0]
self.margins = [2.54, 2.54, 2.54, 2.54]
self.template_name = None
self.format_name = None
@ -92,6 +94,22 @@ class OptionList(_Options.OptionList):
"""
return self.style_name
def set_paper_metric(self,paper_metric):
"""
Sets the paper metric for the OptionList.
@param paper_metric: whether to use metric.
@type paper_name: boolean
"""
self.paper_metric = paper_metric
def get_paper_metric(self):
"""
Returns the paper metric of the OptionList.
@returns: returns whether to use metric
@rtype: boolean
"""
return self.paper_metric
def set_paper_name(self,paper_name):
"""
Sets the paper name for the OptionList.
@ -126,6 +144,22 @@ class OptionList(_Options.OptionList):
"""
return self.orientation
def set_custom_paper_size(self,paper_size):
"""
Sets the custom paper size for the OptionList.
@param paper_size: paper size to set in cm.
@type paper_size: [float, float]
"""
self.custom_paper_size = paper_size
def get_custom_paper_size(self):
"""
Returns the custom paper size for the OptionList.
@returns: returns the custom paper size in cm
@rtype: [float, float]
"""
return self.custom_paper_size
def set_margins(self,margins):
"""
Sets the margins for the OptionList.
@ -209,19 +243,39 @@ class OptionListCollection(_Options.OptionListCollection):
def init_common(self):
# Default values for common options
self.default_style_name = "default"
self.default_paper_metric = Config.get(Config.PAPER_METRIC)
self.default_paper_name = Config.get(Config.PAPER_PREFERENCE)
self.default_template_name = ""
self.default_orientation = BaseDoc.PAPER_PORTRAIT
self.default_custom_paper_size = [29.7, 21.0]
self.default_margins = [2.54, 2.54, 2.54, 2.54]
self.default_format_name = 'print'
self.last_paper_metric = self.default_paper_metric
self.last_paper_name = self.default_paper_name
self.last_orientation = self.default_orientation
self.last_custom_paper_size = copy.copy(self.default_custom_paper_size)
self.last_margins = copy.copy(self.default_margins)
self.last_template_name = self.default_template_name
self.last_format_name = self.default_format_name
self.option_list_map = {}
def set_last_paper_metric(self,paper_metric):
"""
Sets the last paper metric used for the any report in this collection.
@param paper_metric: whether to use metric.
@type paper_name: boolean
"""
self.last_paper_metric = paper_metric
def get_last_paper_metric(self):
"""
Returns the last paper metric used for the any report in this collection.
@returns: returns whether or not to use metric
@rtype: boolean
"""
return self.last_paper_metric
def set_last_paper_name(self,paper_name):
"""
Sets the last paper name used for the any report in this collection.
@ -255,6 +309,23 @@ class OptionListCollection(_Options.OptionListCollection):
"""
return self.last_orientation
def set_last_custom_paper_size(self,custom_paper_size):
"""
Sets the last custom paper size used for the any report in this collection.
@param custom_paper_size: size to set in cm (width, height)
@type margins: [float, float]
"""
self.last_custom_paper_size = copy.copy(custom_paper_size)
def get_last_custom_paper_size(self):
"""
Returns the last custom paper size used for the any report in this
collection.
@returns: list of last custom paper size used in cm (width, height)
@rtype: [float, float]
"""
return copy.copy(self.last_custom_paper_size)
def set_last_margins(self,margins):
"""
Sets the last margins used for the any report in this collection.
@ -323,6 +394,11 @@ class OptionListCollection(_Options.OptionListCollection):
def write_common(self,f):
f.write('<last-common>\n')
if self.get_last_paper_metric() != self.default_paper_metric:
f.write(' <metric value="%d"/>\n' % self.get_last_paper_metric() )
if self.get_last_custom_paper_size() != self.default_custom_paper_size:
size = self.get_last_custom_paper_size()
f.write(' <size value="%f %f"/>\n' % (size[0], size[1]) )
if self.get_last_paper_name() != self.default_paper_name:
f.write(' <paper name="%s"/>\n' % escxml(self.get_last_paper_name()) )
if self.get_last_template_name() != self.default_template_name:
@ -337,6 +413,13 @@ class OptionListCollection(_Options.OptionListCollection):
if option_list.get_style_name() \
and option_list.get_style_name() != self.default_style_name:
f.write(' <style name="%s"/>\n' % escxml(option_list.get_style_name()) )
if option_list.get_paper_metric() \
and option_list.get_paper_metric() != self.default_paper_metric:
f.write(' <metric value="%d"/>\n' % option_list.get_paper_metric() )
if option_list.get_custom_paper_size() \
and option_list.get_custom_paper_size() != self.default_custom_paper_size:
size = self.get_last_custom_paper_size()
f.write(' <size value="%f %f"/>\n' % (size[0], size[1]) )
if option_list.get_paper_name() \
and option_list.get_paper_name() != self.default_paper_name:
f.write(' <paper name="%s"/>\n' % escxml(option_list.get_paper_name()) )
@ -418,6 +501,20 @@ class OptionParser(_Options.OptionParser):
self.collection.set_last_orientation(int(attrs['value']))
else:
self.option_list.set_orientation(int(attrs['value']))
elif tag == "metric":
if self.common:
self.collection.set_last_paper_metric(int(attrs['value']))
else:
self.option_list.set_paper_metric(int(attrs['value']))
elif tag == "size":
width, height = attrs['value'].split()
width = float(width)
height = float(height)
if self.common:
self.collection.set_last_custom_paper_size([width, height])
else:
self.option_list.set_custom_paper_size([width, height])
elif tag == "margin":
pos, value = int(attrs['number']), float(attrs['value'])
if self.common:
@ -465,8 +562,10 @@ class OptionHandler(_Options.OptionHandler):
# Retrieve our options from whole collection
self.style_name = self.option_list_collection.default_style_name
self.paper_metric = self.option_list_collection.get_last_paper_metric()
self.paper_name = self.option_list_collection.get_last_paper_name()
self.orientation = self.option_list_collection.get_last_orientation()
self.custom_paper_size = self.option_list_collection.get_last_custom_paper_size()
self.margins = self.option_list_collection.get_last_margins()
self.template_name = self.option_list_collection.get_last_template_name()
self.format_name = self.option_list_collection.get_last_format_name()
@ -476,10 +575,14 @@ class OptionHandler(_Options.OptionHandler):
self.style_name = self.saved_option_list.get_style_name()
if self.saved_option_list.get_orientation():
self.orientation = self.saved_option_list.get_orientation()
if self.saved_option_list.get_custom_paper_size():
self.custom_paper_size = self.saved_option_list.get_custom_paper_size()
if self.saved_option_list.get_margins():
self.margins = self.saved_option_list.get_margins()
if self.saved_option_list.get_template_name():
self.template_name = self.saved_option_list.get_template_name()
if self.saved_option_list.get_paper_metric():
self.paper_metric = self.saved_option_list.get_paper_metric()
if self.saved_option_list.get_paper_name():
self.paper_name = self.saved_option_list.get_paper_name()
if self.saved_option_list.get_format_name():
@ -489,8 +592,10 @@ class OptionHandler(_Options.OptionHandler):
# First we save common options
self.saved_option_list.set_style_name(self.style_name)
self.saved_option_list.set_orientation(self.orientation)
self.saved_option_list.set_custom_paper_size(self.custom_paper_size)
self.saved_option_list.set_margins(self.margins)
self.saved_option_list.set_template_name(self.template_name)
self.saved_option_list.set_paper_metric(self.paper_metric)
self.saved_option_list.set_paper_name(self.paper_name)
self.saved_option_list.set_format_name(self.format_name)
self.option_list_collection.set_option_list(self.module_name,
@ -498,8 +603,10 @@ class OptionHandler(_Options.OptionHandler):
# Then save last-common options from the current selection
self.option_list_collection.set_last_orientation(self.orientation)
self.option_list_collection.set_last_custom_paper_size(self.custom_paper_size)
self.option_list_collection.set_last_margins(self.margins)
self.option_list_collection.set_last_template_name(self.template_name)
self.option_list_collection.set_last_paper_metric(self.paper_metric)
self.option_list_collection.set_last_paper_name(self.paper_name)
self.option_list_collection.set_last_format_name(self.format_name)
@ -519,6 +626,12 @@ class OptionHandler(_Options.OptionHandler):
def set_format_name(self,format_name):
self.format_name = format_name
def get_paper_metric(self):
return self.paper_metric
def set_paper_metric(self,paper_metric):
self.paper_metric = paper_metric
def get_paper_name(self):
return self.paper_name
@ -549,6 +662,12 @@ class OptionHandler(_Options.OptionHandler):
def set_orientation(self,orientation):
self.orientation = orientation
def get_custom_paper_size(self):
return copy.copy(self.custom_paper_size)
def set_custom_paper_size(self,custom_paper_size):
self.custom_paper_size = copy.copy(custom_paper_size)
def get_margins(self):
return copy.copy(self.margins)

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Stephane Charette
# Copyright (C) 2007-2008 Stephane Charette
# Copyright (C) 2007 Brian G. Matherly
#
# This program is free software; you can redistribute it and/or modify
@ -30,8 +30,6 @@ Family Lines, a GraphViz-based plugin for Gramps.
# python modules
#
#------------------------------------------------------------------------
import os
import time
from gettext import gettext as _
#------------------------------------------------------------------------
@ -42,37 +40,17 @@ from gettext import gettext as _
import logging
log = logging.getLogger(".FamilyLines")
#------------------------------------------------------------------------
#
# GNOME/gtk
#
#------------------------------------------------------------------------
import gtk
import gobject
#------------------------------------------------------------------------
#
# GRAMPS module
#
#------------------------------------------------------------------------
import gen.lib
import Config
import Errors
import Utils
import ThumbNails
import DateHandler
import GrampsWidgets
import ManagedWindow
from PluginUtils import register_report
from ReportBase import Report, ReportUtils, CATEGORY_CODE, MODE_GUI, MODE_CLI
from ReportBase import Report, MenuReportOptions, MODE_GUI, MODE_CLI, CATEGORY_GRAPHVIZ
from ReportBase._ReportDialog import ReportDialog
from PluginUtils import register_report, EnumeratedListOption, BooleanOption, NumberOption, ColourButtonOption, PersonListOption, SurnameColourOption
from QuestionDialog import ErrorDialog, WarningDialog
from BasicUtils import name_displayer as _nd
from DateHandler import displayer as _dd
from DateHandler import parser
from Selectors import selector_factory
from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_GRAPHVIZ, MODE_GUI
from PluginUtils import register_report, EnumeratedListOption, BooleanOption, NumberOption, ColourButtonOption, PersonListOption, SurnameColourOption
#------------------------------------------------------------------------
@ -226,19 +204,15 @@ class FamilyLinesOptions(MenuReportOptions):
def post_init(self, dialog):
# this method is called after all of the controls have been
# created, but before the notebook is shown to the user
# created, but before the notebook itself has been created
# re-order the notebook tabs the way we want
# dialog.notebook.
self.limitParents.gobj.connect('toggled', self.limitChanged)
self.limitChildren.gobj.connect('toggled', self.limitChanged)
self.includeImages.gobj.connect('toggled', self.imagesChanged)
self.limitParents. gobj.connect('toggled', self.limitChanged )
self.limitChildren. gobj.connect('toggled', self.limitChanged )
self.includeImages. gobj.connect('toggled', self.imagesChanged )
# ensure things are initialized correctly when it first comes up
self.limitChanged(self.limitParents.gobj)
self.imagesChanged(self.includeImages.gobj)
self.limitChanged( self.limitParents.gobj )
self.imagesChanged( self.includeImages.gobj )
#------------------------------------------------------------------------

View File

@ -450,17 +450,17 @@ class RelGraphOptions(MenuReportOptions):
incid.set_help(_("Include individual and family IDs."))
menu.add_option(category_name,"incid", incid)
includeImages = BooleanOption(
self.includeImages = BooleanOption(
_('Include thumbnail images of people'), False)
includeImages.set_help(_("Whether to include thumbnails of people."))
menu.add_option(category_name,"includeImages", includeImages)
self.includeImages.set_help(_("Whether to include thumbnails of people."))
menu.add_option(category_name,"includeImages", self.includeImages)
imageOnTheSide = EnumeratedListOption(_("Thumbnail Location"), 0)
imageOnTheSide.add_item(0, _('Above the name'))
imageOnTheSide.add_item(1, _('Beside the name'))
imageOnTheSide.set_help(_("Where the thumbnail image should appear "
self.imageOnTheSide = EnumeratedListOption(_("Thumbnail Location"), 0)
self.imageOnTheSide.add_item(0, _('Above the name'))
self.imageOnTheSide.add_item(1, _('Beside the name'))
self.imageOnTheSide.set_help(_("Where the thumbnail image should appear "
"relative to the name"))
menu.add_option(category_name,"imageOnTheSide",imageOnTheSide)
menu.add_option(category_name,"imageOnTheSide",self.imageOnTheSide)
################################
category_name = _("Graph Style")
@ -491,6 +491,16 @@ class RelGraphOptions(MenuReportOptions):
"to parents and children."))
menu.add_option(category_name,"showfamily", showfamily)
def imageChanged(self, button):
self.imageOnTheSide.gobj.set_sensitive(self.includeImages.gobj.get_active())
def post_init(self, dialog):
self.includeImages.gobj.connect('toggled', self.imageChanged)
self.imageChanged(self.includeImages.gobj)
#------------------------------------------------------------------------
#
#