From 976dd620a2aee263cf1708769608b8d07c7a0d61 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Fri, 11 Jan 2013 16:09:23 +0000 Subject: [PATCH] 6307: Improved To Do gramplets svn: r21067 --- gramps/gen/filters/rules/note/__init__.py | 2 + gramps/gen/filters/rules/note/_hastype.py | 57 ++++ gramps/gen/lib/notetype.py | 2 + gramps/plugins/gramplet/gramplet.gpr.py | 112 ++++++ gramps/plugins/gramplet/todo.py | 393 ++++++++++++++++++++++ gramps/plugins/gramplet/todogramplet.py | 196 +++++++++-- 6 files changed, 739 insertions(+), 23 deletions(-) create mode 100644 gramps/gen/filters/rules/note/_hastype.py create mode 100644 gramps/plugins/gramplet/todo.py diff --git a/gramps/gen/filters/rules/note/__init__.py b/gramps/gen/filters/rules/note/__init__.py index 7b41f3f1f..3f2e9a8e2 100644 --- a/gramps/gen/filters/rules/note/__init__.py +++ b/gramps/gen/filters/rules/note/__init__.py @@ -36,6 +36,7 @@ from ._matchesfilter import MatchesFilter from ._hasnote import HasNote from ._changedsince import ChangedSince from ._hastag import HasTag +from ._hastype import HasType editor_rule_list = [ AllNotes, @@ -49,4 +50,5 @@ editor_rule_list = [ MatchesFilter, ChangedSince, HasTag, + HasType, ] diff --git a/gramps/gen/filters/rules/note/_hastype.py b/gramps/gen/filters/rules/note/_hastype.py new file mode 100644 index 000000000..094252307 --- /dev/null +++ b/gramps/gen/filters/rules/note/_hastype.py @@ -0,0 +1,57 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from ....ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +from ....lib.notetype import NoteType +from .. import Rule + +#------------------------------------------------------------------------- +# +# HasType +# +#------------------------------------------------------------------------- +class HasType(Rule): + """Rule that checks for a note of a particular type.""" + + labels = [ _('Note type:') ] + name = _('Notes with the particular type') + description = _("Matches notes with the particular type ") + category = _('General filters') + + def apply(self, db, note): + if not self.list[0]: + return False + else: + specified_type = NoteType() + specified_type.set_from_xml_str(self.list[0]) + return note.get_type() == specified_type diff --git a/gramps/gen/lib/notetype.py b/gramps/gen/lib/notetype.py index 6ef68327f..2136d04c0 100644 --- a/gramps/gen/lib/notetype.py +++ b/gramps/gen/lib/notetype.py @@ -69,6 +69,7 @@ class NoteType(GrampsType): REPORT_TEXT = 23 # this is used for notes used for reports # indicate a note is html code HTML_CODE = 24 + TODO = 25 _CUSTOM = CUSTOM _DEFAULT = GENERAL @@ -84,6 +85,7 @@ class NoteType(GrampsType): (CITATION, _('Citation'), "Citation"), (REPORT_TEXT, _("Report"), "Report"), (HTML_CODE, _("Html code"), "Html code"), + (TODO, _("To Do"), "To Do"), ] _DATAMAPIGNORE = [ diff --git a/gramps/plugins/gramplet/gramplet.gpr.py b/gramps/plugins/gramplet/gramplet.gpr.py index f29cc71f8..77b5f41cb 100644 --- a/gramps/plugins/gramplet/gramplet.gpr.py +++ b/gramps/plugins/gramplet/gramplet.gpr.py @@ -1076,3 +1076,115 @@ register(GRAMPLET, expand=True, gramplet_title=_("Records") ) + +register(GRAMPLET, + id="Person ToDo", + name=_("Person ToDo"), + description = _("Gramplet showing the ToDo notes for a person"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'PersonToDo', + gramplet_title=_("ToDo"), + navtypes=["Person"], + ) + +register(GRAMPLET, + id="Event ToDo", + name=_("Event ToDo"), + description = _("Gramplet showing the ToDo notes for an event"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'EventToDo', + gramplet_title=_("ToDo"), + navtypes=["Event"], + ) + +register(GRAMPLET, + id="Family ToDo", + name=_("Family ToDo"), + description = _("Gramplet showing the ToDo notes for a family"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'FamilyToDo', + gramplet_title=_("ToDo"), + navtypes=["Family"], + ) + +register(GRAMPLET, + id="Place ToDo", + name=_("Place ToDo"), + description = _("Gramplet showing the ToDo notes for a place"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'PlaceToDo', + gramplet_title=_("ToDo"), + navtypes=["Place"], + ) + +register(GRAMPLET, + id="Source ToDo", + name=_("Source ToDo"), + description = _("Gramplet showing the ToDo notes for a source"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'SourceToDo', + gramplet_title=_("ToDo"), + navtypes=["Source"], + ) + +register(GRAMPLET, + id="Citation ToDo", + name=_("Citation ToDo"), + description = _("Gramplet showing the ToDo notes for a citation"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'CitationToDo', + gramplet_title=_("ToDo"), + navtypes=["Citation"], + ) + +register(GRAMPLET, + id="Repository ToDo", + name=_("Repository ToDo"), + description = _("Gramplet showing the ToDo notes for a repository"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'RepositoryToDo', + gramplet_title=_("ToDo"), + navtypes=["Repository"], + ) + +register(GRAMPLET, + id="Media ToDo", + name=_("Media ToDo"), + description = _("Gramplet showing the ToDo notes for a media object"), + version="1.0.0", + gramps_target_version="4.1", + status = STABLE, + fname="todo.py", + height=200, + gramplet = 'MediaToDo', + gramplet_title=_("ToDo"), + navtypes=["Media"], + ) diff --git a/gramps/plugins/gramplet/todo.py b/gramps/plugins/gramplet/todo.py new file mode 100644 index 000000000..afc1e2d3f --- /dev/null +++ b/gramps/plugins/gramplet/todo.py @@ -0,0 +1,393 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2013 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 +# 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 gramps.gen.plug import Gramplet +from gramps.gui.widgets.styledtexteditor import StyledTextEditor +from gramps.gui.widgets import SimpleButton +from gramps.gen.lib import StyledText, Note, NoteType +from gramps.gen.db import DbTxn +from gramps.gen.ggettext import gettext as _ +from gi.repository import Gtk + +class ToDo(Gramplet): + """ + Displays the ToDo notes for an object. + """ + def init(self): + self.gui.WIDGET = self.build_gui() + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) + self.gui.WIDGET.show() + + def build_gui(self): + """ + Build the GUI interface. + """ + top = Gtk.VBox(False) + + hbox = Gtk.HBox() + self.left = SimpleButton(Gtk.STOCK_GO_BACK, self.left_clicked) + self.left.set_sensitive(False) + hbox.pack_start(self.left, False, False, 0) + self.right = SimpleButton(Gtk.STOCK_GO_FORWARD, self.right_clicked) + self.right.set_sensitive(False) + hbox.pack_start(self.right, False, False, 0) + self.edit = SimpleButton(Gtk.STOCK_EDIT, self.edit_clicked) + hbox.pack_start(self.edit, False, False, 0) + self.new = SimpleButton(Gtk.STOCK_NEW, self.new_clicked) + hbox.pack_start(self.new, False, False, 0) + self.page = Gtk.Label() + hbox.pack_end(self.page, False, False, 10) + + scrolledwindow = Gtk.ScrolledWindow() + scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, + Gtk.PolicyType.AUTOMATIC) + self.texteditor = StyledTextEditor() + self.texteditor.set_editable(False) + self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD) + scrolledwindow.add(self.texteditor) + + top.pack_start(hbox, False, False, 0) + top.pack_start(scrolledwindow, True, True, 0) + top.show_all() + return top + + def get_note_list(self, obj): + """ + Get a list of ToDo notes for the current object. + """ + note_list = [] + for note_handle in obj.get_note_list(): + note = self.dbstate.db.get_note_from_handle(note_handle) + if int(note.get_type()) == NoteType.TODO: + note_list.append(note.get_handle()) + return note_list + + def get_notes(self, obj): + """ + Display the ToDo notes for the current object. + """ + self.obj = obj + self.left.set_sensitive(False) + self.right.set_sensitive(False) + self.texteditor.set_text(StyledText()) + self.note_list = self.get_note_list(obj) + self.page.set_text('') + if len(self.note_list) > 0: + self.set_has_data(True) + if len(self.note_list) > 1: + self.right.set_sensitive(True) + self.current = 0 + self.display_note() + else: + self.set_has_data(False) + + def clear_text(self): + self.left.set_sensitive(False) + self.right.set_sensitive(False) + self.texteditor.set_text(StyledText()) + self.page.set_text('') + self.current = 0 + + def display_note(self): + """ + Display the current note. + """ + note_handle = self.note_list[self.current] + note = self.dbstate.db.get_note_from_handle(note_handle) + self.texteditor.set_text(note.get_styledtext()) + self.page.set_text(_('%(current)d of %(total)d') % + {'current': self.current + 1, + 'total': len(self.note_list)}) + + def left_clicked(self, button): + """ + Display the previous note. + """ + if self.current > 0: + self.current -= 1 + self.right.set_sensitive(True) + if self.current == 0: + self.left.set_sensitive(False) + self.display_note() + + def right_clicked(self, button): + """ + Display the next note. + """ + if self.current < len(self.note_list) - 1: + self.current += 1 + self.left.set_sensitive(True) + if self.current == len(self.note_list) - 1: + self.right.set_sensitive(False) + self.display_note() + + def get_has_data(self, obj): + """ + Return True if the gramplet has data, else return False. + """ + if obj is None: + return False + if self.get_note_list(obj): + return True + return False + + def edit_clicked(self, obj): + """ + Edit current ToDo note. + """ + from gramps.gui.editors import EditNote + note_handle = self.note_list[self.current] + note = self.dbstate.db.get_note_from_handle(note_handle) + try: + EditNote(self.gui.dbstate, self.gui.uistate, [], note) + except AttributeError: + pass + + def new_clicked(self, obj): + """ + Create a new ToDo note. + """ + from gramps.gui.editors import EditNote + note = Note() + note.set_type(NoteType.TODO) + try: + EditNote(self.gui.dbstate, self.gui.uistate, [], note, self.created) + except AttributeError: + pass + +class PersonToDo(ToDo): + """ + Displays the ToDo notes for a person. + """ + def db_changed(self): + self.dbstate.db.connect('person-update', self.update) + + def active_changed(self, handle): + self.update() + + def update_has_data(self): + active_handle = self.get_active('Person') + active = self.dbstate.db.get_person_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Person') + active = self.dbstate.db.get_person_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_person(self.obj, trans) + +class EventToDo(ToDo): + """ + Displays the ToDo notes for an event. + """ + def db_changed(self): + self.dbstate.db.connect('event-update', self.update) + self.connect_signal('Event', self.update) + + def update_has_data(self): + active_handle = self.get_active('Event') + active = self.dbstate.db.get_event_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Event') + active = self.dbstate.db.get_event_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_event(self.obj, trans) + +class FamilyToDo(ToDo): + """ + Displays the ToDo notes for a family. + """ + def db_changed(self): + self.dbstate.db.connect('family-update', self.update) + self.connect_signal('Family', self.update) + + def update_has_data(self): + active_handle = self.get_active('Family') + active = self.dbstate.db.get_family_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Family') + active = self.dbstate.db.get_family_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_family(self.obj, trans) + +class PlaceToDo(ToDo): + """ + Displays the ToDo notes for a place. + """ + def db_changed(self): + self.dbstate.db.connect('place-update', self.update) + self.connect_signal('Place', self.update) + + def update_has_data(self): + active_handle = self.get_active('Place') + active = self.dbstate.db.get_place_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Place') + active = self.dbstate.db.get_place_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_place(self.obj, trans) + +class SourceToDo(ToDo): + """ + Displays the ToDo notes for a source. + """ + def db_changed(self): + self.dbstate.db.connect('source-update', self.update) + self.connect_signal('Source', self.update) + + def update_has_data(self): + active_handle = self.get_active('Source') + active = self.dbstate.db.get_source_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Source') + active = self.dbstate.db.get_source_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_source(self.obj, trans) + +class CitationToDo(ToDo): + """ + Displays the ToDo notes for a Citation. + """ + def db_changed(self): + self.dbstate.db.connect('citation-update', self.update) + self.connect_signal('Citation', self.update) + + def update_has_data(self): + active_handle = self.get_active('Citation') + active = self.dbstate.db.get_citation_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Citation') + active = self.dbstate.db.get_citation_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_citation(self.obj, trans) + +class RepositoryToDo(ToDo): + """ + Displays the ToDo notes for a repository. + """ + def db_changed(self): + self.dbstate.db.connect('repository-update', self.update) + self.connect_signal('Repository', self.update) + + def update_has_data(self): + active_handle = self.get_active('Repository') + active = self.dbstate.db.get_repository_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Repository') + active = self.dbstate.db.get_repository_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_repository(self.obj, trans) + +class MediaToDo(ToDo): + """ + Displays the ToDo notes for a media object. + """ + def db_changed(self): + self.dbstate.db.connect('media-update', self.update) + self.connect_signal('Media', self.update) + + def update_has_data(self): + active_handle = self.get_active('Media') + active = self.dbstate.db.get_object_from_handle(active_handle) + self.set_has_data(self.get_has_data(active)) + + def main(self): + active_handle = self.get_active('Media') + active = self.dbstate.db.get_object_from_handle(active_handle) + if active: + self.get_notes(active) + else: + self.clear_text() + self.set_has_data(False) + + def created(self, handle): + with DbTxn('Attach Note', self.dbstate.db) as trans: + self.obj.add_note(handle) + self.dbstate.db.commit_media_object(self.obj, trans) diff --git a/gramps/plugins/gramplet/todogramplet.py b/gramps/plugins/gramplet/todogramplet.py index 8028acb17..89d9adb53 100644 --- a/gramps/plugins/gramplet/todogramplet.py +++ b/gramps/plugins/gramplet/todogramplet.py @@ -1,6 +1,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2007-2009 Douglas S. Blank +# Copyright (C) 2013 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 @@ -15,35 +16,184 @@ # 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$ +# -#------------------------------------------------------------------------ -# -# GRAMPS modules -# -#------------------------------------------------------------------------ from gramps.gen.plug import Gramplet -from gramps.gen.ggettext import sgettext as _ +from gramps.gui.widgets.styledtexteditor import StyledTextEditor +from gramps.gui.widgets import SimpleButton +from gramps.gen.lib import StyledText, Note, NoteType +from gramps.gen.filters import GenericFilterFactory, rules +from gramps.gen.utils.db import navigation_label +from gramps.gen.db import DbTxn +from gramps.gen.ggettext import gettext as _ +from gi.repository import Gtk -#------------------------------------------------------------------------ -# -# TODOGramplet class -# -#------------------------------------------------------------------------ class TODOGramplet(Gramplet): + """ + Displays all the ToDo notes in the database. + """ def init(self): - # GUI setup: - self.set_tooltip(_("Enter text")) - self.gui.textview.set_editable(True) - self.append_text(_("Enter your TODO list here.")) + self.gui.WIDGET = self.build_gui() + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) + self.gui.WIDGET.show() - def on_load(self): - self.load_data_to_text() + def build_gui(self): + """ + Build the GUI interface. + """ + top = Gtk.VBox(False) + + hbox = Gtk.HBox() + self.left = SimpleButton(Gtk.STOCK_GO_BACK, self.left_clicked) + self.left.set_sensitive(False) + hbox.pack_start(self.left, False, False, 0) + self.right = SimpleButton(Gtk.STOCK_GO_FORWARD, self.right_clicked) + self.right.set_sensitive(False) + hbox.pack_start(self.right, False, False, 0) + self.edit = SimpleButton(Gtk.STOCK_EDIT, self.edit_clicked) + hbox.pack_start(self.edit, False, False, 0) + self.new = SimpleButton(Gtk.STOCK_NEW, self.new_clicked) + hbox.pack_start(self.new, False, False, 0) + self.page = Gtk.Label() + hbox.pack_end(self.page, False, False, 10) + + self.title = Gtk.Label() + self.title.set_alignment(0, 0) + self.title.set_line_wrap(True) + + scrolledwindow = Gtk.ScrolledWindow() + scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC, + Gtk.PolicyType.AUTOMATIC) + self.texteditor = StyledTextEditor() + self.texteditor.set_editable(False) + self.texteditor.set_wrap_mode(Gtk.WrapMode.WORD) + scrolledwindow.add(self.texteditor) - def post_init(self): - self.disconnect("active-changed") + top.pack_start(hbox, False, False, 0) + top.pack_start(self.title, False, False, 4) + top.pack_start(scrolledwindow, True, True, 0) + top.show_all() + return top - def on_save(self): - self.gui.data = [] # clear out old data - self.save_text_to_data() + def main(self): + self.get_notes() + + def get_note_list(self): + """ + Get a list of all ToDo notes. + """ + all_notes = self.dbstate.db.get_note_handles() + FilterClass = GenericFilterFactory('Note') + filter = FilterClass() + filter.add_rule(rules.note.HasType([_("To Do")])) + note_list = filter.apply(self.dbstate.db, all_notes) + return note_list + + def get_notes(self): + """ + Display all the ToDo notes. + """ + self.left.set_sensitive(False) + self.right.set_sensitive(False) + self.texteditor.set_text(StyledText()) + self.note_list = self.get_note_list() + self.page.set_text('') + self.title.set_text('') + if len(self.note_list) > 0: + self.set_has_data(True) + if len(self.note_list) > 1: + self.right.set_sensitive(True) + self.current = 0 + self.display_note() + else: + self.set_has_data(False) + + def clear_text(self): + self.left.set_sensitive(False) + self.right.set_sensitive(False) + self.texteditor.set_text(StyledText()) + self.page.set_text('') + self.title.set_text('') + self.current = 0 + + def display_note(self): + """ + Display the current note. + """ + note_handle = self.note_list[self.current] + note = self.dbstate.db.get_note_from_handle(note_handle) + obj = [x for x in self.dbstate.db.find_backlink_handles(note_handle)] + if obj: + name, obj = navigation_label(self.dbstate.db, obj[0][0], obj[0][1]) + self.title.set_text(name) + else: + self.title.set_text("Unattached") + self.texteditor.set_text(note.get_styledtext()) + self.page.set_text(_('%(current)d of %(total)d') % + {'current': self.current + 1, + 'total': len(self.note_list)}) + + def left_clicked(self, button): + """ + Display the previous note. + """ + if self.current > 0: + self.current -= 1 + self.right.set_sensitive(True) + if self.current == 0: + self.left.set_sensitive(False) + self.display_note() + + def right_clicked(self, button): + """ + Display the next note. + """ + if self.current < len(self.note_list) - 1: + self.current += 1 + self.left.set_sensitive(True) + if self.current == len(self.note_list) - 1: + self.right.set_sensitive(False) + self.display_note() + + def get_has_data(self): + """ + Return True if the gramplet has data, else return False. + """ + if self.get_note_list(): + return True + return False + + def edit_clicked(self, obj): + """ + Edit current ToDo note. + """ + from gramps.gui.editors import EditNote + note_handle = self.note_list[self.current] + note = self.dbstate.db.get_note_from_handle(note_handle) + try: + EditNote(self.gui.dbstate, self.gui.uistate, [], note) + except AttributeError: + pass + + def new_clicked(self, obj): + """ + Create a new ToDo note. + """ + from gramps.gui.editors import EditNote + note = Note() + note.set_type(NoteType.TODO) + try: + EditNote(self.gui.dbstate, self.gui.uistate, [], note) + except AttributeError: + pass + + def update_has_data(self): + self.set_has_data(self.get_has_data()) + + def db_changed(self): + self.dbstate.db.connect('note-add', self.update) + self.dbstate.db.connect('note-delete', self.update) + self.dbstate.db.connect('note-update', self.update)