Web Calendar and Narrative Web report now use Menu Options.
svn: r10010
This commit is contained in:
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user