Added options to Gramplets
svn: r11470
This commit is contained in:
parent
091933b576
commit
ab98ce5d88
@ -225,16 +225,14 @@ class Gramplet(object):
|
|||||||
self.dbstate = gui.dbstate
|
self.dbstate = gui.dbstate
|
||||||
self.init()
|
self.init()
|
||||||
self.on_load()
|
self.on_load()
|
||||||
|
self.build_options()
|
||||||
|
self.make_gui_options()
|
||||||
self.dbstate.connect('database-changed', self._db_changed)
|
self.dbstate.connect('database-changed', self._db_changed)
|
||||||
self.dbstate.connect('active-changed', self.active_changed)
|
self.dbstate.connect('active-changed', self.active_changed)
|
||||||
self.gui.textview.connect('button-press-event',
|
self.gui.textview.connect('button-press-event',
|
||||||
self.on_button_press)
|
self.on_button_press)
|
||||||
self.gui.textview.connect('motion-notify-event',
|
self.gui.textview.connect('motion-notify-event',
|
||||||
self.on_motion)
|
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
|
if self.dbstate.active: # already changed
|
||||||
self._db_changed(self.dbstate.db)
|
self._db_changed(self.dbstate.db)
|
||||||
self.active_changed(self.dbstate.active.handle)
|
self.active_changed(self.dbstate.active.handle)
|
||||||
@ -242,6 +240,9 @@ class Gramplet(object):
|
|||||||
def init(self): # once, constructor
|
def init(self): # once, constructor
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def build_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def main(self): # return false finishes
|
def main(self): # return false finishes
|
||||||
"""
|
"""
|
||||||
Generator which will be run in the background.
|
Generator which will be run in the background.
|
||||||
@ -474,8 +475,41 @@ class Gramplet(object):
|
|||||||
return True
|
return True
|
||||||
return False # did not handle event
|
return False # did not handle event
|
||||||
|
|
||||||
def set_option(self, option_dict):
|
def get_option_widget(self, label):
|
||||||
self.option_dict.update(option_dict)
|
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):
|
def logical_true(value):
|
||||||
return value in ["True", True, 1, "1"]
|
return value in ["True", True, 1, "1"]
|
||||||
|
@ -370,6 +370,10 @@ class GuiEnumeratedListOption(gtk.HBox):
|
|||||||
items = self.__option.get_items()
|
items = self.__option.get_items()
|
||||||
value, description = items[index] # IGNORE:W0612 - description is unused
|
value, description = items[index] # IGNORE:W0612 - description is unused
|
||||||
self.__option.set_value( value )
|
self.__option.set_value( value )
|
||||||
|
self.value_changed()
|
||||||
|
|
||||||
|
def value_changed(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def __update_options(self):
|
def __update_options(self):
|
||||||
"""
|
"""
|
||||||
@ -1411,6 +1415,13 @@ def make_gui_option(option, tooltips, dbstate, uistate, track):
|
|||||||
"""
|
"""
|
||||||
widget = None
|
widget = None
|
||||||
label = True
|
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):
|
if isinstance(option, gen.plug.menu.PersonOption):
|
||||||
widget = GuiPersonOption(option, dbstate, uistate, track, tooltips)
|
widget = GuiPersonOption(option, dbstate, uistate, track, tooltips)
|
||||||
elif isinstance(option, gen.plug.menu.FamilyOption):
|
elif isinstance(option, gen.plug.menu.FamilyOption):
|
||||||
|
@ -33,6 +33,11 @@ import Config
|
|||||||
import DateHandler
|
import DateHandler
|
||||||
import gen.lib
|
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
|
# Hello World, in Gramps Gramplets
|
||||||
#
|
#
|
||||||
@ -469,9 +474,14 @@ class PedigreeGramplet(Gramplet):
|
|||||||
self.max_generations = 100
|
self.max_generations = 100
|
||||||
self.show_dates = 1
|
self.show_dates = 1
|
||||||
self.box_mode = "UTF"
|
self.box_mode = "UTF"
|
||||||
self.set_option({"Max generations": 100})
|
|
||||||
# NumberOption(_("Maximum generations"),
|
def build_options(self):
|
||||||
# 100, -1, 500))
|
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):
|
def on_load(self):
|
||||||
if len(self.gui.data) > 0:
|
if len(self.gui.data) > 0:
|
||||||
@ -640,7 +650,7 @@ class PedigreeGramplet(Gramplet):
|
|||||||
"""
|
"""
|
||||||
Generator which will be run in the background.
|
Generator which will be run in the background.
|
||||||
"""
|
"""
|
||||||
self._boxes = [0] * self.max_generations
|
self._boxes = [0] * (self.max_generations + 1)
|
||||||
self._generations = {}
|
self._generations = {}
|
||||||
self.gui.buffer.set_text("")
|
self.gui.buffer.set_text("")
|
||||||
active_person = self.dbstate.get_active_person()
|
active_person = self.dbstate.get_active_person()
|
||||||
@ -1118,35 +1128,77 @@ class AgeOnDateGramplet(Gramplet):
|
|||||||
date)
|
date)
|
||||||
|
|
||||||
class QuickViewGramplet(Gramplet):
|
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):
|
def active_changed(self, handle):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
from ReportBase import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY,
|
qv_type = self.get_option(_("View Type"))
|
||||||
CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE,
|
quick_type = qv_type.get_value()
|
||||||
CATEGORY_QR_MISC, CATEGORY_QR_PLACE,
|
qv_option = self.get_option(_("Quick Views"))
|
||||||
CATEGORY_QR_REPOSITORY)
|
quick_view = qv_option.get_value()
|
||||||
self.qv_list = get_quick_report_list(CATEGORY_QR_PERSON)
|
if quick_type == CATEGORY_QR_PERSON:
|
||||||
#(self.qv_title, self.qv_category, self.qv_name, self.qv_status)
|
active = self.dbstate.get_active_person()
|
||||||
quick_view = self.qv_list[0][2]
|
if active:
|
||||||
active_person = self.dbstate.get_active_person()
|
|
||||||
if active_person:
|
|
||||||
run_quick_report_by_name(self.gui.dbstate,
|
run_quick_report_by_name(self.gui.dbstate,
|
||||||
self.gui.uistate,
|
self.gui.uistate,
|
||||||
quick_view,
|
quick_view,
|
||||||
active_person.handle,
|
active.handle,
|
||||||
container=self.gui.textview)
|
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",
|
register(type="gramplet",
|
||||||
name= "Top Surnames Gramplet",
|
name= "Top Surnames Gramplet",
|
||||||
@ -1277,6 +1329,7 @@ register(type="gramplet",
|
|||||||
name="Quick View Gramplet",
|
name="Quick View Gramplet",
|
||||||
tname=_("Quick View Gramplet"),
|
tname=_("Quick View Gramplet"),
|
||||||
height=300,
|
height=300,
|
||||||
|
expand=True,
|
||||||
content = QuickViewGramplet,
|
content = QuickViewGramplet,
|
||||||
title=_("Quick View"),
|
title=_("Quick View"),
|
||||||
detached_width = 600,
|
detached_width = 600,
|
||||||
|
Loading…
Reference in New Issue
Block a user