Added a Gramplet that can run a Quick View
svn: r11466
This commit is contained in:
parent
246b3e0bd5
commit
6244a0c033
@ -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("<b><i>%s</i></b>" % 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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
#
|
||||
|
@ -16198,31 +16198,85 @@ Very High</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="gvscrolledwindow">
|
||||
<widget class="GtkVBox" id="vbox143">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_NONE</property>
|
||||
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTextView" id="gvtextview">
|
||||
<widget class="GtkExpander" id="gvoptions">
|
||||
<property name="visible">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="overwrite">False</property>
|
||||
<property name="accepts_tab">True</property>
|
||||
<property name="justification">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap_mode">GTK_WRAP_WORD</property>
|
||||
<property name="cursor_visible">True</property>
|
||||
<property name="pixels_above_lines">0</property>
|
||||
<property name="pixels_below_lines">0</property>
|
||||
<property name="pixels_inside_wrap">0</property>
|
||||
<property name="left_margin">0</property>
|
||||
<property name="right_margin">0</property>
|
||||
<property name="indent">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="expanded">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="vboxtop">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Options</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="type">label_item</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="gvscrolledwindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_NONE</property>
|
||||
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTextView" id="gvtextview">
|
||||
<property name="visible">True</property>
|
||||
<property name="editable">False</property>
|
||||
<property name="overwrite">False</property>
|
||||
<property name="accepts_tab">True</property>
|
||||
<property name="justification">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap_mode">GTK_WRAP_WORD</property>
|
||||
<property name="cursor_visible">True</property>
|
||||
<property name="pixels_above_lines">0</property>
|
||||
<property name="pixels_below_lines">0</property>
|
||||
<property name="pixels_inside_wrap">0</property>
|
||||
<property name="left_margin">0</property>
|
||||
<property name="right_margin">0</property>
|
||||
<property name="indent">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
@ -16350,57 +16404,6 @@ Very High</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkExpander" id="gvoptions">
|
||||
<property name="border_width">10</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="expanded">False</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkVBox" id="option_vbox">
|
||||
<property name="border_width">4</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">True</property>
|
||||
<property name="spacing">0</property>
|
||||
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label18">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Options</property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0.5</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="type">label_item</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
|
@ -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,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user