2005-12-21 02:18:18 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-02-04 03:33:53 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2005-12-21 02:18:18 +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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
|
|
|
NoteBase class for GRAMPS
|
|
|
|
"""
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
__revision__ = "$Revision$"
|
|
|
|
|
2005-12-21 02:18:18 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from _Note import Note
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# NoteBase class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NoteBase:
|
|
|
|
"""
|
|
|
|
Base class for storing notes.
|
|
|
|
"""
|
2007-01-08 07:19:33 +05:30
|
|
|
def __init__(self, source=None):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
Create a new NoteBase, copying from source if not None
|
|
|
|
|
|
|
|
@param source: Object used to initialize the new object
|
|
|
|
@type source: NoteBase
|
|
|
|
"""
|
|
|
|
|
|
|
|
if source and source.note:
|
2006-02-04 04:01:46 +05:30
|
|
|
text = source.note.get()
|
2005-12-21 02:18:18 +05:30
|
|
|
else:
|
2006-02-04 04:01:46 +05:30
|
|
|
text = ""
|
|
|
|
self.note = Note(text)
|
2005-12-21 02:18:18 +05:30
|
|
|
|
2006-02-04 03:33:53 +05:30
|
|
|
def serialize(self):
|
2007-01-08 07:19:33 +05:30
|
|
|
"""
|
|
|
|
Converts the object to a serialized tuple of data
|
|
|
|
"""
|
2006-03-14 09:16:54 +05:30
|
|
|
if self.note == None:
|
|
|
|
self.note = Note()
|
2006-02-04 04:01:46 +05:30
|
|
|
return self.note.serialize()
|
2006-02-04 03:33:53 +05:30
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def unserialize(self, data):
|
|
|
|
"""
|
|
|
|
Converts a serialized tuple of data to an object
|
|
|
|
"""
|
2006-02-04 04:01:46 +05:30
|
|
|
if data is not None:
|
2006-02-04 03:33:53 +05:30
|
|
|
self.note = Note().unserialize(data)
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def set_note(self, text):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
Assigns the specified text to the associated note.
|
|
|
|
|
|
|
|
@param text: Text of the note
|
|
|
|
@type text: str
|
|
|
|
"""
|
|
|
|
if not self.note:
|
|
|
|
self.note = Note()
|
|
|
|
self.note.set(text)
|
|
|
|
|
|
|
|
def get_note(self):
|
|
|
|
"""
|
|
|
|
Returns the text of the current note.
|
|
|
|
|
|
|
|
@returns: the text of the current note
|
|
|
|
@rtype: str
|
|
|
|
"""
|
|
|
|
if self.note:
|
|
|
|
return self.note.get()
|
|
|
|
return ""
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def set_note_format(self, val):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
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)
|
|
|
|
@rtype: bool
|
|
|
|
"""
|
|
|
|
if self.note == None:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return self.note.get_format()
|
|
|
|
|
2007-01-08 07:19:33 +05:30
|
|
|
def set_note_object(self, note_obj):
|
2005-12-21 02:18:18 +05:30
|
|
|
"""
|
|
|
|
Replaces the current L{Note} object associated with the object
|
|
|
|
|
|
|
|
@param note_obj: New L{Note} object to be assigned
|
|
|
|
@type note_obj: L{Note}
|
|
|
|
"""
|
|
|
|
self.note = note_obj
|
|
|
|
|
|
|
|
def get_note_object(self):
|
|
|
|
"""
|
|
|
|
Returns the L{Note} instance associated with the object.
|
|
|
|
|
|
|
|
@returns: L{Note} object assocated with the object
|
|
|
|
@rtype: L{Note}
|
|
|
|
"""
|
|
|
|
return self.note
|
|
|
|
|
|
|
|
def unique_note(self):
|
|
|
|
"""Creates a unique instance of the current note"""
|
|
|
|
self.note = Note(self.note.get())
|