Web Calendar and Narrative Web report now use Menu Options.

svn: r10010
This commit is contained in:
Brian Matherly 2008-02-10 04:09:09 +00:00
parent f9a1b38155
commit 610ac774fa
13 changed files with 1314 additions and 1314 deletions

View File

@ -1,3 +1,18 @@
2008-02-09 Brian Matherly <brian@gramps-project.org>
* src/ReportBase/_WebReportDialog.py:
* src/ReportBase/_ReportDialog.py:
* src/ReportBase/Makefile.am
* src/ReportBase/_BareReportDialog.py:
* src/ReportBase/_ReportOptions.py:
* src/plugins/WebCal.py:
* src/plugins/BookReport.py:
* src/plugins/NarrativeWeb.py:
* src/PluginUtils/__init__.py:
* src/PluginUtils/_MenuOptions.py:
* src/PluginUtils/_GuiOptions.py:
* src/BaseDoc.py:
Web Calendar and Narrative Web report now use Menu Options.
2008-02-08 Raphael Ackermann <raphael.ackermann@gmail.com>
* src/Editors/_EditEvent.py:
* src/Editors/_EditFamily.py:

View File

@ -1052,6 +1052,18 @@ class StyleSheet:
self.draw_styles = {}
self.table_styles = {}
self.cell_styles = {}
def is_empty(self):
"Checks if any styles are defined"
style_count = len(self.para_styles) + \
len(self.draw_styles) + \
len(self.table_styles) + \
len(self.cell_styles)
print style_count
if style_count > 0:
return False
else:
return True
def add_paragraph_style(self, name, style):
"""

View File

@ -28,14 +28,22 @@ Specific option handling for a GUI.
#
#------------------------------------------------------------------------
from gettext import gettext as _
import os
import sys
#-------------------------------------------------------------------------
#
# gtk modules
#
#-------------------------------------------------------------------------
import gtk
import gobject
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import gtk
import gobject
import Utils
import GrampsWidgets
import ManagedWindow
@ -164,7 +172,7 @@ class GuiStringOption(gtk.Entry):
"""
Handle the change of the value.
"""
self.__option.set_value( self.__entry.get_text() )
self.__option.set_value( self.get_text() )
#-------------------------------------------------------------------------
#
@ -591,6 +599,165 @@ class GuiFamilyOption(gtk.HBox):
avail = self.__option.get_available()
self.set_sensitive(avail)
#-------------------------------------------------------------------------
#
# GuiNoteOption class
#
#-------------------------------------------------------------------------
class GuiNoteOption(gtk.HBox):
"""
This class displays an option that allows a note from the
database to be selected.
"""
def __init__(self, option, dbstate, uistate, track, tooltip):
"""
@param option: The option to display.
@type option: MenuOption.NoteOption
@return: nothing
"""
gtk.HBox.__init__(self)
self.__option = option
self.__dbstate = dbstate
self.__db = dbstate.get_database()
self.__uistate = uistate
self.__track = track
self.__note_label = gtk.Label()
self.__note_label.set_alignment(0.0, 0.5)
pevt = gtk.EventBox()
pevt.add(self.__note_label)
note_button = GrampsWidgets.SimpleButton(gtk.STOCK_INDEX,
self.__get_note_clicked)
note_button.set_relief(gtk.RELIEF_NORMAL)
self.pack_start(pevt, False)
self.pack_end(note_button, False)
# Initialize to the current value
nid = self.__option.get_value()
note = self.__db.get_note_from_gramps_id(nid)
self.__update_note(note)
tooltip.set_tip(pevt, self.__option.get_help())
tooltip.set_tip(note_button, _('Select an existing note'))
self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail()
def __get_note_clicked(self, obj): # IGNORE:W0613 - obj is unused
"""
Handle the button to choose a different note.
"""
select_class = selector_factory('Note')
sel = select_class(self.__dbstate, self.__uistate, self.__track)
note = sel.run()
self.__update_note(note)
def __update_note(self, note):
"""
Update the currently selected note.
"""
if note:
note_id = note.get_gramps_id()
txt = " ".join(note.get(markup=False).split())
if len(txt) > 35:
txt = txt[:35]+"..."
else:
txt = txt
txt = "%s [%s]" % (txt, note_id)
self.__note_label.set_text( txt )
self.__option.set_value(note_id)
else:
txt = "<i>%s</i>" % _('No note given, click button to select one')
self.__note_label.set_text( txt )
self.__note_label.set_use_markup(True)
self.__option.set_value("")
def __update_avail(self):
"""
Update the availability (sensitivity) of this widget.
"""
avail = self.__option.get_available()
self.set_sensitive(avail)
#-------------------------------------------------------------------------
#
# GuiMediaOption class
#
#-------------------------------------------------------------------------
class GuiMediaOption(gtk.HBox):
"""
This class displays an option that allows a media object from the
database to be selected.
"""
def __init__(self, option, dbstate, uistate, track, tooltip):
"""
@param option: The option to display.
@type option: MenuOption.MediaOption
@return: nothing
"""
gtk.HBox.__init__(self)
self.__option = option
self.__dbstate = dbstate
self.__db = dbstate.get_database()
self.__uistate = uistate
self.__track = track
self.__media_label = gtk.Label()
self.__media_label.set_alignment(0.0, 0.5)
pevt = gtk.EventBox()
pevt.add(self.__media_label)
media_button = GrampsWidgets.SimpleButton(gtk.STOCK_INDEX,
self.__get_media_clicked)
media_button.set_relief(gtk.RELIEF_NORMAL)
self.pack_start(pevt, False)
self.pack_end(media_button, False)
# Initialize to the current value
mid = self.__option.get_value()
media = self.__db.get_object_from_gramps_id(mid)
self.__update_media(media)
tooltip.set_tip(pevt, self.__option.get_help())
tooltip.set_tip(media_button, _('Select an existing media object'))
self.__option.connect('avail-changed', self.__update_avail)
self.__update_avail()
def __get_media_clicked(self, obj): # IGNORE:W0613 - obj is unused
"""
Handle the button to choose a different note.
"""
select_class = selector_factory('MediaObject')
sel = select_class(self.__dbstate, self.__uistate, self.__track)
media = sel.run()
self.__update_media(media)
def __update_media(self, media):
"""
Update the currently selected media.
"""
if media:
media_id = media.get_gramps_id()
txt = "%s [%s]" % (media.get_description(), media_id)
self.__media_label.set_text( txt )
self.__option.set_value(media_id)
else:
txt = "<i>%s</i>" % _('No image given, click button to select one')
self.__media_label.set_text( txt )
self.__media_label.set_use_markup(True)
self.__option.set_value("")
def __update_avail(self):
"""
Update the availability (sensitivity) of this widget.
"""
avail = self.__option.get_available()
self.set_sensitive(avail)
#-------------------------------------------------------------------------
#
# GuiPersonListOption class
@ -868,6 +1035,102 @@ class GuiSurnameColourOption(gtk.HBox):
i = self.__model.get_iter(path)
self.__model.remove(i)
self.__value_changed()
#-------------------------------------------------------------------------
#
# GuiDestinationOption class
#
#-------------------------------------------------------------------------
class GuiDestinationOption(gtk.HBox):
"""
This class displays an option that is a simple one-line string.
"""
def __init__(self, option, dbstate, uistate, track, tooltip):
"""
@param option: The option to display.
@type option: MenuOption.StringOption
@return: nothing
"""
gtk.HBox.__init__(self)
self.__option = option
self.__entry = gtk.Entry()
self.__entry.set_text( self.__option.get_value() )
self.__entry.connect('changed', self.__text_changed)
self.__button = gtk.Button()
img = gtk.Image()
img.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
self.__button.add(img)
self.__button.connect('clicked', self.__select_file)
self.pack_start(self.__entry, True, True)
self.pack_end(self.__button, False, False)
tooltip.set_tip(self, self.__option.get_help())
self.__option.connect('options-changed', self.__option_changed)
def __text_changed(self, obj): # IGNORE:W0613 - obj is unused
"""
Handle the change of the value.
"""
self.__option.set_value( self.__entry.get_text() )
def __select_file(self, obj):
"""
Handle the user's request to select a file (or directory).
"""
if self.__option.get_directory_entry():
my_action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER
else:
my_action = gtk.FILE_CHOOSER_ACTION_SAVE
fcd = gtk.FileChooserDialog(_("Save As"), action=my_action,
buttons=(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN,
gtk.RESPONSE_OK))
name = os.path.abspath(self.__option.get_value())
if self.__option.get_directory_entry():
while not os.path.isdir(name):
# Keep looking up levels to find a valid drive.
name, tail = os.path.split(name)
if not name:
# Avoid infinite loops
name = os.getcwd()
fcd.set_current_folder(name)
else:
fcd.set_current_name(name)
status = fcd.run()
if status == gtk.RESPONSE_OK:
path = unicode(fcd.get_filename(), sys.getfilesystemencoding())
print path
if path:
if not self.__option.get_directory_entry() and \
not path.endswith(self.__option.get_extension()):
path = path + self.__option.get_extension()
self.__entry.set_text(path)
self.__option.set_value(path)
fcd.destroy()
def __option_changed(self):
"""
Handle a change of the option.
"""
extension = self.__option.get_extension()
directory = self.__option.get_directory_entry()
value = self.__option.get_value()
if not directory and not value.endswith(extension):
value = value + extension
self.__option.set_value(value)
elif directory and value.endswith(extension):
value = value[:-len(extension)]
self.__option.set_value(value)
self.__entry.set_text( self.__option.get_value() )
#------------------------------------------------------------------------
#
@ -932,10 +1195,27 @@ class GuiMenuOptions:
found = True
label = True
if isinstance(option, _MenuOptions.PersonOption):
widget = GuiPersonOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.FamilyOption):
widget = GuiFamilyOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.NoteOption):
widget = GuiNoteOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.MediaOption):
widget = GuiMediaOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.PersonListOption):
widget = GuiPersonListOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.NumberOption):
widget = GuiNumberOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
@ -945,6 +1225,10 @@ class GuiMenuOptions:
dialog.uistate, dialog.track,
self.__tooltips)
label = False
elif isinstance(option, _MenuOptions.DestinationOption):
widget = GuiDestinationOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.StringOption):
widget = GuiStringOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
@ -957,14 +1241,6 @@ class GuiMenuOptions:
widget = GuiTextOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.FamilyOption):
widget = GuiFamilyOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.PersonListOption):
widget = GuiPersonListOption(option, dialog.dbstate,
dialog.uistate, dialog.track,
self.__tooltips)
elif isinstance(option, _MenuOptions.ColourOption):
widget = GuiColourOption(option, dialog.dbstate,
dialog.uistate, dialog.track,

View File

@ -404,7 +404,7 @@ class FilterOption(EnumeratedListOption):
"""
Return the currently selected filter object.
@return: A person filter object.
@return: A filter object.
"""
return self.__filters[self.get_value()]
@ -413,7 +413,7 @@ class FilterOption(EnumeratedListOption):
# PersonOption class
#
#-------------------------------------------------------------------------
class PersonOption(Option):
class PersonOption(StringOption):
"""
This class describes an option that allows a person from the
database to be selected.
@ -423,19 +423,19 @@ class PersonOption(Option):
@param label: A friendly label to be applied to this option.
Example: "Center Person"
@type label: string
@param value: A default Gramps ID of a person for this option.
@param value: A Gramps ID of a person for this option.
Example: "p11"
@type value: string
@return: nothing
"""
Option.__init__(self, label, "")
StringOption.__init__(self, label, "")
#-------------------------------------------------------------------------
#
# FamilyOption class
#
#-------------------------------------------------------------------------
class FamilyOption(Option):
class FamilyOption(StringOption):
"""
This class describes an option that allows a family from the
database to be selected.
@ -445,14 +445,57 @@ class FamilyOption(Option):
@param label: A friendly label to be applied to this option.
Example: "Center Family"
@type label: string
@param value: A default Gramps ID of a family for this option.
@param value: A Gramps ID of a family for this option.
Example: "f11"
@type value: string
@param dbstate: The database state for the database to be used..
@type value: DbState
@return: nothing
"""
Option.__init__(self, label, "")
StringOption.__init__(self, label, "")
#-------------------------------------------------------------------------
#
# NoteOption class
#
#-------------------------------------------------------------------------
class NoteOption(StringOption):
"""
This class describes an option that allows a note from the
database to be selected.
"""
def __init__(self, label):
"""
@param label: A friendly label to be applied to this option.
Example: "Title Note"
@type label: string
@param value: A Gramps ID of a note for this option.
Example: "n11"
@type value: string
@return: nothing
"""
StringOption.__init__(self, label, "")
#-------------------------------------------------------------------------
#
# MediaOption class
#
#-------------------------------------------------------------------------
class MediaOption(StringOption):
"""
This class describes an option that allows a media object from the
database to be selected.
"""
def __init__(self, label):
"""
@param label: A friendly label to be applied to this option.
Example: "Image"
@type label: string
@param value: A Gramps ID of a media object for this option.
Example: "m11"
@type value: string
@return: nothing
"""
StringOption.__init__(self, label, "")
#-------------------------------------------------------------------------
#
# PersonListOption class
@ -498,6 +541,69 @@ class SurnameColourOption(Option):
"""
Option.__init__(self, label, "")
#-------------------------------------------------------------------------
#
# DestinationOption class
#
#-------------------------------------------------------------------------
class DestinationOption(StringOption):
"""
This class describes an option that specifies a destination file or path.
The destination can be a directory or a file. If the destination is a file,
the extension can be specified.
"""
__signals__ = { 'options-changed' : None }
def __init__(self, label, value):
"""
@param label: A friendly label to be applied to this option.
Example: "File Name"
@type label: string
@param value: A default destination for this option.
Example: "/home/username/Desktop/"
Example: "/home/username/Desktop/report.pdf"
@type value: string
@param is_directory: Specifies whether the destination is a directory
or a file.
@type value: bool
@return: nothing
"""
StringOption.__init__(self, label, value)
self.__is_directory = False
self.__extension = ""
def set_directory_entry(self, is_directory):
"""
@param is_directory: Specifies whether the destination is a directory
or a file.
@type value: bool
@return: nothing
"""
self.__is_directory = is_directory
self.emit('options-changed')
def get_directory_entry(self):
"""
@return: True if the destination is a directory. False if the
destination is a file.
"""
return self.__is_directory
def set_extension(self, extension):
"""
@param extension: Specifies the extension for the destination file.
@type value: str
@return: nothing
"""
self.__extension = extension
def get_extension(self):
"""
@return: The extension for the destination file.
"""
return self.__extension
#-------------------------------------------------------------------------
#
# Menu class

View File

@ -31,7 +31,8 @@
from _MenuOptions import (NumberOption, BooleanOption, TextOption,
EnumeratedListOption, FilterOption, StringOption,
ColourOption, PersonOption, PersonListOption,
SurnameColourOption, FamilyOption)
SurnameColourOption, FamilyOption, DestinationOption,
NoteOption, MediaOption)
from _GuiOptions import GuiMenuOptions
from _PluginMgr import (register_export, register_import, register_tool,
register_report, register_relcalc, relationship_class,

View File

@ -25,7 +25,8 @@ pkgdata_PYTHON = \
_StyleEditor.py\
_TemplateParser.py\
_TextFormatComboBox.py\
_TextReportDialog.py
_TextReportDialog.py\
_WebReportDialog.py
pkgpyexecdir = @pkgpyexecdir@/ReportBase
pkgpythondir = @pkgpythondir@/ReportBase

View File

@ -303,6 +303,13 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
and to read in any user defined styles for this report. It
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.options.make_default_style(self.default_style)
if self.default_style.is_empty():
# Don't display the option of no styles are used
return
# Styles Frame
label = gtk.Label("%s:" % _("Style"))
@ -319,10 +326,6 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
xoptions=gtk.SHRINK|gtk.FILL,yoptions=gtk.SHRINK)
self.col += 1
# Build the default style set for this report.
self.default_style = BaseDoc.StyleSheet()
self.options.make_default_style(self.default_style)
# Build the initial list of available styles sets. This
# includes the default style set and any style sets saved from
# previous invocations of gramps.
@ -437,8 +440,9 @@ class BareReportDialog(ManagedWindow.ManagedWindow):
retrieves a value whether or not the menu is displayed on the
screen. The subclass will know whether this menu was enabled.
This is for simplicity of programming."""
(style_name,self.selected_style) = self.style_menu.get_value()
self.options.handler.set_default_stylesheet_name(style_name)
if not self.default_style.is_empty():
(style_name, self.selected_style) = self.style_menu.get_value()
self.options.handler.set_default_stylesheet_name(style_name)
#------------------------------------------------------------------------
#

View File

@ -291,7 +291,10 @@ def report(dbstate,uistate,person,report_class,options_class,
elif category == CATEGORY_GRAPHVIZ:
from _GraphvizReportDialog import GraphvizReportDialog
dialog_class = GraphvizReportDialog
elif category in (CATEGORY_BOOK,CATEGORY_CODE,CATEGORY_VIEW,CATEGORY_WEB):
elif category == CATEGORY_WEB:
from _WebReportDialog import WebReportDialog
dialog_class = WebReportDialog
elif category in (CATEGORY_BOOK,CATEGORY_CODE,CATEGORY_VIEW):
try:
report_class(dbstate,uistate,person)
except Errors.WindowActiveError:

View File

@ -533,6 +533,26 @@ class OptionParser(_Options.OptionParser):
else:
# Tag is not report-specific, so we let the base class handle it.
_Options.OptionParser.endElement(self,tag)
#------------------------------------------------------------------------
#
# Empty class to keep the BaseDoc-targeted format happy
# Yes, this is a hack. Find some other way to pass around documents so that
# we don't have to handle them for reports that don't use documents (web)
#
#------------------------------------------------------------------------
class EmptyDoc:
def init(self):
pass
def set_creator(self, creator):
pass
def open(self, filename):
pass
def close(self):
pass
#-------------------------------------------------------------------------
#
@ -557,7 +577,7 @@ class OptionHandler(_Options.OptionHandler):
"""
# These are needed for running reports.
# We will not need to save/retreive them, just keep around.
self.doc = None
self.doc = EmptyDoc() # Nasty hack. Text reports replace this
self.output = None
# Retrieve our options from whole collection

View File

@ -0,0 +1,55 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2008 Brian G. Matherly
#
# 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
#
# $Id:$
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _ReportDialog import ReportDialog
from ReportBase import CATEGORY_WEB
#-------------------------------------------------------------------------
#
# WebReportDialog class
#
#-------------------------------------------------------------------------
class WebReportDialog(ReportDialog):
"""
The WebReportDialog base class. This is a base class for generating
dialogs for web page reports.
"""
def __init__(self, dbstate, uistate, person,
option_class, name, trans_name):
"""Initialize a dialog"""
self.category = CATEGORY_WEB
ReportDialog.__init__(self, dbstate, uistate, person, option_class,
name, trans_name)
def setup_target_frame(self):
"""Target frame is not used."""
pass
def parse_target_frame(self):
"""Target frame is not used."""
return 1

View File

@ -76,7 +76,7 @@ import ManagedWindow
# Import from specific modules in ReportBase
from ReportBase._Constants import CATEGORY_BOOK, MODE_GUI, MODE_CLI
from ReportBase._BookFormatComboBox import BookFormatComboBox
from ReportBase._BareReportDialog import BareReportDialog
from ReportBase._ReportDialog import ReportDialog
from ReportBase._DocReportDialog import DocReportDialog
from ReportBase._CommandLineReport import CommandLineReport
from ReportBase._ReportOptions import ReportOptions
@ -809,7 +809,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow):
self.bk_model.clear()
for saved_item in book.get_item_list():
name = saved_item.get_name()
item = BookItem(self.dbase, name)
item = BookItem(self.db, name)
item.option_class = saved_item.option_class
_initialize_options(item.option_class, self.dbstate)
item.set_style_name(saved_item.get_style_name())
@ -1025,7 +1025,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow):
# Book Item Options dialog
#
#------------------------------------------------------------------------
class BookItemDialog(BareReportDialog):
class BookItemDialog(ReportDialog):
"""
This class overrides the interface methods common for different reports
@ -1037,7 +1037,7 @@ class BookItemDialog(BareReportDialog):
self.database = dbstate.db
self.option_class = option_class
BareReportDialog.__init__(self, dbstate, uistate, None,
ReportDialog.__init__(self, dbstate, uistate, None,
option_class, name, translated_name, track)
def on_ok_clicked(self, obj):

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff