GEPS008: Re-structure Simple access and Quick Reports

svn: r19732
This commit is contained in:
Nick Hall 2012-05-31 23:46:57 +00:00
parent eba22c4062
commit 65d707d649
47 changed files with 847 additions and 728 deletions

View File

@ -119,6 +119,7 @@ src/gen/plug/docgen/Makefile
src/gen/plug/menu/Makefile src/gen/plug/menu/Makefile
src/gen/plug/report/Makefile src/gen/plug/report/Makefile
src/gen/proxy/Makefile src/gen/proxy/Makefile
src/gen/simple/Makefile
src/gen/utils/Makefile src/gen/utils/Makefile
src/gui/Makefile src/gui/Makefile
src/gui/editors/Makefile src/gui/editors/Makefile
@ -129,13 +130,13 @@ src/gui/glade/Makefile
src/gui/logger/Makefile src/gui/logger/Makefile
src/gui/merge/Makefile src/gui/merge/Makefile
src/gui/plug/Makefile src/gui/plug/Makefile
src/gui/plug/quick/Makefile
src/gui/plug/report/Makefile src/gui/plug/report/Makefile
src/gui/selectors/Makefile src/gui/selectors/Makefile
src/gui/views/Makefile src/gui/views/Makefile
src/gui/views/treemodels/Makefile src/gui/views/treemodels/Makefile
src/gui/widgets/Makefile src/gui/widgets/Makefile
src/docgen/Makefile src/docgen/Makefile
src/Simple/Makefile
src/plugins/Makefile src/plugins/Makefile
src/plugins/docgen/Makefile src/plugins/docgen/Makefile
src/plugins/drawreport/Makefile src/plugins/drawreport/Makefile

View File

@ -328,6 +328,10 @@ src/gen/plug/report/utils.py
# gen proxy API # gen proxy API
src/gen/proxy/private.py src/gen/proxy/private.py
# gen.simple
src/gen/simple/_simpleaccess.py
src/gen/simple/_simpletable.py
# gui - GUI code # gui - GUI code
src/gui/aboutdialog.py src/gui/aboutdialog.py
src/gui/columnorder.py src/gui/columnorder.py
@ -426,6 +430,9 @@ src/gui/merge/mergesource.py
src/gui/plug/_dialogs.py src/gui/plug/_dialogs.py
src/gui/plug/_guioptions.py src/gui/plug/_guioptions.py
src/gui/plug/_windows.py src/gui/plug/_windows.py
src/gui/plug/quick/_quickreports.py
src/gui/plug/quick/_quicktable.py
src/gui/plug/quick/_textbufdoc.py
src/gui/plug/report/_docreportdialog.py src/gui/plug/report/_docreportdialog.py
src/gui/plug/report/_graphvizreportdialog.py src/gui/plug/report/_graphvizreportdialog.py
src/gui/plug/report/_papermenu.py src/gui/plug/report/_papermenu.py
@ -471,9 +478,6 @@ src/gui/widgets/tageditor.py
src/gui/widgets/undoableentry.py src/gui/widgets/undoableentry.py
src/gui/widgets/validatedmaskedentry.py src/gui/widgets/validatedmaskedentry.py
# Simple API
src/Simple/_SimpleTable.py
# Config package # Config package
src/config.py src/config.py

View File

@ -220,6 +220,10 @@ src/gen/proxy/filter.py
src/gen/proxy/living.py src/gen/proxy/living.py
src/gen/proxy/proxybase.py src/gen/proxy/proxybase.py
# gen.simple
src/gen/simple/__init__.py
src/gen/simple/_simpledoc.py
# gen utils API # gen utils API
src/gen/utils/__init__.py src/gen/utils/__init__.py
src/gen/utils/callback.py src/gen/utils/callback.py
@ -362,9 +366,6 @@ src/plugins/rel/rel_ru.py
src/plugins/rel/rel_sk.py src/plugins/rel/rel_sk.py
src/plugins/rel/rel_sv.py src/plugins/rel/rel_sv.py
# Simple API
src/Simple/_SimpleDoc.py
# #
# web # web
# #

View File

@ -217,7 +217,7 @@ class WriterOptionBox(object):
def show_preview_data(self, widget): def show_preview_data(self, widget):
from DbState import DbState from DbState import DbState
from QuickReports import run_quick_report_by_name from gui.plug.quick import run_quick_report_by_name
if widget.proxy_name == "unfiltered": if widget.proxy_name == "unfiltered":
dbstate = self.dbstate dbstate = self.dbstate
else: else:

View File

@ -8,8 +8,7 @@ SUBDIRS = \
gen \ gen \
gui \ gui \
images \ images \
plugins \ plugins
Simple
gdirdir=$(prefix)/share/gramps gdirdir=$(prefix)/share/gramps
@ -38,7 +37,6 @@ gdir_PYTHON = \
MacTransUtils.py\ MacTransUtils.py\
ManagedWindow.py\ ManagedWindow.py\
QuestionDialog.py\ QuestionDialog.py\
QuickReports.py\
RecentFiles.py\ RecentFiles.py\
Relationship.py\ Relationship.py\
Reorder.py\ Reorder.py\

View File

@ -722,7 +722,7 @@ class ScratchFamilyLink(ScratchHandleWrapper):
self.refresh() self.refresh()
def refresh(self): def refresh(self):
from Simple import SimpleAccess from gen.simple import SimpleAccess
if self._handle: if self._handle:
family = self._db.get_family_from_handle(self._handle) family = self._db.get_family_from_handle(self._handle)
if family: if family:

View File

@ -1,21 +0,0 @@
# This is the src/Report level Makefile for Gramps
# $Id$
pkgpythondir = $(datadir)/@PACKAGE@/Simple
pkgpython_PYTHON = \
_SimpleDoc.py\
_SimpleAccess.py\
_SimpleTable.py\
__init__.py
pkgpyexecdir = @pkgpyexecdir@/Simple
# Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = "../"
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
pychecker $(pkgpython_PYTHON));

View File

@ -1,636 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2008 Donald N. Allingham
# Copyright (C) 2009 Douglas S. Blank
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Simple/_SimpleTable.py
# $Id$
#
"""
Provide a simplified table creation interface
"""
import cgi
import copy
from gen.ggettext import sgettext as _
from TransUtils import trans_objclass
import cPickle as pickle
import gen.lib
import Errors
import config
import gen.datehandler
class SimpleTable(object):
"""
Provide a simplified table creation interface.
"""
def __init__(self, access, title=None):
"""
Initialize the class with a simpledb
"""
self.access = access
self.title = title
self.__columns = []
self.__cell_markup = {} # [col][row] = "<b>data</b>"
self.__cell_type = {} # [col] = "text"
self.__rows = []
self.__raw_data = []
self.__link = []
self.__sort_col = None
self.__sort_reverse = False
self.__link_col = None
self._callback_leftclick = None
self._callback_leftdouble = None
self.model_index_of_column = {}
def get_row_count(self):
return len(self.__rows)
def get_row(self, index):
return self.__rows[index]
def get_raw_data(self, index):
return self.__raw_data[index]
def columns(self, *cols):
"""
Set the columns
"""
self.__columns = [unicode(col) for col in cols]
self.__sort_vals = [[] for i in range(len(self.__columns))]
def set_callback(self, which, callback):
"""
Override (or add) a function for click/double-click
"""
if which == "leftclick":
self._callback_leftclick = callback
elif which == "leftdouble":
self._callback_leftdouble = callback
def button_press_event(self, treeview, event):
import gtk
index = None
button_code = None
event_time = None
func = None
if type(event) == bool: # enter
button_code = 3
event_time = 0
selection = treeview.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if node:
treeview.grab_focus()
index = store.get_value(node, 0)
# FIXME: make popup come where cursor is
#rectangle = treeview.get_visible_rect()
#column = treeview.get_column(0)
#rectangle = treeview.get_cell_area("0:0",
#x, y = rectangle.x, rectangle.y
#func = lambda menu: (x, y, True)
elif event.button == 3:
button_code = 3
event_time = event.time
x = int(event.x)
y = int(event.y)
path_info = treeview.get_path_at_pos(x, y)
func = None
if path_info is not None:
path, col, cellx, celly = path_info
selection = treeview.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if path:
treeview.grab_focus()
treeview.set_cursor(path, col, 0)
if store and node:
index = store.get_value(node, 0) # index Below,
# you need index, treeview, path, button_code,
# func, and event_time
if index is not None:
popup = gtk.Menu()
if (index is not None and self.__link[index]):
# See details (edit, etc):
objclass, handle = self.__link[index]
menu_item = gtk.MenuItem(_("the object|See %s details") % trans_objclass(objclass))
menu_item.connect("activate",
lambda widget: self.on_table_doubleclick(treeview))
popup.append(menu_item)
menu_item.show()
# Add other items to menu:
if (self._callback_leftclick or
(index is not None and self.__link[index])):
objclass, handle = self.__link[index]
if objclass == 'Person':
menu_item = gtk.MenuItem(_("the object|Make %s active") % trans_objclass('Person'))
menu_item.connect("activate",
lambda widget: self.on_table_click(treeview))
popup.append(menu_item)
menu_item.show()
if (self.simpledoc.doc.dbstate.db !=
self.simpledoc.doc.dbstate.db.basedb and
(index is not None and self.__link[index])):
objclass, handle = self.__link[index]
if (objclass == 'Filter' and
handle[0] in ['Person', 'Family', 'Place', 'Event',
'Repository', 'Note', 'MediaObject',
'Citation', 'Source']):
menu_item = gtk.MenuItem(_("See data not in Filter"))
menu_item.connect("activate",
lambda widget: self.show_not_in_filter(handle[0]))
popup.append(menu_item)
menu_item.show()
# Show the popup menu:
popup.popup(None, None, func, button_code, event_time)
return True
return False
def show_not_in_filter(self, obj_class):
from QuickReports import run_quick_report_by_name
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
'Inverse %s' % obj_class)
def on_table_doubleclick(self, obj):
"""
Handle events on tables. obj is a treeview
"""
from gui.editors import (EditPerson, EditEvent, EditFamily, EditCitation, EditSource,
EditPlace, EditRepository, EditNote, EditMedia)
selection = obj.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if not node:
return
index = store.get_value(node, 0) # index
if self._callback_leftdouble:
self._callback_leftdouble(store.get_value(node, 1))
return True
elif self.__link[index]:
objclass, handle = self.__link[index]
if isinstance(handle, list):
handle = handle[0]
if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle)
if person:
try:
EditPerson(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], person)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Event':
event = self.access.dbase.get_event_from_handle(handle)
if event:
try:
EditEvent(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], event)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Family':
ref = self.access.dbase.get_family_from_handle(handle)
if ref:
try:
EditFamily(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Citation':
ref = self.access.dbase.get_citation_from_handle(handle)
if ref:
try:
EditCitation(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Source':
ref = self.access.dbase.get_source_from_handle(handle)
if ref:
try:
EditSource(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Place':
ref = self.access.dbase.get_place_from_handle(handle)
if ref:
try:
EditPlace(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Repository':
ref = self.access.dbase.get_repository_from_handle(handle)
if ref:
try:
EditRepository(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Note':
ref = self.access.dbase.get_note_from_handle(handle)
if ref:
try:
EditNote(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass in ['Media', 'MediaObject']:
ref = self.access.dbase.get_object_from_handle(handle)
if ref:
try:
EditMedia(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'PersonList':
from QuickReports import run_quick_report_by_name
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
'list of people',
handles=handle)
elif objclass == 'Filter':
from QuickReports import run_quick_report_by_name
if isinstance(handle, list):
handle = handle[0]
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
handle)
return False # didn't handle event
def on_table_click(self, obj):
"""
Handle events on tables. obj is a treeview
"""
selection = obj.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath)
if not node:
return
index = store.get_value(node, 0) # index
if self._callback_leftclick:
self._callback_leftclick(store.get_value(node, 1))
return True
elif self.__link[index]:
objclass, handle = self.__link[index]
if isinstance(handle, list):
handle = handle[0]
if objclass == 'Person':
import gobject
# If you emmit the signal here and it causes this table to be deleted,
# then you'll crash Python:
#self.simpledoc.doc.uistate.set_active(handle, 'Person')
# So, let's return from this, then change the active person:
return gobject.timeout_add(100, self.simpledoc.doc.uistate.set_active, handle, 'Person')
return True
return False # didn't handle event
def row_sort_val(self, col, val):
"""
Add a row of data to sort by.
"""
self.__sort_vals[col].append(val)
def set_link_col(self, col):
"""
Manually sets the column that defines link.
col is either a number (column) or a (object_type_name, handle).
"""
self.__link_col = col
def row(self, *data):
"""
Add a row of data.
"""
retval = []
link = None
row = len(self.__rows)
self.__raw_data.append([])
for col in range(len(data)):
item = data[col]
self.__raw_data[-1].append(item)
# FIXME: add better text representations of these objects
if item is None:
retval.append("")
elif isinstance(item, basestring):
if item == "checkbox":
retval.append("")
self.set_cell_type(col, "checkbox")
else:
retval.append(item)
elif isinstance(item, (int, float, long)):
retval.append(item)
self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Family', item.handle)
elif isinstance(item, gen.lib.Citation):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Citation', item.handle)
elif isinstance(item, gen.lib.Source):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Source', item.handle)
elif isinstance(item, gen.lib.Event):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note):
retval.append(self.access.describe(item))
if (self.__link_col == col or link is None):
link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date):
text = gen.datehandler.displayer.display(item)
retval.append(text)
if item.get_valid():
if item.format:
self.set_cell_markup(col, row,
item.format % cgi.escape(text))
self.row_sort_val(col, item.sortval)
else:
# sort before others:
self.row_sort_val(col, -1)
# give formatted version:
invalid_date_format = config.get('preferences.invalid-date-format')
self.set_cell_markup(col, row,
invalid_date_format % cgi.escape(text))
if (self.__link_col == col or link is None):
link = ('Date', item)
elif isinstance(item, gen.lib.Span):
text = str(item)
retval.append(text)
self.row_sort_val(col, item)
elif isinstance(item, list): # [text, "PersonList", handle, ...]
retval.append(item[0])
link = (item[1], item[2:])
else:
retval.append(str(item))
if (self.__link_col == col or link is None):
if hasattr(item, "get_url"):
link = ("url", item.get_url())
self.__link.append(link)
self.__rows.append(retval)
def sort(self, column_name, reverse=False):
self.__sort_col = column_name
self.__sort_reverse = reverse
def __sort(self):
idx = self.__columns.index(self.__sort_col)
# FIXME: move raw_data with this
if self.__sort_reverse:
self.__rows.sort(lambda a, b: -cmp(a[idx],b[idx]))
else:
self.__rows.sort(lambda a, b: cmp(a[idx],b[idx]))
def toggle(self, obj, path, col):
"""
obj - column widget
path - row
col - column
"""
self.treeview.get_model()[path][col] = not \
self.treeview.get_model()[path][col]
def write(self, document):
self.simpledoc = document # simpledoc; simpledoc.doc = docgen object
if self.simpledoc.doc.type == "standard":
doc = self.simpledoc.doc
columns = len(self.__columns)
doc.start_table('simple', 'Table')
doc._tbl.set_column_widths([100/columns] * columns)
doc._tbl.set_columns(columns)
if self.title:
doc.start_row()
doc.start_cell('TableHead', span=columns)
doc.start_paragraph('TableTitle')
doc.write_text(_(self.title))
doc.end_paragraph()
doc.end_cell()
doc.end_row()
if self.__sort_col:
self.__sort()
doc.start_row()
for col in self.__columns:
doc.start_cell('TableHeaderCell', span=1)
doc.write_text(col, 'TableTitle')
doc.end_cell()
doc.end_row()
index = 0
for row in self.__rows:
doc.start_row()
for col in row:
doc.start_cell('TableDataCell', span=1)
obj_type, handle = None, None
if isinstance(self.__link_col, tuple):
obj_type, handle = self.__link_col
elif isinstance(self.__link_col, list):
obj_type, handle = self.__link_col[index]
elif self.__link[index]:
obj_type, handle = self.__link[index]
######
if obj_type:
if obj_type.lower() == "url":
doc.start_link(handle)
else:
doc.start_link("/%s/%s" %
(obj_type.lower(), handle))
doc.write_text(col, 'Normal')
if obj_type:
doc.stop_link()
doc.end_cell()
doc.end_row()
index += 1
doc.end_table()
doc.start_paragraph("Normal")
doc.end_paragraph()
elif self.simpledoc.doc.type == "gtk":
import gtk
from gui.widgets.multitreeview import MultiTreeView
from ScratchPad import ScratchPadListView, ACTION_COPY
from DdTargets import DdTargets
buffer = self.simpledoc.doc.buffer
text_view = self.simpledoc.doc.text_view
model_index = 1 # start after index
if self.__sort_col:
sort_index = self.__columns.index(self.__sort_col)
else:
sort_index = 0
treeview = MultiTreeView()
treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[(DdTargets.HANDLE_LIST.drag_type, gtk.TARGET_SAME_WIDGET, 0)],
gtk.gdk.ACTION_COPY)
#treeview.enable_model_drag_dest(DdTargets.all_targets(),
# gtk.gdk.ACTION_DEFAULT)
treeview.connect('drag_data_get', self.object_drag_data_get)
treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
#treeview.connect('row-activated', on_table_doubleclick, self)
#treeview.connect('cursor-changed', on_table_click, self)
treeview.connect('button-press-event', self.button_press_event)
treeview.connect('select-cursor-row', self.button_press_event)
renderer = gtk.CellRendererText()
types = [int] # index
cnt = 0
sort_data = []
sort_data_types = []
for col in self.__columns:
if self.get_cell_type(cnt) == "text":
types.append(str)
if self.get_cell_markup(cnt):
column = gtk.TreeViewColumn(col,renderer,markup=model_index)
else:
column = gtk.TreeViewColumn(col,renderer,text=model_index)
elif self.get_cell_type(cnt) == "checkbox":
types.append(bool)
toggle_renderer = gtk.CellRendererToggle()
toggle_renderer.set_property('activatable', True)
toggle_renderer.connect("toggled", self.toggle, model_index)
column = gtk.TreeViewColumn(col, toggle_renderer)
column.add_attribute(toggle_renderer, "active", model_index)
column.set_resizable(True)
if self.__sort_vals[cnt] != []:
sort_data.append(self.__sort_vals[cnt])
column.set_sort_column_id(len(self.__columns) +
len(sort_data))
sort_data_types.append(int)
else:
column.set_sort_column_id(model_index)
treeview.append_column(column)
self.model_index_of_column[col] = model_index
#if model_index == sort_index:
# FIXME: what to set here?
model_index += 1
cnt += 1
if self.title:
self.simpledoc.paragraph(self.title)
# Make a GUI to put the tree view in
types += sort_data_types
model = gtk.ListStore(*types)
treeview.set_model(model)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
iter = buffer.get_end_iter()
anchor = buffer.create_child_anchor(iter)
text_view.add_child_at_anchor(treeview, anchor)
self.treeview= treeview
count = 0
for data in self.__rows:
col = 0
rowdata = []
for cell in data:
rowdata.append(self.get_cell_markup(col, count, cell))
col += 1
try:
model.append(row=([count] + list(rowdata) + [col[count] for col in sort_data]))
except:
print "error in row %d: data: %s, sort data: %d" % (count, rowdata, len(sort_data[0]))
count += 1
text_view.show_all()
self.simpledoc.paragraph("")
self.simpledoc.paragraph("")
def object_drag_data_get(self, widget, context, sel_data, info, time):
tree_selection = widget.get_selection()
model, paths = tree_selection.get_selected_rows()
retval = []
for path in paths:
node = model.get_iter(path)
index = model.get_value(node,0)
if (index is not None and self.__link[index]):
retval.append(self.__link[index])
sel_data.set(sel_data.target, 8, pickle.dumps(retval))
return True
def get_cell_markup(self, x, y=None, data=None):
"""
See if a column has formatting (if x and y are supplied) or
see if a cell has formatting. If it does, return the formatted
string, otherwise return data that is escaped (if that column
has formatting), or just the plain data.
"""
if x in self.__cell_markup:
if y is None:
return True # markup for this column
elif y in self.__cell_markup[x]:
return self.__cell_markup[x][y]
else:
return cgi.escape(data)
else:
if y is None:
return False # no markup for this column
else:
return data
def get_cell_type(self, col):
"""
See if a column has a type, else return "text" as default.
"""
if col in self.__cell_type:
return self.__cell_type[col]
return "text"
def set_cell_markup(self, x, y, data):
"""
Set the cell at position [x][y] to a formatted string.
"""
col_dict = self.__cell_markup.get(x, {})
col_dict[y] = data
self.__cell_markup[x] = col_dict
def set_cell_type(self, col, value):
"""
Set the cell type at position [x].
"""
self.__cell_type[col] = value

View File

@ -9,8 +9,7 @@ docgen_PYTHON = \
__init__.py \ __init__.py \
CSVTab.py \ CSVTab.py \
ODSTab.py \ ODSTab.py \
TabbedDoc.py \ TabbedDoc.py
TextBufDoc.py
# Clean up all the byte-compiled files # Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo MOSTLYCLEANFILES = *pyc *pyo

View File

@ -22,5 +22,4 @@
from TabbedDoc import TabbedDoc from TabbedDoc import TabbedDoc
from ODSTab import ODSTab from ODSTab import ODSTab
from TextBufDoc import TextBufDoc
from CSVTab import CSVTab from CSVTab import CSVTab

View File

@ -15,6 +15,7 @@ SUBDIRS = \
mime \ mime \
plug \ plug \
proxy \ proxy \
simple \
utils utils
pkgpythondir = $(datadir)/@PACKAGE@/gen pkgpythondir = $(datadir)/@PACKAGE@/gen

View File

@ -27,4 +27,4 @@ interfaces (gui, cli and web).
""" """
__all__ = [ "datehandler", "db", "display", "filters", "lib", "locale", "merge", __all__ = [ "datehandler", "db", "display", "filters", "lib", "locale", "merge",
"mime", "plug", "proxy", "utils" ] "mime", "plug", "proxy", "simple", "utils" ]

View File

@ -0,0 +1,21 @@
# This is the src/gen/simple level Makefile for Gramps
# $Id$
pkgpythondir = $(datadir)/@PACKAGE@/gen/simple
pkgpython_PYTHON = \
_simpledoc.py\
_simpleaccess.py\
_simpletable.py\
__init__.py
pkgpyexecdir = @pkgpyexecdir@/gen/simple
# Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = "../../"
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
pychecker $(pkgpython_PYTHON));

View File

@ -23,7 +23,7 @@
"Simple access routines" "Simple access routines"
from _SimpleAccess import * from _simpleaccess import *
from _SimpleDoc import * from _simpledoc import *
from _SimpleTable import * from _simpletable import *

View File

@ -19,7 +19,6 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# Simple/_SimpleAccess.py
# $Id$ # $Id$
# #

View File

@ -17,7 +17,6 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# Simple/_SimpleDoc.py
# $Id$ # $Id$
# #

View File

@ -0,0 +1,282 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2008 Donald N. Allingham
# Copyright (C) 2009 Douglas S. Blank
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
#
"""
Provide a simplified table creation interface
"""
import cgi
from gen.ggettext import sgettext as _
import gen.lib
import config
import gen.datehandler
class SimpleTable(object):
"""
Provide a simplified table creation interface.
"""
def __init__(self, access, title=None):
"""
Initialize the class with a simpledb
"""
self.access = access
self.title = title
self._columns = []
self._cell_markup = {} # [col][row] = "<b>data</b>"
self._cell_type = {} # [col] = "text"
self._rows = []
self._raw_data = []
self._link = []
self._sort_col = None
self._sort_reverse = False
self._link_col = None
self._callback_leftclick = None
self._callback_leftdouble = None
self.model_index_of_column = {}
def get_row_count(self):
return len(self._rows)
def get_row(self, index):
return self._rows[index]
def get_raw_data(self, index):
return self._raw_data[index]
def columns(self, *cols):
"""
Set the columns
"""
self._columns = [unicode(col) for col in cols]
self._sort_vals = [[] for i in range(len(self._columns))]
def row_sort_val(self, col, val):
"""
Add a row of data to sort by.
"""
self._sort_vals[col].append(val)
def set_link_col(self, col):
"""
Manually sets the column that defines link.
col is either a number (column) or a (object_type_name, handle).
"""
self._link_col = col
def row(self, *data):
"""
Add a row of data.
"""
retval = []
link = None
row = len(self._rows)
self._raw_data.append([])
for col in range(len(data)):
item = data[col]
self._raw_data[-1].append(item)
# FIXME: add better text representations of these objects
if item is None:
retval.append("")
elif isinstance(item, basestring):
if item == "checkbox":
retval.append("")
self.set_cell_type(col, "checkbox")
else:
retval.append(item)
elif isinstance(item, (int, float, long)):
retval.append(item)
self.row_sort_val(col, item)
elif isinstance(item, gen.lib.Person):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Person', item.handle)
elif isinstance(item, gen.lib.Family):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Family', item.handle)
elif isinstance(item, gen.lib.Citation):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Citation', item.handle)
elif isinstance(item, gen.lib.Source):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Source', item.handle)
elif isinstance(item, gen.lib.Event):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Event', item.handle)
elif isinstance(item, gen.lib.MediaObject):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Media', item.handle)
elif isinstance(item, gen.lib.Place):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Place', item.handle)
elif isinstance(item, gen.lib.Repository):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Repository', item.handle)
elif isinstance(item, gen.lib.Note):
retval.append(self.access.describe(item))
if (self._link_col == col or link is None):
link = ('Note', item.handle)
elif isinstance(item, gen.lib.Date):
text = gen.datehandler.displayer.display(item)
retval.append(text)
if item.get_valid():
if item.format:
self.set_cell_markup(col, row,
item.format % cgi.escape(text))
self.row_sort_val(col, item.sortval)
else:
# sort before others:
self.row_sort_val(col, -1)
# give formatted version:
invalid_date_format = config.get('preferences.invalid-date-format')
self.set_cell_markup(col, row,
invalid_date_format % cgi.escape(text))
if (self._link_col == col or link is None):
link = ('Date', item)
elif isinstance(item, gen.lib.Span):
text = str(item)
retval.append(text)
self.row_sort_val(col, item)
elif isinstance(item, list): # [text, "PersonList", handle, ...]
retval.append(item[0])
link = (item[1], item[2:])
else:
retval.append(str(item))
if (self._link_col == col or link is None):
if hasattr(item, "get_url"):
link = ("url", item.get_url())
self._link.append(link)
self._rows.append(retval)
def sort(self, column_name, reverse=False):
self._sort_col = column_name
self._sort_reverse = reverse
def _sort(self):
idx = self._columns.index(self._sort_col)
# FIXME: move raw_data with this
if self._sort_reverse:
self._rows.sort(lambda a, b: -cmp(a[idx],b[idx]))
else:
self._rows.sort(lambda a, b: cmp(a[idx],b[idx]))
def write(self, document):
doc = document.doc
columns = len(self._columns)
doc.start_table('simple', 'Table')
doc._tbl.set_column_widths([100/columns] * columns)
doc._tbl.set_columns(columns)
if self.title:
doc.start_row()
doc.start_cell('TableHead', span=columns)
doc.start_paragraph('TableTitle')
doc.write_text(_(self.title))
doc.end_paragraph()
doc.end_cell()
doc.end_row()
if self._sort_col:
self._sort()
doc.start_row()
for col in self._columns:
doc.start_cell('TableHeaderCell', span=1)
doc.write_text(col, 'TableTitle')
doc.end_cell()
doc.end_row()
index = 0
for row in self._rows:
doc.start_row()
for col in row:
doc.start_cell('TableDataCell', span=1)
obj_type, handle = None, None
if isinstance(self._link_col, tuple):
obj_type, handle = self._link_col
elif isinstance(self._link_col, list):
obj_type, handle = self._link_col[index]
elif self._link[index]:
obj_type, handle = self._link[index]
######
if obj_type:
if obj_type.lower() == "url":
doc.start_link(handle)
else:
doc.start_link("/%s/%s" %
(obj_type.lower(), handle))
doc.write_text(col, 'Normal')
if obj_type:
doc.stop_link()
doc.end_cell()
doc.end_row()
index += 1
doc.end_table()
doc.start_paragraph("Normal")
doc.end_paragraph()
def get_cell_markup(self, x, y=None, data=None):
"""
See if a column has formatting (if x and y are supplied) or
see if a cell has formatting. If it does, return the formatted
string, otherwise return data that is escaped (if that column
has formatting), or just the plain data.
"""
if x in self._cell_markup:
if y is None:
return True # markup for this column
elif y in self._cell_markup[x]:
return self._cell_markup[x][y]
else:
return cgi.escape(data)
else:
if y is None:
return False # no markup for this column
else:
return data
def get_cell_type(self, col):
"""
See if a column has a type, else return "text" as default.
"""
if col in self._cell_type:
return self._cell_type[col]
return "text"
def set_cell_markup(self, x, y, data):
"""
Set the cell at position [x][y] to a formatted string.
"""
col_dict = self._cell_markup.get(x, {})
col_dict[y] = data
self._cell_markup[x] = col_dict
def set_cell_type(self, col, value):
"""
Set the cell type at position [x].
"""
self._cell_type[col] = value

View File

@ -37,7 +37,7 @@ from gen.ggettext import gettext as _
import ManagedWindow import ManagedWindow
import GrampsDisplay import GrampsDisplay
from glade import Glade from glade import Glade
from Simple import SimpleAccess from gen.simple import SimpleAccess
WEB, EVENT, FAMILY, MEDIA, NOTE, PERSON, PLACE, REPOSITORY, SOURCE = range(9) WEB, EVENT, FAMILY, MEDIA, NOTE, PERSON, PLACE, REPOSITORY, SOURCE = range(9)
OBJECT_MAP = { OBJECT_MAP = {

View File

@ -302,7 +302,7 @@ class EditPrimary(ManagedWindow.ManagedWindow, DbGUIElement):
""" """
Create actions and ui of context menu Create actions and ui of context menu
""" """
from QuickReports import create_quickreport_menu from gui.plug.quick import create_quickreport_menu
self.popupmanager = gtk.UIManager() self.popupmanager = gtk.UIManager()
#add custom actions #add custom actions

View File

@ -4,7 +4,9 @@
# but that is not necessarily portable. # but that is not necessarily portable.
# If not using GNU make, then list all .py files individually # If not using GNU make, then list all .py files individually
SUBDIRS = report SUBDIRS = \
quick \
report
pkgpythondir = $(datadir)/@PACKAGE@/gui/plug pkgpythondir = $(datadir)/@PACKAGE@/gui/plug

View File

@ -27,7 +27,7 @@
__author__="jfriant" __author__="jfriant"
__date__ ="$Apr 20, 2010 3:13:24 PM$" __date__ ="$Apr 20, 2010 3:13:24 PM$"
from gui.plug import tool import tool
from _guioptions import make_gui_option, add_gui_options from _guioptions import make_gui_option, add_gui_options
from gen.plug import MenuOptions from gen.plug import MenuOptions

View File

@ -52,7 +52,8 @@ from gen.plug import PluginRegister, PTYPE_STR, load_addon_file
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
from gui.utils import open_file_with_default_application from gui.utils import open_file_with_default_application
from gui.pluginmanager import GuiPluginManager from gui.pluginmanager import GuiPluginManager
from gui.plug import tool, add_gui_options import tool
from _guioptions import add_gui_options
from QuestionDialog import InfoDialog from QuestionDialog import InfoDialog
from gui.editors import EditPerson from gui.editors import EditPerson
import Utils import Utils

View File

@ -0,0 +1,21 @@
# This is the src/gui/plug/quick level Makefile for Gramps
# $Id: Makefile.am 18851 2012-02-10 20:25:15Z josipsf $
pkgpythondir = $(datadir)/@PACKAGE@/gui/plug/quick
pkgpython_PYTHON = \
__init__.py\
_quickreports.py\
_quicktable.py\
_textbufdoc.py
pkgpyexecdir = @pkgpyexecdir@/gui/plug/quick
# Clean up all the byte-compiled files
MOSTLYCLEANFILES = *pyc *pyo
GRAMPS_PY_MODPATH = "../../../"
pycheck:
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
pychecker $(pkgpython_PYTHON));

View File

@ -0,0 +1,35 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001 David R. Hampton
# Copyright (C) 2001-2006 Donald N. Allingham
# Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# $Id$
"Quick Report Framework"
from _quickreports import (create_web_connect_menu,
create_quickreport_menu,
get_quick_report_list,
run_quick_report_by_name,
run_quick_report_by_name_direct,
run_report)
from _quicktable import QuickTable
from _textbufdoc import TextBufDoc

View File

@ -40,7 +40,7 @@ from cStringIO import StringIO
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import logging import logging
log = logging.getLogger(".QuickReports") log = logging.getLogger(".quickreports")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -60,6 +60,8 @@ from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, CATEGORY_QR_MEDIA,
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY,
CATEGORY_QR_NOTE, CATEGORY_QR_CITATION, CATEGORY_QR_NOTE, CATEGORY_QR_CITATION,
CATEGORY_QR_SOURCE_OR_CITATION) CATEGORY_QR_SOURCE_OR_CITATION)
from _textbufdoc import TextBufDoc
from gen.simple import make_basic_stylesheet
def flatten(L): def flatten(L):
""" """
@ -202,8 +204,6 @@ def run_quick_report_by_name_direct(report_name, database, document, handle):
""" """
Useful for running one quick report from another Useful for running one quick report from another
""" """
from docgen import TextBufDoc
from Simple import make_basic_stylesheet
report = None report = None
pmgr = GuiPluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_quick_reports(): for pdata in pmgr.get_reg_quick_reports():
@ -237,8 +237,6 @@ def run_report(dbstate, uistate, category, handle, pdata, container=None,
**kwargs are only used for special quick views that allow additional **kwargs are only used for special quick views that allow additional
arguments, and that are run by run_quick_report_by_name(). arguments, and that are run by run_quick_report_by_name().
""" """
from docgen import TextBufDoc
from Simple import make_basic_stylesheet
pmgr = GuiPluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
mod = pmgr.load_plugin(pdata) mod = pmgr.load_plugin(pdata)
if not mod: if not mod:

View File

@ -0,0 +1,405 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2008 Donald N. Allingham
# Copyright (C) 2009 Douglas S. Blank
# Copyright (C) 2011 Tim G L Lyons
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
#
"""
Provide a simplified table creation interface
"""
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import cPickle as pickle
#-------------------------------------------------------------------------
#
# GNOME modules
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.ggettext import sgettext as _
from gen.simple import SimpleTable
from TransUtils import trans_objclass
import Errors
from gui.widgets.multitreeview import MultiTreeView
from ScratchPad import ScratchPadListView, ACTION_COPY
from DdTargets import DdTargets
from gui.plug.quick import run_quick_report_by_name
from gui.editors import (EditPerson, EditEvent, EditFamily, EditCitation,
EditSource, EditPlace, EditRepository, EditNote,
EditMedia)
#-------------------------------------------------------------------------
#
# QuickTable class
#
#-------------------------------------------------------------------------
class QuickTable(SimpleTable):
"""
Provide a simplified table creation interface.
"""
def set_callback(self, which, callback):
"""
Override (or add) a function for click/double-click
"""
if which == "leftclick":
self._callback_leftclick = callback
elif which == "leftdouble":
self._callback_leftdouble = callback
def button_press_event(self, treeview, event):
index = None
button_code = None
event_time = None
func = None
if type(event) == bool: # enter
button_code = 3
event_time = 0
selection = treeview.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if node:
treeview.grab_focus()
index = store.get_value(node, 0)
# FIXME: make popup come where cursor is
#rectangle = treeview.get_visible_rect()
#column = treeview.get_column(0)
#rectangle = treeview.get_cell_area("0:0",
#x, y = rectangle.x, rectangle.y
#func = lambda menu: (x, y, True)
elif event.button == 3:
button_code = 3
event_time = event.time
x = int(event.x)
y = int(event.y)
path_info = treeview.get_path_at_pos(x, y)
func = None
if path_info is not None:
path, col, cellx, celly = path_info
selection = treeview.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if path:
treeview.grab_focus()
treeview.set_cursor(path, col, 0)
if store and node:
index = store.get_value(node, 0) # index Below,
# you need index, treeview, path, button_code,
# func, and event_time
if index is not None:
popup = gtk.Menu()
if (index is not None and self._link[index]):
# See details (edit, etc):
objclass, handle = self._link[index]
menu_item = gtk.MenuItem(_("the object|See %s details") % trans_objclass(objclass))
menu_item.connect("activate",
lambda widget: self.on_table_doubleclick(treeview))
popup.append(menu_item)
menu_item.show()
# Add other items to menu:
if (self._callback_leftclick or
(index is not None and self._link[index])):
objclass, handle = self._link[index]
if objclass == 'Person':
menu_item = gtk.MenuItem(_("the object|Make %s active") % trans_objclass('Person'))
menu_item.connect("activate",
lambda widget: self.on_table_click(treeview))
popup.append(menu_item)
menu_item.show()
if (self.simpledoc.doc.dbstate.db !=
self.simpledoc.doc.dbstate.db.basedb and
(index is not None and self._link[index])):
objclass, handle = self._link[index]
if (objclass == 'Filter' and
handle[0] in ['Person', 'Family', 'Place', 'Event',
'Repository', 'Note', 'MediaObject',
'Citation', 'Source']):
menu_item = gtk.MenuItem(_("See data not in Filter"))
menu_item.connect("activate",
lambda widget: self.show_not_in_filter(handle[0]))
popup.append(menu_item)
menu_item.show()
# Show the popup menu:
popup.popup(None, None, func, button_code, event_time)
return True
return False
def show_not_in_filter(self, obj_class):
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
'Inverse %s' % obj_class)
def on_table_doubleclick(self, obj):
"""
Handle events on tables. obj is a treeview
"""
selection = obj.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath) if tpath else None
if not node:
return
index = store.get_value(node, 0) # index
if self._callback_leftdouble:
self._callback_leftdouble(store.get_value(node, 1))
return True
elif self._link[index]:
objclass, handle = self._link[index]
if isinstance(handle, list):
handle = handle[0]
if objclass == 'Person':
person = self.access.dbase.get_person_from_handle(handle)
if person:
try:
EditPerson(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], person)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Event':
event = self.access.dbase.get_event_from_handle(handle)
if event:
try:
EditEvent(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], event)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Family':
ref = self.access.dbase.get_family_from_handle(handle)
if ref:
try:
EditFamily(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Citation':
ref = self.access.dbase.get_citation_from_handle(handle)
if ref:
try:
EditCitation(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Source':
ref = self.access.dbase.get_source_from_handle(handle)
if ref:
try:
EditSource(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Place':
ref = self.access.dbase.get_place_from_handle(handle)
if ref:
try:
EditPlace(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Repository':
ref = self.access.dbase.get_repository_from_handle(handle)
if ref:
try:
EditRepository(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'Note':
ref = self.access.dbase.get_note_from_handle(handle)
if ref:
try:
EditNote(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass in ['Media', 'MediaObject']:
ref = self.access.dbase.get_object_from_handle(handle)
if ref:
try:
EditMedia(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate, [], ref)
return True # handled event
except Errors.WindowActiveError:
pass
elif objclass == 'PersonList':
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
'list of people',
handles=handle)
elif objclass == 'Filter':
if isinstance(handle, list):
handle = handle[0]
run_quick_report_by_name(self.simpledoc.doc.dbstate,
self.simpledoc.doc.uistate,
'filterbyname',
handle)
return False # didn't handle event
def on_table_click(self, obj):
"""
Handle events on tables. obj is a treeview
"""
selection = obj.get_selection()
store, paths = selection.get_selected_rows()
tpath = paths[0] if len(paths) > 0 else None
node = store.get_iter(tpath)
if not node:
return
index = store.get_value(node, 0) # index
if self._callback_leftclick:
self._callback_leftclick(store.get_value(node, 1))
return True
elif self._link[index]:
objclass, handle = self._link[index]
if isinstance(handle, list):
handle = handle[0]
if objclass == 'Person':
import gobject
# If you emmit the signal here and it causes this table to be deleted,
# then you'll crash Python:
#self.simpledoc.doc.uistate.set_active(handle, 'Person')
# So, let's return from this, then change the active person:
return gobject.timeout_add(100, self.simpledoc.doc.uistate.set_active, handle, 'Person')
return True
return False # didn't handle event
def object_drag_data_get(self, widget, context, sel_data, info, time):
tree_selection = widget.get_selection()
model, paths = tree_selection.get_selected_rows()
retval = []
for path in paths:
node = model.get_iter(path)
index = model.get_value(node,0)
if (index is not None and self._link[index]):
retval.append(self._link[index])
sel_data.set(sel_data.target, 8, pickle.dumps(retval))
return True
def toggle(self, obj, path, col):
"""
obj - column widget
path - row
col - column
"""
self.treeview.get_model()[path][col] = not \
self.treeview.get_model()[path][col]
def write(self, document):
self.simpledoc = document
buffer = self.simpledoc.doc.buffer
text_view = self.simpledoc.doc.text_view
model_index = 1 # start after index
if self._sort_col:
sort_index = self._columns.index(self._sort_col)
else:
sort_index = 0
treeview = MultiTreeView()
treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
[(DdTargets.HANDLE_LIST.drag_type, gtk.TARGET_SAME_WIDGET, 0)],
gtk.gdk.ACTION_COPY)
#treeview.enable_model_drag_dest(DdTargets.all_targets(),
# gtk.gdk.ACTION_DEFAULT)
treeview.connect('drag_data_get', self.object_drag_data_get)
treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
#treeview.connect('row-activated', on_table_doubleclick, self)
#treeview.connect('cursor-changed', on_table_click, self)
treeview.connect('button-press-event', self.button_press_event)
treeview.connect('select-cursor-row', self.button_press_event)
renderer = gtk.CellRendererText()
types = [int] # index
cnt = 0
sort_data = []
sort_data_types = []
for col in self._columns:
if self.get_cell_type(cnt) == "text":
types.append(str)
if self.get_cell_markup(cnt):
column = gtk.TreeViewColumn(col,renderer,markup=model_index)
else:
column = gtk.TreeViewColumn(col,renderer,text=model_index)
elif self.get_cell_type(cnt) == "checkbox":
types.append(bool)
toggle_renderer = gtk.CellRendererToggle()
toggle_renderer.set_property('activatable', True)
toggle_renderer.connect("toggled", self.toggle, model_index)
column = gtk.TreeViewColumn(col, toggle_renderer)
column.add_attribute(toggle_renderer, "active", model_index)
column.set_resizable(True)
if self._sort_vals[cnt] != []:
sort_data.append(self._sort_vals[cnt])
column.set_sort_column_id(len(self._columns) +
len(sort_data))
sort_data_types.append(int)
else:
column.set_sort_column_id(model_index)
treeview.append_column(column)
self.model_index_of_column[col] = model_index
#if model_index == sort_index:
# FIXME: what to set here?
model_index += 1
cnt += 1
if self.title:
self.simpledoc.paragraph(self.title)
# Make a GUI to put the tree view in
types += sort_data_types
model = gtk.ListStore(*types)
treeview.set_model(model)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
iter = buffer.get_end_iter()
anchor = buffer.create_child_anchor(iter)
text_view.add_child_at_anchor(treeview, anchor)
self.treeview= treeview
count = 0
for data in self._rows:
col = 0
rowdata = []
for cell in data:
rowdata.append(self.get_cell_markup(col, count, cell))
col += 1
try:
model.append(row=([count] + list(rowdata) + [col[count] for col in sort_data]))
except:
print "error in row %d: data: %s, sort data: %d" % (count, rowdata, len(sort_data[0]))
count += 1
text_view.show_all()
self.simpledoc.paragraph("")
self.simpledoc.paragraph("")

View File

@ -64,6 +64,7 @@ from QuestionDialog import QuestionDialog, QuestionDialog2
from gui.filtereditor import FilterEditor from gui.filtereditor import FilterEditor
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
from DdTargets import DdTargets from DdTargets import DdTargets
from gui.plug.quick import create_quickreport_menu, create_web_connect_menu
#---------------------------------------------------------------- #----------------------------------------------------------------
# #
@ -740,8 +741,6 @@ class ListView(NavigationView):
""" """
if not self.dbstate.open: if not self.dbstate.open:
return False return False
from QuickReports import (create_quickreport_menu,
create_web_connect_menu)
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
if self.type_list() == LISTFLAT: if self.type_list() == LISTFLAT:
self.edit(obj) self.edit(obj)

View File

@ -47,7 +47,7 @@ from gui.editors import EditPerson, EditFamily
import ManagedWindow import ManagedWindow
import ConfigParser import ConfigParser
from gui.utils import add_menuitem from gui.utils import add_menuitem
from QuickReports import run_quick_report_by_name from gui.plug.quick import run_quick_report_by_name
import GrampsDisplay import GrampsDisplay
from glade import Glade from glade import Glade
from gui.pluginmanager import GuiPluginManager from gui.pluginmanager import GuiPluginManager

View File

@ -310,7 +310,7 @@ class StyledTextEditor(gtk.TextView):
""" """
Return a string useful for a tooltip given a LinkTag object. Return a string useful for a tooltip given a LinkTag object.
""" """
from Simple import SimpleAccess from gen.simple import SimpleAccess
win_obj = find_parent_with_attr(self, attr="dbstate") win_obj = find_parent_with_attr(self, attr="dbstate")
display = link_tag.data display = link_tag.data
if win_obj: if win_obj:

View File

@ -37,7 +37,7 @@ on a particular date.
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
import gen.datehandler import gen.datehandler
from QuickReports import run_quick_report_by_name from gui.plug.quick import run_quick_report_by_name
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #

View File

@ -20,7 +20,7 @@
# #
from ListModel import ListModel, NOSORT from ListModel import ListModel, NOSORT
from QuickReports import run_quick_report_by_name from gui.plug.quick import run_quick_report_by_name
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import gtk import gtk

View File

@ -25,7 +25,7 @@
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
from QuickReports import run_quick_report_by_name from gui.plug.quick import run_quick_report_by_name
import gen.lib import gen.lib
#------------------------------------------------------------------------ #------------------------------------------------------------------------

View File

@ -33,7 +33,7 @@
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.plug import Gramplet from gen.plug import Gramplet
from gen.ggettext import sgettext as _ from gen.ggettext import sgettext as _
from QuickReports import run_quick_report_by_name, get_quick_report_list from gui.plug.quick import run_quick_report_by_name, get_quick_report_list
from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY,
CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_NOTE, CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_NOTE,
CATEGORY_QR_MISC, CATEGORY_QR_PLACE, CATEGORY_QR_MEDIA, CATEGORY_QR_MISC, CATEGORY_QR_PLACE, CATEGORY_QR_MEDIA,

View File

@ -27,7 +27,8 @@
Display references for any object Display references for any object
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from Utils import probably_alive from Utils import probably_alive
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import gen.datehandler import gen.datehandler
@ -41,7 +42,7 @@ def run(database, document, date):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
if not date.get_valid(): if not date.get_valid():
sdoc.paragraph("Date is not a valid date.") sdoc.paragraph("Date is not a valid date.")
return return

View File

@ -22,13 +22,14 @@
# #
# #
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
def run(database, document, attribute, value=None): def run(database, document, attribute, value=None):
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
sdoc.title(_("People who have the '%s' Attribute") % attribute) sdoc.title(_("People who have the '%s' Attribute") % attribute)
sdoc.paragraph("") sdoc.paragraph("")
stab.columns(_("Person"), str(attribute)) stab.columns(_("Person"), str(attribute))

View File

@ -27,9 +27,10 @@
Display filtered data Display filtered data
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from Utils import media_path_full from Utils import media_path_full
from QuickReports import run_quick_report_by_name_direct from gui.plug.quick import run_quick_report_by_name_direct
from gen.lib import Person from gen.lib import Person
import gen.datehandler import gen.datehandler
@ -81,7 +82,7 @@ def run(database, document, filter_name, *args, **kwargs):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
if (filter_name == 'all'): if (filter_name == 'all'):
sdoc.title(_("Summary counts of current selection")) sdoc.title(_("Summary counts of current selection"))
sdoc.paragraph("") sdoc.paragraph("")

View File

@ -25,7 +25,8 @@
Display link references for a note Display link references for a note
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.lib import StyledTextTagType from gen.lib import StyledTextTagType
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
@ -37,7 +38,7 @@ def run(database, document, obj):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
# display the title # display the title
sdoc.title(_("Link References for this note")) sdoc.title(_("Link References for this note"))

View File

@ -26,7 +26,8 @@
Display all events on a particular day. Display all events on a particular day.
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc, SimpleTable
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import gen.lib import gen.lib
@ -66,11 +67,11 @@ def run(database, document, main_event):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
stab.set_link_col(3) stab.set_link_col(3)
yeartab = SimpleTable(sdb) yeartab = QuickTable(sdb)
yeartab.set_link_col(3) yeartab.set_link_col(3)
histab = SimpleTable(sdb) histab = QuickTable(sdb)
histab.set_link_col(3) histab.set_link_col(3)
# display the title # display the title

View File

@ -27,7 +27,8 @@
Display references for any object Display references for any object
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
def get_ref(db, objclass, handle): def get_ref(db, objclass, handle):
@ -62,7 +63,7 @@ def run(database, document, object, item, trans):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
# display the title # display the title
sdoc.title(_("References for this %s") % trans) sdoc.title(_("References for this %s") % trans)

View File

@ -34,7 +34,8 @@
Display RepoRef for sources related to active repository Display RepoRef for sources related to active repository
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
def run(database, document, repo): def run(database, document, repo):
@ -46,7 +47,7 @@ def run(database, document, repo):
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
# First we find repository and add its text # First we find repository and add its text

View File

@ -27,7 +27,8 @@
Display a people who have a person's same surname or given name. Display a people who have a person's same surname or given name.
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
from gen.ggettext import ngettext from gen.ggettext import ngettext
import gen.lib import gen.lib
@ -95,7 +96,7 @@ def run(database, document, person):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
if isinstance(person, gen.lib.Person): if isinstance(person, gen.lib.Person):
surname = sdb.surname(person) surname = sdb.surname(person)
rsurname = person.get_primary_name().get_group_name() rsurname = person.get_primary_name().get_group_name()
@ -137,7 +138,7 @@ def run_given(database, document, person):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
if isinstance(person, gen.lib.Person): if isinstance(person, gen.lib.Person):
rgivenname = person.get_primary_name().get_first_name() rgivenname = person.get_primary_name().get_first_name()
else: else:

View File

@ -26,7 +26,8 @@
Display a person's events, both personal and family Display a person's events, both personal and family
""" """
from Simple import SimpleAccess, by_date, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, by_date, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
def run(database, document, person): def run(database, document, person):
@ -38,7 +39,7 @@ def run(database, document, person):
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
# get the personal events # get the personal events
event_list = sdb.events(person) event_list = sdb.events(person)
@ -74,7 +75,7 @@ def run_fam(database, document, family):
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
# get the family events # get the family events
event_list = [(_('Family'), x) for x in sdb.events(family)] event_list = [(_('Family'), x) for x in sdb.events(family)]
@ -112,7 +113,7 @@ def run_fam(database, document, family):
document.has_data = True document.has_data = True
stab.write(sdoc) stab.write(sdoc)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
sdoc.header1(_("Personal events of the children")) sdoc.header1(_("Personal events of the children"))
stab.columns(_("Family Member"), _("Event Type"), stab.columns(_("Family Member"), _("Event Type"),
_("Event Date"), _("Event Place")) _("Event Date"), _("Event Place"))

View File

@ -31,7 +31,7 @@ Display a person's relations to the home person
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from Simple import SimpleAccess, SimpleDoc from gen.simple import SimpleAccess, SimpleDoc
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import Relationship import Relationship

View File

@ -33,7 +33,8 @@ Display a person's father or mother lineage
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.lib import gen.lib
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
__FMT = "%-30s\t%-12s\t%-12s" __FMT = "%-30s\t%-12s\t%-12s"
@ -57,7 +58,7 @@ def run_father(database, document, person):
" People in this lineage all share the same Y-chromosome." " People in this lineage all share the same Y-chromosome."
)) ))
sd.paragraph("") sd.paragraph("")
stab = SimpleTable(sa) stab = QuickTable(sa)
stab.columns(_("Name Father"), _("Birth Date"), _("Death Date"), _("Remark")) stab.columns(_("Name Father"), _("Birth Date"), _("Death Date"), _("Remark"))
make_details(gen.lib.Person.MALE, person, sa, sd, database, stab) make_details(gen.lib.Person.MALE, person, sa, sd, database, stab)
stab.write(sd) stab.write(sd)
@ -89,7 +90,7 @@ def run_mother(database, document, person):
)) ))
sd.paragraph("") sd.paragraph("")
stab = SimpleTable(sa) stab = QuickTable(sa)
stab.columns(_("Name Mother"), _("Birth"), _("Death Date"), _("Remark")) stab.columns(_("Name Mother"), _("Birth"), _("Death Date"), _("Remark"))
make_details(gen.lib.Person.FEMALE, person, sa, sd, database, stab) make_details(gen.lib.Person.FEMALE, person, sa, sd, database, stab)
stab.write(sd) stab.write(sd)

View File

@ -26,7 +26,8 @@
Display a person's siblings in a report window Display a person's siblings in a report window
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from gen.simple import SimpleAccess, SimpleDoc
from gui.plug.quick import QuickTable
import Relationship import Relationship
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
@ -38,7 +39,7 @@ def run(database, document, person):
# setup the simple access functions # setup the simple access functions
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = QuickTable(sdb)
rel_class = Relationship.get_relationship_calculator() rel_class = Relationship.get_relationship_calculator()
# display the title # display the title

View File

@ -56,7 +56,7 @@ from webapp.dbdjango import DbDjango
# Gramps Modules # Gramps Modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from Simple import SimpleTable, SimpleAccess, make_basic_stylesheet from gen.simple import SimpleTable, SimpleAccess, make_basic_stylesheet
import Utils import Utils
import DbState import DbState
from gen.datehandler import displayer, parser from gen.datehandler import displayer, parser