2007-09-17 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/ReportBase/_ReportDialog.py: Paper settings better handling. * src/docgen/GtkPrint.py: Custom size paper name translatable. svn: r8986
This commit is contained in:
parent
5244b16a5a
commit
8108c3a59e
@ -1,3 +1,7 @@
|
||||
2007-09-17 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/ReportBase/_ReportDialog.py: Paper settings better handling.
|
||||
* src/docgen/GtkPrint.py: Custom size paper name translatable.
|
||||
|
||||
2007-09-17 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
|
||||
* src/ReportBase/_MenuOptions.py: Set SVN properties.
|
||||
* src/docgen/GtkPrint.py: Round up paper size values received from
|
||||
|
@ -169,7 +169,10 @@ class ReportDialog(BareReportDialog):
|
||||
def make_document(self):
|
||||
"""Create a document of the type requested by the user.
|
||||
"""
|
||||
pstyle = PaperStyle(self.paper, self.orien, *self.paper_margins)
|
||||
pstyle = PaperStyle(self.paper_size,
|
||||
self.paper_orientation,
|
||||
*self.paper_margins)
|
||||
|
||||
self.doc = self.format(self.selected_style, pstyle, self.template_name)
|
||||
|
||||
self.options.set_document(self.doc)
|
||||
@ -312,50 +315,56 @@ class ReportDialog(BareReportDialog):
|
||||
|
||||
def size_changed(self, obj):
|
||||
"""Paper size combobox 'changed' callback."""
|
||||
(paper, name) = self.papersize_menu.get_value()
|
||||
size, name = self.get_paper_size()
|
||||
|
||||
is_custom = name == _("Custom Size")
|
||||
self.pwidth.set_sensitive(is_custom)
|
||||
self.pheight.set_sensitive(is_custom)
|
||||
|
||||
if paper.get_width() > 0 and paper.get_height() > 0:
|
||||
if self.metric.get_active():
|
||||
self.pwidth.set_text("%.2f" % paper.get_width())
|
||||
self.pheight.set_text("%.2f" % paper.get_height())
|
||||
else:
|
||||
self.pwidth.set_text("%.2f" % paper.get_width_inches())
|
||||
self.pheight.set_text("%.2f" % paper.get_height_inches())
|
||||
|
||||
def units_changed(self, obj):
|
||||
"""Metric checkbox 'toggled' callback."""
|
||||
(paper, name) = self.papersize_menu.get_value()
|
||||
|
||||
if self.metric.get_active():
|
||||
self.lunits1.set_text("cm")
|
||||
self.lunits2.set_text("cm")
|
||||
self.lunits3.set_text("cm")
|
||||
self.lunits4.set_text("cm")
|
||||
self.lunits5.set_text("cm")
|
||||
self.lunits6.set_text("cm")
|
||||
self.pwidth.set_text("%.2f" % paper.get_width())
|
||||
self.pheight.set_text("%.2f" % paper.get_height())
|
||||
self.lmargin.set_text("%.2f" % 2.54)
|
||||
self.rmargin.set_text("%.2f" % 2.54)
|
||||
self.tmargin.set_text("%.2f" % 2.54)
|
||||
self.bmargin.set_text("%.2f" % 2.54)
|
||||
if self.paper_unit == 'cm':
|
||||
self.pwidth.set_text("%.2f" % size.get_width())
|
||||
self.pheight.set_text("%.2f" % size.get_height())
|
||||
elif self.paper_unit == 'in.':
|
||||
self.pwidth.set_text("%.2f" % size.get_width_inches())
|
||||
self.pheight.set_text("%.2f" % size.get_height_inches())
|
||||
else:
|
||||
self.lunits1.set_text("in.")
|
||||
self.lunits2.set_text("in.")
|
||||
self.lunits3.set_text("in.")
|
||||
self.lunits4.set_text("in.")
|
||||
self.lunits5.set_text("in.")
|
||||
self.lunits6.set_text("in.")
|
||||
self.pwidth.set_text("%.2f" % paper.get_width_inches())
|
||||
self.pheight.set_text("%.2f" % paper.get_height_inches())
|
||||
self.lmargin.set_text("%.2f" % 1.0)
|
||||
self.rmargin.set_text("%.2f" % 1.0)
|
||||
self.tmargin.set_text("%.2f" % 1.0)
|
||||
self.bmargin.set_text("%.2f" % 1.0)
|
||||
raise ValueError('Paper dimension unit "%s" is not allowed' %
|
||||
self.paper_unit)
|
||||
|
||||
def units_changed(self, checkbox):
|
||||
"""Metric checkbox 'toggled' callback."""
|
||||
paper_size, paper_name = self.get_paper_size()
|
||||
paper_margins = self.get_paper_margins()
|
||||
|
||||
if checkbox.get_active():
|
||||
self.paper_unit = 'cm'
|
||||
self.paper_unit_multiplier = 1.0
|
||||
else:
|
||||
self.paper_unit = 'in.'
|
||||
self.paper_unit_multiplier = 2.54
|
||||
|
||||
self.lunits1.set_text(self.paper_unit)
|
||||
self.lunits2.set_text(self.paper_unit)
|
||||
self.lunits3.set_text(self.paper_unit)
|
||||
self.lunits4.set_text(self.paper_unit)
|
||||
self.lunits5.set_text(self.paper_unit)
|
||||
self.lunits6.set_text(self.paper_unit)
|
||||
|
||||
if self.paper_unit == 'cm':
|
||||
self.pwidth.set_text("%.2f" % paper_size.get_width())
|
||||
self.pheight.set_text("%.2f" % paper_size.get_height())
|
||||
else:
|
||||
self.pwidth.set_text("%.2f" % paper_size.get_width_inches())
|
||||
self.pheight.set_text("%.2f" % paper_size.get_height_inches())
|
||||
|
||||
self.lmargin.set_text("%.2f" %
|
||||
(paper_margins[0] / self.paper_unit_multiplier))
|
||||
self.rmargin.set_text("%.2f" %
|
||||
(paper_margins[1] / self.paper_unit_multiplier))
|
||||
self.tmargin.set_text("%.2f" %
|
||||
(paper_margins[2] / self.paper_unit_multiplier))
|
||||
self.bmargin.set_text("%.2f" %
|
||||
(paper_margins[3] / self.paper_unit_multiplier))
|
||||
|
||||
def setup_paper_frame(self):
|
||||
"""Set up the paper selection frame of the dialog."""
|
||||
@ -387,6 +396,8 @@ class ReportDialog(BareReportDialog):
|
||||
self.metric.connect('toggled',self.units_changed)
|
||||
|
||||
# set initial values
|
||||
self.paper_unit = 'cm'
|
||||
self.paper_unit_multiplier = 1.0
|
||||
self.papersize_menu.set(paper_sizes,
|
||||
self.options.handler.get_paper_name())
|
||||
self.orientation_menu.set(self.options.handler.get_orientation())
|
||||
@ -527,56 +538,72 @@ class ReportDialog(BareReportDialog):
|
||||
format_name = self.format_menu.get_clname()
|
||||
self.options.handler.set_format_name(format_name)
|
||||
|
||||
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'):
|
||||
try:
|
||||
h = float(unicode(self.pheight.get_text()))
|
||||
w = float(unicode(self.pwidth.get_text()))
|
||||
|
||||
if h <= 1.0 or w <= 1.0:
|
||||
papersize.set_height(29.7)
|
||||
papersize.set_width(21.0)
|
||||
else:
|
||||
papersize.set_height(h * self.paper_unit_multiplier)
|
||||
papersize.set_width(w * self.paper_unit_multiplier)
|
||||
except:
|
||||
papersize.set_height(29.7)
|
||||
papersize.set_width(21.0)
|
||||
|
||||
return papersize, papername
|
||||
|
||||
def get_paper_margins(self):
|
||||
"""Get and validate margin values from dialog entries.
|
||||
|
||||
Values returned in [cm].
|
||||
|
||||
"""
|
||||
paper_margins = []
|
||||
paper_margins.append(unicode(self.lmargin.get_text()))
|
||||
paper_margins.append(unicode(self.rmargin.get_text()))
|
||||
paper_margins.append(unicode(self.tmargin.get_text()))
|
||||
paper_margins.append(unicode(self.bmargin.get_text()))
|
||||
|
||||
for i, margin in enumerate(paper_margins):
|
||||
try:
|
||||
paper_margins[i] = float(margin)
|
||||
paper_margins[i] = paper_margins[i] * self.paper_unit_multiplier
|
||||
paper_margins[i] = max(paper_margins[i], 0)
|
||||
except:
|
||||
self.paper_margins[i] = 2.54
|
||||
|
||||
return paper_margins
|
||||
|
||||
def parse_paper_frame(self):
|
||||
"""Parse the paper frame of the dialog.
|
||||
|
||||
Save the user selected choices for later use.
|
||||
|
||||
"""
|
||||
(self.paper, paper_name) = self.papersize_menu.get_value()
|
||||
self.paper_size, paper_name = self.get_paper_size()
|
||||
|
||||
self.options.handler.set_paper_name(paper_name)
|
||||
self.options.handler.set_paper(self.paper)
|
||||
self.options.handler.set_paper(self.paper_size)
|
||||
|
||||
if self.metric.get_active():
|
||||
multiplier = 1
|
||||
else:
|
||||
multiplier = 2.54
|
||||
|
||||
if self.paper.get_height() <= 0 or self.paper.get_width() <= 0:
|
||||
try:
|
||||
h = float(unicode(self.pheight.get_text()))
|
||||
w = float(unicode(self.pwidth.get_text()))
|
||||
|
||||
if h <= 1.0 or w <= 1.0:
|
||||
self.paper.set_height(29.7)
|
||||
self.paper.set_width(21.0)
|
||||
else:
|
||||
self.paper.set_height(h * multiplier)
|
||||
self.paper.set_width(w * multiplier)
|
||||
except:
|
||||
self.paper.set_height(29.7)
|
||||
self.paper.set_width(21.0)
|
||||
self.paper_orientation = self.orientation_menu.get_value()
|
||||
self.options.handler.set_orientation(self.paper_orientation)
|
||||
|
||||
self.orien = self.orientation_menu.get_value()
|
||||
self.options.handler.set_orientation(self.orien)
|
||||
self.paper_margins = self.get_paper_margins()
|
||||
|
||||
# get the margin values and do some basic verification
|
||||
self.paper_margins = []
|
||||
self.paper_margins.append(unicode(self.lmargin.get_text()))
|
||||
self.paper_margins.append(unicode(self.rmargin.get_text()))
|
||||
self.paper_margins.append(unicode(self.tmargin.get_text()))
|
||||
self.paper_margins.append(unicode(self.bmargin.get_text()))
|
||||
for i, margin in enumerate(self.paper_margins):
|
||||
try:
|
||||
self.paper_margins[i] = float(margin)
|
||||
self.paper_margins[i] = self.paper_margins[i] * multiplier
|
||||
except:
|
||||
self.paper_margins[i] = 2.54
|
||||
|
||||
if self.paper_margins[i] < 0:
|
||||
self.paper_margins[i] = 0
|
||||
|
||||
def parse_html_frame(self):
|
||||
"""Parse the html frame of the dialog. Save the user selected
|
||||
html template name for later use. Note that this routine
|
||||
|
@ -128,9 +128,11 @@ def paperstyle_to_pagesetup(paper_style):
|
||||
gramps_paper_size = paper_style.get_size()
|
||||
gramps_paper_name = gramps_paper_size.get_name()
|
||||
|
||||
# FIXME it is wrong to use translatable text in comparison.
|
||||
# How can we distinguish custom size though?
|
||||
if gramps_to_gtk.has_key(gramps_paper_name):
|
||||
paper_size = gtk.PaperSize(gramps_to_gtk[gramps_paper_name])
|
||||
elif gramps_paper_name == "Custom Size":
|
||||
elif gramps_paper_name == _("Custom Size"):
|
||||
paper_width = gramps_paper_size.get_width() * 10
|
||||
paper_height = gramps_paper_size.get_height() * 10
|
||||
paper_size = gtk.paper_size_new_custom("custom",
|
||||
@ -153,9 +155,7 @@ def paperstyle_to_pagesetup(paper_style):
|
||||
else:
|
||||
page_setup.set_orientation(gtk.PAGE_ORIENTATION_LANDSCAPE)
|
||||
|
||||
# gtk.PageSize provides default margins for the standard papers.
|
||||
# Anyhow, we overwrite those with the settings from Gramps,
|
||||
# though at the moment all of them are fixed at 1 inch.
|
||||
# Set paper margins
|
||||
page_setup.set_top_margin(paper_style.get_top_margin() * 10,
|
||||
gtk.UNIT_MM)
|
||||
page_setup.set_bottom_margin(paper_style.get_bottom_margin() * 10,
|
||||
|
Loading…
Reference in New Issue
Block a user