From 219a325c43add9caa44324145487645015210cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Charette?= Date: Sat, 12 Jan 2008 11:37:21 +0000 Subject: [PATCH] remember metric & custom paper size, issue #1481 svn: r9782 --- ChangeLog | 12 +++ src/Config/_GrampsConfigKeys.py | 2 + src/ReportBase/_BareReportDialog.py | 2 +- src/ReportBase/_DocReportDialog.py | 8 +- src/ReportBase/_GraphvizReportDialog.py | 10 +- src/ReportBase/_PaperMenu.py | 28 ++++-- src/ReportBase/_ReportOptions.py | 119 ++++++++++++++++++++++++ src/plugins/GVFamilyLines.py | 44 ++------- src/plugins/GVRelGraph.py | 26 ++++-- 9 files changed, 196 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 552c55f14..cb9ca4763 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-01-12 Stéphane Charette + * 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 * src/ReportBase/_BareReportDialog.py: allow scroll arrows on the notebook if there are too many tabs to display diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index 46a8717d2..df8142578 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -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 : '', diff --git a/src/ReportBase/_BareReportDialog.py b/src/ReportBase/_BareReportDialog.py index c830814c3..c28b03e45 100644 --- a/src/ReportBase/_BareReportDialog.py +++ b/src/ReportBase/_BareReportDialog.py @@ -149,7 +149,7 @@ class BareReportDialog(ManagedWindow.ManagedWindow): self.setup_target_frame() self.setup_format_frame() self.setup_style_frame() - + self.notebook = gtk.Notebook() self.notebook.set_scrollable(True) self.notebook.set_border_width(6) diff --git a/src/ReportBase/_DocReportDialog.py b/src/ReportBase/_DocReportDialog.py index f9fa54249..643976258 100644 --- a/src/ReportBase/_DocReportDialog.py +++ b/src/ReportBase/_DocReportDialog.py @@ -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) @@ -291,10 +293,12 @@ class DocReportDialog(ReportDialog): self.parse_format_frame() 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() diff --git a/src/ReportBase/_GraphvizReportDialog.py b/src/ReportBase/_GraphvizReportDialog.py index 15065e989..2557f2108 100644 --- a/src/ReportBase/_GraphvizReportDialog.py +++ b/src/ReportBase/_GraphvizReportDialog.py @@ -885,9 +885,11 @@ class GraphvizReportDialog(ReportDialog): self.paper_label = gtk.Label('%s'%_("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() @@ -944,10 +946,12 @@ class GraphvizReportDialog(ReportDialog): # Preparation 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() diff --git a/src/ReportBase/_PaperMenu.py b/src/ReportBase/_PaperMenu.py index b98045077..19d93d461 100644 --- a/src/ReportBase/_PaperMenu.py +++ b/src/ReportBase/_PaperMenu.py @@ -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): @@ -243,13 +247,12 @@ class PaperFrame(gtk.HBox): def get_paper_size(self): """Read and validate paper size values. - + If needed update the dimensions from the width, height entries, and worst case fallback to A4 size. - + """ 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'): @@ -290,7 +293,17 @@ class PaperFrame(gtk.HBox): paper_margins[i] = 2.54 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 diff --git a/src/ReportBase/_ReportOptions.py b/src/ReportBase/_ReportOptions.py index 3bdd5a8f7..dd367604d 100644 --- a/src/ReportBase/_ReportOptions.py +++ b/src/ReportBase/_ReportOptions.py @@ -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('\n') + if self.get_last_paper_metric() != self.default_paper_metric: + f.write(' \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(' \n' % (size[0], size[1]) ) if self.get_last_paper_name() != self.default_paper_name: f.write(' \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('