From 6244a0c033eff970b0631117e65b8a8fb445d91f Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 13 Dec 2008 16:59:14 +0000 Subject: [PATCH] Added a Gramplet that can run a Quick View svn: r11466 --- src/DataViews/GrampletView.py | 11 ++- src/QuickReports.py | 40 +++++++-- src/Simple/_SimpleTable.py | 5 +- src/docgen/TextBufDoc.py | 16 +++- src/glade/gramps.glade | 145 ++++++++++++++++---------------- src/plugins/DefaultGramplets.py | 54 ++++++++++-- 6 files changed, 180 insertions(+), 91 deletions(-) diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index 09e1a722a..b4a9e32ab 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -234,7 +234,7 @@ class Gramplet(object): # 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.option_vbox.add(gtk.Label(item)) + 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) @@ -474,8 +474,8 @@ class Gramplet(object): return True return False # did not handle event - def set_options(self, option_dict): - self.option_dict = option_dict + def set_option(self, option_dict): + self.option_dict.update(option_dict) def logical_true(value): return value in ["True", True, 1, "1"] @@ -511,10 +511,10 @@ class GuiGramplet: self.xml = glade.XML(const.GLADE_FILE, 'gvgramplet', "gramps") self.mainframe = self.xml.get_widget('gvgramplet') self.gvoptions = self.xml.get_widget('gvoptions') - self.option_vbox = self.xml.get_widget('option_vbox') self.textview = self.xml.get_widget('gvtextview') self.buffer = self.textview.get_buffer() self.scrolledwindow = self.xml.get_widget('gvscrolledwindow') + self.vboxtop = self.xml.get_widget('vboxtop') self.titlelabel = self.xml.get_widget('gvtitle') self.titlelabel.set_text("%s" % self.title) self.titlelabel.set_use_markup(True) @@ -719,6 +719,9 @@ class GuiGramplet: """ return self.gvproperties + def get_container_widget(self): + return self.scrolledwindow + class MyScrolledWindow(gtk.ScrolledWindow): def show_all(self): # first show them all: diff --git a/src/QuickReports.py b/src/QuickReports.py index 9a818d8c3..7d6695a32 100644 --- a/src/QuickReports.py +++ b/src/QuickReports.py @@ -108,6 +108,20 @@ def by_menu_name(first, second): def make_quick_report_callback(lst, category, dbstate, uistate, handle): return lambda x: run_report(dbstate, uistate, category, handle, lst[0]) +def get_quick_report_list(qv_category=None): + """ + Returns a list of quick views: [(translated name, category, name, status)] + CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, CATEGORY_QR_EVENT, + CATEGORY_QR_SOURCE, CATEGORY_QR_MISC, CATEGORY_QR_PLACE, + CATEGORY_QR_REPOSITORY or None for all + """ + names = [] + pmgr = PluginManager.get_instance() + for item in pmgr.get_quick_report_list(): + if qv_category == item[2] or qv_category == None: + names.append(item[1:]) # (see below for item struct) + return names + def run_quick_report_by_name(dbstate, uistate, report_name, handle, **kwargs): # [0] - function # [1] - translated name @@ -150,13 +164,24 @@ def run_quick_report_by_name_direct(report_name, database, document, handle): raise AttributeError, ("No such quick report '%s'" % report_name) def run_report(dbstate, uistate, category, handle, func, **kwargs): + """ + Run a Quick Report. + kwargs can take an optional document=obj to pass the report + the document, rather than putting it in a new window. + """ from docgen import TextBufDoc from Simple import make_basic_stylesheet - + container = None if handle: d = TextBufDoc(make_basic_stylesheet(), None, None) d.dbstate = dbstate d.uistate = uistate + if "container" in kwargs: + container = kwargs["container"] + del kwargs["container"] + d.change_active = False + else: + d.change_active = True if isinstance(handle, basestring): # a handle if category == CATEGORY_QR_PERSON : obj = dbstate.db.get_person_from_handle(handle) @@ -177,10 +202,15 @@ def run_report(dbstate, uistate, category, handle, func, **kwargs): else: # allow caller to send object directly obj = handle if obj: - d.open("") - retval = func(dbstate.db, d, obj, **kwargs) - d.close() - return retval + if container: + result = d.open("", container=container) + func(dbstate.db, d, obj, **kwargs) + return result + else: + d.open("") + retval = func(dbstate.db, d, obj, **kwargs) + d.close() + return retval else: print "QuickView Error: failed to run report: no obj" else: diff --git a/src/Simple/_SimpleTable.py b/src/Simple/_SimpleTable.py index a022dcc4d..8f4f794fc 100644 --- a/src/Simple/_SimpleTable.py +++ b/src/Simple/_SimpleTable.py @@ -152,8 +152,9 @@ class SimpleTable: elif self.__link[index]: objclass, handle = self.__link[index] if objclass == 'Person': - person = self.access.dbase.get_person_from_handle(handle) - self.simpledoc.doc.dbstate.change_active_person(person) + if self.simpledoc.doc.change_active: + person = self.access.dbase.get_person_from_handle(handle) + self.simpledoc.doc.dbstate.change_active_person(person) return True return False # didn't handle event diff --git a/src/docgen/TextBufDoc.py b/src/docgen/TextBufDoc.py index 7ef36554a..5d59b7335 100644 --- a/src/docgen/TextBufDoc.py +++ b/src/docgen/TextBufDoc.py @@ -81,6 +81,13 @@ class DisplayBuf(ManagedWindow.ManagedWindow): def get_title(self): return self.title +class DocumentManager: + def __init__(self, title, document, text_view): + self.title = title + self.document = document + document.text_view = text_view + text_view.set_buffer(document.buffer) + #------------------------------------------------------------------------ # # TextBuf @@ -93,7 +100,7 @@ class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc): # Opens the file, resets the text buffer. # #-------------------------------------------------------------------- - def open(self, filename): + def open(self, filename, container=None): self.type = "gtk" self.tag_table = gtk.TextTagTable() @@ -147,8 +154,11 @@ class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc): self.tag_table.add(tag) self.buffer = gtk.TextBuffer(self.tag_table) - DisplayBuf(_('Quick View'), self) - return + if container: + return DocumentManager(_('Quick View'), self, container) + else: + DisplayBuf(_('Quick View'), self) + return #-------------------------------------------------------------------- # diff --git a/src/glade/gramps.glade b/src/glade/gramps.glade index 199393d31..8b3443a53 100644 --- a/src/glade/gramps.glade +++ b/src/glade/gramps.glade @@ -16198,31 +16198,85 @@ Very High GTK_SHADOW_IN - + True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT + False + 0 - + True - False - False - True - GTK_JUSTIFY_LEFT - GTK_WRAP_WORD - True - 0 - 0 - 0 - 0 - 0 - 0 - + True + False + 0 + + + + + + + + True + Options + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + 0 + False + False + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + False + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0 + True + True + @@ -16350,57 +16404,6 @@ Very High True - - - - 10 - True - True - False - 0 - - - - 4 - True - True - 0 - - - - - - - - - - True - Options - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - - - - 0 - False - True - - diff --git a/src/plugins/DefaultGramplets.py b/src/plugins/DefaultGramplets.py index 60a41afb6..9594b9251 100644 --- a/src/plugins/DefaultGramplets.py +++ b/src/plugins/DefaultGramplets.py @@ -25,7 +25,7 @@ import cgi from BasicUtils import name_displayer from DataViews import register, Gramplet from PluginUtils import * -from QuickReports import run_quick_report_by_name +from QuickReports import run_quick_report_by_name, get_quick_report_list from ReportBase import ReportUtils from TransUtils import sgettext as _ from Utils import media_path_full @@ -83,8 +83,8 @@ class CalendarGramplet(Gramplet): for signal in db_signals: self.dbstate.db.connect(signal, lambda *args: self.run_update(signal, *args)) - self.gui.scrolledwindow.remove(self.gui.textview) - self.gui.scrolledwindow.add_with_viewport(self.gui.calendar) + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(self.gui.calendar) self.gui.calendar.show() self.birthdays = True self.dates = {} @@ -469,7 +469,7 @@ class PedigreeGramplet(Gramplet): self.max_generations = 100 self.show_dates = 1 self.box_mode = "UTF" - #self.set_option("max_generations", + self.set_option({"Max generations": 100}) # NumberOption(_("Maximum generations"), # 100, -1, 500)) @@ -685,6 +685,7 @@ class StatsGramplet(Gramplet): def db_changed(self): self.dbstate.db.connect('person-add', self.update) + self.dbstate.db.connect('person-edit', self.update) self.dbstate.db.connect('person-delete', self.update) self.dbstate.db.connect('family-add', self.update) self.dbstate.db.connect('family-delete', self.update) @@ -1104,8 +1105,8 @@ class AgeOnDateGramplet(Gramplet): vbox.pack_start(description, True) vbox.pack_start(hbox, False) vbox.pack_start(button, False) - self.gui.scrolledwindow.remove(self.gui.textview) - self.gui.scrolledwindow.add_with_viewport(vbox) + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(vbox) vbox.show_all() def run(self, obj): @@ -1116,6 +1117,37 @@ class AgeOnDateGramplet(Gramplet): 'ageondate', 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) + register(type="gramplet", name= "Top Surnames Gramplet", tname=_("Top Surnames Gramplet"), @@ -1241,3 +1273,13 @@ register(type="gramplet", detached_height = 400, ) +register(type="gramplet", + name="Quick View Gramplet", + tname=_("Quick View Gramplet"), + height=300, + content = QuickViewGramplet, + title=_("Quick View"), + detached_width = 600, + detached_height = 400, + ) +