* src/ReportBase/_PaperMenu.py: get margins in PaperFrame constructor
* src/ReportBase/_DocReportDialog.py: pass margins to PaperFrame constructor * src/ReportBase/_ReportOptions.py: added getters/setters for margins 2007-12-16 Douglas S. Blank <dblank@cs.brynmawr.edu> svn: r9523
This commit is contained in:
parent
4ba6f344a7
commit
a163da2218
@ -1,3 +1,8 @@
|
||||
2007-12-16 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||
* src/ReportBase/_PaperMenu.py: get margins in PaperFrame constructor
|
||||
* src/ReportBase/_DocReportDialog.py: pass margins to PaperFrame constructor
|
||||
* src/ReportBase/_ReportOptions.py: added getters/setters for margins
|
||||
|
||||
2007-12-16 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||
* src/plugins/Calendar.py: fixed MenuOption's EnumeratedList to match
|
||||
Brian's changes on 2007-12-15.
|
||||
|
@ -179,7 +179,9 @@ class DocReportDialog(ReportDialog):
|
||||
|
||||
def setup_report_options_frame(self):
|
||||
self.paper_frame = PaperFrame(self.options.handler.get_paper_name(),
|
||||
self.options.handler.get_orientation())
|
||||
self.options.handler.get_orientation(),
|
||||
self.options.handler.get_margins(),
|
||||
)
|
||||
self.setup_html_frame()
|
||||
ReportDialog.setup_report_options_frame(self)
|
||||
|
||||
@ -292,6 +294,7 @@ class DocReportDialog(ReportDialog):
|
||||
|
||||
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.parse_user_options()
|
||||
|
||||
|
@ -142,7 +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):
|
||||
def __init__(self,default_name,default_orientation,
|
||||
margins=[2.54,2.54,2.54,2.54]):
|
||||
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")
|
||||
@ -176,6 +177,11 @@ class PaperFrame(gtk.HBox):
|
||||
# set initial values
|
||||
self.paper_unit = 'cm'
|
||||
self.paper_unit_multiplier = 1.0
|
||||
|
||||
self.lmargin.set_text("%.2f" % margins[0])
|
||||
self.rmargin.set_text("%.2f" % margins[1])
|
||||
self.tmargin.set_text("%.2f" % margins[2])
|
||||
self.bmargin.set_text("%.2f" % margins[3])
|
||||
|
||||
self.paper_table.show_all()
|
||||
self.add(self.paper_table)
|
||||
|
@ -31,6 +31,7 @@ Report option handling, including saving and parsing.
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import copy
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
def escxml(d):
|
||||
@ -71,6 +72,7 @@ class OptionList(_Options.OptionList):
|
||||
self.style_name = None
|
||||
self.paper_name = None
|
||||
self.orientation = None
|
||||
self.margins = [2.54, 2.54, 2.54, 2.54]
|
||||
self.template_name = None
|
||||
self.format_name = None
|
||||
|
||||
@ -124,6 +126,42 @@ class OptionList(_Options.OptionList):
|
||||
"""
|
||||
return self.orientation
|
||||
|
||||
def set_margins(self,margins):
|
||||
"""
|
||||
Sets the margins for the OptionList.
|
||||
@param margins: margins to set. Possible values are floats in cm
|
||||
@type margins: [float, float, float, float]
|
||||
"""
|
||||
self.margins = copy.copy(margins)
|
||||
|
||||
def get_margins(self):
|
||||
"""
|
||||
Returns the margins for the OptionList.
|
||||
@returns margins: returns the margins, floats in cm
|
||||
@rtype margins: [float, float, float, float]
|
||||
"""
|
||||
return copy.copy(self.margins)
|
||||
|
||||
def set_margin(self,pos,value):
|
||||
"""
|
||||
Sets a margin for the OptionList.
|
||||
@param pos: Position of margin [left, right, top, bottom]
|
||||
@param value: floating point in cm
|
||||
@type pos: int
|
||||
@type value: float
|
||||
"""
|
||||
self.margins[pos] = value
|
||||
|
||||
def get_margin(self,pos):
|
||||
"""
|
||||
Returns a margin for the OptionList.
|
||||
@param pos: Position of margin [left, right, top, bottom]
|
||||
@type pos: int
|
||||
@returns: float cm of margin
|
||||
@rtype: float
|
||||
"""
|
||||
return self.margins[pos]
|
||||
|
||||
def set_template_name(self,template_name):
|
||||
"""
|
||||
Sets the template name for the OptionList.
|
||||
@ -174,10 +212,12 @@ class OptionListCollection(_Options.OptionListCollection):
|
||||
self.default_paper_name = Config.get(Config.PAPER_PREFERENCE)
|
||||
self.default_template_name = ""
|
||||
self.default_orientation = BaseDoc.PAPER_PORTRAIT
|
||||
self.default_margins = [2.54, 2.54, 2.54, 2.54]
|
||||
self.default_format_name = 'print'
|
||||
|
||||
self.last_paper_name = self.default_paper_name
|
||||
self.last_orientation = self.default_orientation
|
||||
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 = {}
|
||||
@ -215,6 +255,44 @@ class OptionListCollection(_Options.OptionListCollection):
|
||||
"""
|
||||
return self.last_orientation
|
||||
|
||||
def set_last_margins(self,margins):
|
||||
"""
|
||||
Sets the last margins used for the any report in this collection.
|
||||
@param margins: margins to set in cm (left, right, top, bottom)
|
||||
@type margins: [float, float, float, float]
|
||||
"""
|
||||
self.last_margins = copy.copy(margins)
|
||||
|
||||
def get_last_margins(self):
|
||||
"""
|
||||
Returns the last margins used for the any report in this
|
||||
collection.
|
||||
@returns: list of last margins used in cm (left, right, top, bottom)
|
||||
@rtype: [float, float, float, float]
|
||||
"""
|
||||
return copy.copy(self.last_margins)
|
||||
|
||||
def set_last_margin(self,pos,value):
|
||||
"""
|
||||
Sets the last margin used for the any report in this collection.
|
||||
@param pos: pos to set (0-4) (left, right, top, bottom)
|
||||
@type pos: int
|
||||
@param value: value to set the margin to in cm
|
||||
@type value: float
|
||||
"""
|
||||
self.last_margins[pos] = value
|
||||
|
||||
def get_last_margin(self,pos):
|
||||
"""
|
||||
Returns the last margins used for the any report in this
|
||||
collection.
|
||||
@param pos: position in margins list
|
||||
@type pos: int
|
||||
@returns: last margin used in pos
|
||||
@rtype: float
|
||||
"""
|
||||
return self.last_margins[pos]
|
||||
|
||||
def set_last_template_name(self,template_name):
|
||||
"""
|
||||
Sets the last template used for the any report in this collection.
|
||||
@ -253,6 +331,10 @@ class OptionListCollection(_Options.OptionListCollection):
|
||||
f.write(' <format name="%s"/>\n' % escxml(self.get_last_format_name()) )
|
||||
if self.get_last_orientation() != self.default_orientation:
|
||||
f.write(' <orientation value="%d"/>\n' % self.get_last_orientation() )
|
||||
if self.get_last_margins() != self.default_margins:
|
||||
margins = self.get_last_margins()
|
||||
for pos in range(len(margins)):
|
||||
f.write(' <margin number="%s" value="%f"/>\n' % (pos, margins[pos]))
|
||||
f.write('</last-common>\n')
|
||||
|
||||
def write_module_common(self,f,option_list):
|
||||
@ -271,6 +353,11 @@ class OptionListCollection(_Options.OptionListCollection):
|
||||
if option_list.get_orientation() \
|
||||
and option_list.get_orientation() != self.default_orientation:
|
||||
f.write(' <orientation value="%d"/>\n' % option_list.get_orientation() )
|
||||
if option_list.get_margins() \
|
||||
and option_list.get_margins() != self.default_margins:
|
||||
margins = option_list.get_margins()
|
||||
for pos in range(len(margins)):
|
||||
f.write(' <margin number="%s" value="%f"/>\n' % (pos, margins[pos]))
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
@ -335,6 +422,12 @@ class OptionParser(_Options.OptionParser):
|
||||
self.collection.set_last_orientation(int(attrs['value']))
|
||||
else:
|
||||
self.option_list.set_orientation(int(attrs['value']))
|
||||
elif tag == "margin":
|
||||
pos, value = int(attrs['number']), float(attrs['value'])
|
||||
if self.common:
|
||||
self.collection.set_last_margin(pos, value)
|
||||
else:
|
||||
self.option_list.set_margin(pos, value)
|
||||
else:
|
||||
# Tag is not report-specific, so we let the base class handle it.
|
||||
_Options.OptionParser.startElement(self,tag,attrs)
|
||||
@ -378,6 +471,7 @@ class OptionHandler(_Options.OptionHandler):
|
||||
self.style_name = self.option_list_collection.default_style_name
|
||||
self.paper_name = self.option_list_collection.get_last_paper_name()
|
||||
self.orientation = self.option_list_collection.get_last_orientation()
|
||||
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()
|
||||
|
||||
@ -386,6 +480,8 @@ 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_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_name():
|
||||
@ -397,6 +493,7 @@ 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_margins(self.margins)
|
||||
self.saved_option_list.set_template_name(self.template_name)
|
||||
self.saved_option_list.set_paper_name(self.paper_name)
|
||||
self.saved_option_list.set_format_name(self.format_name)
|
||||
@ -405,6 +502,7 @@ 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_margins(self.margins)
|
||||
self.option_list_collection.set_last_template_name(self.template_name)
|
||||
self.option_list_collection.set_last_paper_name(self.paper_name)
|
||||
self.option_list_collection.set_last_format_name(self.format_name)
|
||||
@ -455,6 +553,12 @@ class OptionHandler(_Options.OptionHandler):
|
||||
def set_orientation(self,orientation):
|
||||
self.orientation = orientation
|
||||
|
||||
def get_margins(self):
|
||||
return copy.copy(self.margins)
|
||||
|
||||
def set_margins(self,margins):
|
||||
self.margins = copy.copy(margins)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Base Options class
|
||||
|
Loading…
Reference in New Issue
Block a user