GEPS 011: Tagging - Extended to Family, Note and Media objects

svn: r16025
This commit is contained in:
Nick Hall
2010-10-22 23:22:33 +00:00
parent e25cec5186
commit c3e527b4fb
76 changed files with 1294 additions and 1312 deletions

View File

@@ -225,9 +225,9 @@ class ListView(NavigationView):
column = gtk.TreeViewColumn(name, self.renderer)
if self.model and self.model.marker_column() is not None:
mcol = self.model.marker_column()
column.add_attribute(self.renderer, 'foreground', mcol)
if self.model and self.model.color_column() is not None:
fg_col = self.model.color_column()
column.add_attribute(self.renderer, 'foreground', fg_col)
if pair[1] in self.markup_columns:
column.add_attribute(self.renderer, 'markup', pair[1])

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2010 Nick Hall
#
# 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
@@ -26,6 +27,7 @@
#-------------------------------------------------------------------------
import logging
log = logging.getLogger(".")
import locale
#-------------------------------------------------------------------------
#
@@ -56,8 +58,6 @@ from gui.views.treemodels.flatbasemodel import FlatBaseModel
#-------------------------------------------------------------------------
class FamilyModel(FlatBaseModel):
_MARKER_COL = 13
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None,
skip=set(), sort_map=None):
self.gen_cursor = db.get_family_cursor
@@ -68,11 +68,11 @@ class FamilyModel(FlatBaseModel):
self.column_mother,
self.column_type,
self.column_marriage,
self.column_tags,
self.column_change,
self.column_handle,
self.column_tooltip,
self.column_marker_text,
self.column_marker_color,
self.column_tag_color,
self.column_tooltip,
]
self.smap = [
self.column_id,
@@ -80,20 +80,20 @@ class FamilyModel(FlatBaseModel):
self.sort_mother,
self.column_type,
self.sort_marriage,
self.column_tags,
self.sort_change,
self.column_handle,
self.column_tooltip,
self.column_marker_text,
self.column_marker_color,
self.column_tag_color,
self.column_tooltip,
]
FlatBaseModel.__init__(self, db, scol, order, tooltip_column=7,
FlatBaseModel.__init__(self, db, scol, order, tooltip_column=9,
search=search, skip=skip, sort_map=sort_map)
def marker_column(self):
def color_column(self):
"""
Return the column for marker colour.
Return the color column.
"""
return 9
return 8
def on_get_n_columns(self):
return len(self.fmap)+1
@@ -159,27 +159,6 @@ class FamilyModel(FlatBaseModel):
def column_change(self, data):
return Utils.format_time(data[12])
def column_marker_text(self, data):
try:
if data[FamilyModel._MARKER_COL]:
return str(data[FamilyModel._MARKER_COL])
except IndexError:
return ""
return ""
def column_marker_color(self, data):
try:
col = data[FamilyModel._MARKER_COL][0]
if col == gen.lib.MarkerType.COMPLETE:
return self.complete_color
elif col == gen.lib.MarkerType.TODO_TYPE:
return self.todo_color
elif col == gen.lib.MarkerType.CUSTOM:
return self.custom_color
except IndexError:
pass
return None
def column_tooltip(self, data):
if const.USE_TIPS:
try:
@@ -191,3 +170,30 @@ class FamilyModel(FlatBaseModel):
return t
else:
return u''
def get_tag_name(self, tag_handle):
"""
Return the tag name from the given tag handle.
"""
return self.db.get_tag_from_handle(tag_handle).get_name()
def column_tag_color(self, data):
"""
Return the tag color.
"""
tag_color = '#000000000000'
tag_priority = None
for handle in data[13]:
tag = self.db.get_tag_from_handle(handle)
this_priority = tag.get_priority()
if tag_priority is None or this_priority < tag_priority:
tag_color = tag.get_color()
tag_priority = this_priority
return tag_color
def column_tags(self, data):
"""
Return the sorted list of tags.
"""
tag_list = map(self.get_tag_name, data[13])
return ', '.join(sorted(tag_list, key=locale.strxfrm))

View File

@@ -2,7 +2,8 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2009 Benny Malengier
# Copyright (C) 2009 Benny Malengier
# Copyright (C) 2010 Nick Hall
#
# 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
@@ -493,9 +494,9 @@ class FlatBaseModel(gtk.GenericTreeModel):
"""
return self._tooltip_column
def marker_column(self):
def color_column(self):
"""
Return the column for marker colour.
Return the color column.
"""
return None

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2010 Nick Hall
#
# 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
@@ -27,6 +28,7 @@
from gen.ggettext import gettext as _
import logging
log = logging.getLogger(".")
import locale
#-------------------------------------------------------------------------
#
@@ -64,9 +66,11 @@ class MediaModel(FlatBaseModel):
self.column_id,
self.column_mime,
self.column_path,
self.column_change,
self.column_date,
self.column_tags,
self.column_change,
self.column_handle,
self.column_tag_color,
self.column_tooltip
]
@@ -75,13 +79,22 @@ class MediaModel(FlatBaseModel):
self.column_id,
self.column_mime,
self.column_path,
self.sort_change,
self.sort_date,
self.column_tags,
self.sort_change,
self.column_handle,
self.column_tag_color,
self.column_tooltip
]
FlatBaseModel.__init__(self, db, scol, order, tooltip_column=7,
FlatBaseModel.__init__(self, db, scol, order, tooltip_column=9,
search=search, skip=skip, sort_map=sort_map)
def color_column(self):
"""
Return the color column.
"""
return 8
def on_get_n_columns(self):
return len(self.fmap)+1
@@ -141,3 +154,30 @@ class MediaModel(FlatBaseModel):
return t
else:
return u''
def get_tag_name(self, tag_handle):
"""
Return the tag name from the given tag handle.
"""
return self.db.get_tag_from_handle(tag_handle).get_name()
def column_tag_color(self, data):
"""
Return the tag color.
"""
tag_color = '#000000000000'
tag_priority = None
for handle in data[10]:
tag = self.db.get_tag_from_handle(handle)
this_priority = tag.get_priority()
if tag_priority is None or this_priority < tag_priority:
tag_color = tag.get_color()
tag_priority = this_priority
return tag_color
def column_tags(self, data):
"""
Return the sorted list of tags.
"""
tag_list = map(self.get_tag_name, data[10])
return ', '.join(sorted(tag_list, key=locale.strxfrm))

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2010 Nick Hall
#
# 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
@@ -26,6 +27,7 @@
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".gui.notemodel")
import locale
#-------------------------------------------------------------------------
#
@@ -41,7 +43,7 @@ import gtk
#-------------------------------------------------------------------------
import Utils
from gui.views.treemodels.flatbasemodel import FlatBaseModel
from gen.lib import (Note, NoteType, MarkerType, StyledText)
from gen.lib import (Note, NoteType, StyledText)
#-------------------------------------------------------------------------
#
@@ -60,26 +62,26 @@ class NoteModel(FlatBaseModel):
self.column_preview,
self.column_id,
self.column_type,
self.column_marker,
self.column_tags,
self.column_change,
self.column_handle,
self.column_marker_color
self.column_tag_color
]
self.smap = [
self.column_preview,
self.column_id,
self.column_type,
self.column_marker,
self.column_tags,
self.sort_change,
self.column_handle,
self.column_marker_color
self.column_tag_color
]
FlatBaseModel.__init__(self, db, scol, order, search=search,
skip=skip, sort_map=sort_map)
def marker_column(self):
def color_column(self):
"""
Return the column for marker colour.
Return the color column.
"""
return 6
@@ -101,12 +103,6 @@ class NoteModel(FlatBaseModel):
temp.set(data[Note.POS_TYPE])
return unicode(str(temp))
def column_marker(self, data):
"""Return the marker type of the Note in readable format."""
temp = MarkerType()
temp.set(data[Note.POS_MARKER])
return unicode(str(temp))
def column_preview(self, data):
"""Return a shortend version of the Note's text."""
#data is the encoding in the database, make it a unicode object
@@ -118,23 +114,35 @@ class NoteModel(FlatBaseModel):
else:
return note
def column_marker_color(self, data):
"""Return the color of the Note's marker type if exist."""
try:
col = data[Note.POS_MARKER][MarkerType.POS_VALUE]
if col == MarkerType.COMPLETE:
return self.complete_color
elif col == MarkerType.TODO_TYPE:
return self.todo_color
elif col == MarkerType.CUSTOM:
return self.custom_color
else:
return None
except IndexError:
return None
def sort_change(self, data):
return "%012x" % data[Note.POS_CHANGE]
def column_change(self,data):
return Utils.format_time(data[Note.POS_CHANGE])
def get_tag_name(self, tag_handle):
"""
Return the tag name from the given tag handle.
"""
return self.db.get_tag_from_handle(tag_handle).get_name()
def column_tag_color(self, data):
"""
Return the tag color.
"""
tag_color = '#000000000000'
tag_priority = None
for handle in data[Note.POS_TAGS]:
tag = self.db.get_tag_from_handle(handle)
this_priority = tag.get_priority()
if tag_priority is None or this_priority < tag_priority:
tag_color = tag.get_color()
tag_priority = this_priority
return tag_color
def column_tags(self, data):
"""
Return the sorted list of tags.
"""
tag_list = map(self.get_tag_name, data[Note.POS_TAGS])
return ', '.join(sorted(tag_list, key=locale.strxfrm))

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2009 Gary Burton
# Copyright (C) 2009 Nick Hall
# Copyright (C) 2009-2010 Nick Hall
# Copyright (C) 2009 Benny Malengier
#
# This program is free software; you can redistribute it and/or modify
@@ -57,7 +57,7 @@ _LOG = logging.getLogger(".")
#
#-------------------------------------------------------------------------
import const
from gen.lib import Name, EventRef, EventType, EventRoleType, MarkerType
from gen.lib import Name, EventRef, EventType, EventRoleType
from gen.display.name import displayer as name_displayer
import DateHandler
import ToolTips
@@ -79,9 +79,8 @@ COLUMN_DEATH = 5
COLUMN_BIRTH = 6
COLUMN_EVENT = 7
COLUMN_FAMILY = 8
COLUMN_TAGS = 21
COLUMN_CHANGE = 17
COLUMN_MARKER = 18
COLUMN_TAGS = 18
invalid_date_format = config.get('preferences.invalid-date-format')
@@ -121,7 +120,6 @@ class PeopleBaseModel(object):
self.column_tags,
self.column_change,
self.column_int_id,
self.column_marker_text,
self.column_tag_color,
self.column_tooltip,
]
@@ -137,7 +135,6 @@ class PeopleBaseModel(object):
self.column_tags,
self.sort_change,
self.column_int_id,
self.column_marker_text,
self.column_tag_color,
self.column_tooltip,
]
@@ -150,11 +147,11 @@ class PeopleBaseModel(object):
self.lru_bdate = LRU(PeopleBaseModel._CACHE_SIZE)
self.lru_ddate = LRU(PeopleBaseModel._CACHE_SIZE)
def marker_column(self):
def color_column(self):
"""
Return the column for marker colour.
Return the color column.
"""
return 12
return 11
def clear_local_cache(self, handle=None):
""" Clear the LRU cache """
@@ -419,11 +416,6 @@ class PeopleBaseModel(object):
return "<i>" + cgi.escape(place_title) + "</i>"
return u""
def column_marker_text(self, data):
if COLUMN_MARKER < len(data):
return str(data[COLUMN_MARKER])
return ""
def column_tooltip(self, data):
if const.USE_TIPS:
return ToolTips.TipFromFunction(
@@ -446,7 +438,7 @@ class PeopleBaseModel(object):
"""
Return the tag color.
"""
tag_color = None
tag_color = '#000000000000'
tag_priority = None
for handle in data[COLUMN_TAGS]:
tag = self.db.get_tag_from_handle(handle)

View File

@@ -379,9 +379,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
"""
return self._tooltip_column
def marker_column(self):
def color_column(self):
"""
Return the marker color column.
Return the color column.
"""
return None
@@ -772,7 +772,7 @@ class TreeBaseModel(gtk.GenericTreeModel):
node = self.nodemap.node(nodeid)
if node.handle is None:
# Header rows dont get the foreground color set
if col == self.marker_column():
if col == self.color_column():
return None
# Look for header fuction for column and call it