Merge multiple notes branch

svn: r8182
This commit is contained in:
Alex Roitman
2007-02-20 00:39:10 +00:00
parent deee3846be
commit 961a543cda
34 changed files with 1002 additions and 471 deletions

View File

@@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2000-2007 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
@@ -26,13 +26,6 @@ NoteBase class for GRAMPS
__revision__ = "$Revision$"
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _Note import Note
#-------------------------------------------------------------------------
#
# NoteBase class
@@ -41,6 +34,10 @@ from _Note import Note
class NoteBase:
"""
Base class for storing notes.
Starting in 2.3 branch, the objects may have multiple notes.
Internally, this class maintains a list of Note handles,
as a note_list attribute of the NoteBase object.
"""
def __init__(self, source=None):
"""
@@ -50,90 +47,80 @@ class NoteBase:
@type source: NoteBase
"""
if source and source.note:
text = source.note.get()
if source:
self.note_list = [handle for handle in source.note_list]
else:
text = ""
self.note = Note(text)
self.note_list = []
def serialize(self):
"""
Converts the object to a serialized tuple of data
"""
if self.note == None:
self.note = Note()
return self.note.serialize()
return self.note_list
def unserialize(self, data):
"""
Converts a serialized tuple of data to an object
"""
if data is not None:
self.note = Note().unserialize(data)
self.note_list = [handle for handle in data]
def set_note(self, text):
def add_note(self,handle):
"""
Assigns the specified text to the associated note.
Adds the L{Note} handle to the list of note handles.
@param text: Text of the note
@type text: str
"""
if not self.note:
self.note = Note()
self.note.set(text)
@param handle: L{Note} handle to add the list of notes
@type handle: str
def get_note(self, markup=False):
"""
Returns the text of the current note.
@returns: the text of the current note
@rtype: str
"""
if self.note:
return self.note.get(markup)
return ""
def set_note_format(self, val):
"""
Sets the note's format to the given value. The format indicates
whether the text is flowed (wrapped) or preformatted.
@param val: True indicates the text is flowed
@type val: bool
"""
if self.note:
self.note.set_format(val)
def get_note_format(self):
"""
Returns the current note's format
@returns: True indicates that the note should be flowed (wrapped)
@return: True if handle was added, False if it already was in the list
@rtype: bool
"""
if self.note == None:
if handle in self.note_list:
return False
else:
return self.note.get_format()
self.note_list.append(handle)
return True
def set_note_object(self, note_obj):
def remove_note(self,handle):
"""
Replaces the current L{Note} object associated with the object
Removes the specified handle from the list of note handles.
@param note_obj: New L{Note} object to be assigned
@type note_obj: L{Note}
@param handle: L{Note} handle to remove from the list of notes
@type handle: str
@return: True if handle was removed, False if it was not in the list
@rtype: bool
"""
self.note = note_obj
if handle in self.note_list:
self.note_list.remove(handle)
return True
else:
return False
def get_note_object(self):
def get_note_list(self):
"""
Returns the L{Note} instance associated with the object.
Returns the list of L{Note} handles associated with the object
@returns: L{Note} object assocated with the object
@rtype: L{Note}
@return: The list of L{Note} handles
@rtype: list
"""
return self.note
return self.note_list
def unique_note(self):
"""Creates a unique instance of the current note"""
self.note = Note(self.note.get())
def set_note_list(self,note_list):
"""
Assign the passed list to be object's list of L{Note} handles.
@param note_list: List of L{Note} handles to be set on the object
@type note_list: list
"""
self.note_list = note_list
def get_referenced_note_handles(self):
"""
Returns the list of (classname,handle) tuples for all referenced notes.
This method should be used to get the L{Note} portion of the list
by objects that store note lists.
@return: List of (classname,handle) tuples for referenced objects.
@rtype: list
"""
return [('Note',handle) for handle in self.note_list]