From 18984b840e0372c62b7e2f3a5828c522ed8c1941 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 26 Feb 2007 01:39:16 +0000 Subject: [PATCH] 2007-02-25 Don Allingham * src/DataViews/__init__.py: Add NoteView * src/DataViews/_NoteView.py: Added * src/Config/_GrampsConfigKeys.py: Added new keys to handle note dialog width * src/Editors/__init__.py: Add _EditNote.py * src/Editors/_EditNote.py: Added * src/DisplayTabs/_NoteTab.py: Updated to the new list format * src/GrampsWidgets.py: Add checkbox support * src/glade/gramps.glade: Added edit_note * data/gramps.schemas.in: new keys svn: r8240 --- ChangeLog | 12 ++ data/gramps.schemas.in | 24 ++++ src/Config/_GrampsConfigKeys.py | 4 + src/DataViews/_NoteView.py | 13 +- src/DataViews/__init__.py | 1 - src/DisplayTabs/_NoteTab.py | 19 ++- src/Editors/Makefile.am | 1 + src/Editors/_EditNote.py | 243 ++++++++++++++++++++++++++++++++ src/Editors/__init__.py | 1 + src/GrampsWidgets.py | 2 +- src/glade/gramps.glade | 180 +++++++++++++++++++++++ 11 files changed, 485 insertions(+), 15 deletions(-) create mode 100644 src/Editors/_EditNote.py diff --git a/ChangeLog b/ChangeLog index 998cce2d7..76250e55b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-02-25 Don Allingham + * src/DataViews/__init__.py: Add NoteView + * src/DataViews/_NoteView.py: Added + * src/Config/_GrampsConfigKeys.py: Added new keys to handle note dialog + width + * src/Editors/__init__.py: Add _EditNote.py + * src/Editors/_EditNote.py: Added + * src/DisplayTabs/_NoteTab.py: Updated to the new list format + * src/GrampsWidgets.py: Add checkbox support + * src/glade/gramps.glade: Added edit_note + * data/gramps.schemas.in: new keys + 2007-02-25 Brian Matherly * src/plugins/AncestorChart2.py: Fix index error diff --git a/data/gramps.schemas.in b/data/gramps.schemas.in index fdc8431e3..d933cb3ba 100644 --- a/data/gramps.schemas.in +++ b/data/gramps.schemas.in @@ -297,6 +297,30 @@ + + /schemas/apps/gramps/interface/note-height + /apps/gramps/interface/note-height + gramps + int + 500 + + Height of the note editor interface. + Specifies the height of the note editor interface. + + + + + /schemas/apps/gramps/interface/note-width + /apps/gramps/interface/note-width + gramps + int + 700 + + Width of the note editor interface. + Specifies the width of the note editor interface. + + + /schemas/apps/gramps/interface/person-height /apps/gramps/interface/person-height diff --git a/src/Config/_GrampsConfigKeys.py b/src/Config/_GrampsConfigKeys.py index 78fb61dbd..26a3f656d 100644 --- a/src/Config/_GrampsConfigKeys.py +++ b/src/Config/_GrampsConfigKeys.py @@ -49,6 +49,8 @@ HEIGHT = ('interface','height', 1) WIDTH = ('interface','width', 1) FAMILY_HEIGHT = ('interface','family-height', 1) FAMILY_WIDTH = ('interface','family-width', 1) +NOTE_HEIGHT = ('interface','note-height', 1) +NOTE_WIDTH = ('interface','note-width', 1) PERSON_HEIGHT = ('interface','person-height', 1) PERSON_WIDTH = ('interface','person-width', 1) EVENT_HEIGHT = ('interface','event-height', 1) @@ -148,6 +150,8 @@ default_value = { WIDTH : 775, FAMILY_HEIGHT : 500, FAMILY_WIDTH : 700, + NOTE_HEIGHT : 500, + NOTE_WIDTH : 700, PERSON_HEIGHT : 550, PERSON_WIDTH : 750, EVENT_HEIGHT : 450, diff --git a/src/DataViews/_NoteView.py b/src/DataViews/_NoteView.py index 2237667bf..4c3a4171f 100644 --- a/src/DataViews/_NoteView.py +++ b/src/DataViews/_NoteView.py @@ -48,6 +48,7 @@ import Config from DdTargets import DdTargets from QuestionDialog import QuestionDialog, ErrorDialog from Filters.SideBar import NoteSidebarFilter +from Editors import EditNote #------------------------------------------------------------------------- # @@ -109,9 +110,6 @@ class NoteView(PageView.ListView): self.add_action('FilterEdit', None, _('Note Filter Editor'), callback=self.filter_editor,) -# def drag_info(self): -# return DdTargets.PLACE_LINK - def column_editor(self, obj): pass # import ColumnOrder @@ -168,16 +166,14 @@ class NoteView(PageView.ListView): def on_double_click(self, obj, event): handle = self.first_selected() - note = self.dbstate.db.get_note_from_handle(handle) + note = RelLib.Note() try: - #EditPlace(self.dbstate, self.uistate, [], place) - print handle + EditNote(self.dbstate, self.uistate, [], note) except Errors.WindowActiveError: pass def add(self, obj): try: - #EditPlace(self.dbstate, self.uistate, [], RelLib.Place()) pass except Errors.WindowActiveError: pass @@ -226,8 +222,7 @@ class NoteView(PageView.ListView): for handle in mlist: note = self.dbstate.db.get_note_from_handle(handle) try: - #EditPlace(self.dbstate, self.uistate, [], place) - print handle + EditNote(self.dbstate, self.uistate, [], note) except Errors.WindowActiveError: pass diff --git a/src/DataViews/__init__.py b/src/DataViews/__init__.py index a89e819d3..a8aa5d8f7 100644 --- a/src/DataViews/__init__.py +++ b/src/DataViews/__init__.py @@ -34,7 +34,6 @@ from _EventView import EventView from _SourceView import SourceView from _PlaceView import PlaceView from _MediaView import MediaView -#from _MapView import MapView from _RepositoryView import RepositoryView from _NoteView import NoteView diff --git a/src/DisplayTabs/_NoteTab.py b/src/DisplayTabs/_NoteTab.py index 37422e87c..6e4683f81 100644 --- a/src/DisplayTabs/_NoteTab.py +++ b/src/DisplayTabs/_NoteTab.py @@ -33,9 +33,12 @@ from gettext import gettext as _ # #------------------------------------------------------------------------- import Spell +import Errors + from DisplayTabs import log from _NoteModel import NoteModel from _EmbeddedList import EmbeddedList +from Editors import EditNote #------------------------------------------------------------------------- # @@ -69,7 +72,11 @@ class NoteTab(EmbeddedList): return ((1, 0), (1, 1)) def add_button_clicked(self, obj): - pass + note = RelLib.Note() + try: + EditNote(self.dbstate, self.uistate, [], note) + except Errors.WindowActiveError: + pass def add_callback(self, name): self.get_data().append(name) @@ -77,9 +84,13 @@ class NoteTab(EmbeddedList): self.rebuild() def edit_button_clicked(self, obj): - note = self.get_selected() - if note: - print note + handle = self.get_selected() + if handle: + note = self.dbstate.db.get_note_from_handle(handle) + try: + EditNote(self.dbstate, self.uistate, [], note) + except Errors.WindowActiveError: + pass def edit_callback(self, name): self.changed = True diff --git a/src/Editors/Makefile.am b/src/Editors/Makefile.am index a9968edcb..1e872a0b9 100644 --- a/src/Editors/Makefile.am +++ b/src/Editors/Makefile.am @@ -28,6 +28,7 @@ pkgdata_PYTHON = \ _EditSecondary.py \ _EditSource.py \ _EditSourceRef.py \ + _EditNote.py \ _EditUrl.py pkgpyexecdir = @pkgpyexecdir@/Editors diff --git a/src/Editors/_EditNote.py b/src/Editors/_EditNote.py new file mode 100644 index 000000000..08922993e --- /dev/null +++ b/src/Editors/_EditNote.py @@ -0,0 +1,243 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-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$ + +#------------------------------------------------------------------------- +# +# Python classes +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GTK libraries +# +#------------------------------------------------------------------------- +import gtk +import pango + +#------------------------------------------------------------------------- +# +# GRAMPS classes +# +#------------------------------------------------------------------------- +import const +import Spell +import Config +from _EditPrimary import EditPrimary +from MarkupText import EditorBuffer +from GrampsWidgets import * + +#------------------------------------------------------------------------- +# +# NoteTab +# +#------------------------------------------------------------------------- +class EditNote(EditPrimary): + + def __init__(self, state, uistate, track, note, callback=None): + """ + Creates an EditPerson window. Associates a person with the window. + """ + EditPrimary.__init__(self, state, uistate, track, note, + state.db.get_note_from_handle, callback) + + def empty_object(self): + """ + Returns an empty Person object for comparison for changes. This + is used by the base class (EditPrimary) + """ + return RelLib.Note() + + def get_menu_title(self): + if self.obj.get_handle(): + title = _('Note') + ': %s' % self.obj.get_gramps_id() + else: + title = _('New Note') + return title + + def _local_init(self): + """ + Local initialization function. Performs basic initialization, + including setting up widgets and the glade interface. This is called + by the base class of EditPrimary, and overridden here. + """ + self.top = gtk.glade.XML(const.gladeFile, "edit_note", "gramps") + win = self.top.get_widget("edit_note") + self.set_window(win, None, self.get_menu_title()) + + width = Config.get(Config.NOTE_WIDTH) + height = Config.get(Config.NOTE_HEIGHT) + self.window.set_default_size(width, height) + + self.type = self.top.get_widget('type') + self.format = self.top.get_widget('format') + + container = self.top.get_widget('container') + container.pack_start(self.build_interface()) + container.show_all() + + def _setup_fields(self): + + self.type_selector = MonitoredDataType( + self.top.get_widget("type"), + self.obj.set_type, + self.obj.get_type, + self.db.readonly, + ) + + self.check = MonitoredCheckbox( + self.obj, + self.format, + self.obj.set_format, + self.obj.get_format, + ) + + def _connect_signals(self): + """ + Connects any signals that need to be connected. Called by the + init routine of the base class (_EditPrimary). + """ + self.define_ok_button(self.top.get_widget('ok'),self.save) + self.define_cancel_button(self.top.get_widget('cancel')) + + def build_interface(self): + BUTTON = [(_('Italic'),gtk.STOCK_ITALIC,'i','I'), + (_('Bold'),gtk.STOCK_BOLD,'b','B'), + (_('Underline'),gtk.STOCK_UNDERLINE,'u','U'), + #('Separator', None, None, None), + ] + + vbox = gtk.VBox() + + self.text = gtk.TextView() + self.text.set_accepts_tab(True) + # Accelerator dictionary used for formatting shortcuts + # key: tuple(key, modifier) + # value: widget, to emit 'activate' signal on + self.accelerator = {} + self.text.connect('key-press-event', self._on_key_press_event) + + if self.obj and self.obj.get_format(): + self.format.set_active(True) + self.text.set_wrap_mode(gtk.WRAP_NONE) + else: + self.format.set_active(False) + self.text.set_wrap_mode(gtk.WRAP_WORD) + self.spellcheck = Spell.Spell(self.text) + + self.format.connect('toggled', self.flow_changed) + + scroll = gtk.ScrolledWindow() + scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + scroll.set_shadow_type(gtk.SHADOW_IN) + scroll.add(self.text) + # FIXME: is this signal called at all + scroll.connect('focus-out-event', self.update) + + hbox = gtk.HBox() + hbox.set_spacing(0) + hbox.set_border_width(0) + vbox.pack_start(hbox, False) + + vbox.pack_start(scroll, True) + vbox.set_spacing(6) + vbox.set_border_width(6) + + self.buf = EditorBuffer() + self.text.set_buffer(self.buf) + tooltips = gtk.Tooltips() + for tip, stock, markup, accel in BUTTON: + if markup: + button = gtk.ToggleButton() + image = gtk.Image() + image.set_from_stock(stock, gtk.ICON_SIZE_MENU) + button.set_image(image) + button.set_relief(gtk.RELIEF_NONE) + tooltips.set_tip(button, tip) + self.buf.setup_widget_from_xml(button, markup) + key, mod = gtk.accelerator_parse(accel) + self.accelerator[(key, mod)] = button + hbox.pack_start(button, False) + else: + hbox.pack_start(gtk.VSeparator(), False) + + if self.obj: + self.empty = False + self.buf.set_text(self.obj.get(markup=True)) + #log.debug("Text: %s" % self.buf.get_text()) + else: + self.empty = True + + self.buf.connect('changed', self.update) + self.buf.connect_after('apply-tag', self.update) + self.buf.connect_after('remove-tag', self.update) + #self.rebuild() + return vbox + + def _on_key_press_event(self, widget, event): + #log.debug("Key %s (%d) was pressed on %s" % + #(gtk.gdk.keyval_name(event.keyval), event.keyval, widget)) + key = event.keyval + mod = event.state + if self.accelerator.has_key((key, mod)): + self.accelerator[(key, mod)].emit('activate') + return True + + def update(self, obj, *args): + if self.obj: + start = self.buf.get_start_iter() + stop = self.buf.get_end_iter() + text = self.buf.get_text(start, stop) + self.obj.set(text) + else: + print "NOTE OBJ DOES NOT EXIST" + return False + + def flow_changed(self, obj): + if obj.get_active(): + self.text.set_wrap_mode(gtk.WRAP_NONE) + self.obj.set_format(True) + else: + self.text.set_wrap_mode(gtk.WRAP_WORD) + self.obj.set_format(False) + + def save(self, *obj): + """ + Save the data. + """ + trans = self.db.transaction_begin() + if self.obj.get_handle(): + self.db.commit_note(self.obj,trans) + else: + self.db.add_note(self.obj,trans) + self.db.transaction_commit(trans, _("Edit Note")) + + if self.callback: + self.callback(self.obj) + self.close() + + def _cleanup_on_exit(self): + (width, height) = self.window.get_size() + Config.set(Config.NOTE_WIDTH, width) + Config.set(Config.NOTE_HEIGHT, height) + Config.sync() diff --git a/src/Editors/__init__.py b/src/Editors/__init__.py index 9f344fd96..ace2ec81b 100644 --- a/src/Editors/__init__.py +++ b/src/Editors/__init__.py @@ -18,6 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +from _EditNote import * from _EditAddress import * from _EditAttribute import * from _EditEvent import * diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index ce3c833f2..9ad7f059f 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -316,7 +316,7 @@ class MonitoredCheckbox: self.obj = obj self.set_val = set_val self.get_val = get_val - self.obj.set_active(get_val()) + self.button.set_active(get_val()) def _on_toggle(self, obj): self.set_val(obj.get_active()) diff --git a/src/glade/gramps.glade b/src/glade/gramps.glade index cbbcc444a..dd444b272 100644 --- a/src/glade/gramps.glade +++ b/src/glade/gramps.glade @@ -14982,4 +14982,184 @@ Very High + + True + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + 500 + 400 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + False + 0 + + + + + + + 0 + True + True + + + + + + 6 + True + 1 + 3 + False + 6 + 6 + + + + True + Type + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + False + True + True + + + 1 + 2 + 0 + 1 + fill + + + + + + True + True + Preformatted + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 2 + 3 + 0 + 1 + fill + + + + + + 0 + False + True + + + + + 0 + True + True + + + + + +