part 2 basedoc: move BaseDoc.py to /gen/plug/docgen and add /gen/plug/docbackend

that was missing in part 1 
 Still to come: makefiles and splitting new basedoc.py in small files


svn: r12591
This commit is contained in:
Benny Malengier
2009-05-29 22:25:44 +00:00
parent f999ba9cc4
commit 8dd7adc607
54 changed files with 1384 additions and 594 deletions

View File

@@ -42,7 +42,8 @@ log = logging.getLogger(".")
#-------------------------------------------------------------------------
import gen
import Utils
import BaseDoc
from gen.plug.docgen import StyleSheet, StyleSheetList, PaperStyle
from gen.plug.docgen.basedoc import (PAPER_PORTRAIT, PAPER_LANDSCAPE)
from BasicUtils import name_displayer
from ReportBase import CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, \
CATEGORY_GRAPHVIZ
@@ -185,19 +186,19 @@ class CommandLineReport(object):
if paper.get_name() != _("Custom Size") ]
self.options_help['papero'][2] = [
"%d\tPortrait" % BaseDoc.PAPER_PORTRAIT,
"%d\tLandscape" % BaseDoc.PAPER_LANDSCAPE ]
"%d\tPortrait" % PAPER_PORTRAIT,
"%d\tLandscape" % PAPER_LANDSCAPE ]
self.options_help['template'][2] = os.path.join(const.USER_HOME,
"whatever_name")
if self.category in (CATEGORY_TEXT, CATEGORY_DRAW):
default_style = BaseDoc.StyleSheet()
default_style = StyleSheet()
self.option_class.make_default_style(default_style)
# Read all style sheets available for this item
style_file = self.option_class.handler.get_stylesheet_savefile()
self.style_list = BaseDoc.StyleSheetList(style_file, default_style)
self.style_list = StyleSheetList(style_file, default_style)
self.options_help['style'][2] = self.style_list.get_style_names()
@@ -330,12 +331,12 @@ class CommandLineReport(object):
self.template_name = self.options_dict['template']
if self.category in (CATEGORY_TEXT, CATEGORY_DRAW):
default_style = BaseDoc.StyleSheet()
default_style = StyleSheet()
self.option_class.make_default_style(default_style)
# Read all style sheets available for this item
style_file = self.option_class.handler.get_stylesheet_savefile()
self.style_list = BaseDoc.StyleSheetList(style_file,default_style)
self.style_list = StyleSheetList(style_file,default_style)
# Get the selected stylesheet
style_name = self.option_class.handler.get_default_stylesheet_name()
@@ -401,7 +402,7 @@ def cl_report(database, name, category, report_class, options_class,
CATEGORY_GRAPHVIZ]:
clr.option_class.handler.doc = clr.format(
clr.selected_style,
BaseDoc.PaperStyle(clr.paper,clr.orien),
PaperStyle(clr.paper,clr.orien),
clr.template_name)
MyReport = report_class(database, clr.option_class)
MyReport.doc.init()

View File

@@ -22,8 +22,8 @@
"""
Provide utilities for printing endnotes in text reports.
"""
import BaseDoc
from gen.plug.docgen import FontStyle, ParagraphStyle
from gen.plug.docgen.basedoc import FONT_SANS_SERIF
from gettext import gettext as _
def add_endnote_styles(style_sheet):
@@ -31,11 +31,11 @@ def add_endnote_styles(style_sheet):
Add paragraph styles to a style sheet to be used for displaying endnotes.
@param style_sheet: Style sheet
@type style_sheet: L{Basedoc.StyleSheet}
@type style_sheet: L{docgen.StyleSheet}
"""
font = BaseDoc.FontStyle()
font.set(face=BaseDoc.FONT_SANS_SERIF, size=14, italic=1)
para = BaseDoc.ParagraphStyle()
font = FontStyle()
font.set(face=FONT_SANS_SERIF, size=14, italic=1)
para = ParagraphStyle()
para.set_font(font)
para.set_header_level(2)
para.set_top_margin(0.25)
@@ -43,14 +43,14 @@ def add_endnote_styles(style_sheet):
para.set_description(_('The style used for the generation header.'))
style_sheet.add_paragraph_style("Endnotes-Header", para)
para = BaseDoc.ParagraphStyle()
para = ParagraphStyle()
para.set(first_indent=-0.75, lmargin=.75)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_description(_('The basic style used for the endnotes source display.'))
style_sheet.add_paragraph_style("Endnotes-Source", para)
para = BaseDoc.ParagraphStyle()
para = ParagraphStyle()
para.set(lmargin=1.5)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
@@ -89,7 +89,7 @@ def write_endnotes(bibliography, database, doc):
@param database: The database that the sources come from.
@type database: GrampsDbBase
@param doc: The document to write the endnotes into.
@type doc: L{BaseDoc.TextDoc}
@type doc: L{docgen.TextDoc}
"""
if bibliography.get_citation_count() == 0:
return

View File

@@ -47,7 +47,7 @@ import gobject
#
#-------------------------------------------------------------------------------
import Utils
import BaseDoc
from gen.plug.docgen import BaseDoc, GVDoc
import Config
from ReportBase import CATEGORY_GRAPHVIZ
from _ReportDialog import ReportDialog
@@ -143,14 +143,14 @@ def _run_long_process_in_thread(func, header):
# GVDocBase
#
#-------------------------------------------------------------------------------
class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
class GVDocBase(BaseDoc, GVDoc):
"""
Base document generator for all Graphiz document generators. Classes that
inherit from this class will only need to implement the close function.
The close function will generate the actual file of the appropriate type.
"""
def __init__(self, options, paper_style):
BaseDoc.BaseDoc.__init__(self, None, paper_style, None)
BaseDoc.__init__(self, None, paper_style, None)
self._filename = None
self._dot = StringIO()
@@ -231,7 +231,7 @@ class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
self._dot.write(text.encode('utf8', 'xmlcharrefreplace'))
def open(self, filename):
""" Implement BaseDoc.BaseDoc.open() """
""" Implement BaseDoc.open() """
self._filename = os.path.normpath(os.path.abspath(filename))
def close(self):
@@ -264,7 +264,7 @@ class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
Add a node to this graph. Nodes can be different shapes like boxes and
circles.
Implements BaseDoc.GVDoc.add_node().
Implements GVDoc.add_node().
"""
text = '['
@@ -298,7 +298,7 @@ class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
"""
Add a link between two nodes.
Implementes BaseDoc.GVDoc.add_link().
Implementes GVDoc.add_link().
"""
self.write(' %s -> %s' % (id1, id2))
@@ -325,7 +325,7 @@ class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
"""
Add a comment.
Implementes BaseDoc.GVDoc.add_comment().
Implementes GVDoc.add_comment().
"""
tmp = comment.split('\n')
for line in tmp:
@@ -338,13 +338,13 @@ class GVDocBase(BaseDoc.BaseDoc, BaseDoc.GVDoc):
self.write('# %s\n' % text)
def start_subgraph(self, graph_id):
""" Implement BaseDoc.GVDoc.start_subgraph() """
""" Implement GVDoc.start_subgraph() """
self.write(' subgraph cluster_%s\n' % graph_id)
self.write(' {\n')
self.write(' style="invis";\n') # no border around subgraph (#0002176)
def end_subgraph(self):
""" Implement BaseDoc.GVDoc.end_subgraph() """
""" Implement GVDoc.end_subgraph() """
self.write(' }\n')
#-------------------------------------------------------------------------------

View File

@@ -40,7 +40,8 @@ import gobject
# GRAMPS modules
#
#-------------------------------------------------------------------------
import BaseDoc
from gen.plug.docgen import PaperStyle, PaperSize
from gen.plug.docgen.basedoc import (PAPER_PORTRAIT, PAPER_LANDSCAPE)
import const
import Utils
from glade import Glade
@@ -104,7 +105,7 @@ class PaperComboBox(gtk.ComboBox):
#-------------------------------------------------------------------------
class OrientationComboBox(gtk.ComboBox):
def __init__(self,default=BaseDoc.PAPER_PORTRAIT):
def __init__(self,default=PAPER_PORTRAIT):
gtk.ComboBox.__init__(self)
self.store = gtk.ListStore(gobject.TYPE_STRING)
@@ -116,13 +117,13 @@ class OrientationComboBox(gtk.ComboBox):
self.store.append(row=[_('Portrait')])
self.store.append(row=[_('Landscape')])
if default == BaseDoc.PAPER_PORTRAIT:
if default == PAPER_PORTRAIT:
self.set_active(0)
else:
self.set_active(1)
def set_value(self,value=0):
if value == BaseDoc.PAPER_PORTRAIT:
if value == PAPER_PORTRAIT:
self.set_active(0)
else:
self.set_active(1)
@@ -132,9 +133,9 @@ class OrientationComboBox(gtk.ComboBox):
if active < 0:
return None
if active == 0:
return BaseDoc.PAPER_PORTRAIT
return PAPER_PORTRAIT
else:
return BaseDoc.PAPER_LANDSCAPE
return PAPER_LANDSCAPE
#-------------------------------------------------------------------------
#
@@ -308,7 +309,7 @@ class PaperFrame(gtk.HBox):
paper_orientation = self.orientation_menu.get_value()
paper_margins = self.get_paper_margins()
pstyle = BaseDoc.PaperStyle(paper_size,
pstyle = PaperStyle(paper_size,
paper_orientation,
*paper_margins)
return pstyle
@@ -343,7 +344,7 @@ class PageSizeParser(handler.ContentHandler):
name = attrs['name']
height = Utils.gfloat(attrs['height'])
width = Utils.gfloat(attrs['width'])
self.paper_list.append(BaseDoc.PaperSize(name, height,width))
self.paper_list.append(PaperSize(name, height,width))
#-------------------------------------------------------------------------
#
@@ -356,27 +357,27 @@ try:
the_file = open(const.PAPERSIZE)
parser.parse(the_file)
the_file.close()
paper_sizes.append(BaseDoc.PaperSize(_("Custom Size"),-1,-1))
paper_sizes.append(PaperSize(_("Custom Size"),-1,-1))
except (IOError,OSError,SAXParseException):
paper_sizes = [
BaseDoc.PaperSize("Letter",27.94,21.59),
BaseDoc.PaperSize("Legal",35.56,21.59),
BaseDoc.PaperSize("A0",118.9,84.1),
BaseDoc.PaperSize("A1",84.1,59.4),
BaseDoc.PaperSize("A2",59.4,42.0),
BaseDoc.PaperSize("A3",42.0,29.7),
BaseDoc.PaperSize("A4",29.7,21.0),
BaseDoc.PaperSize("A5",21.0,14.8),
BaseDoc.PaperSize("B0",141.4,100.0),
BaseDoc.PaperSize("B1",100.0,70.7),
BaseDoc.PaperSize("B2",70.7,50.0),
BaseDoc.PaperSize("B3",50.0,35.3),
BaseDoc.PaperSize("B4",35.3,25.0),
BaseDoc.PaperSize("B5",25.0,17.6),
BaseDoc.PaperSize("B6",17.6,12.5),
BaseDoc.PaperSize("B",43.18,27.94),
BaseDoc.PaperSize("C",55.88,43.18),
BaseDoc.PaperSize("D",86.36, 55.88),
BaseDoc.PaperSize("E",111.76,86.36),
BaseDoc.PaperSize(_("Custom Size"),-1,-1)
PaperSize("Letter",27.94,21.59),
PaperSize("Legal",35.56,21.59),
PaperSize("A0",118.9,84.1),
PaperSize("A1",84.1,59.4),
PaperSize("A2",59.4,42.0),
PaperSize("A3",42.0,29.7),
PaperSize("A4",29.7,21.0),
PaperSize("A5",21.0,14.8),
PaperSize("B0",141.4,100.0),
PaperSize("B1",100.0,70.7),
PaperSize("B2",70.7,50.0),
PaperSize("B3",50.0,35.3),
PaperSize("B4",35.3,25.0),
PaperSize("B5",25.0,17.6),
PaperSize("B6",17.6,12.5),
PaperSize("B",43.18,27.94),
PaperSize("C",55.88,43.18),
PaperSize("D",86.36, 55.88),
PaperSize("E",111.76,86.36),
PaperSize(_("Custom Size"),-1,-1)
]

View File

@@ -51,7 +51,7 @@ from QuestionDialog import ErrorDialog, OptionDialog
from ReportBase import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK,
CATEGORY_CODE, CATEGORY_WEB, CATEGORY_GRAPHVIZ,
standalone_categories)
import BaseDoc
from gen.plug.docgen import StyleSheet, StyleSheetList
import ManagedWindow
from _StyleComboBox import StyleComboBox
from _StyleEditor import StyleListDisplay
@@ -291,7 +291,7 @@ class ReportDialog(ManagedWindow.ManagedWindow):
the builds a menu of all the available styles for the user to
choose from."""
# Build the default style set for this report.
self.default_style = BaseDoc.StyleSheet()
self.default_style = StyleSheet()
self.options.make_default_style(self.default_style)
if self.default_style.is_empty():
@@ -316,7 +316,7 @@ class ReportDialog(ManagedWindow.ManagedWindow):
# Build the initial list of available styles sets. This
# includes the default style set and any style sets saved from
# previous invocations of gramps.
self.style_sheet_list = BaseDoc.StyleSheetList(
self.style_sheet_list = StyleSheetList(
self.options.handler.get_stylesheet_savefile(),
self.default_style)

View File

@@ -55,7 +55,7 @@ except:
#-------------------------------------------------------------------------
import const
import Config
import BaseDoc
from gen.plug.docgen.basedoc import PAPER_PORTRAIT
from PluginUtils import _Options, GuiMenuOptions
#-------------------------------------------------------------------------
@@ -131,7 +131,7 @@ class OptionList(_Options.OptionList):
"""
Set the orientation for the OptionList.
@param orientation: orientation to set. Possible values are
BaseDoc.PAPER_LANDSCAPE or BaseDoc.PAPER_PORTRAIT
PAPER_LANDSCAPE or PAPER_PORTRAIT
@type orientation: int
"""
self.orientation = orientation
@@ -140,7 +140,7 @@ class OptionList(_Options.OptionList):
"""
Return the orientation for the OptionList.
@returns: returns the selected orientation. Valid values are
BaseDoc.PAPER_LANDSCAPE or BaseDoc.PAPER_PORTRAIT
PAPER_LANDSCAPE or PAPER_PORTRAIT
@rtype: int
"""
return self.orientation
@@ -247,7 +247,7 @@ class OptionListCollection(_Options.OptionListCollection):
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_orientation = 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'

View File

@@ -50,7 +50,8 @@ from gen.lib.person import Person
from BasicUtils import name_displayer as _nd
from Utils import media_path_full
from QuestionDialog import WarningDialog
import BaseDoc
from gen.plug.docgen import IndexMark
from gen.plug.docgen.basedoc import INDEX_TYPE_ALP
#------------------------------------------------------------------------
#
@@ -3101,7 +3102,7 @@ def get_person_mark(db, person):
else:
key = "%s (%s - %s)" % (name, birth, death)
return BaseDoc.IndexMark( key, BaseDoc.INDEX_TYPE_ALP )
return IndexMark( key, INDEX_TYPE_ALP )
#-------------------------------------------------------------------------
#

View File

@@ -50,7 +50,10 @@ from gtk.gdk import Color
#------------------------------------------------------------------------
import Utils
import const
import BaseDoc
from gen.plug.docgen import StyleSheet
from gen.plug.docgen.basedoc import (FONT_SERIF, FONT_SANS_SERIF,
PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
PARA_ALIGN_JUSTIFY)
import ListModel
import ManagedWindow
from glade import Glade
@@ -189,7 +192,7 @@ class StyleEditor(object):
self.current_p = None
self.current_name = None
self.style = BaseDoc.StyleSheet(style)
self.style = StyleSheet(style)
self.parent = parent
self.top = Glade(toplevel='editor')
self.window = self.top.toplevel
@@ -242,18 +245,18 @@ class StyleEditor(object):
font = p.get_font()
self.top.get_object("size").set_value(font.get_size())
if font.get_type_face() == BaseDoc.FONT_SERIF:
if font.get_type_face() == FONT_SERIF:
self.top.get_object("roman").set_active(1)
else:
self.top.get_object("swiss").set_active(1)
self.top.get_object("bold").set_active(font.get_bold())
self.top.get_object("italic").set_active(font.get_italic())
self.top.get_object("underline").set_active(font.get_underline())
if p.get_alignment() == BaseDoc.PARA_ALIGN_LEFT:
if p.get_alignment() == PARA_ALIGN_LEFT:
self.top.get_object("lalign").set_active(1)
elif p.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT:
elif p.get_alignment() == PARA_ALIGN_RIGHT:
self.top.get_object("ralign").set_active(1)
elif p.get_alignment() == BaseDoc.PARA_ALIGN_CENTER:
elif p.get_alignment() == PARA_ALIGN_CENTER:
self.top.get_object("calign").set_active(1)
else:
self.top.get_object("jalign").set_active(1)
@@ -303,21 +306,21 @@ class StyleEditor(object):
font.set_size(self.top.get_object("size").get_value_as_int())
if self.top.get_object("roman").get_active():
font.set_type_face(BaseDoc.FONT_SERIF)
font.set_type_face(FONT_SERIF)
else:
font.set_type_face(BaseDoc.FONT_SANS_SERIF)
font.set_type_face(FONT_SANS_SERIF)
font.set_bold(self.top.get_object("bold").get_active())
font.set_italic(self.top.get_object("italic").get_active())
font.set_underline(self.top.get_object("underline").get_active())
if self.top.get_object("lalign").get_active():
p.set_alignment(BaseDoc.PARA_ALIGN_LEFT)
p.set_alignment(PARA_ALIGN_LEFT)
elif self.top.get_object("ralign").get_active():
p.set_alignment(BaseDoc.PARA_ALIGN_RIGHT)
p.set_alignment(PARA_ALIGN_RIGHT)
elif self.top.get_object("calign").get_active():
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_alignment(PARA_ALIGN_CENTER)
else:
p.set_alignment(BaseDoc.PARA_ALIGN_JUSTIFY)
p.set_alignment(PARA_ALIGN_JUSTIFY)
p.set_right_margin(self.top.get_object("rmargin").get_value())
p.set_left_margin(self.top.get_object("lmargin").get_value())