In .:
* src/Selectors/_SelectPerson.py: Use new package. * src/plugins/RelCalc.py: Use new package. * src/DataViews/_PersonView.py: Use new package. * src/DisplayModels: Make new package. * src/Makefile.am: Remove old files. In po: * POTFILES.in: Add new files; remove old files. svn: r6683
This commit is contained in:
parent
66c08cbf34
commit
3b6d63e48f
@ -1,4 +1,9 @@
|
||||
2006-05-16 Alex Roitman <shura@gramps-project.org>
|
||||
* src/Selectors/_SelectPerson.py: Use new package.
|
||||
* src/plugins/RelCalc.py: Use new package.
|
||||
* src/DataViews/_PersonView.py: Use new package.
|
||||
* src/DisplayModels: Make new package.
|
||||
* src/Makefile.am: Remove old files.
|
||||
* src/Filters/_PersonSidebarFilter.py: Import gettext.
|
||||
* src/Filters/_SidebarFilter.py: Import gettext.
|
||||
* src/Filters/Makefile.am: Ship new files.
|
||||
|
@ -195,6 +195,7 @@ src/RelLib/Makefile
|
||||
src/Config/Makefile
|
||||
src/Mime/Makefile
|
||||
src/DisplayTabs/Makefile
|
||||
src/DisplayModels/Makefile
|
||||
src/ObjectSelector/Makefile
|
||||
src/Selectors/Makefile
|
||||
src/GrampsLogger/Makefile
|
||||
|
@ -1,5 +1,5 @@
|
||||
2006-05-16 Alex Roitman <shura@gramps-project.org>
|
||||
* POTFILES.in: Add new files.
|
||||
* POTFILES.in: Add new files; remove old files.
|
||||
|
||||
2006-05-15 Alex Roitman <shura@gramps-project.org>
|
||||
* POTFILES.in: Add new files.
|
||||
|
@ -16,7 +16,6 @@ src/const.py
|
||||
src/DateEdit.py
|
||||
src/Date.py
|
||||
src/DdTargets.py
|
||||
src/DisplayModels.py
|
||||
src/DisplayState.py
|
||||
src/Errors.py
|
||||
src/Exporter.py
|
||||
@ -34,7 +33,6 @@ src/MergePeople.py
|
||||
src/NameDisplay.py
|
||||
src/Navigation.py
|
||||
src/PageView.py
|
||||
src/PeopleModel.py
|
||||
src/QuestionDialog.py
|
||||
src/RecentFiles.py
|
||||
src/Relationship.py
|
||||
@ -94,6 +92,15 @@ src/docgen/PSDrawDoc.py
|
||||
src/docgen/RTFDoc.py
|
||||
src/docgen/SpreadSheetDoc.py
|
||||
src/docgen/SvgDrawDoc.py
|
||||
src/DisplayModels/_BaseModel.py
|
||||
src/DisplayModels/_EventModel.py
|
||||
src/DisplayModels/_FamilyModel.py
|
||||
src/DisplayModels/_MediaModel.py
|
||||
src/DisplayModels/_PeopleModel.py
|
||||
src/DisplayModels/_PlaceModel.py
|
||||
src/DisplayModels/_RepositoryModel.py
|
||||
src/DisplayModels/_SourceModel.py
|
||||
src/DisplayModels/__init__.py
|
||||
src/DisplayTabs/_AddrEmbedList.py
|
||||
src/DisplayTabs/_AddressModel.py
|
||||
src/DisplayTabs/_AttrEmbedList.py
|
||||
|
@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
@ -50,7 +49,7 @@ from gtk.gdk import ACTION_COPY, BUTTON1_MASK
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import RelLib
|
||||
import PeopleModel
|
||||
from DisplayModels import PeopleModel
|
||||
import PageView
|
||||
import GrampsWidgets
|
||||
import NameDisplay
|
||||
@ -384,7 +383,7 @@ class PersonView(PageView.PersonNavView):
|
||||
else:
|
||||
filter_info = (PeopleModel.SEARCH, self.search_bar.get_value())
|
||||
|
||||
self.model = PeopleModel.PeopleModel(self.dbstate.db, filter_info)
|
||||
self.model = PeopleModel(self.dbstate.db, filter_info)
|
||||
|
||||
self.tree.set_model(self.model)
|
||||
|
||||
|
@ -1,838 +0,0 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2005 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
from gettext import gettext as _
|
||||
import locale
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import NameDisplay
|
||||
import DateHandler
|
||||
import RelLib
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import const
|
||||
from Filters import SearchFilter
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Localized constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_codeset = GrampsLocale.codeset
|
||||
|
||||
def sfunc(a,b):
|
||||
return locale.strcoll(a[0],b[0])
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# BaseModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class BaseModel(gtk.GenericTreeModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING,
|
||||
tooltip_column=None, search=None):
|
||||
gtk.GenericTreeModel.__init__(self)
|
||||
self.prev_handle = None
|
||||
self.prev_data = None
|
||||
self.set_property("leak_references",False)
|
||||
self.db = db
|
||||
self.sort_func = self.smap[scol]
|
||||
self.sort_col = scol
|
||||
|
||||
if search:
|
||||
col = search[0]
|
||||
text = search[1]
|
||||
inv = search[2]
|
||||
func = lambda x: self.on_get_value(x, col) or u""
|
||||
self.search = SearchFilter(func, text, inv)
|
||||
else:
|
||||
self.search = None
|
||||
|
||||
self.reverse = (order == gtk.SORT_DESCENDING)
|
||||
self.tooltip_column = tooltip_column
|
||||
self.rebuild_data()
|
||||
|
||||
def set_sort_column(self,col):
|
||||
self.sort_func = self.smap[col]
|
||||
|
||||
def sort_keys(self):
|
||||
cursor = self.gen_cursor()
|
||||
sarray = []
|
||||
data = cursor.next()
|
||||
|
||||
while data:
|
||||
key = locale.strxfrm(self.sort_func(data[1]))
|
||||
sarray.append((key,data[0]))
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
sarray.sort()
|
||||
|
||||
if self.reverse:
|
||||
sarray.reverse()
|
||||
|
||||
return [ x[1] for x in sarray ]
|
||||
|
||||
def rebuild_data(self):
|
||||
if self.db.is_open():
|
||||
if self.search:
|
||||
self.datalist = [h for h in self.sort_keys()\
|
||||
if self.search.match(h)]
|
||||
else:
|
||||
self.datalist = self.sort_keys()
|
||||
i = 0
|
||||
self.indexlist = {}
|
||||
for key in self.datalist:
|
||||
self.indexlist[key] = i
|
||||
i += 1
|
||||
else:
|
||||
self.datalist = []
|
||||
self.indexlist = {}
|
||||
|
||||
def add_row_by_handle(self,handle):
|
||||
self.datalist = self.sort_keys()
|
||||
i = 0
|
||||
self.indexlist = {}
|
||||
for key in self.datalist:
|
||||
self.indexlist[key] = i
|
||||
i += 1
|
||||
index = self.indexlist[handle]
|
||||
node = self.get_iter(index)
|
||||
self.row_inserted(index,node)
|
||||
|
||||
def delete_row_by_handle(self,handle):
|
||||
index = self.indexlist[handle]
|
||||
self.indexlist = {}
|
||||
self.datalist = []
|
||||
i = 0
|
||||
for key in self.sort_keys():
|
||||
if key != handle:
|
||||
self.indexlist[key] = i
|
||||
self.datalist.append(key)
|
||||
i += 1
|
||||
self.row_deleted(index)
|
||||
|
||||
def update_row_by_handle(self,handle):
|
||||
index = self.indexlist[handle]
|
||||
node = self.get_iter(index)
|
||||
self.row_changed(index,node)
|
||||
|
||||
def on_get_flags(self):
|
||||
'''returns the GtkTreeModelFlags for this particular type of model'''
|
||||
return gtk.TREE_MODEL_LIST_ONLY | gtk.TREE_MODEL_ITERS_PERSIST
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return 1
|
||||
|
||||
def on_get_path(self, node):
|
||||
'''returns the tree path (a tuple of indices at the various
|
||||
levels) for a particular node.'''
|
||||
return self.indexlist[node]
|
||||
|
||||
def on_get_column_type(self,index):
|
||||
if index == self.tooltip_column:
|
||||
return object
|
||||
return str
|
||||
|
||||
def on_get_iter(self, path):
|
||||
try:
|
||||
return self.datalist[path[0]]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def on_get_value(self,node,col):
|
||||
try:
|
||||
if node != self.prev_handle:
|
||||
self.prev_data = self.map(str(node))
|
||||
self.prev_handle = node
|
||||
return self.fmap[col](self.prev_data)
|
||||
except:
|
||||
return u''
|
||||
|
||||
def on_iter_next(self, node):
|
||||
'''returns the next node at this level of the tree'''
|
||||
try:
|
||||
return self.datalist[self.indexlist[node]+1]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def on_iter_children(self,node):
|
||||
"""Return the first child of the node"""
|
||||
if node == None and self.datalist:
|
||||
return self.datalist[0]
|
||||
return None
|
||||
|
||||
def on_iter_has_child(self, node):
|
||||
'''returns true if this node has children'''
|
||||
if node == None:
|
||||
return len(self.datalist) > 0
|
||||
return False
|
||||
|
||||
def on_iter_n_children(self,node):
|
||||
if node == None:
|
||||
return len(self.datalist)
|
||||
return 0
|
||||
|
||||
def on_iter_nth_child(self,node,n):
|
||||
if node == None:
|
||||
return self.datalist[n]
|
||||
return None
|
||||
|
||||
def on_iter_parent(self, node):
|
||||
'''returns the parent of this node'''
|
||||
return None
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SourceModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class SourceModel(BaseModel):
|
||||
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
|
||||
self.map = db.get_raw_source_data
|
||||
self.gen_cursor = db.get_source_cursor
|
||||
self.fmap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
self.column_author,
|
||||
self.column_abbrev,
|
||||
self.column_pubinfo,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
self.column_author,
|
||||
self.column_abbrev,
|
||||
self.column_pubinfo,
|
||||
self.sort_change,
|
||||
]
|
||||
BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_title(self,data):
|
||||
return unicode(data[2])
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_author(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_abbrev(self,data):
|
||||
return unicode(data[7])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_pubinfo(self,data):
|
||||
return unicode(data[4])
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[8])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[8]
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_source_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.",exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PlaceModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class PlaceModel(BaseModel):
|
||||
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
|
||||
self.gen_cursor = db.get_place_cursor
|
||||
self.map = db.get_raw_place_data
|
||||
self.fmap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_parish,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_longitude,
|
||||
self.column_latitude,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_parish,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_longitude,
|
||||
self.column_latitude,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=12,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_name(self,data):
|
||||
return unicode(data[2])
|
||||
|
||||
def column_longitude(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_latitude(self,data):
|
||||
return unicode(data[4])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_parish(self,data):
|
||||
try:
|
||||
return data[5][1]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_city(self,data):
|
||||
try:
|
||||
return data[5][0][0]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_county(self,data):
|
||||
try:
|
||||
return data[5][2]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_state(self,data):
|
||||
try:
|
||||
return data[5][0][1]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_country(self,data):
|
||||
try:
|
||||
return data[5][0][2]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_postal_code(self,data):
|
||||
try:
|
||||
return data[5][0][3]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[11]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[11])),
|
||||
_codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(
|
||||
self.db, lambda:
|
||||
self.db.get_place_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# FamilyModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class FamilyModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_family_cursor
|
||||
self.map = db.get_raw_family_data
|
||||
self.fmap = [
|
||||
self.column_id,
|
||||
self.column_father,
|
||||
self.column_mother,
|
||||
self.column_type,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_id,
|
||||
self.sort_father,
|
||||
self.sort_mother,
|
||||
self.column_type,
|
||||
self.sort_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=6,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_father(self,data):
|
||||
if data[2]:
|
||||
person = self.db.get_person_from_handle(data[2])
|
||||
return unicode(NameDisplay.displayer.sorted_name(person.primary_name))
|
||||
else:
|
||||
return u""
|
||||
|
||||
def sort_father(self,data):
|
||||
if data[2]:
|
||||
person = self.db.get_person_from_handle(data[2])
|
||||
return NameDisplay.displayer.sort_string(person.primary_name)
|
||||
else:
|
||||
return u""
|
||||
|
||||
def column_mother(self,data):
|
||||
if data[3]:
|
||||
person = self.db.get_person_from_handle(data[3])
|
||||
return unicode(NameDisplay.displayer.sorted_name(person.primary_name))
|
||||
else:
|
||||
return u""
|
||||
|
||||
def sort_mother(self,data):
|
||||
if data[3]:
|
||||
person = self.db.get_person_from_handle(data[3])
|
||||
return NameDisplay.displayer.sort_string(person.primary_name)
|
||||
else:
|
||||
return u""
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.FamilyRelType(data[5]))
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[13]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[13])),
|
||||
_codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_family_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# MediaModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class MediaModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_media_cursor
|
||||
self.map = db.get_raw_object_data
|
||||
|
||||
self.fmap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_mime,
|
||||
self.column_path,
|
||||
self.column_change,
|
||||
self.column_date,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_mime,
|
||||
self.column_path,
|
||||
self.sort_change,
|
||||
self.column_date,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=7,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_description(self,data):
|
||||
try:
|
||||
return unicode(data[4])
|
||||
except:
|
||||
return unicode(data[4],'latin1')
|
||||
|
||||
def column_path(self,data):
|
||||
try:
|
||||
return unicode(data[2])
|
||||
except:
|
||||
return unicode(data[2].encode('iso-8859-1'))
|
||||
|
||||
def column_mime(self,data):
|
||||
if data[3]:
|
||||
return unicode(data[3])
|
||||
else:
|
||||
return _('Note')
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_date(self,data):
|
||||
if data[9]:
|
||||
date = RelLib.Date()
|
||||
date.unserialize(data[9])
|
||||
return unicode(DateHandler.displayer.display(date))
|
||||
return u''
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[8]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[8])),
|
||||
_codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_object_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# EventModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class EventModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_event_cursor
|
||||
self.map = db.get_raw_event_data
|
||||
|
||||
self.fmap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_date,
|
||||
self.column_place,
|
||||
self.column_cause,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip,
|
||||
]
|
||||
self.smap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_date,
|
||||
self.column_place,
|
||||
self.column_cause,
|
||||
self.sort_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=8,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_description(self,data):
|
||||
return data[4]
|
||||
|
||||
def column_cause(self,data):
|
||||
return data[6]
|
||||
|
||||
def column_place(self,data):
|
||||
if data[5]:
|
||||
return self.db.get_place_from_handle(data[5]).get_title()
|
||||
else:
|
||||
return u''
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.EventType(data[2]))
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_date(self,data):
|
||||
if data[3]:
|
||||
event = RelLib.Event()
|
||||
event.unserialize(data)
|
||||
return DateHandler.get_date(event)
|
||||
return u''
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[10]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[10])),
|
||||
_codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_event_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# RepositoryModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class RepositoryModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_repository_cursor
|
||||
self.get_handles = db.get_repository_handles
|
||||
self.map = db.get_raw_repository_data
|
||||
self.fmap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_home_url,
|
||||
self.column_street,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_email,
|
||||
self.column_search_url,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
|
||||
self.smap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_home_url,
|
||||
self.column_street,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_email,
|
||||
self.column_search_url,
|
||||
self.column_handle,
|
||||
]
|
||||
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=12,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.RepositoryType(data[2]))
|
||||
|
||||
def column_name(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_city(self,data):
|
||||
try:
|
||||
if data[4]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[4][0])
|
||||
return addr.get_city()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_street(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_street()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_county(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_county()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_state(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_state()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_country(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_country()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_postal_code(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_postal_code()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_phone(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_phone()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_email(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.EMAIL:
|
||||
return unicode(url.path)
|
||||
return u''
|
||||
|
||||
def column_search_url(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.WEB_SEARCH:
|
||||
return unicode(url.path)
|
||||
return u''
|
||||
|
||||
def column_home_url(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.WEB_HOME:
|
||||
return unicode(url.path)
|
||||
return u""
|
||||
|
||||
def column_tooltip(self,data):
|
||||
return ""
|
||||
# try:
|
||||
# t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_repository_from_handle(data[0]))
|
||||
# except:
|
||||
# log.error("Failed to create tooltip.", exc_info=True)
|
||||
# return t
|
||||
|
26
src/DisplayModels/Makefile.am
Normal file
26
src/DisplayModels/Makefile.am
Normal file
@ -0,0 +1,26 @@
|
||||
# This is the src/DisplayModels level Makefile for Gramps
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/DisplayModels
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
__init__.py \
|
||||
_BaseModel.py \
|
||||
_EventModel.py \
|
||||
_FamilyModel.py \
|
||||
_MediaModel.py \
|
||||
_PeopleModel.py \
|
||||
_PlaceModel.py \
|
||||
_RepositoryModel.py \
|
||||
_SourceModel.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/DisplayModels
|
||||
pkgpythondir = @pkgpythondir@/DisplayModels
|
||||
|
||||
# Clean up all the byte-compiled files
|
||||
MOSTLYCLEANFILES = *pyc *pyo
|
||||
|
||||
GRAMPS_PY_MODPATH = "../"
|
||||
|
||||
pycheck:
|
||||
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
|
||||
pychecker $(pkgdata_PYTHON));
|
201
src/DisplayModels/_BaseModel.py
Normal file
201
src/DisplayModels/_BaseModel.py
Normal file
@ -0,0 +1,201 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import locale
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from Filters import SearchFilter
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# BaseModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class BaseModel(gtk.GenericTreeModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING,
|
||||
tooltip_column=None, search=None):
|
||||
gtk.GenericTreeModel.__init__(self)
|
||||
self.prev_handle = None
|
||||
self.prev_data = None
|
||||
self.set_property("leak_references",False)
|
||||
self.db = db
|
||||
self.sort_func = self.smap[scol]
|
||||
self.sort_col = scol
|
||||
|
||||
if search:
|
||||
col = search[0]
|
||||
text = search[1]
|
||||
inv = search[2]
|
||||
func = lambda x: self.on_get_value(x, col) or u""
|
||||
self.search = SearchFilter(func, text, inv)
|
||||
else:
|
||||
self.search = None
|
||||
|
||||
self.reverse = (order == gtk.SORT_DESCENDING)
|
||||
self.tooltip_column = tooltip_column
|
||||
self.rebuild_data()
|
||||
|
||||
def set_sort_column(self,col):
|
||||
self.sort_func = self.smap[col]
|
||||
|
||||
def sort_keys(self):
|
||||
cursor = self.gen_cursor()
|
||||
sarray = []
|
||||
data = cursor.next()
|
||||
|
||||
while data:
|
||||
key = locale.strxfrm(self.sort_func(data[1]))
|
||||
sarray.append((key,data[0]))
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
|
||||
sarray.sort()
|
||||
|
||||
if self.reverse:
|
||||
sarray.reverse()
|
||||
|
||||
return [ x[1] for x in sarray ]
|
||||
|
||||
def rebuild_data(self):
|
||||
if self.db.is_open():
|
||||
if self.search:
|
||||
self.datalist = [h for h in self.sort_keys()\
|
||||
if self.search.match(h)]
|
||||
else:
|
||||
self.datalist = self.sort_keys()
|
||||
i = 0
|
||||
self.indexlist = {}
|
||||
for key in self.datalist:
|
||||
self.indexlist[key] = i
|
||||
i += 1
|
||||
else:
|
||||
self.datalist = []
|
||||
self.indexlist = {}
|
||||
|
||||
def add_row_by_handle(self,handle):
|
||||
self.datalist = self.sort_keys()
|
||||
i = 0
|
||||
self.indexlist = {}
|
||||
for key in self.datalist:
|
||||
self.indexlist[key] = i
|
||||
i += 1
|
||||
index = self.indexlist[handle]
|
||||
node = self.get_iter(index)
|
||||
self.row_inserted(index,node)
|
||||
|
||||
def delete_row_by_handle(self,handle):
|
||||
index = self.indexlist[handle]
|
||||
self.indexlist = {}
|
||||
self.datalist = []
|
||||
i = 0
|
||||
for key in self.sort_keys():
|
||||
if key != handle:
|
||||
self.indexlist[key] = i
|
||||
self.datalist.append(key)
|
||||
i += 1
|
||||
self.row_deleted(index)
|
||||
|
||||
def update_row_by_handle(self,handle):
|
||||
index = self.indexlist[handle]
|
||||
node = self.get_iter(index)
|
||||
self.row_changed(index,node)
|
||||
|
||||
def on_get_flags(self):
|
||||
'''returns the GtkTreeModelFlags for this particular type of model'''
|
||||
return gtk.TREE_MODEL_LIST_ONLY | gtk.TREE_MODEL_ITERS_PERSIST
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return 1
|
||||
|
||||
def on_get_path(self, node):
|
||||
'''returns the tree path (a tuple of indices at the various
|
||||
levels) for a particular node.'''
|
||||
return self.indexlist[node]
|
||||
|
||||
def on_get_column_type(self,index):
|
||||
if index == self.tooltip_column:
|
||||
return object
|
||||
return str
|
||||
|
||||
def on_get_iter(self, path):
|
||||
try:
|
||||
return self.datalist[path[0]]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def on_get_value(self,node,col):
|
||||
try:
|
||||
if node != self.prev_handle:
|
||||
self.prev_data = self.map(str(node))
|
||||
self.prev_handle = node
|
||||
return self.fmap[col](self.prev_data)
|
||||
except:
|
||||
return u''
|
||||
|
||||
def on_iter_next(self, node):
|
||||
'''returns the next node at this level of the tree'''
|
||||
try:
|
||||
return self.datalist[self.indexlist[node]+1]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def on_iter_children(self,node):
|
||||
"""Return the first child of the node"""
|
||||
if node == None and self.datalist:
|
||||
return self.datalist[0]
|
||||
return None
|
||||
|
||||
def on_iter_has_child(self, node):
|
||||
'''returns true if this node has children'''
|
||||
if node == None:
|
||||
return len(self.datalist) > 0
|
||||
return False
|
||||
|
||||
def on_iter_n_children(self,node):
|
||||
if node == None:
|
||||
return len(self.datalist)
|
||||
return 0
|
||||
|
||||
def on_iter_nth_child(self,node,n):
|
||||
if node == None:
|
||||
return self.datalist[n]
|
||||
return None
|
||||
|
||||
def on_iter_parent(self, node):
|
||||
'''returns the parent of this node'''
|
||||
return None
|
129
src/DisplayModels/_EventModel.py
Normal file
129
src/DisplayModels/_EventModel.py
Normal file
@ -0,0 +1,129 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import DateHandler
|
||||
import RelLib
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# EventModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class EventModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_event_cursor
|
||||
self.map = db.get_raw_event_data
|
||||
|
||||
self.fmap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_date,
|
||||
self.column_place,
|
||||
self.column_cause,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip,
|
||||
]
|
||||
self.smap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_date,
|
||||
self.column_place,
|
||||
self.column_cause,
|
||||
self.sort_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=8,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_description(self,data):
|
||||
return data[4]
|
||||
|
||||
def column_cause(self,data):
|
||||
return data[6]
|
||||
|
||||
def column_place(self,data):
|
||||
if data[5]:
|
||||
return self.db.get_place_from_handle(data[5]).get_title()
|
||||
else:
|
||||
return u''
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.EventType(data[2]))
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_date(self,data):
|
||||
if data[3]:
|
||||
event = RelLib.Event()
|
||||
event.unserialize(data)
|
||||
return DateHandler.get_date(event)
|
||||
return u''
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[10]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[10])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_event_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
138
src/DisplayModels/_FamilyModel.py
Normal file
138
src/DisplayModels/_FamilyModel.py
Normal file
@ -0,0 +1,138 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import NameDisplay
|
||||
import RelLib
|
||||
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# FamilyModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class FamilyModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_family_cursor
|
||||
self.map = db.get_raw_family_data
|
||||
self.fmap = [
|
||||
self.column_id,
|
||||
self.column_father,
|
||||
self.column_mother,
|
||||
self.column_type,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_id,
|
||||
self.sort_father,
|
||||
self.sort_mother,
|
||||
self.column_type,
|
||||
self.sort_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=6,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_father(self,data):
|
||||
if data[2]:
|
||||
person = self.db.get_person_from_handle(data[2])
|
||||
return unicode(NameDisplay.displayer.sorted_name(person.primary_name))
|
||||
else:
|
||||
return u""
|
||||
|
||||
def sort_father(self,data):
|
||||
if data[2]:
|
||||
person = self.db.get_person_from_handle(data[2])
|
||||
return NameDisplay.displayer.sort_string(person.primary_name)
|
||||
else:
|
||||
return u""
|
||||
|
||||
def column_mother(self,data):
|
||||
if data[3]:
|
||||
person = self.db.get_person_from_handle(data[3])
|
||||
return unicode(NameDisplay.displayer.sorted_name(person.primary_name))
|
||||
else:
|
||||
return u""
|
||||
|
||||
def sort_mother(self,data):
|
||||
if data[3]:
|
||||
person = self.db.get_person_from_handle(data[3])
|
||||
return NameDisplay.displayer.sort_string(person.primary_name)
|
||||
else:
|
||||
return u""
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.FamilyRelType(data[5]))
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[13]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[13])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_family_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
134
src/DisplayModels/_MediaModel.py
Normal file
134
src/DisplayModels/_MediaModel.py
Normal file
@ -0,0 +1,134 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
from gettext import gettext as _
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import DateHandler
|
||||
import RelLib
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# MediaModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class MediaModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_media_cursor
|
||||
self.map = db.get_raw_object_data
|
||||
|
||||
self.fmap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_mime,
|
||||
self.column_path,
|
||||
self.column_change,
|
||||
self.column_date,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_description,
|
||||
self.column_id,
|
||||
self.column_mime,
|
||||
self.column_path,
|
||||
self.sort_change,
|
||||
self.column_date,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=7,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_description(self,data):
|
||||
try:
|
||||
return unicode(data[4])
|
||||
except:
|
||||
return unicode(data[4],'latin1')
|
||||
|
||||
def column_path(self,data):
|
||||
try:
|
||||
return unicode(data[2])
|
||||
except:
|
||||
return unicode(data[2].encode('iso-8859-1'))
|
||||
|
||||
def column_mime(self,data):
|
||||
if data[3]:
|
||||
return unicode(data[3])
|
||||
else:
|
||||
return _('Note')
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_date(self,data):
|
||||
if data[9]:
|
||||
date = RelLib.Date()
|
||||
date.unserialize(data[9])
|
||||
return unicode(DateHandler.displayer.display(date))
|
||||
return u''
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[8]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[8])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_object_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
@ -37,7 +37,6 @@ import time
|
||||
import cgi
|
||||
import sys
|
||||
import locale
|
||||
import Config
|
||||
|
||||
try:
|
||||
set()
|
||||
@ -70,31 +69,9 @@ import NameDisplay
|
||||
import DateHandler
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import Config
|
||||
from Filters import SearchFilter
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Localized constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_codeset = GrampsLocale.codeset
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
_ID_COL = 1
|
||||
_GENDER_COL = 2
|
||||
_NAME_COL = 3
|
||||
_DEATH_COL = 5
|
||||
_BIRTH_COL = 6
|
||||
_EVENT_COL = 7
|
||||
_FAMILY_COL = 8
|
||||
_CHANGE_COL = 17
|
||||
_MARKER_COL = 18
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python 2.3 has a bug in the unicode sorting using locale.strcoll. Seems
|
||||
@ -120,10 +97,6 @@ else:
|
||||
mylist.sort(locale.strcoll)
|
||||
return mylist
|
||||
|
||||
GENERIC = 0
|
||||
SEARCH = 1
|
||||
FAST = 2
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PeopleModel
|
||||
@ -135,6 +108,33 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
the PersonView
|
||||
"""
|
||||
|
||||
# Model types
|
||||
GENERIC = 0
|
||||
SEARCH = 1
|
||||
FAST = 2
|
||||
|
||||
# Column numbers
|
||||
_ID_COL = 1
|
||||
_GENDER_COL = 2
|
||||
_NAME_COL = 3
|
||||
_DEATH_COL = 5
|
||||
_BIRTH_COL = 6
|
||||
_EVENT_COL = 7
|
||||
_FAMILY_COL = 8
|
||||
_CHANGE_COL = 17
|
||||
_MARKER_COL = 18
|
||||
|
||||
|
||||
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
|
||||
|
||||
# dynamic calculation of column indices, for use by various Views
|
||||
COLUMN_INT_ID = 13
|
||||
|
||||
# indices into main column definition table
|
||||
COLUMN_DEF_LIST = 0
|
||||
COLUMN_DEF_HEADER = 1
|
||||
COLUMN_DEF_TYPE = 2
|
||||
|
||||
def __init__(self, db, filter_info=None, skip=[]):
|
||||
"""
|
||||
Initialize the model building the initial data
|
||||
@ -164,10 +164,10 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
self.path2iter = {}
|
||||
self.sname_sub = {}
|
||||
if filter_info:
|
||||
if filter_info[0] == GENERIC:
|
||||
if filter_info[0] == PeopleModel.GENERIC:
|
||||
data_filter = filter_info[1]
|
||||
self._build_data = self._build_filter_sub
|
||||
elif filter_info[0] == SEARCH:
|
||||
elif filter_info[0] == PeopleModel.SEARCH:
|
||||
col = filter_info[1][0]
|
||||
text = filter_info[1][1]
|
||||
inv = filter_info[1][2]
|
||||
@ -210,7 +210,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
while node:
|
||||
handle, d = node
|
||||
if not (handle in skip or (dfilter and not dfilter.match(handle))):
|
||||
name_data = d[_NAME_COL]
|
||||
name_data = d[PeopleModel._NAME_COL]
|
||||
self.sortnames[handle] = nsn(name_data)
|
||||
try:
|
||||
self.temp_sname_sub[name_data[5]].append(handle)
|
||||
@ -233,7 +233,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
for handle in handle_list:
|
||||
d = self.db.get_raw_person_data(handle)
|
||||
if not (handle in skip or (dfilter and not dfilter.match(handle))):
|
||||
name_data = d[_NAME_COL]
|
||||
name_data = d[PeopleModel._NAME_COL]
|
||||
self.sortnames[handle] = nsn(name_data)
|
||||
try:
|
||||
self.temp_sname_sub[name_data[5]].append(handle)
|
||||
@ -287,7 +287,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
return gtk.TREE_MODEL_ITERS_PERSIST
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(COLUMN_DEFS)
|
||||
return len(PeopleModel.COLUMN_DEFS)
|
||||
|
||||
def on_get_path(self, node):
|
||||
'''returns the tree path (a tuple of indices at the various
|
||||
@ -302,7 +302,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
return self.iter2path.has_key(handle)
|
||||
|
||||
def on_get_column_type(self, index):
|
||||
return COLUMN_DEFS[index][COLUMN_DEF_TYPE]
|
||||
return PeopleModel.COLUMN_DEFS[index][PeopleModel.COLUMN_DEF_TYPE]
|
||||
|
||||
def on_get_iter(self, path):
|
||||
try:
|
||||
@ -321,11 +321,11 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
if col == self.marker_color_column:
|
||||
return None
|
||||
# test for 'header' column being empty (most are)
|
||||
if not COLUMN_DEFS[col][COLUMN_DEF_HEADER]:
|
||||
if not PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_HEADER]:
|
||||
return u''
|
||||
# return values for 'header' row, calling a function
|
||||
# according to column_defs table
|
||||
val = COLUMN_DEFS[col][COLUMN_DEF_HEADER](self, node)
|
||||
val = PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_HEADER](self, node)
|
||||
return val
|
||||
else:
|
||||
# return values for 'data' row, calling a function
|
||||
@ -334,7 +334,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
if node != self.prev_handle:
|
||||
self.prev_data = self.db.get_raw_person_data(str(node))
|
||||
self.prev_handle = node
|
||||
return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,
|
||||
return PeopleModel.COLUMN_DEFS[col][PeopleModel.COLUMN_DEF_LIST](self,
|
||||
self.prev_data, node)
|
||||
except:
|
||||
return None
|
||||
@ -393,13 +393,13 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
|
||||
def column_sort_name(self, data, node):
|
||||
n = Name()
|
||||
n.unserialize(data[_NAME_COL])
|
||||
n.unserialize(data[PeopleModel._NAME_COL])
|
||||
return NameDisplay.displayer.sort_string(n)
|
||||
|
||||
def column_spouse(self, data, node):
|
||||
spouses_names = u""
|
||||
handle = data[0]
|
||||
for family_handle in data[_FAMILY_COL]:
|
||||
for family_handle in data[PeopleModel._FAMILY_COL]:
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
for spouse_id in [family.get_father_handle(),
|
||||
family.get_mother_handle()]:
|
||||
@ -415,30 +415,31 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
|
||||
def column_name(self, data, node):
|
||||
n = Name()
|
||||
n.unserialize(data[_NAME_COL])
|
||||
n.unserialize(data[PeopleModel._NAME_COL])
|
||||
return NameDisplay.displayer.sorted_name(n)
|
||||
|
||||
def column_id(self, data, node):
|
||||
return data[_ID_COL]
|
||||
return data[PeopleModel._ID_COL]
|
||||
|
||||
def column_change(self, data, node):
|
||||
return unicode(
|
||||
time.strftime('%x %X', time.localtime(data[_CHANGE_COL])),
|
||||
_codeset)
|
||||
time.strftime('%x %X',
|
||||
time.localtime(data[PeopleModel._CHANGE_COL])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def column_gender(self, data, node):
|
||||
return _GENDER[data[_GENDER_COL]]
|
||||
return PeopleModel._GENDER[data[PeopleModel._GENDER_COL]]
|
||||
|
||||
def column_birth_day(self, data, node):
|
||||
if data[_BIRTH_COL]:
|
||||
if data[PeopleModel._BIRTH_COL]:
|
||||
b = EventRef()
|
||||
b.unserialize(data[_BIRTH_COL])
|
||||
b.unserialize(data[PeopleModel._BIRTH_COL])
|
||||
birth = self.db.get_event_from_handle(b.ref)
|
||||
date_str = DateHandler.get_date(birth)
|
||||
if date_str != "":
|
||||
return cgi.escape(date_str)
|
||||
|
||||
for event_ref in data[_EVENT_COL]:
|
||||
for event_ref in data[PeopleModel._EVENT_COL]:
|
||||
er = EventRef()
|
||||
er.unserialize(event_ref)
|
||||
event = self.db.get_event_from_handle(er.ref)
|
||||
@ -451,15 +452,15 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
return u""
|
||||
|
||||
def column_death_day(self, data, node):
|
||||
if data[_DEATH_COL]:
|
||||
if data[PeopleModel._DEATH_COL]:
|
||||
dr = EventRef()
|
||||
dr.unserialize(data[_DEATH_COL])
|
||||
dr.unserialize(data[PeopleModel._DEATH_COL])
|
||||
death = self.db.get_event_from_handle(dr.ref)
|
||||
date_str = DateHandler.get_date(death)
|
||||
if date_str != "":
|
||||
return cgi.escape(date_str)
|
||||
|
||||
for event_ref in data[_EVENT_COL]:
|
||||
for event_ref in data[PeopleModel._EVENT_COL]:
|
||||
er = EventRef()
|
||||
er.unserialize(event_ref)
|
||||
event = self.db.get_event_from_handle(er.ref)
|
||||
@ -472,17 +473,17 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
return u""
|
||||
|
||||
def column_cause_of_death(self, data, node):
|
||||
if data[_DEATH_COL]:
|
||||
if data[PeopleModel._DEATH_COL]:
|
||||
dr = EventRef()
|
||||
dr.unserialize(data[_DEATH_COL])
|
||||
dr.unserialize(data[PeopleModel._DEATH_COL])
|
||||
return self.db.get_event_from_handle(dr.ref).get_cause()
|
||||
else:
|
||||
return u""
|
||||
|
||||
def column_birth_place(self, data, node):
|
||||
if data[_BIRTH_COL]:
|
||||
if data[PeopleModel._BIRTH_COL]:
|
||||
br = EventRef()
|
||||
br.unserialize(data[_BIRTH_COL])
|
||||
br.unserialize(data[PeopleModel._BIRTH_COL])
|
||||
event = self.db.get_event_from_handle(br.ref)
|
||||
if event:
|
||||
place_handle = event.get_place_handle()
|
||||
@ -492,7 +493,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
if place_title != "":
|
||||
return cgi.escape(place_title)
|
||||
|
||||
for event_ref in data[_EVENT_COL]:
|
||||
for event_ref in data[PeopleModel._EVENT_COL]:
|
||||
er = EventRef()
|
||||
er.unserialize(event_ref)
|
||||
event = self.db.get_event_from_handle(er.ref)
|
||||
@ -508,9 +509,9 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
return u""
|
||||
|
||||
def column_death_place(self, data, node):
|
||||
if data[_DEATH_COL]:
|
||||
if data[PeopleModel._DEATH_COL]:
|
||||
dr = EventRef()
|
||||
dr.unserialize(data[_DEATH_COL])
|
||||
dr.unserialize(data[PeopleModel._DEATH_COL])
|
||||
event = self.db.get_event_from_handle(dr.ref)
|
||||
if event:
|
||||
place_handle = event.get_place_handle()
|
||||
@ -520,7 +521,7 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
if place_title != "":
|
||||
return cgi.escape(place_title)
|
||||
|
||||
for event_ref in data[_EVENT_COL]:
|
||||
for event_ref in data[PeopleModel._EVENT_COL]:
|
||||
er = EventRef()
|
||||
er.unserialize(event_ref)
|
||||
event = self.db.get_event_from_handle(er.ref)
|
||||
@ -537,20 +538,20 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
|
||||
def column_marker_text(self, data, node):
|
||||
try:
|
||||
if data[_MARKER_COL]:
|
||||
return str(data[_MARKER_COL])
|
||||
if data[PeopleModel._MARKER_COL]:
|
||||
return str(data[PeopleModel._MARKER_COL])
|
||||
except IndexError:
|
||||
return ""
|
||||
return ""
|
||||
|
||||
def column_marker_color(self, data, node):
|
||||
try:
|
||||
if data[_MARKER_COL]:
|
||||
if data[_MARKER_COL][0] == MarkerType.COMPLETE:
|
||||
if data[PeopleModel._MARKER_COL]:
|
||||
if data[PeopleModel._MARKER_COL][0] == MarkerType.COMPLETE:
|
||||
return self.complete_color
|
||||
if data[_MARKER_COL][0] == MarkerType.TODO:
|
||||
if data[PeopleModel._MARKER_COL][0] == MarkerType.TODO:
|
||||
return self.todo_color
|
||||
if data[_MARKER_COL][0] == MarkerType.CUSTOM:
|
||||
if data[PeopleModel._MARKER_COL][0] == MarkerType.CUSTOM:
|
||||
return self.custom_color
|
||||
except IndexError:
|
||||
pass
|
||||
@ -575,35 +576,25 @@ class PeopleModel(gtk.GenericTreeModel):
|
||||
def column_header_view(self, node):
|
||||
return True
|
||||
|
||||
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ]
|
||||
# table of column definitions
|
||||
# (unless this is declared after the PeopleModel class, an error is thrown)
|
||||
|
||||
# table of column definitions
|
||||
# (unless this is declared after the PeopleModel class, an error is thrown)
|
||||
COLUMN_DEFS = [
|
||||
(column_name, column_header, str),
|
||||
(column_id, None, str),
|
||||
(column_gender, None, str),
|
||||
(column_birth_day, None, str),
|
||||
(column_birth_place, None, str),
|
||||
(column_death_day, None, str),
|
||||
(column_death_place, None, str),
|
||||
(column_spouse, None, str),
|
||||
(column_change, None, str),
|
||||
(column_cause_of_death, None, str),
|
||||
(column_marker_text, None, str),
|
||||
(column_marker_color, None, str),
|
||||
# the order of the above columns must match PeopleView.column_names
|
||||
|
||||
COLUMN_DEFS = [
|
||||
(PeopleModel.column_name, PeopleModel.column_header, str),
|
||||
(PeopleModel.column_id, None, str),
|
||||
(PeopleModel.column_gender, None, str),
|
||||
(PeopleModel.column_birth_day, None, str),
|
||||
(PeopleModel.column_birth_place, None, str),
|
||||
(PeopleModel.column_death_day, None, str),
|
||||
(PeopleModel.column_death_place, None, str),
|
||||
(PeopleModel.column_spouse, None, str),
|
||||
(PeopleModel.column_change, None, str),
|
||||
(PeopleModel.column_cause_of_death, None, str),
|
||||
(PeopleModel.column_marker_text, None, str),
|
||||
(PeopleModel.column_marker_color, None, str),
|
||||
# the order of the above columns must match PeopleView.column_names
|
||||
|
||||
# these columns are hidden, and must always be last in the list
|
||||
(PeopleModel.column_tooltip, None, object),
|
||||
(PeopleModel.column_int_id, None, str),
|
||||
]
|
||||
|
||||
# dynamic calculation of column indices, for use by various Views
|
||||
COLUMN_INT_ID = 13
|
||||
|
||||
# indices into main column definition table
|
||||
COLUMN_DEF_LIST = 0
|
||||
COLUMN_DEF_HEADER = 1
|
||||
COLUMN_DEF_TYPE = 2
|
||||
# these columns are hidden, and must always be last in the list
|
||||
(column_tooltip, None, object),
|
||||
(column_int_id, None, str),
|
||||
]
|
161
src/DisplayModels/_PlaceModel.py
Normal file
161
src/DisplayModels/_PlaceModel.py
Normal file
@ -0,0 +1,161 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PlaceModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class PlaceModel(BaseModel):
|
||||
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
|
||||
self.gen_cursor = db.get_place_cursor
|
||||
self.map = db.get_raw_place_data
|
||||
self.fmap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_parish,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_longitude,
|
||||
self.column_latitude,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_parish,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_longitude,
|
||||
self.column_latitude,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
]
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=12,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_name(self,data):
|
||||
return unicode(data[2])
|
||||
|
||||
def column_longitude(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_latitude(self,data):
|
||||
return unicode(data[4])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_parish(self,data):
|
||||
try:
|
||||
return data[5][1]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_city(self,data):
|
||||
try:
|
||||
return data[5][0][0]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_county(self,data):
|
||||
try:
|
||||
return data[5][2]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_state(self,data):
|
||||
try:
|
||||
return data[5][0][1]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_country(self,data):
|
||||
try:
|
||||
return data[5][0][2]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_postal_code(self,data):
|
||||
try:
|
||||
return data[5][0][3]
|
||||
except:
|
||||
return u''
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[11]
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[11])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(
|
||||
self.db, lambda:
|
||||
self.db.get_place_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.", exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
221
src/DisplayModels/_RepositoryModel.py
Normal file
221
src/DisplayModels/_RepositoryModel.py
Normal file
@ -0,0 +1,221 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
import RelLib
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# RepositoryModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class RepositoryModel(BaseModel):
|
||||
|
||||
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
|
||||
self.gen_cursor = db.get_repository_cursor
|
||||
self.get_handles = db.get_repository_handles
|
||||
self.map = db.get_raw_repository_data
|
||||
self.fmap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_home_url,
|
||||
self.column_street,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_email,
|
||||
self.column_search_url,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
|
||||
self.smap = [
|
||||
self.column_name,
|
||||
self.column_id,
|
||||
self.column_type,
|
||||
self.column_home_url,
|
||||
self.column_street,
|
||||
self.column_postal_code,
|
||||
self.column_city,
|
||||
self.column_county,
|
||||
self.column_state,
|
||||
self.column_country,
|
||||
self.column_email,
|
||||
self.column_search_url,
|
||||
self.column_handle,
|
||||
]
|
||||
|
||||
BaseModel.__init__(self, db, scol, order, tooltip_column=12,
|
||||
search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_type(self,data):
|
||||
return str(RelLib.RepositoryType(data[2]))
|
||||
|
||||
def column_name(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_city(self,data):
|
||||
try:
|
||||
if data[4]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[4][0])
|
||||
return addr.get_city()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_street(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_street()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_county(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_county()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_state(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_state()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_country(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_country()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_postal_code(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_postal_code()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_phone(self,data):
|
||||
try:
|
||||
if data[5]:
|
||||
addr = RelLib.Address()
|
||||
addr.unserialize(data[5][0])
|
||||
return addr.get_phone()
|
||||
else:
|
||||
return u''
|
||||
except:
|
||||
return u''
|
||||
|
||||
def column_email(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.EMAIL:
|
||||
return unicode(url.path)
|
||||
return u''
|
||||
|
||||
def column_search_url(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.WEB_SEARCH:
|
||||
return unicode(url.path)
|
||||
return u''
|
||||
|
||||
def column_home_url(self,data):
|
||||
if data[6]:
|
||||
for i in data[6]:
|
||||
url = RelLib.Url()
|
||||
url.unserialize(i)
|
||||
if url.get_type() == RelLib.UrlType.WEB_HOME:
|
||||
return unicode(url.path)
|
||||
return u""
|
||||
|
||||
def column_tooltip(self,data):
|
||||
return ""
|
||||
# try:
|
||||
# t = ToolTips.TipFromFunction(self.db, lambda: self.db.get_repository_from_handle(data[0]))
|
||||
# except:
|
||||
# log.error("Failed to create tooltip.", exc_info=True)
|
||||
# return t
|
115
src/DisplayModels/_SourceModel.py
Normal file
115
src/DisplayModels/_SourceModel.py
Normal file
@ -0,0 +1,115 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import time
|
||||
import logging
|
||||
log = logging.getLogger(".")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GNOME/GTK modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import ToolTips
|
||||
import GrampsLocale
|
||||
from _BaseModel import BaseModel
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# SourceModel
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class SourceModel(BaseModel):
|
||||
|
||||
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
|
||||
self.map = db.get_raw_source_data
|
||||
self.gen_cursor = db.get_source_cursor
|
||||
self.fmap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
self.column_author,
|
||||
self.column_abbrev,
|
||||
self.column_pubinfo,
|
||||
self.column_change,
|
||||
self.column_handle,
|
||||
self.column_tooltip
|
||||
]
|
||||
self.smap = [
|
||||
self.column_title,
|
||||
self.column_id,
|
||||
self.column_author,
|
||||
self.column_abbrev,
|
||||
self.column_pubinfo,
|
||||
self.sort_change,
|
||||
]
|
||||
BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search)
|
||||
|
||||
def on_get_n_columns(self):
|
||||
return len(self.fmap)+1
|
||||
|
||||
def column_title(self,data):
|
||||
return unicode(data[2])
|
||||
|
||||
def column_handle(self,data):
|
||||
return unicode(data[0])
|
||||
|
||||
def column_author(self,data):
|
||||
return unicode(data[3])
|
||||
|
||||
def column_abbrev(self,data):
|
||||
return unicode(data[7])
|
||||
|
||||
def column_id(self,data):
|
||||
return unicode(data[1])
|
||||
|
||||
def column_pubinfo(self,data):
|
||||
return unicode(data[4])
|
||||
|
||||
def column_change(self,data):
|
||||
return unicode(time.strftime('%x %X',time.localtime(data[8])),
|
||||
GrampsLocale.codeset)
|
||||
|
||||
def sort_change(self,data):
|
||||
return "%012x" % data[8]
|
||||
|
||||
def column_tooltip(self,data):
|
||||
if const.use_tips:
|
||||
try:
|
||||
t = ToolTips.TipFromFunction(self.db, lambda:
|
||||
self.db.get_source_from_handle(data[0]))
|
||||
except:
|
||||
log.error("Failed to create tooltip.",exc_info=True)
|
||||
return t
|
||||
else:
|
||||
return u''
|
28
src/DisplayModels/__init__.py
Normal file
28
src/DisplayModels/__init__.py
Normal file
@ -0,0 +1,28 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
#
|
||||
# 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$
|
||||
|
||||
from _PeopleModel import PeopleModel
|
||||
from _FamilyModel import FamilyModel
|
||||
from _EventModel import EventModel
|
||||
from _SourceModel import SourceModel
|
||||
from _PlaceModel import PlaceModel
|
||||
from _MediaModel import MediaModel
|
||||
from _RepositoryModel import RepositoryModel
|
@ -8,6 +8,7 @@ SUBDIRS = \
|
||||
Filters \
|
||||
GrampsDb \
|
||||
DisplayTabs \
|
||||
DisplayModels \
|
||||
GrampsLogger \
|
||||
Mime \
|
||||
Models \
|
||||
@ -38,7 +39,6 @@ gdir_PYTHON = \
|
||||
DateEdit.py\
|
||||
Date.py\
|
||||
DdTargets.py\
|
||||
DisplayModels.py\
|
||||
DisplayState.py\
|
||||
Errors.py\
|
||||
Exporter.py\
|
||||
@ -58,7 +58,6 @@ gdir_PYTHON = \
|
||||
NameDisplay.py\
|
||||
Navigation.py\
|
||||
PageView.py\
|
||||
PeopleModel.py\
|
||||
QuestionDialog.py\
|
||||
RecentFiles.py\
|
||||
Relationship.py\
|
||||
|
@ -42,7 +42,7 @@ import pango
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import PeopleModel
|
||||
from DisplayModels import PeopleModel
|
||||
import ManagedWindow
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -68,9 +68,9 @@ class SelectPerson(ManagedWindow.ManagedWindow):
|
||||
self.glade.get_widget('title'),
|
||||
title)
|
||||
|
||||
self.model = PeopleModel.PeopleModel(self.db,
|
||||
(PeopleModel.FAST, filter),
|
||||
skip=skip)
|
||||
self.model = PeopleModel(self.db,
|
||||
(PeopleModel.FAST, filter),
|
||||
skip=skip)
|
||||
|
||||
self.add_columns(self.plist)
|
||||
self.plist.set_model(self.model)
|
||||
|
@ -47,7 +47,7 @@ import NameDisplay
|
||||
import ManagedWindow
|
||||
import ListModel
|
||||
import DateHandler
|
||||
import PeopleModel
|
||||
from DisplayModels import PeopleModel
|
||||
|
||||
from QuestionDialog import ErrorDialog
|
||||
from PluginUtils import Tool, relationship_class, register_tool
|
||||
@ -104,7 +104,7 @@ class RelCalc(Tool.Tool, ManagedWindow.ManagedWindow):
|
||||
|
||||
self.tree = self.glade.get_widget("peopleList")
|
||||
|
||||
self.model = PeopleModel.PeopleModel(self.db,None)
|
||||
self.model = PeopleModel(self.db,None)
|
||||
self.tree.set_model(self.model)
|
||||
|
||||
column = gtk.TreeViewColumn(_('Name'), gtk.CellRendererText(),text=0)
|
||||
|
Loading…
Reference in New Issue
Block a user