2003-06-02 19:04:18 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-07-01 00:28:14 +05:30
|
|
|
# Copyright (C) 2003-2007 Donald N. Allingham
|
2008-01-06 02:12:05 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2003-06-02 19:04:18 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-10-20 08:17:03 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-06-12 04:03:01 +05:30
|
|
|
# Written by Alex Roitman,
|
2003-08-26 09:37:00 +05:30
|
|
|
# largely based on the BaseDoc classes by Don Allingham
|
2003-06-12 04:03:01 +05:30
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".BookReport")
|
2009-05-15 01:45:59 +05:30
|
|
|
import os
|
2006-03-05 10:01:24 +05:30
|
|
|
|
2003-06-10 10:19:39 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SAX interface
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
2008-01-23 11:11:46 +05:30
|
|
|
from xml.sax import make_parser, handler, SAXParseException
|
2008-04-20 08:33:39 +05:30
|
|
|
from xml.sax.saxutils import escape
|
2003-06-10 10:19:39 +05:30
|
|
|
except:
|
2008-01-23 11:11:46 +05:30
|
|
|
from _xmlplus.sax import make_parser, handler, SAXParseException
|
2008-04-20 08:33:39 +05:30
|
|
|
from _xmlplus.sax.saxutils import escape
|
2003-06-10 10:19:39 +05:30
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-19 01:37:09 +05:30
|
|
|
import gtk
|
2009-03-19 07:54:29 +05:30
|
|
|
import gobject
|
2003-06-02 19:04:18 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-30 10:45:54 +05:30
|
|
|
import const
|
2003-06-02 19:04:18 +05:30
|
|
|
import Utils
|
|
|
|
import ListModel
|
2006-05-31 06:18:07 +05:30
|
|
|
import Errors
|
2003-08-26 09:37:00 +05:30
|
|
|
import BaseDoc
|
2006-05-02 02:41:26 +05:30
|
|
|
from QuestionDialog import WarningDialog, ErrorDialog
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import PersonOption, FilterOption, FamilyOption
|
2006-06-01 00:56:34 +05:30
|
|
|
import ManagedWindow
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2006-06-01 00:56:34 +05:30
|
|
|
|
|
|
|
# Import from specific modules in ReportBase
|
2008-10-02 09:32:10 +05:30
|
|
|
from ReportBase import CATEGORY_BOOK, book_categories
|
2008-02-10 09:39:09 +05:30
|
|
|
from ReportBase._ReportDialog import ReportDialog
|
2007-12-13 07:22:03 +05:30
|
|
|
from ReportBase._DocReportDialog import DocReportDialog
|
2006-06-01 00:56:34 +05:30
|
|
|
from ReportBase._CommandLineReport import CommandLineReport
|
|
|
|
from ReportBase._ReportOptions import ReportOptions
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
from BasicUtils import name_displayer as _nd
|
|
|
|
|
2008-05-19 09:44:11 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Private Constants
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
_UNSUPPORTED = _("Unsupported")
|
|
|
|
|
2008-01-06 02:12:05 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Private Functions
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-01-23 11:11:46 +05:30
|
|
|
def _initialize_options(options, dbstate):
|
|
|
|
"""
|
|
|
|
Validates all options by making sure that their values are consistent with
|
|
|
|
the database.
|
|
|
|
|
|
|
|
menu: The Menu class
|
|
|
|
dbase: the database the options will be applied to
|
|
|
|
"""
|
|
|
|
dbase = dbstate.get_database()
|
|
|
|
if not hasattr(options, "menu"):
|
|
|
|
return
|
|
|
|
menu = options.menu
|
|
|
|
|
|
|
|
for name in menu.get_all_option_names():
|
|
|
|
option = menu.get_option_by_name(name)
|
|
|
|
|
|
|
|
if isinstance(option, PersonOption):
|
|
|
|
person = dbstate.get_active_person()
|
|
|
|
option.set_value(person.get_gramps_id())
|
|
|
|
|
|
|
|
elif isinstance(option, FamilyOption):
|
|
|
|
person = dbstate.get_active_person()
|
|
|
|
family_list = person.get_family_handle_list()
|
|
|
|
if family_list:
|
|
|
|
family_handle = family_list[0]
|
|
|
|
else:
|
|
|
|
family_handle = dbase.get_family_handles()[0]
|
|
|
|
family = dbase.get_family_from_handle(family_handle)
|
|
|
|
option.set_value(family.get_gramps_id())
|
|
|
|
|
|
|
|
def _get_subject(options, dbase):
|
2008-01-06 02:12:05 +05:30
|
|
|
"""
|
|
|
|
Attempts to determine the subject of a set of options. The subject would
|
|
|
|
likely be a person (using a PersonOption) or a filter (using a
|
2008-01-23 11:11:46 +05:30
|
|
|
FilterOption)
|
2008-01-06 02:12:05 +05:30
|
|
|
|
|
|
|
options: The ReportOptions class
|
2008-01-23 11:11:46 +05:30
|
|
|
dbase: the database for which it corresponds
|
2008-01-06 02:12:05 +05:30
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
if not hasattr(options, "menu"):
|
2008-01-06 02:12:05 +05:30
|
|
|
return _("Not Applicable")
|
|
|
|
menu = options.menu
|
2008-01-23 11:11:46 +05:30
|
|
|
|
2008-01-06 02:12:05 +05:30
|
|
|
option_names = menu.get_all_option_names()
|
2008-01-23 11:11:46 +05:30
|
|
|
|
2008-01-06 02:12:05 +05:30
|
|
|
for name in option_names:
|
|
|
|
option = menu.get_option_by_name(name)
|
2008-01-23 11:11:46 +05:30
|
|
|
|
|
|
|
if isinstance(option, FilterOption):
|
2008-01-18 11:09:50 +05:30
|
|
|
return option.get_filter().get_name()
|
2008-01-23 11:11:46 +05:30
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
elif isinstance(option, PersonOption):
|
2008-01-06 02:12:05 +05:30
|
|
|
gid = option.get_value()
|
2008-01-23 11:11:46 +05:30
|
|
|
person = dbase.get_person_from_gramps_id(gid)
|
2008-01-06 02:12:05 +05:30
|
|
|
return _nd.display(person)
|
2008-01-23 11:11:46 +05:30
|
|
|
|
|
|
|
elif isinstance(option, FamilyOption):
|
|
|
|
family = dbase.get_family_from_gramps_id(option.get_value())
|
|
|
|
family_id = family.get_gramps_id()
|
|
|
|
fhandle = family.get_father_handle()
|
|
|
|
mhandle = family.get_mother_handle()
|
|
|
|
|
|
|
|
if fhandle:
|
|
|
|
father = dbase.get_person_from_handle(fhandle)
|
|
|
|
father_name = _nd.display(father)
|
|
|
|
else:
|
|
|
|
father_name = _("unknown father")
|
|
|
|
|
|
|
|
if mhandle:
|
|
|
|
mother = dbase.get_person_from_handle(mhandle)
|
|
|
|
mother_name = _nd.display(mother)
|
|
|
|
else:
|
|
|
|
mother_name = _("unknown mother")
|
|
|
|
|
|
|
|
name = _("%s and %s (%s)") % (father_name, mother_name, family_id)
|
|
|
|
return name
|
|
|
|
|
2008-01-06 02:12:05 +05:30
|
|
|
return _("Not Applicable")
|
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Book Item class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class BookItem(object):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
Interface into the book item -- a smallest element of the book.
|
|
|
|
"""
|
|
|
|
|
2008-04-22 07:41:47 +05:30
|
|
|
def __init__(self, dbase, name):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new empty BookItem.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
2008-04-22 07:41:47 +05:30
|
|
|
name: the book item is retreived
|
2003-06-16 21:59:35 +05:30
|
|
|
from the book item registry using name for lookup
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
self.dbase = dbase
|
2003-06-11 10:09:53 +05:30
|
|
|
self.style_name = "default"
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
|
|
|
|
for item in pmgr.get_book_item_list():
|
2005-01-14 10:32:20 +05:30
|
|
|
if item[4] == name:
|
|
|
|
self.translated_name = item[0]
|
2005-12-06 12:08:09 +05:30
|
|
|
if item[5]:
|
2008-05-19 09:44:11 +05:30
|
|
|
self.category = _UNSUPPORTED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2008-10-02 09:32:10 +05:30
|
|
|
self.category = book_categories[item[1]]
|
2004-12-22 07:26:37 +05:30
|
|
|
self.write_item = item[2]
|
2005-01-14 10:32:20 +05:30
|
|
|
self.name = item[4]
|
2008-01-24 18:20:33 +05:30
|
|
|
self.option_class = item[3](self.name, self.dbase)
|
2007-12-13 07:22:03 +05:30
|
|
|
self.option_class.load_previous_values()
|
2003-06-11 10:09:53 +05:30
|
|
|
|
|
|
|
def get_name(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the name of the item.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.name
|
|
|
|
|
2005-01-14 10:32:20 +05:30
|
|
|
def get_translated_name(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the translated name of the item.
|
2005-01-14 10:32:20 +05:30
|
|
|
"""
|
|
|
|
return self.translated_name
|
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
def get_category(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the category of the item.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.category
|
|
|
|
|
|
|
|
def get_write_item(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the report-writing function of the item.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.write_item
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def set_style_name(self, style_name):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the style name for the item.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
style_name: name of the style to set.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.style_name = style_name
|
|
|
|
|
|
|
|
def get_style_name(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the style name of the item.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.style_name
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Book class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class Book(object):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2003-06-16 21:59:35 +05:30
|
|
|
Interface into the user-defined book -- a collection of book items.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def __init__(self, obj=None):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new empty Book.
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
obj: if not None, creates the Book from the values in
|
|
|
|
obj, instead of creating an empty Book.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
self.name = ""
|
|
|
|
self.dbname = ""
|
|
|
|
if obj:
|
|
|
|
self.item_list = obj.item_list
|
|
|
|
else:
|
|
|
|
self.item_list = []
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def set_name(self, name):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the name of the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
name: the name to set.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def get_name(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the name of the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_dbname(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the name of the database file used for the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.dbname
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def set_dbname(self, name):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set the name of the database file used for the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
name: a filename to set.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.dbname = name
|
|
|
|
|
|
|
|
def clear(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Clears the contents of the book.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.item_list = []
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def append_item(self, item):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Add an item to the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
item: an item to append.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.item_list.append(item)
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def insert_item(self, index, item):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Inserts an item into the given position in the book.
|
|
|
|
|
|
|
|
index: a position index.
|
|
|
|
item: an item to append.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
self.item_list.insert(index, item)
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def pop_item(self, index):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Pop an item from given position in the book.
|
|
|
|
|
|
|
|
index: a position index.
|
|
|
|
"""
|
2003-06-12 04:03:01 +05:30
|
|
|
return self.item_list.pop(index)
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def get_item(self, index):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return an item at a given position in the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
index: a position index.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.item_list[index]
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def set_item(self, index, item):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Set an item at a given position in the book.
|
2003-06-16 21:59:35 +05:30
|
|
|
|
|
|
|
index: a position index.
|
|
|
|
item: an item to set.
|
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
self.item_list[index] = item
|
|
|
|
|
|
|
|
def get_item_list(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return list of items in the current book.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.item_list
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# BookList class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class BookList(object):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2003-06-16 21:59:35 +05:30
|
|
|
Interface into the user-defined list of books.
|
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
BookList is loaded from a specified XML file if it exists.
|
|
|
|
"""
|
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, filename, dbase):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new BookList from the books that may be defined in the
|
2003-06-11 10:09:53 +05:30
|
|
|
specified file.
|
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
file: XML file that contains book items definitions
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
self.dbase = dbase
|
2003-06-11 10:09:53 +05:30
|
|
|
self.bookmap = {}
|
2008-01-23 11:11:46 +05:30
|
|
|
self.file = os.path.join(const.HOME_DIR, filename)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.parse()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def delete_book(self, name):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove a book from the list. Since each book must have a
|
2003-06-11 10:09:53 +05:30
|
|
|
unique name, the name is used to delete the book.
|
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
name: name of the book to delete
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
del self.bookmap[name]
|
|
|
|
|
|
|
|
def get_book_map(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the map of names to books.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
return self.bookmap
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def get_book(self, name):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the Book associated with the name
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
name: name associated with the desired Book.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
return self.bookmap[name]
|
|
|
|
|
|
|
|
def get_book_names(self):
|
2008-02-24 19:25:55 +05:30
|
|
|
"Return a list of all the book names in the BookList"
|
2003-06-11 10:09:53 +05:30
|
|
|
return self.bookmap.keys()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def set_book(self, name, book):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Add or replaces a Book in the BookList.
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
name: name assocated with the Book to add or replace.
|
|
|
|
book: definition of the Book
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
self.bookmap[name] = book
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
"""
|
|
|
|
Saves the current BookList to the associated file.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
f = open(self.file, "w")
|
2003-09-05 10:08:43 +05:30
|
|
|
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
2003-06-11 10:09:53 +05:30
|
|
|
f.write('<booklist>\n')
|
2009-05-27 02:18:09 +05:30
|
|
|
for name in self.bookmap:
|
2003-06-11 10:09:53 +05:30
|
|
|
book = self.get_book(name)
|
|
|
|
dbname = book.get_dbname()
|
2008-01-23 11:11:46 +05:30
|
|
|
f.write('<book name="%s" database="%s">\n' % (name, dbname) )
|
2003-06-11 10:09:53 +05:30
|
|
|
for item in book.get_item_list():
|
2005-01-14 10:32:20 +05:30
|
|
|
f.write(' <item name="%s" trans_name="%s">\n' %
|
|
|
|
(item.get_name(),item.get_translated_name() ) )
|
2008-04-20 08:33:39 +05:30
|
|
|
options = item.option_class.handler.options_dict
|
2009-05-27 02:18:09 +05:30
|
|
|
for option_name, option_value in options.iteritems():
|
2008-05-26 01:25:47 +05:30
|
|
|
if isinstance(option_value, (list, tuple)):
|
2008-04-20 08:33:39 +05:30
|
|
|
f.write(' <option name="%s" value="" '
|
|
|
|
'length="%d">\n' % (
|
|
|
|
escape(option_name),
|
|
|
|
len(options[option_name]) ) )
|
2009-05-27 02:18:09 +05:30
|
|
|
for list_index in range(len(option_value)):
|
2008-04-20 08:33:39 +05:30
|
|
|
option_type = \
|
|
|
|
Utils.type_name(option_value[list_index])
|
|
|
|
value = escape(unicode(option_value[list_index]))
|
|
|
|
value = value.replace('"', '"')
|
|
|
|
f.write(' <listitem number="%d" type="%s" '
|
|
|
|
'value="%s"/>\n' % (
|
|
|
|
list_index,
|
|
|
|
option_type,
|
|
|
|
value ) )
|
|
|
|
f.write(' </option>\n')
|
2003-09-02 08:29:19 +05:30
|
|
|
else:
|
2004-12-22 07:26:37 +05:30
|
|
|
option_type = Utils.type_name(option_value)
|
2008-04-20 08:33:39 +05:30
|
|
|
value = escape(unicode(option_value))
|
|
|
|
value = value.replace('"', '"')
|
|
|
|
f.write(' <option name="%s" type="%s" '
|
|
|
|
'value="%s"/>\n' % (
|
|
|
|
escape(option_name),
|
|
|
|
option_type,
|
|
|
|
value) )
|
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
f.write(' <style name="%s"/>\n' % item.get_style_name() )
|
|
|
|
f.write(' </item>\n')
|
|
|
|
f.write('</book>\n')
|
|
|
|
|
|
|
|
f.write('</booklist>\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
"""
|
|
|
|
Loads the BookList from the associated file, if it exists.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
p = make_parser()
|
2008-01-24 18:20:33 +05:30
|
|
|
p.setContentHandler(BookParser(self, self.dbase))
|
2007-07-01 00:28:14 +05:30
|
|
|
the_file = open(self.file)
|
|
|
|
p.parse(the_file)
|
|
|
|
the_file.close()
|
2008-04-06 10:29:18 +05:30
|
|
|
except (IOError, OSError, ValueError, SAXParseException, KeyError, \
|
|
|
|
AttributeError):
|
2003-06-11 10:09:53 +05:30
|
|
|
pass
|
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# BookParser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class BookParser(handler.ContentHandler):
|
|
|
|
"""
|
|
|
|
SAX parsing class for the Books XML file.
|
|
|
|
"""
|
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, booklist, dbase):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a BookParser class that populates the passed booklist.
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
booklist: BookList to be loaded from the file.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
handler.ContentHandler.__init__(self)
|
2008-01-24 18:20:33 +05:30
|
|
|
self.dbase = dbase
|
2003-06-11 10:09:53 +05:30
|
|
|
self.booklist = booklist
|
|
|
|
self.b = None
|
|
|
|
self.i = None
|
|
|
|
self.o = None
|
2004-12-22 07:26:37 +05:30
|
|
|
self.an_o_name = None
|
|
|
|
self.an_o_value = None
|
2003-06-11 10:09:53 +05:30
|
|
|
self.s = None
|
|
|
|
self.bname = None
|
|
|
|
self.iname = None
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def startElement(self, tag, attrs):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
Overridden class that handles the start of a XML element
|
|
|
|
"""
|
|
|
|
if tag == "book":
|
|
|
|
self.b = Book()
|
|
|
|
self.bname = attrs['name']
|
|
|
|
self.b.set_name(self.bname)
|
|
|
|
self.dbname = attrs['database']
|
|
|
|
self.b.set_dbname(self.dbname)
|
|
|
|
elif tag == "item":
|
2008-01-24 18:20:33 +05:30
|
|
|
self.i = BookItem(self.dbase, attrs['name'])
|
2004-12-22 07:26:37 +05:30
|
|
|
self.o = {}
|
2003-06-11 10:09:53 +05:30
|
|
|
elif tag == "option":
|
2004-12-22 07:26:37 +05:30
|
|
|
self.an_o_name = attrs['name']
|
2008-07-18 21:40:27 +05:30
|
|
|
if attrs.has_key('length'):
|
2004-12-22 07:26:37 +05:30
|
|
|
self.an_o_value = []
|
2003-09-02 08:29:19 +05:30
|
|
|
else:
|
2004-12-22 07:26:37 +05:30
|
|
|
converter = Utils.get_type_converter_by_name(attrs['type'])
|
|
|
|
self.an_o_value = converter(attrs['value'])
|
2003-09-02 08:29:19 +05:30
|
|
|
elif tag == "listitem":
|
2004-12-22 07:26:37 +05:30
|
|
|
converter = Utils.get_type_converter_by_name(attrs['type'])
|
|
|
|
self.an_o_value.append(converter(attrs['value']))
|
2003-06-11 10:09:53 +05:30
|
|
|
elif tag == "style":
|
|
|
|
self.s = attrs['name']
|
2008-02-20 10:22:10 +05:30
|
|
|
else:
|
|
|
|
pass
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def endElement(self, tag):
|
2003-06-16 21:59:35 +05:30
|
|
|
"Overridden class that handles the end of a XML element"
|
2003-09-02 08:29:19 +05:30
|
|
|
if tag == "option":
|
2004-12-22 07:26:37 +05:30
|
|
|
self.o[self.an_o_name] = self.an_o_value
|
2003-09-02 08:29:19 +05:30
|
|
|
elif tag == "item":
|
2004-12-22 07:26:37 +05:30
|
|
|
self.i.option_class.handler.options_dict.update(self.o)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.i.set_style_name(self.s)
|
|
|
|
self.b.append_item(self.i)
|
|
|
|
elif tag == "book":
|
2008-01-23 11:11:46 +05:30
|
|
|
self.booklist.set_book(self.bname, self.b)
|
2003-06-11 10:09:53 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# BookList Display class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class BookListDisplay(object):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2003-06-16 21:59:35 +05:30
|
|
|
Interface into a dialog with the list of available books.
|
|
|
|
|
|
|
|
Allows the user to select and/or delete a book from the list.
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def __init__(self, booklist, nodelete=0, dosave=0):
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a BookListDisplay object that displays the books in BookList.
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2003-06-16 21:59:35 +05:30
|
|
|
booklist: books that are displayed
|
|
|
|
nodelete: if not 0 then the Delete button is hidden
|
2004-12-22 07:26:37 +05:30
|
|
|
dosave: if 1 then the book list is saved on hitting OK
|
2003-06-11 10:09:53 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
self.booklist = booklist
|
2004-12-22 07:26:37 +05:30
|
|
|
self.dosave = dosave
|
2009-05-15 01:45:59 +05:30
|
|
|
self.xml = Glade()
|
|
|
|
self.top = self.xml.toplevel
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2006-06-05 04:53:10 +05:30
|
|
|
ManagedWindow.set_titles(self.top,
|
2009-04-14 00:29:08 +05:30
|
|
|
self.xml.get_object('title'),_('Available Books'))
|
2003-06-11 10:09:53 +05:30
|
|
|
|
|
|
|
if nodelete:
|
2009-04-14 00:29:08 +05:30
|
|
|
delete_button = self.xml.get_object("delete_button")
|
2003-06-11 10:09:53 +05:30
|
|
|
delete_button.hide()
|
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
self.xml.connect_signals({
|
2003-06-11 10:09:53 +05:30
|
|
|
"on_booklist_cancel_clicked" : self.on_booklist_cancel_clicked,
|
|
|
|
"on_booklist_ok_clicked" : self.on_booklist_ok_clicked,
|
|
|
|
"on_booklist_delete_clicked" : self.on_booklist_delete_clicked
|
|
|
|
})
|
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
title_label = self.xml.get_object('title')
|
2003-06-11 10:09:53 +05:30
|
|
|
title_label.set_text(Utils.title(_('Book List')))
|
2005-02-24 05:55:34 +05:30
|
|
|
title_label.set_use_markup(True)
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
self.blist = ListModel.ListModel(self.xml.get_object("list"),
|
2003-06-11 10:09:53 +05:30
|
|
|
[('Name',-1,10)],)
|
|
|
|
self.redraw()
|
|
|
|
self.selection = None
|
|
|
|
self.top.run()
|
|
|
|
|
|
|
|
def redraw(self):
|
2003-06-12 04:03:01 +05:30
|
|
|
"""Redraws the list of currently available books"""
|
2003-06-11 10:09:53 +05:30
|
|
|
|
|
|
|
self.blist.model.clear()
|
|
|
|
names = self.booklist.get_book_names()
|
|
|
|
if not len(names):
|
|
|
|
return
|
|
|
|
for name in names:
|
2005-01-14 10:32:20 +05:30
|
|
|
the_iter = self.blist.add([name])
|
|
|
|
if the_iter:
|
|
|
|
self.blist.selection.select_iter(the_iter)
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_booklist_ok_clicked(self, obj):
|
2008-02-24 19:25:55 +05:30
|
|
|
"""Return selected book. Saves the current list into xml file."""
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.blist.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if the_iter:
|
2008-01-23 11:11:46 +05:30
|
|
|
data = self.blist.get_data(the_iter, [0])
|
2007-06-25 08:09:21 +05:30
|
|
|
self.selection = self.booklist.get_book(unicode(data[0]))
|
2004-12-22 07:26:37 +05:30
|
|
|
if self.dosave:
|
|
|
|
self.booklist.save()
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_booklist_delete_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Deletes selected book from the list.
|
|
|
|
|
|
|
|
This change is not final. OK button has to be clicked to save the list.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.blist.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if not the_iter:
|
2003-06-11 10:09:53 +05:30
|
|
|
return
|
2008-01-23 11:11:46 +05:30
|
|
|
data = self.blist.get_data(the_iter, [0])
|
2008-03-12 08:21:16 +05:30
|
|
|
self.booklist.delete_book(unicode(data[0]))
|
2005-01-14 10:32:20 +05:30
|
|
|
self.blist.remove(the_iter)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.top.run()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_booklist_cancel_clicked(self, obj):
|
2003-06-11 10:09:53 +05:30
|
|
|
pass
|
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 00:56:34 +05:30
|
|
|
class BookOptions(ReportOptions):
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
ReportOptions.__init__(self, name, dbase)
|
2004-12-23 06:27:56 +05:30
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
|
|
|
'bookname' : '',
|
|
|
|
}
|
|
|
|
self.options_help = {
|
|
|
|
'bookname' : ("=name","Name of the book. MANDATORY",
|
2008-03-03 04:33:52 +05:30
|
|
|
BookList('books.xml',dbase).get_book_names(),
|
2004-12-22 07:26:37 +05:30
|
|
|
False),
|
|
|
|
}
|
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2003-06-11 10:09:53 +05:30
|
|
|
# Book creation dialog
|
2003-06-02 19:04:18 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-06-01 00:56:34 +05:30
|
|
|
class BookReportSelector(ManagedWindow.ManagedWindow):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Interface into a dialog setting up the book.
|
|
|
|
|
|
|
|
Allows the user to add/remove/reorder/setup items for the current book
|
|
|
|
and to clear/load/save/edit whole books.
|
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, dbstate, uistate):
|
2006-06-01 00:56:34 +05:30
|
|
|
self.db = dbstate.db
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
|
|
|
self.title = _('Book Report')
|
2003-06-11 10:09:53 +05:30
|
|
|
self.file = "books.xml"
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
2006-06-01 00:56:34 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.xml = Glade(toplevel="top")
|
|
|
|
window = self.xml.toplevel
|
2009-04-14 01:31:29 +05:30
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
title_label = self.xml.get_object('title')
|
2008-01-23 11:11:46 +05:30
|
|
|
self.set_window(window, title_label, self.title)
|
2009-04-15 21:12:10 +05:30
|
|
|
window.show()
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
self.xml.connect_signals({
|
2003-06-02 19:04:18 +05:30
|
|
|
"on_add_clicked" : self.on_add_clicked,
|
|
|
|
"on_remove_clicked" : self.on_remove_clicked,
|
|
|
|
"on_up_clicked" : self.on_up_clicked,
|
|
|
|
"on_down_clicked" : self.on_down_clicked,
|
|
|
|
"on_setup_clicked" : self.on_setup_clicked,
|
|
|
|
"on_clear_clicked" : self.on_clear_clicked,
|
2003-06-09 05:37:31 +05:30
|
|
|
"on_save_clicked" : self.on_save_clicked,
|
|
|
|
"on_open_clicked" : self.on_open_clicked,
|
2003-06-11 10:09:53 +05:30
|
|
|
"on_edit_clicked" : self.on_edit_clicked,
|
2003-06-02 19:04:18 +05:30
|
|
|
"on_book_ok_clicked" : self.on_book_ok_clicked,
|
|
|
|
"destroy_passed_object" : self.close
|
|
|
|
})
|
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
self.avail_tree = self.xml.get_object("avail_tree")
|
|
|
|
self.book_tree = self.xml.get_object("book_tree")
|
2008-01-23 11:11:46 +05:30
|
|
|
self.avail_tree.connect('button-press-event', self.av_button_press)
|
|
|
|
self.book_tree.connect('button-press-event', self.bk_button_press)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
self.name_entry = self.xml.get_object("name_entry")
|
2003-07-05 23:55:25 +05:30
|
|
|
self.name_entry.set_text(_('New Book'))
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2009-04-14 00:29:08 +05:30
|
|
|
avail_label = self.xml.get_object('avail_label')
|
2003-10-02 09:16:09 +05:30
|
|
|
avail_label.set_text("<b>%s</b>" % _("_Available items"))
|
2005-02-24 05:55:34 +05:30
|
|
|
avail_label.set_use_markup(True)
|
|
|
|
avail_label.set_use_underline(True)
|
2009-04-14 00:29:08 +05:30
|
|
|
book_label = self.xml.get_object('book_label')
|
2003-10-02 09:16:09 +05:30
|
|
|
book_label.set_text("<b>%s</b>" % _("Current _book"))
|
2005-02-24 05:55:34 +05:30
|
|
|
book_label.set_use_underline(True)
|
|
|
|
book_label.set_use_markup(True)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
av_titles = [ (_('Name'), 0, 150),
|
|
|
|
(_('Type'), 1, 50 ),
|
|
|
|
( '' , -1, 0 ) ]
|
|
|
|
|
|
|
|
bk_titles = [ (_('Item name'), -1, 150),
|
|
|
|
(_('Type'), -1, 50 ),
|
|
|
|
( '', -1, 0 ),
|
|
|
|
(_('Subject'), -1, 50 ) ]
|
2004-05-07 09:57:44 +05:30
|
|
|
|
|
|
|
self.av_ncols = len(av_titles)
|
|
|
|
self.bk_ncols = len(bk_titles)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
self.av_model = ListModel.ListModel(self.avail_tree, av_titles)
|
|
|
|
self.bk_model = ListModel.ListModel(self.book_tree, bk_titles)
|
2003-06-02 19:04:18 +05:30
|
|
|
self.draw_avail_list()
|
2003-06-11 10:09:53 +05:30
|
|
|
|
|
|
|
self.book = Book()
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def build_menu_names(self, obj):
|
|
|
|
return (_("Book selection list"), self.title)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
|
|
|
def draw_avail_list(self):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Draw the list with the selections available for the book.
|
|
|
|
|
|
|
|
The selections are read from the book item registry.
|
|
|
|
"""
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
if not pmgr.get_book_item_list():
|
2003-06-08 05:08:13 +05:30
|
|
|
return
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
for book_item in pmgr.get_book_item_list():
|
2005-12-06 12:08:09 +05:30
|
|
|
if book_item[5]:
|
2008-05-19 09:44:11 +05:30
|
|
|
category = _UNSUPPORTED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
2008-10-02 09:32:10 +05:30
|
|
|
category = book_categories[book_item[1]]
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
data = [ book_item[0], category, book_item[4] ]
|
2003-06-08 05:08:13 +05:30
|
|
|
new_iter = self.av_model.add(data)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
|
|
|
self.av_model.connect_model()
|
|
|
|
|
2003-06-08 05:08:13 +05:30
|
|
|
if new_iter:
|
|
|
|
self.av_model.selection.select_iter(new_iter)
|
|
|
|
path = self.av_model.model.get_path(new_iter)
|
2003-06-02 19:04:18 +05:30
|
|
|
col = self.avail_tree.get_column(0)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.avail_tree.scroll_to_cell(path, col, 1, 1, 0.0)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def open_book(self, book):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Open the book: set the current set of selections to this book's items.
|
|
|
|
|
|
|
|
book: the book object to load.
|
|
|
|
"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if book.get_dbname() == self.db.get_save_path():
|
2003-06-12 04:03:01 +05:30
|
|
|
same_db = 1
|
|
|
|
else:
|
|
|
|
same_db = 0
|
|
|
|
WarningDialog(_('Different database'), _(
|
2006-06-01 00:56:34 +05:30
|
|
|
'This book was created with the references to database '
|
|
|
|
'%s.\n\n This makes references to the central person '
|
|
|
|
'saved in the book invalid.\n\n'
|
2003-06-12 04:03:01 +05:30
|
|
|
'Therefore, the central person for each item is being set '
|
2003-06-16 21:59:35 +05:30
|
|
|
'to the active person of the currently opened database.' )
|
2003-06-12 04:03:01 +05:30
|
|
|
% book.get_dbname() )
|
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book.clear()
|
|
|
|
self.bk_model.clear()
|
|
|
|
for saved_item in book.get_item_list():
|
|
|
|
name = saved_item.get_name()
|
2008-02-10 09:39:09 +05:30
|
|
|
item = BookItem(self.db, name)
|
2004-12-22 07:26:37 +05:30
|
|
|
item.option_class = saved_item.option_class
|
2008-01-23 11:11:46 +05:30
|
|
|
_initialize_options(item.option_class, self.dbstate)
|
2003-06-11 10:09:53 +05:30
|
|
|
item.set_style_name(saved_item.get_style_name())
|
|
|
|
self.book.append_item(item)
|
2004-05-07 09:57:44 +05:30
|
|
|
|
2006-06-01 00:56:34 +05:30
|
|
|
data = [ item.get_translated_name(),
|
|
|
|
item.get_category(), item.get_name() ]
|
2008-01-06 02:12:05 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
data[2] = _get_subject(item.option_class, self.db)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.bk_model.add(data)
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_add_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Add an item to the current selections.
|
|
|
|
|
|
|
|
Use the selected available item to get the item's name in the registry.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.av_model.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if not the_iter:
|
2003-06-02 19:04:18 +05:30
|
|
|
return
|
2008-01-23 11:11:46 +05:30
|
|
|
data = self.av_model.get_data(the_iter, range(self.av_ncols))
|
2008-01-24 18:20:33 +05:30
|
|
|
item = BookItem(self.db, data[2])
|
2008-01-23 11:11:46 +05:30
|
|
|
_initialize_options(item.option_class, self.dbstate)
|
|
|
|
data[2] = _get_subject(item.option_class, self.db)
|
2003-06-02 19:04:18 +05:30
|
|
|
self.bk_model.add(data)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book.append_item(item)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_remove_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Remove the item from the current list of selections.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.bk_model.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if not the_iter:
|
2003-06-02 19:04:18 +05:30
|
|
|
return
|
2003-06-11 10:09:53 +05:30
|
|
|
row = self.bk_model.get_selected_row()
|
|
|
|
self.book.pop_item(row)
|
2005-01-14 10:32:20 +05:30
|
|
|
self.bk_model.remove(the_iter)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_clear_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Clear the whole current book.
|
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
self.bk_model.clear()
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book.clear()
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_up_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Move the currently selected item one row up in the selection list.
|
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
row = self.bk_model.get_selected_row()
|
|
|
|
if not row or row == -1:
|
|
|
|
return
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.bk_model.get_selected()
|
|
|
|
data = self.bk_model.get_data(the_iter, range(self.bk_ncols))
|
2005-01-14 10:32:20 +05:30
|
|
|
self.bk_model.remove(the_iter)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.bk_model.insert(row-1, data, None, 1)
|
2003-06-11 10:09:53 +05:30
|
|
|
item = self.book.pop_item(row)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.book.insert_item(row-1, item)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_down_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Move the currently selected item one row down in the selection list.
|
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
row = self.bk_model.get_selected_row()
|
|
|
|
if row + 1 >= self.bk_model.count or row == -1:
|
2004-05-07 09:57:44 +05:30
|
|
|
return
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.bk_model.get_selected()
|
|
|
|
data = self.bk_model.get_data(the_iter, range(self.bk_ncols))
|
2005-01-14 10:32:20 +05:30
|
|
|
self.bk_model.remove(the_iter)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.bk_model.insert(row+1, data, None, 1)
|
2003-06-11 10:09:53 +05:30
|
|
|
item = self.book.pop_item(row)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.book.insert_item(row+1, item)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_setup_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Configure currently selected item.
|
|
|
|
"""
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.bk_model.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if not the_iter:
|
2003-06-02 19:04:18 +05:30
|
|
|
return
|
2008-01-23 11:11:46 +05:30
|
|
|
data = self.bk_model.get_data(the_iter, range(self.bk_ncols))
|
2003-06-11 10:09:53 +05:30
|
|
|
row = self.bk_model.get_selected_row()
|
|
|
|
item = self.book.get_item(row)
|
2004-12-22 07:26:37 +05:30
|
|
|
option_class = item.option_class
|
2008-01-23 11:11:46 +05:30
|
|
|
item_dialog = BookItemDialog(self.dbstate, self.uistate, option_class,
|
2006-06-01 00:56:34 +05:30
|
|
|
item.get_name(),
|
|
|
|
item.get_translated_name(),
|
|
|
|
self.track)
|
2004-12-22 07:26:37 +05:30
|
|
|
response = item_dialog.window.run()
|
2009-05-15 01:45:59 +05:30
|
|
|
if response == gtk.RESPONSE_OK:
|
2008-01-23 11:11:46 +05:30
|
|
|
subject = _get_subject(option_class, self.db)
|
|
|
|
self.bk_model.model.set_value(the_iter, 2, subject)
|
|
|
|
self.book.set_item(row, item)
|
2006-06-01 01:01:33 +05:30
|
|
|
item_dialog.close()
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def bk_button_press(self, obj, event):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Double-click on the current book selection is the same as setup.
|
2003-08-29 08:38:02 +05:30
|
|
|
Right click evokes the context menu.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
|
|
|
self.on_setup_clicked(obj)
|
2003-08-29 08:38:02 +05:30
|
|
|
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
2003-10-20 08:17:03 +05:30
|
|
|
self.build_bk_context_menu(event)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def av_button_press(self, obj, event):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Double-click on the available selection is the same as add.
|
2003-08-29 08:38:02 +05:30
|
|
|
Right click evokes the context menu.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
2003-06-02 19:04:18 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
|
|
|
self.on_add_clicked(obj)
|
2003-08-29 08:38:02 +05:30
|
|
|
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
2003-10-20 08:17:03 +05:30
|
|
|
self.build_av_context_menu(event)
|
2003-08-29 08:38:02 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def build_bk_context_menu(self, event):
|
2003-08-29 08:38:02 +05:30
|
|
|
"""Builds the menu with item-centered and book-centered options."""
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.bk_model.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if the_iter:
|
2003-08-29 08:38:02 +05:30
|
|
|
sensitivity = 1
|
|
|
|
else:
|
|
|
|
sensitivity = 0
|
|
|
|
entries = [
|
|
|
|
(gtk.STOCK_GO_UP, self.on_up_clicked, sensitivity),
|
|
|
|
(gtk.STOCK_GO_DOWN, self.on_down_clicked, sensitivity),
|
|
|
|
(_("Setup"), self.on_setup_clicked, sensitivity),
|
|
|
|
(gtk.STOCK_REMOVE, self.on_remove_clicked, sensitivity),
|
|
|
|
(None,None,0),
|
|
|
|
(gtk.STOCK_CLEAR, self.on_clear_clicked, 1),
|
|
|
|
(gtk.STOCK_SAVE, self.on_save_clicked, 1),
|
|
|
|
(gtk.STOCK_OPEN, self.on_open_clicked, 1),
|
|
|
|
(_("Edit"), self.on_edit_clicked,1 ),
|
|
|
|
]
|
|
|
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.set_title(_('Book Menu'))
|
2008-01-23 11:11:46 +05:30
|
|
|
for stock_id, callback, sensitivity in entries:
|
2003-08-29 08:38:02 +05:30
|
|
|
item = gtk.ImageMenuItem(stock_id)
|
|
|
|
if callback:
|
2008-01-23 11:11:46 +05:30
|
|
|
item.connect("activate", callback)
|
2003-08-29 08:38:02 +05:30
|
|
|
item.set_sensitive(sensitivity)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
2008-01-23 11:11:46 +05:30
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
2003-08-29 08:38:02 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def build_av_context_menu(self, event):
|
2003-08-29 08:38:02 +05:30
|
|
|
"""Builds the menu with the single Add option."""
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
store, the_iter = self.av_model.get_selected()
|
2005-01-14 10:32:20 +05:30
|
|
|
if the_iter:
|
2003-08-29 08:38:02 +05:30
|
|
|
sensitivity = 1
|
|
|
|
else:
|
|
|
|
sensitivity = 0
|
|
|
|
entries = [
|
|
|
|
(gtk.STOCK_ADD, self.on_add_clicked, sensitivity),
|
|
|
|
]
|
|
|
|
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.set_title(_('Available Items Menu'))
|
2008-01-23 11:11:46 +05:30
|
|
|
for stock_id, callback, sensitivity in entries:
|
2003-08-29 08:38:02 +05:30
|
|
|
item = gtk.ImageMenuItem(stock_id)
|
|
|
|
if callback:
|
2008-01-23 11:11:46 +05:30
|
|
|
item.connect("activate", callback)
|
2003-08-29 08:38:02 +05:30
|
|
|
item.set_sensitive(sensitivity)
|
|
|
|
item.show()
|
|
|
|
menu.append(item)
|
2008-01-23 11:11:46 +05:30
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
2003-06-02 19:04:18 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_book_ok_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Run final BookReportDialog with the current book.
|
|
|
|
"""
|
|
|
|
if self.book.item_list:
|
2008-02-20 10:22:10 +05:30
|
|
|
BookReportDialog(self.dbstate, self.uistate,
|
2008-01-23 11:11:46 +05:30
|
|
|
self.book, BookOptions)
|
2006-06-01 00:56:34 +05:30
|
|
|
self.close()
|
2003-06-10 10:19:39 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_save_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Save the current book in the xml booklist file.
|
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
self.book_list = BookList(self.file, self.db)
|
2003-12-17 21:36:36 +05:30
|
|
|
name = unicode(self.name_entry.get_text())
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book.set_name(name)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.book.set_dbname(self.db.get_save_path())
|
2008-01-23 11:11:46 +05:30
|
|
|
self.book_list.set_book(name, self.book)
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book_list.save()
|
2003-06-09 05:37:31 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_open_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Run the BookListDisplay dialog to present the choice of books to open.
|
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
self.book_list = BookList(self.file, self.db)
|
2008-01-23 11:11:46 +05:30
|
|
|
booklistdisplay = BookListDisplay(self.book_list, 1, 0)
|
2003-06-11 10:09:53 +05:30
|
|
|
booklistdisplay.top.destroy()
|
|
|
|
book = booklistdisplay.selection
|
|
|
|
if book:
|
|
|
|
self.open_book(book)
|
2004-12-22 07:26:37 +05:30
|
|
|
self.name_entry.set_text(book.get_name())
|
2003-06-11 10:09:53 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def on_edit_clicked(self, obj):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
Run the BookListDisplay dialog to present the choice of books to delete.
|
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
self.book_list = BookList(self.file, self.db)
|
2008-01-23 11:11:46 +05:30
|
|
|
booklistdisplay = BookListDisplay(self.book_list, 0, 1)
|
2003-06-11 10:09:53 +05:30
|
|
|
booklistdisplay.top.destroy()
|
2003-06-10 10:19:39 +05:30
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Book Item Options dialog
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-02-10 09:39:09 +05:30
|
|
|
class BookItemDialog(ReportDialog):
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
This class overrides the interface methods common for different reports
|
|
|
|
in a way specific for this report. This is a book item dialog.
|
|
|
|
"""
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def __init__(self, dbstate, uistate, option_class, name, translated_name,
|
2006-06-01 00:56:34 +05:30
|
|
|
track=[]):
|
2008-02-19 09:54:56 +05:30
|
|
|
self.category = CATEGORY_BOOK
|
2006-06-01 00:56:34 +05:30
|
|
|
self.database = dbstate.db
|
2004-12-22 07:26:37 +05:30
|
|
|
self.option_class = option_class
|
2008-02-20 10:22:10 +05:30
|
|
|
ReportDialog.__init__(self, dbstate, uistate,
|
2008-01-23 11:11:46 +05:30
|
|
|
option_class, name, translated_name, track)
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
def on_ok_clicked(self, obj):
|
|
|
|
"""The user is satisfied with the dialog choices. Parse all options
|
|
|
|
and close the window."""
|
|
|
|
|
|
|
|
# Preparation
|
|
|
|
self.parse_style_frame()
|
|
|
|
self.parse_user_options()
|
|
|
|
|
|
|
|
self.options.handler.save_options()
|
2008-02-19 09:54:56 +05:30
|
|
|
|
|
|
|
def setup_target_frame(self):
|
|
|
|
"""Target frame is not used."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def parse_target_frame(self):
|
|
|
|
"""Target frame is not used."""
|
|
|
|
return 1
|
2009-03-19 07:54:29 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# _BookFormatComboBox
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class _BookFormatComboBox(gtk.ComboBox):
|
|
|
|
|
|
|
|
def __init__(self, active):
|
|
|
|
|
|
|
|
gtk.ComboBox.__init__(self)
|
|
|
|
|
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
self.__bookdoc_plugins = []
|
|
|
|
for plugin in pmgr.get_docgen_plugins():
|
|
|
|
if plugin.get_text_support() and plugin.get_draw_support():
|
|
|
|
self.__bookdoc_plugins.append(plugin)
|
|
|
|
|
|
|
|
self.store = gtk.ListStore(gobject.TYPE_STRING)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell, True)
|
|
|
|
self.add_attribute(cell, 'text', 0)
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
active_index = 0
|
|
|
|
for plugin in self.__bookdoc_plugins:
|
|
|
|
name = plugin.get_name()
|
|
|
|
self.store.append(row=[name])
|
|
|
|
if plugin.get_extension() == active:
|
|
|
|
active_index = index
|
|
|
|
index = index + 1
|
|
|
|
self.set_active(active_index)
|
|
|
|
|
|
|
|
def get_active_plugin(self):
|
|
|
|
"""
|
|
|
|
Get the plugin represented by the currently active selection.
|
|
|
|
"""
|
|
|
|
return self.__bookdoc_plugins[self.get_active()]
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2003-06-08 05:08:13 +05:30
|
|
|
# The final dialog - paper, format, target, etc.
|
2003-06-02 19:04:18 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-12-13 07:22:03 +05:30
|
|
|
class BookReportDialog(DocReportDialog):
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
A usual Report.Dialog subclass.
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a dialog selecting target, format, and paper/HTML options.
|
2003-06-16 21:59:35 +05:30
|
|
|
"""
|
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, dbstate, uistate, book, options):
|
2009-03-19 07:54:29 +05:30
|
|
|
self.format_menu = None
|
2004-12-22 07:26:37 +05:30
|
|
|
self.options = options
|
2005-12-06 12:08:09 +05:30
|
|
|
self.page_html_added = False
|
2008-02-20 10:22:10 +05:30
|
|
|
DocReportDialog.__init__(self, dbstate, uistate, options,
|
2008-01-23 11:11:46 +05:30
|
|
|
'book', _("Book Report"))
|
2003-06-11 10:09:53 +05:30
|
|
|
self.book = book
|
2006-06-01 00:56:34 +05:30
|
|
|
self.database = dbstate.db
|
2003-08-26 09:37:00 +05:30
|
|
|
self.selected_style = BaseDoc.StyleSheet()
|
2003-07-11 08:22:59 +05:30
|
|
|
|
2003-06-11 10:09:53 +05:30
|
|
|
for item in self.book.get_item_list():
|
2003-07-18 11:47:28 +05:30
|
|
|
# Set up default style
|
2003-08-26 09:37:00 +05:30
|
|
|
default_style = BaseDoc.StyleSheet()
|
2004-12-22 07:26:37 +05:30
|
|
|
make_default_style = item.option_class.make_default_style
|
2003-07-18 11:47:28 +05:30
|
|
|
make_default_style(default_style)
|
|
|
|
|
|
|
|
# Read all style sheets available for this item
|
2004-12-22 07:26:37 +05:30
|
|
|
style_file = item.option_class.handler.get_stylesheet_savefile()
|
2008-01-23 11:11:46 +05:30
|
|
|
style_list = BaseDoc.StyleSheetList(style_file, default_style)
|
2003-07-18 11:47:28 +05:30
|
|
|
|
|
|
|
# Get the selected stylesheet
|
2004-12-22 07:26:37 +05:30
|
|
|
style_name = item.option_class.handler.get_default_stylesheet_name()
|
2003-07-18 11:47:28 +05:30
|
|
|
style_sheet = style_list.get_style_sheet(style_name)
|
|
|
|
|
2007-06-13 09:43:00 +05:30
|
|
|
for this_style_name in style_sheet.get_paragraph_style_names():
|
|
|
|
self.selected_style.add_paragraph_style(
|
|
|
|
this_style_name,style_sheet.get_paragraph_style(this_style_name))
|
2003-06-08 05:08:13 +05:30
|
|
|
|
2007-06-25 08:32:45 +05:30
|
|
|
for this_style_name in style_sheet.get_draw_style_names():
|
|
|
|
self.selected_style.add_draw_style(
|
|
|
|
this_style_name,style_sheet.get_draw_style(this_style_name))
|
|
|
|
|
|
|
|
for this_style_name in style_sheet.get_table_style_names():
|
|
|
|
self.selected_style.add_table_style(
|
|
|
|
this_style_name,style_sheet.get_table_style(this_style_name))
|
|
|
|
|
|
|
|
for this_style_name in style_sheet.get_cell_style_names():
|
|
|
|
self.selected_style.add_cell_style(
|
|
|
|
this_style_name,style_sheet.get_cell_style(this_style_name))
|
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
response = self.window.run()
|
2009-05-15 01:45:59 +05:30
|
|
|
if response == gtk.RESPONSE_OK:
|
2004-12-22 07:26:37 +05:30
|
|
|
try:
|
|
|
|
self.make_report()
|
|
|
|
except (IOError,OSError),msg:
|
|
|
|
ErrorDialog(str(msg))
|
2006-06-06 09:43:50 +05:30
|
|
|
self.close()
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2003-06-08 05:08:13 +05:30
|
|
|
def setup_style_frame(self): pass
|
|
|
|
def setup_other_frames(self): pass
|
|
|
|
def parse_style_frame(self): pass
|
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
def get_title(self):
|
2003-06-08 05:08:13 +05:30
|
|
|
return _("Book Report")
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def get_header(self, name):
|
2003-06-12 04:03:01 +05:30
|
|
|
return _("GRAMPS Book")
|
2003-06-08 05:08:13 +05:30
|
|
|
|
2003-07-05 23:55:25 +05:30
|
|
|
def get_stylesheet_savefile(self):
|
|
|
|
"""Needed solely for forming sane filename for the output."""
|
|
|
|
return "book.xml"
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def make_doc_menu(self, active=None):
|
2003-06-08 05:08:13 +05:30
|
|
|
"""Build a menu of document types that are appropriate for
|
|
|
|
this text report. This menu will be generated based upon
|
|
|
|
whether the document requires table support, etc."""
|
2009-03-19 07:54:29 +05:30
|
|
|
self.format_menu = _BookFormatComboBox( active )
|
2003-06-08 05:08:13 +05:30
|
|
|
|
|
|
|
def make_document(self):
|
|
|
|
"""Create a document of the type requested by the user."""
|
2007-12-13 07:22:03 +05:30
|
|
|
pstyle = self.paper_frame.get_paper_style()
|
|
|
|
self.doc = self.format(self.selected_style, pstyle, self.template_name)
|
2003-06-08 05:08:13 +05:30
|
|
|
|
2003-07-13 05:39:29 +05:30
|
|
|
self.rptlist = []
|
2003-06-11 10:09:53 +05:30
|
|
|
for item in self.book.get_item_list():
|
2004-12-23 23:09:47 +05:30
|
|
|
item.option_class.set_document(self.doc)
|
2004-12-22 07:26:37 +05:30
|
|
|
report_class = item.get_write_item()
|
2008-02-20 10:22:10 +05:30
|
|
|
obj = write_book_item(self.database,
|
2008-01-23 11:11:46 +05:30
|
|
|
report_class, item.option_class)
|
2004-12-22 07:26:37 +05:30
|
|
|
self.rptlist.append(obj)
|
2003-07-13 05:39:29 +05:30
|
|
|
self.doc.open(self.target_path)
|
2007-01-25 08:52:46 +05:30
|
|
|
|
2009-03-16 09:52:12 +05:30
|
|
|
if self.open_with_app.get_active():
|
|
|
|
self.doc.open_requested()
|
2003-07-13 05:39:29 +05:30
|
|
|
|
|
|
|
def make_report(self):
|
|
|
|
"""The actual book report. Start it out, then go through the item list
|
|
|
|
and call each item's write_book_item method."""
|
|
|
|
|
2003-09-13 10:26:04 +05:30
|
|
|
self.doc.init()
|
2007-03-30 08:00:42 +05:30
|
|
|
newpage = 0
|
2003-07-13 05:39:29 +05:30
|
|
|
for item in self.rptlist:
|
2007-03-30 08:00:42 +05:30
|
|
|
if newpage:
|
|
|
|
self.doc.page_break()
|
|
|
|
newpage = 1
|
2004-12-30 09:42:01 +05:30
|
|
|
item.begin_report()
|
2003-06-25 09:05:44 +05:30
|
|
|
item.write_report()
|
2003-06-08 05:08:13 +05:30
|
|
|
self.doc.close()
|
2003-06-02 19:04:18 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2004-12-22 07:26:37 +05:30
|
|
|
# Function to write books from command line
|
2003-06-02 19:04:18 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-01-23 11:11:46 +05:30
|
|
|
def cl_report(database, name, category, options_str_dict):
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
clr = CommandLineReport(database, name, category,
|
|
|
|
BookOptions, options_str_dict)
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
# Exit here if show option was given
|
|
|
|
if clr.show:
|
|
|
|
return
|
2008-03-14 09:24:42 +05:30
|
|
|
|
2008-07-17 23:40:32 +05:30
|
|
|
if 'bookname' not in clr.options_dict:
|
2008-03-14 09:24:42 +05:30
|
|
|
print "Please Specify a book name"
|
|
|
|
return
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
book_list = BookList('books.xml', database)
|
2004-12-22 07:26:37 +05:30
|
|
|
book_name = clr.options_dict['bookname']
|
|
|
|
book = book_list.get_book(book_name)
|
|
|
|
selected_style = BaseDoc.StyleSheet()
|
|
|
|
|
|
|
|
for item in book.get_item_list():
|
|
|
|
# Set up default style
|
|
|
|
default_style = BaseDoc.StyleSheet()
|
|
|
|
make_default_style = item.option_class.make_default_style
|
|
|
|
make_default_style(default_style)
|
|
|
|
|
|
|
|
# Read all style sheets available for this item
|
|
|
|
style_file = item.option_class.handler.get_stylesheet_savefile()
|
2008-01-23 11:11:46 +05:30
|
|
|
style_list = BaseDoc.StyleSheetList(style_file, default_style)
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
# Get the selected stylesheet
|
|
|
|
style_name = item.option_class.handler.get_default_stylesheet_name()
|
|
|
|
style_sheet = style_list.get_style_sheet(style_name)
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
for this_style_name in style_sheet.get_paragraph_style_names():
|
|
|
|
selected_style.add_paragraph_style(
|
|
|
|
this_style_name,
|
|
|
|
style_sheet.get_paragraph_style(this_style_name))
|
2004-12-22 07:26:37 +05:30
|
|
|
|
|
|
|
# write report
|
2008-01-23 11:11:46 +05:30
|
|
|
doc = clr.format(selected_style, clr.paper, clr.template_name, clr.orien)
|
2006-03-05 10:01:24 +05:30
|
|
|
rptlist = []
|
|
|
|
for item in book.get_item_list():
|
|
|
|
item.option_class.set_document(doc)
|
|
|
|
report_class = item.get_write_item()
|
2008-02-20 10:22:10 +05:30
|
|
|
obj = write_book_item(database,
|
2008-01-23 11:11:46 +05:30
|
|
|
report_class, item.option_class)
|
2006-03-05 10:01:24 +05:30
|
|
|
rptlist.append(obj)
|
2007-03-30 08:00:42 +05:30
|
|
|
|
2006-03-05 10:01:24 +05:30
|
|
|
doc.open(clr.option_class.get_output())
|
|
|
|
doc.init()
|
2007-03-30 08:00:42 +05:30
|
|
|
newpage = 0
|
2006-03-05 10:01:24 +05:30
|
|
|
for item in rptlist:
|
2007-03-30 08:00:42 +05:30
|
|
|
if newpage:
|
|
|
|
doc.page_break()
|
|
|
|
newpage = 1
|
2006-03-05 10:01:24 +05:30
|
|
|
item.begin_report()
|
|
|
|
item.write_report()
|
|
|
|
doc.close()
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2006-05-31 06:18:07 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Generic task function for book report
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-02-20 10:22:10 +05:30
|
|
|
def write_book_item(database, report_class, options_class):
|
2006-05-31 06:18:07 +05:30
|
|
|
"""Write the Timeline Graph using options set.
|
|
|
|
All user dialog has already been handled and the output file opened."""
|
|
|
|
try:
|
2008-02-20 10:22:10 +05:30
|
|
|
return report_class(database, options_class)
|
2006-05-31 06:18:07 +05:30
|
|
|
except Errors.ReportError, msg:
|
2008-01-23 11:11:46 +05:30
|
|
|
(m1, m2) = msg.messages()
|
|
|
|
ErrorDialog(m1, m2)
|
2006-05-31 06:18:07 +05:30
|
|
|
except Errors.FilterError, msg:
|
2008-01-23 11:11:46 +05:30
|
|
|
(m1, m2) = msg.messages()
|
|
|
|
ErrorDialog(m1, m2)
|
2006-05-31 06:18:07 +05:30
|
|
|
except:
|
|
|
|
log.error("Failed to write book item.", exc_info=True)
|
|
|
|
return None
|
|
|
|
|
2003-06-02 19:04:18 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_report(
|
2006-06-01 00:56:34 +05:30
|
|
|
name = 'book',
|
|
|
|
category = CATEGORY_BOOK,
|
|
|
|
report_class = BookReportSelector,
|
|
|
|
options_class = cl_report,
|
2008-10-02 09:32:10 +05:30
|
|
|
modes = PluginManager.REPORT_MODE_GUI | PluginManager.REPORT_MODE_CLI,
|
2008-03-02 04:17:48 +05:30
|
|
|
translated_name = _("Book Report"),
|
2006-06-01 00:56:34 +05:30
|
|
|
status = _("Stable"),
|
2008-03-02 04:17:48 +05:30
|
|
|
description = _("Produces a book containing several reports."),
|
2006-06-01 00:56:34 +05:30
|
|
|
author_name = "Alex Roitman",
|
|
|
|
author_email = "shura@gramps-project.org"
|
|
|
|
)
|