diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index b4a9e32ab..035cda1f1 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -225,16 +225,14 @@ class Gramplet(object): self.dbstate = gui.dbstate self.init() self.on_load() + self.build_options() + self.make_gui_options() self.dbstate.connect('database-changed', self._db_changed) self.dbstate.connect('active-changed', self.active_changed) self.gui.textview.connect('button-press-event', self.on_button_press) self.gui.textview.connect('motion-notify-event', self.on_motion) - # Add options to section on detached view - # FIXME: too many options will expand section: need scrollable area - for item in self.option_dict: - self.gui.gvoptions.add(gtk.Label(item)) if self.dbstate.active: # already changed self._db_changed(self.dbstate.db) self.active_changed(self.dbstate.active.handle) @@ -242,6 +240,9 @@ class Gramplet(object): def init(self): # once, constructor pass + def build_options(self): + pass + def main(self): # return false finishes """ Generator which will be run in the background. @@ -474,9 +475,42 @@ class Gramplet(object): return True return False # did not handle event - def set_option(self, option_dict): - self.option_dict.update(option_dict) - + def get_option_widget(self, label): + return self.option_dict[label][0] + + def get_option(self, label): + return self.option_dict[label][1] + + def add_option(self, option): + from PluginUtils import make_gui_option + #tooltips, dbstate, uistate, track + widget, label = make_gui_option(option, None, self.dbstate, + self.gui.uistate,None) + self.option_dict.update({option.get_label(): (widget, option)}) + + def make_gui_options(self): + topbox = gtk.VBox() + hbox = gtk.HBox() + labels = gtk.VBox() + options = gtk.VBox() + hbox.add(labels) + hbox.add(options) + topbox.add(hbox) + self.gui.gvoptions.add(topbox) + for item in self.option_dict: + labels.add(gtk.Label(item + ":")) + options.add(self.option_dict[item][0]) # widget + save_button = gtk.Button(stock=gtk.STOCK_SAVE) + topbox.add(save_button) + save_button.connect('clicked', self.save_update_options) + + def save_update_options(self, obj): + self.save_options() + self.update() + + def save_options(self): + pass + def logical_true(value): return value in ["True", True, 1, "1"] diff --git a/src/PluginUtils/_GuiOptions.py b/src/PluginUtils/_GuiOptions.py index c3e4e3a0b..468b4e9dc 100644 --- a/src/PluginUtils/_GuiOptions.py +++ b/src/PluginUtils/_GuiOptions.py @@ -370,6 +370,10 @@ class GuiEnumeratedListOption(gtk.HBox): items = self.__option.get_items() value, description = items[index] # IGNORE:W0612 - description is unused self.__option.set_value( value ) + self.value_changed() + + def value_changed(self): + pass def __update_options(self): """ @@ -1411,6 +1415,13 @@ def make_gui_option(option, tooltips, dbstate, uistate, track): """ widget = None label = True + if tooltips == None: + tooltips = gtk.Tooltips() + elif type(tooltips) == type(""): + msg = tooltips + tooltips = gtk.Tooltips() + # FIXME: what widget? + #tooltips.set_tip(gui.scrolledwindow, msg) if isinstance(option, gen.plug.menu.PersonOption): widget = GuiPersonOption(option, dbstate, uistate, track, tooltips) elif isinstance(option, gen.plug.menu.FamilyOption): diff --git a/src/plugins/DefaultGramplets.py b/src/plugins/DefaultGramplets.py index 9594b9251..7dc11af2f 100644 --- a/src/plugins/DefaultGramplets.py +++ b/src/plugins/DefaultGramplets.py @@ -33,6 +33,11 @@ import Config import DateHandler import gen.lib +from ReportBase import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, + CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, + CATEGORY_QR_MISC, CATEGORY_QR_PLACE, + CATEGORY_QR_REPOSITORY) + # # Hello World, in Gramps Gramplets # @@ -469,9 +474,14 @@ class PedigreeGramplet(Gramplet): self.max_generations = 100 self.show_dates = 1 self.box_mode = "UTF" - self.set_option({"Max generations": 100}) - # NumberOption(_("Maximum generations"), - # 100, -1, 500)) + + def build_options(self): + from gen.plug.menu import NumberOption + self.add_option(NumberOption(_("Max generations"), + self.max_generations, 1, 100)) + + def save_options(self): + self.max_generations = int(self.get_option(_("Max generations")).get_value()) def on_load(self): if len(self.gui.data) > 0: @@ -640,7 +650,7 @@ class PedigreeGramplet(Gramplet): """ Generator which will be run in the background. """ - self._boxes = [0] * self.max_generations + self._boxes = [0] * (self.max_generations + 1) self._generations = {} self.gui.buffer.set_text("") active_person = self.dbstate.get_active_person() @@ -1118,35 +1128,77 @@ class AgeOnDateGramplet(Gramplet): date) class QuickViewGramplet(Gramplet): - def init(self): - pass - #import gtk - #self.tooltip = _("Double-click a day for details") - #self.gui.picklist = gtk.combo_box_new_text() - #iter = self.gui.buffer.get_end_iter() - #anchor = self.gui.buffer.create_child_anchor(iter) - #vbox = self.gui.xml.get_widget("vbox_top") - #vbox.add(self.gui.picklist) - #self.gui.picklist.show() - def active_changed(self, handle): self.update() def main(self): - from ReportBase import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, - CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, - CATEGORY_QR_MISC, CATEGORY_QR_PLACE, - CATEGORY_QR_REPOSITORY) - self.qv_list = get_quick_report_list(CATEGORY_QR_PERSON) - #(self.qv_title, self.qv_category, self.qv_name, self.qv_status) - quick_view = self.qv_list[0][2] - active_person = self.dbstate.get_active_person() - if active_person: - run_quick_report_by_name(self.gui.dbstate, - self.gui.uistate, - quick_view, - active_person.handle, - container=self.gui.textview) + qv_type = self.get_option(_("View Type")) + quick_type = qv_type.get_value() + qv_option = self.get_option(_("Quick Views")) + quick_view = qv_option.get_value() + if quick_type == CATEGORY_QR_PERSON: + active = self.dbstate.get_active_person() + if active: + run_quick_report_by_name(self.gui.dbstate, + self.gui.uistate, + quick_view, + active.handle, + container=self.gui.textview) + else: + active_list = [] + for item in self.gui.uistate.viewmanager.pages: + if (item.get_title() == _("Families") and + quick_type == CATEGORY_QR_FAMILY): + active_list = item.selected_handles() + elif (item.get_title() == _("Events") and + quick_type == CATEGORY_QR_EVENT): + active_list = item.selected_handles() + elif (item.get_title() == _("Sources") and + quick_type == CATEGORY_QR_SOURCE): + active_list = item.selected_handles() + elif (item.get_title() == _("Places") and + quick_type == CATEGORY_QR_PLACE): + active_list = item.selected_handles() + elif (item.get_title() == _("Repositories") and + quick_type == CATEGORY_QR_REPOSITORY): + active_list = item.selected_handles() + if len(active_list) > 0: + run_quick_report_by_name(self.gui.dbstate, + self.gui.uistate, + quick_view, + active_list[0], + container=self.gui.textview) + + def build_options(self): + from gen.plug.menu import EnumeratedListOption + # Add types: + type_list = EnumeratedListOption(_("View Type"), CATEGORY_QR_PERSON) + for item in [(CATEGORY_QR_PERSON, "Person"), + (CATEGORY_QR_FAMILY, "Family"), + (CATEGORY_QR_EVENT, "Event"), + (CATEGORY_QR_SOURCE, "Source"), + (CATEGORY_QR_PLACE, "Place"), + (CATEGORY_QR_REPOSITORY, "Repository")]: + type_list.add_item(item[0], item[1]) + # Add particular lists: + qv_list = get_quick_report_list(CATEGORY_QR_PERSON) + list_option = EnumeratedListOption(_("Quick Views"), qv_list[0][2]) + for item in qv_list: + #(title, category, name, status) + list_option.add_item(item[2], item[0]) + self.add_option(type_list) + self.add_option(list_option) + type_widget = self.get_option_widget(_("View Type")) + type_widget.value_changed = self.rebuild_option_list + + def rebuild_option_list(self): + qv_option = self.get_option(_("View Type")) + list_option = self.get_option(_("Quick Views")) + list_option.clear() + qv_list = get_quick_report_list(qv_option.get_value()) + for item in qv_list: + #(title, category, name, status) + list_option.add_item(item[2], item[0]) register(type="gramplet", name= "Top Surnames Gramplet", @@ -1277,6 +1329,7 @@ register(type="gramplet", name="Quick View Gramplet", tname=_("Quick View Gramplet"), height=300, + expand=True, content = QuickViewGramplet, title=_("Quick View"), detached_width = 600,