2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-03-29 04:52:46 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2007-03-28 03:17:18 +05:30
|
|
|
# $Id$
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
2008-03-29 04:52:46 +05:30
|
|
|
_LOG = logging.getLogger(".DisplayModels.NoteModel")
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from _BaseModel import BaseModel
|
2008-03-29 04:52:46 +05:30
|
|
|
from gen.lib import (Note, NoteType, MarkerType, StyledText)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-03-29 04:52:46 +05:30
|
|
|
# NoteModel
|
2007-02-13 23:26:31 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NoteModel(BaseModel):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""
|
|
|
|
"""
|
|
|
|
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None,
|
2007-02-13 23:26:31 +05:30
|
|
|
skip=set(), sort_map=None):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Setup initial values for instance variables."""
|
2007-02-20 10:05:34 +05:30
|
|
|
self.gen_cursor = db.get_note_cursor
|
|
|
|
self.map = db.get_raw_note_data
|
2007-02-13 23:26:31 +05:30
|
|
|
self.fmap = [
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_preview,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_id,
|
2007-02-20 10:05:34 +05:30
|
|
|
self.column_type,
|
2007-03-28 19:30:03 +05:30
|
|
|
self.column_marker,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_handle,
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_marker_color
|
2008-03-29 04:52:46 +05:30
|
|
|
]
|
2007-02-13 23:26:31 +05:30
|
|
|
self.smap = [
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_preview,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_id,
|
2007-02-20 10:05:34 +05:30
|
|
|
self.column_type,
|
2007-03-28 19:30:03 +05:30
|
|
|
self.column_marker,
|
2007-02-13 23:26:31 +05:30
|
|
|
self.column_handle,
|
2008-01-10 02:45:28 +05:30
|
|
|
self.column_marker_color
|
2008-03-29 04:52:46 +05:30
|
|
|
]
|
2007-04-19 17:48:38 +05:30
|
|
|
self.marker_color_column = 5
|
2008-03-29 04:52:46 +05:30
|
|
|
BaseModel.__init__(self, db, scol, order, search=search,
|
|
|
|
skip=skip, sort_map=sort_map)
|
2007-02-13 23:26:31 +05:30
|
|
|
|
|
|
|
def on_get_n_columns(self):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Return the column number of the Note tab."""
|
|
|
|
return len(self.fmap) + 1
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_handle(self, data):
|
|
|
|
"""Return the handle of the Note."""
|
|
|
|
return data[Note.POS_HANDLE]
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_id(self, data):
|
|
|
|
"""Return the id of the Note."""
|
|
|
|
return unicode(data[Note.POS_ID])
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_type(self, data):
|
|
|
|
"""Return the type of the Note in readable format."""
|
|
|
|
temp = NoteType()
|
|
|
|
temp.set(data[Note.POS_TYPE])
|
2007-02-20 10:05:34 +05:30
|
|
|
return unicode(str(temp))
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2007-03-28 19:30:03 +05:30
|
|
|
def column_marker(self, data):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Return the marker type of the Note in readable format."""
|
|
|
|
temp = MarkerType()
|
|
|
|
temp.set(data[Note.POS_MARKER])
|
2007-03-28 19:30:03 +05:30
|
|
|
return unicode(str(temp))
|
|
|
|
|
2008-03-29 04:52:46 +05:30
|
|
|
def column_preview(self, data):
|
|
|
|
"""Return a shortend version of the Note's text."""
|
2008-02-14 14:28:37 +05:30
|
|
|
#data is the encoding in the database, make it a unicode object
|
|
|
|
#for universal work
|
2008-03-29 04:52:46 +05:30
|
|
|
note = unicode(data[Note.POS_TEXT][StyledText.POS_TEXT])
|
|
|
|
note = " ".join(note.split())
|
2007-02-20 10:05:34 +05:30
|
|
|
if len(note) > 80:
|
2008-03-29 04:52:46 +05:30
|
|
|
return note[:80] + "..."
|
2007-02-20 10:05:34 +05:30
|
|
|
else:
|
|
|
|
return note
|
2007-02-13 23:26:31 +05:30
|
|
|
|
2007-04-19 17:48:38 +05:30
|
|
|
def column_marker_color(self, data):
|
2008-03-29 04:52:46 +05:30
|
|
|
"""Return the color of the Note's marker type if exist."""
|
2007-04-19 17:48:38 +05:30
|
|
|
try:
|
2008-03-29 04:52:46 +05:30
|
|
|
col = data[Note.POS_MARKER][MarkerType.POS_VALUE]
|
|
|
|
if col == MarkerType.COMPLETE:
|
2007-04-19 17:48:38 +05:30
|
|
|
return self.complete_color
|
2008-03-29 04:52:46 +05:30
|
|
|
elif col == MarkerType.TODO_TYPE:
|
2007-04-19 17:48:38 +05:30
|
|
|
return self.todo_color
|
2008-03-29 04:52:46 +05:30
|
|
|
elif col == MarkerType.CUSTOM:
|
2007-04-19 17:48:38 +05:30
|
|
|
return self.custom_color
|
2008-03-29 04:52:46 +05:30
|
|
|
else:
|
|
|
|
return None
|
2007-04-19 17:48:38 +05:30
|
|
|
except IndexError:
|
2008-03-29 04:52:46 +05:30
|
|
|
return None
|