From ad36ca1d56268dc584ac7f2cc705a3c510b52103 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 20 Feb 2007 04:35:34 +0000 Subject: [PATCH] 2007-02-19 Don Allingham * src/DataViews/_NoteView.py: Display data and columns * src/RelLib/__init__.py: import NoteType * src/DisplayModels/_NoteModel.py: Display data and columns * src/GrampsDbUtils/_GedcomParse.py: note import improvements svn: r8186 --- ChangeLog | 6 ++ src/DataViews/_NoteView.py | 27 ++++--- src/DisplayModels/_NoteModel.py | 30 ++++---- src/GrampsDbUtils/_GedcomParse.py | 124 ++++++++++-------------------- src/RelLib/__init__.py | 1 + 5 files changed, 77 insertions(+), 111 deletions(-) diff --git a/ChangeLog b/ChangeLog index b679ab2e4..285d64f01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-02-19 Don Allingham + * src/DataViews/_NoteView.py: Display data and columns + * src/RelLib/__init__.py: import NoteType + * src/DisplayModels/_NoteModel.py: Display data and columns + * src/GrampsDbUtils/_GedcomParse.py: note import improvements + 2007-02-19 Brian Matherly * src/plugins/DescendChart.py: include blank pages option * src/plugins/AncestorChart2.py: include blank pages option diff --git a/src/DataViews/_NoteView.py b/src/DataViews/_NoteView.py index 031533990..59e101da1 100644 --- a/src/DataViews/_NoteView.py +++ b/src/DataViews/_NoteView.py @@ -58,6 +58,7 @@ from gettext import gettext as _ column_names = [ _('ID'), + _('Type'), _('Preview'), ] @@ -76,10 +77,10 @@ class NoteView(PageView.ListView): def __init__(self, dbstate, uistate): signal_map = { -# 'place-add' : self.row_add, -# 'place-update' : self.row_update, -# 'place-delete' : self.row_delete, -# 'place-rebuild' : self.build_tree, + 'note-add' : self.row_add, + 'note-update' : self.row_update, + 'note-delete' : self.row_delete, + 'note-rebuild' : self.build_tree, } self.func_list = { @@ -123,11 +124,10 @@ class NoteView(PageView.ListView): def set_column_order(self, clist): #self.dbstate.db.set_place_column_order(clist) - print "build_columns" self.build_columns() def column_order(self): - return [(1, 0, 100), (1, 1, 100)] + return [(1, 0, 100), (1, 1, 100), (1, 2, 100)] def get_stock(self): return 'gramps-notes' @@ -166,7 +166,7 @@ class NoteView(PageView.ListView): def on_double_click(self, obj, event): handle = self.first_selected() - #place = self.dbstate.db.get_place_from_handle(handle) + note = self.dbstate.db.get_note_from_handle(handle) try: #EditPlace(self.dbstate, self.uistate, [], place) print handle @@ -222,7 +222,7 @@ class NoteView(PageView.ListView): self.selection.selected_foreach(self.blist, mlist) for handle in mlist: - #place = self.dbstate.db.get_place_from_handle(handle) + note = self.dbstate.db.get_note_from_handle(handle) try: #EditPlace(self.dbstate, self.uistate, [], place) print handle @@ -230,9 +230,8 @@ class NoteView(PageView.ListView): pass def get_handle_from_gramps_id(self, gid): - print None -# obj = self.dbstate.db.get_place_from_gramps_id(gid) -# if obj: -# return obj.get_handle() -# else: -# return None + obj = self.dbstate.db.get_note_from_gramps_id(gid) + if obj: + return obj.get_handle() + else: + return None diff --git a/src/DisplayModels/_NoteModel.py b/src/DisplayModels/_NoteModel.py index 1f27ac938..ba62ffd26 100644 --- a/src/DisplayModels/_NoteModel.py +++ b/src/DisplayModels/_NoteModel.py @@ -44,6 +44,7 @@ import const import ToolTips import GrampsLocale from _BaseModel import BaseModel +import RelLib #------------------------------------------------------------------------- # @@ -56,15 +57,17 @@ class NoteModel(BaseModel): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None, skip=set(), sort_map=None): - self.gen_cursor = db.get_place_cursor - self.map = db.get_raw_place_data + self.gen_cursor = db.get_note_cursor + self.map = db.get_raw_note_data self.fmap = [ self.column_id, + self.column_type, self.column_preview, self.column_handle, ] self.smap = [ self.column_id, + self.column_type, self.column_preview, self.column_handle, ] @@ -75,19 +78,20 @@ class NoteModel(BaseModel): return len(self.fmap)+1 def column_handle(self,data): - return "" + return data[0] def column_id(self,data): - return "" + return unicode(data[1]) + + def column_type(self,data): + temp = RelLib.NoteType() + temp.set(data[4]) + return unicode(str(temp)) def column_preview(self,data): - return "" + note = " ".join(data[2].split()) + if len(note) > 80: + return note[:80]+"..." + else: + return note - def sort_change(self,data): - return "" - - def column_change(self,data): - return "" - - def column_tooltip(self,data): - return '' diff --git a/src/GrampsDbUtils/_GedcomParse.py b/src/GrampsDbUtils/_GedcomParse.py index 218647741..3e52da31d 100644 --- a/src/GrampsDbUtils/_GedcomParse.py +++ b/src/GrampsDbUtils/_GedcomParse.py @@ -1643,7 +1643,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.person, 1, state.note) + self.parse_note(line, state.person, 1) def func_person_rnote(self, line, state): """ @@ -1654,7 +1654,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.person, 1, state.note) + self.parse_note(line, state.person, 1) def func_person_addr(self, line, state): """ @@ -1735,8 +1735,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.add_to_note(self.parse_note(line, state.name, - state.level+1, state.note)) + self.parse_note(line, state.name, state.level+1) def func_name_alia(self, line, state): """ @@ -1964,7 +1963,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.addr, state.level+1, '') + self.parse_note(line, state.addr, state.level+1) def func_ignore(self, line, state): """ @@ -2149,7 +2148,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.lds_ord, state.level+1, '') + self.parse_note(line, state.lds_ord, state.level+1) def func_lds_stat(self, line, state): """ @@ -2245,10 +2244,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - if not line.data.strip() or line.data and line.data[0] != "@": - self.parse_note_data(state.level+1) - else: - self.skip_subordinate_levels(state.level+1) + self.parse_note(line, state.person, state.level+1) def func_person_famc_primary(self, line, state): """ @@ -2291,7 +2287,7 @@ class GedcomParser(UpdateCallback): """ handle = self.find_family_handle(self.fid_map[line.data]) state.person.add_family_handle(handle) - state.add_to_note(self.parse_optional_note(2)) + self.parse_optional_note(self.person, 2) def func_person_asso(self, line, state): """ @@ -2380,8 +2376,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_note(line, state.ref, state.level, "") - state.ref.add_note(note) + self.parse_note(line, state.ref, state.level) #------------------------------------------------------------------- # @@ -2687,7 +2682,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.family, state.level, '') + self.parse_note(line, state.family, state.level) def func_family_chan(self, line, state): """ @@ -2932,8 +2927,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_note(line, state.place, state.level+1, '') - state.place.add_note(note) + self.parse_note(line, state.place, state.level+1) def func_event_place_form(self, line, state): """ @@ -2973,7 +2967,6 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - print ">>>>", line state.location = RelLib.Location() state.location.set_street(line.data) state.note = None @@ -3022,7 +3015,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.event, state.level+1,'') + self.parse_note(line, state.event, state.level+1) def func_event_source(self, line, state): """ @@ -3286,7 +3279,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.parse_note(line, state.addr, state.level+1, '') + self.parse_note(line, state.addr, state.level+1) def func_srcref_page(self, line, state): """ @@ -3383,8 +3376,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_comment(line, state.src_ref, state.level+1, '') - state.src_ref.add_note(note) + self.parse_note(line, state.src_ref, state.level+1) def func_srcref_text(self, line, state): """ @@ -3513,8 +3505,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_note(line, state.repo_ref, state.level+1, "") - state.repo_ref.set_note(note) + self.parse_note(line, state.repo_ref, state.level+1) def func_source_abbr(self, line, state): """ @@ -3544,7 +3535,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.source.set_note(line.data) + state.source.add_note(line.data) def func_source_note(self, line, state): """ @@ -3553,8 +3544,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_note(line, state.source, state.level+1, '') - state.source.set_note(note) + self.parse_note(line, state.source, state.level+1) def func_source_auth(self, line, state): """ @@ -3672,8 +3662,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - note = self.parse_note(line, state.media, state.level+1, '') - state.media.set_note(note) + self.parse_note(line, state.media, state.level+1) def func_obje_blob(self, line, state): """ @@ -3766,8 +3755,7 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - info = self.parse_note(line, state.attr, state.level+1, '') - state.attr.set_note(info) + self.parse_note(line, state.attr, state.level+1) #---------------------------------------------------------------------- # @@ -3868,7 +3856,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() val = state.location.get_street() if val: val = "%s, %s" % (val, line.data.strip()) @@ -3883,7 +3872,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() state.location.set_date_object(line.data) def func_location_city(self, line, state): @@ -3893,7 +3883,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() state.location.set_city(line.data) def func_location_stae(self, line, state): @@ -3903,7 +3894,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() state.location.set_state(line.data) def func_location_post(self, line, state): @@ -3913,7 +3905,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() state.location.set_postal_code(line.data) def func_location_ctry(self, line, state): @@ -3923,7 +3916,8 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() + if not state.location: + state.location = RelLib.Location() state.location.set_country(line.data) def func_location_note(self, line, state): @@ -3933,60 +3927,26 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - state.location = RelLib.Location() - state.note = self.parse_note_simple(line, state.level+1) + if not state.location: + state.location = RelLib.Location() + self.parse_note(line, state.location, state.level+1) ############################################################################### - def parse_note_data(self, level): - while True: - line = self.get_next() - if self.level_is_finished(line, level): - break - elif line.token in (TOKEN_SOUR, TOKEN_CHAN, TOKEN_REFN, - TOKEN_IGNORE): - self.skip_subordinate_levels(level+1) - elif line.token == TOKEN_RIN: - continue - else: - self.not_recognized(level+1) - - def parse_note_base(self, line, obj, level, old_note, task): + def parse_note(self, line, obj, level): # reference to a named note defined elsewhere - print line if line.token == TOKEN_RNOTE: - note_obj = self.note_map.get(line.data) - if note_obj: - new_note = note_obj.get() - else: - new_note = u"" + obj.add_note(line.data.strip()) else: - new_note = line.data + new_note = Note(line.data) + self.dbase.commit_note(new_note,self.trans) + obj.add_note(new_note.handle) self.skip_subordinate_levels(level+1) - if old_note: - note = u"%s\n%s" % (old_note, line.data) - else: - note = new_note - task(note) - return note - - def parse_note_simple(self, line, level): - # reference to a named note defined elsewhere - if line.data and line.data[0] == "@": - note_obj = self.note_map.get(line.data) - note = note_obj.get() - else: - note = line.data - self.skip_subordinate_levels(level+1) - return note - - def parse_note(self, line, obj, level, old_note): - return self.parse_note_base(line, obj, level, old_note, obj.set_note) def parse_comment(self, line, obj, level, old_note): return self.parse_note_base(line, obj, level, old_note, obj.set_note) - def parse_optional_note(self, level): + def parse_optional_note(self, obj, level): note = "" while True: line = self.get_next() @@ -3994,11 +3954,7 @@ class GedcomParser(UpdateCallback): if self.level_is_finished(line, level): return note elif line.token == TOKEN_NOTE: - if not line.data.strip() or line.data and line.data[0] != "@": - note = line.data - self.parse_note_data(level+1) - else: - self.skip_subordinate_levels(level+1) + self.parse_note(line, obj, level) else: self.not_recognized(level+1) return None diff --git a/src/RelLib/__init__.py b/src/RelLib/__init__.py index 0c35f39ef..9b4967853 100644 --- a/src/RelLib/__init__.py +++ b/src/RelLib/__init__.py @@ -72,3 +72,4 @@ from _FamilyRelType import FamilyRelType from _SourceMediaType import SourceMediaType from _EventRoleType import EventRoleType from _MarkerType import MarkerType +from _NoteType import NoteType