From a7ad83b3ff1c27e86b94e42c16b14ac346d4eeac Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 4 Mar 2007 02:55:43 +0000 Subject: [PATCH] 2007-03-03 Don Allingham * src/GrampsDb/_GrampsGEDDB.py: readonly database for GEDCOM * src/Editors/_EditNote.py: add additional fields * src/RelLib/_Note.py: cleanup * src/DisplayTabs/_NoteModel.py: display correctly * src/GrampsWidgets.py: readonly support for checkbox * src/glade/gramps.glade: note fixes * src/DisplayModels/_NoteModel.py: display data correctly * src/GrampsDbUtils/_GedcomParse.py: cleanup * example/gramps/example.gramps: new note support * example/gedcom/sample.ged: new note support svn: r8264 --- ChangeLog | 12 ++++ example/gedcom/sample.ged | 2 + src/DisplayModels/_NoteModel.py | 6 ++ src/DisplayTabs/_NoteModel.py | 2 +- src/Editors/_EditNote.py | 99 +++++++++++++++----------- src/GrampsDb/_GrampsGEDDB.py | 3 +- src/GrampsDbUtils/_GedcomParse.py | 52 ++++---------- src/GrampsWidgets.py | 3 +- src/RelLib/_Note.py | 10 +-- src/glade/gramps.glade | 113 +++++++++++++++++++++++++++--- 10 files changed, 206 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfc6ff01f..777003c00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-03-03 Don Allingham + * src/GrampsDb/_GrampsGEDDB.py: readonly database for GEDCOM + * src/Editors/_EditNote.py: add additional fields + * src/RelLib/_Note.py: cleanup + * src/DisplayTabs/_NoteModel.py: display correctly + * src/GrampsWidgets.py: readonly support for checkbox + * src/glade/gramps.glade: note fixes + * src/DisplayModels/_NoteModel.py: display data correctly + * src/GrampsDbUtils/_GedcomParse.py: cleanup + * example/gramps/example.gramps: new note support + * example/gedcom/sample.ged: new note support + 2007-03-02 Brian Matherly * src/plugins/AncestorChart2.py: * src/plugins/DescendChart.py: diff --git a/example/gedcom/sample.ged b/example/gedcom/sample.ged index 792538866..171eb6061 100755 --- a/example/gedcom/sample.ged +++ b/example/gedcom/sample.ged @@ -13,6 +13,8 @@ 1 GEDC 2 VERS 5.5 2 FORM LINEAGE-LINKED +1 PLAC +2 FORM city, state 1 _SCHEMA 2 INDI 3 _FA1 diff --git a/src/DisplayModels/_NoteModel.py b/src/DisplayModels/_NoteModel.py index ba62ffd26..892a54876 100644 --- a/src/DisplayModels/_NoteModel.py +++ b/src/DisplayModels/_NoteModel.py @@ -26,6 +26,7 @@ #------------------------------------------------------------------------- import time import logging +import re log = logging.getLogger(".") #------------------------------------------------------------------------- @@ -90,6 +91,11 @@ class NoteModel(BaseModel): def column_preview(self,data): note = " ".join(data[2].split()) + note = re.sub(r'(<.*?>)', '', note) + note = note.replace('&', '&') + note = note.replace('<', '<') + note = note.replace('>', '>') + if len(note) > 80: return note[:80]+"..." else: diff --git a/src/DisplayTabs/_NoteModel.py b/src/DisplayTabs/_NoteModel.py index f4a128c5e..51b1a657f 100644 --- a/src/DisplayTabs/_NoteModel.py +++ b/src/DisplayTabs/_NoteModel.py @@ -41,6 +41,6 @@ class NoteModel(gtk.ListStore): note = self.db.get_note_from_handle(handle) self.append(row=[ str(note.get_type()), - note.get().replace('\n', ' ')[:80], + note.delete_tags(note.get()).replace('\n', ' ')[:80], handle, ]) diff --git a/src/Editors/_EditNote.py b/src/Editors/_EditNote.py index 08922993e..bb91b9b44 100644 --- a/src/Editors/_EditNote.py +++ b/src/Editors/_EditNote.py @@ -102,16 +102,28 @@ class EditNote(EditPrimary): self.top.get_widget("type"), self.obj.set_type, self.obj.get_type, - self.db.readonly, - ) + self.db.readonly) self.check = MonitoredCheckbox( self.obj, self.format, self.obj.set_format, self.obj.get_format, - ) + readonly = self.db.readonly) + self.gid = MonitoredEntry( + self.top.get_widget('id'), + self.obj.set_gramps_id, + self.obj.get_gramps_id, + self.db.readonly) + + self.marker = MonitoredDataType( + self.top.get_widget('marker'), + self.obj.set_marker, + self.obj.get_marker, + self.db.readonly, + self.db.get_marker_types()) + def _connect_signals(self): """ Connects any signals that need to be connected. Called by the @@ -131,11 +143,6 @@ class EditNote(EditPrimary): 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) @@ -143,51 +150,61 @@ class EditNote(EditPrimary): 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) + self.buf = EditorBuffer() + self.text.set_buffer(self.buf) + + if self.obj: + self.empty = False + self.buf.set_text(self.obj.get(markup=True)) + else: + self.empty = True + + if not self.dbstate.db.readonly: + self.accelerator = {} + hbox = gtk.HBox() + hbox.set_spacing(0) + hbox.set_border_width(0) + vbox.pack_start(hbox, False) + + 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) 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.dbstate.db.readonly: + self.text.set_editable(False) + return vbox + + # Accelerator dictionary used for formatting shortcuts + # key: tuple(key, modifier) + # value: widget, to emit 'activate' signal on + self.text.connect('key-press-event', self._on_key_press_event) + + self.spellcheck = Spell.Spell(self.text) + + self.format.connect('toggled', self.flow_changed) - 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) diff --git a/src/GrampsDb/_GrampsGEDDB.py b/src/GrampsDb/_GrampsGEDDB.py index f168539cd..c751c17f2 100644 --- a/src/GrampsDb/_GrampsGEDDB.py +++ b/src/GrampsDb/_GrampsGEDDB.py @@ -44,7 +44,7 @@ class GrampsGEDDB(GrampsInMemDB): """creates a new GrampsDB""" GrampsInMemDB.__init__(self) - def load(self,name,callback, mode="w"): + def load(self, name, callback, mode="w"): if self.db_is_open: self.close() GrampsInMemDB.load(self,name,callback,mode) @@ -59,6 +59,7 @@ class GrampsGEDDB(GrampsInMemDB): self.bookmarks = GrampsDbBookmarks(self.metadata.get('bookmarks',[])) self.db_is_open = True + self.readonly = True return 1 def load_from(self, other_database, filename, callback): diff --git a/src/GrampsDbUtils/_GedcomParse.py b/src/GrampsDbUtils/_GedcomParse.py index 310cb77b9..1a7129129 100644 --- a/src/GrampsDbUtils/_GedcomParse.py +++ b/src/GrampsDbUtils/_GedcomParse.py @@ -834,6 +834,10 @@ class GedcomParser(UpdateCallback): TOKEN_NAME : self.__header_subm_name, } + self.place_form = { + TOKEN_FORM : self.__place_form, + } + # look for existing place titles, build a map self.place_names = {} cursor = dbase.get_place_cursor() @@ -4171,7 +4175,16 @@ class GedcomParser(UpdateCallback): @param state: The current state @type state: CurrentState """ - self.__parse_place_form(2) + self.__parse_level(state, self.place_form, self.__undefined) + + def __place_form(self, line, state): + """ + @param line: The current line in GedLine format + @type line: GedLine + @param state: The current state + @type state: CurrentState + """ + self.place_parser.parse_form(line) def __header_date(self, line, state): """ @@ -4219,8 +4232,7 @@ class GedcomParser(UpdateCallback): def __parse_source_reference(self, src_ref, level, handle): """Reads the data associated with a SOUR reference""" - state = GedcomUtils.CurrentState() - state.level = level+1 + state = GedcomUtils.CurrentState(level=level+1) state.src_ref = src_ref state.handle = handle self.__parse_level(state, self.srcref_parse_tbl, self.__ignore) @@ -4237,34 +4249,6 @@ class GedcomParser(UpdateCallback): if self.__level_is_finished(line, level): return - def ignore_change_data(self, level): - line = self.__get_next_line() - if line.token == TOKEN_CHAN: - self.__skip_subordinate_levels(level+1) - else: - self._backup() - - def __parse_place_form(self, level): - while True: - line = self.__get_next_line() - - if self.__level_is_finished(line, level): - break - elif line.token == TOKEN_FORM: - self.place_parser.parse_form(line) - else: - self.__not_recognized(level+1) - - def __parse_date(self, level): - while True: - line = self.__get_next_line() - if self.__level_is_finished(line, level): - break - elif line.token == TOKEN_TIME: - pass - else: - self.__not_recognized(level+1) - def handle_source(self, line, level): source_ref = RelLib.SourceRef() if line.data and line.data[0] != "@": @@ -4316,12 +4300,6 @@ class GedcomParser(UpdateCallback): self.dbase.pmap_index = new_pmax - #-------------------------------------------------------------------- - # - # - # - #-------------------------------------------------------------------- - def __parse_change(self, line, obj, level): """ CHANGE_DATE:= diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index 9ad7f059f..cca27b845 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -309,7 +309,7 @@ class PrivacyButton: class MonitoredCheckbox: - def __init__(self, obj, button, set_val, get_val, on_toggle=None): + def __init__(self, obj, button, set_val, get_val, on_toggle=None, readonly = False): self.button = button self.button.connect('toggled', self._on_toggle) self.on_toggle = on_toggle @@ -317,6 +317,7 @@ class MonitoredCheckbox: self.set_val = set_val self.get_val = get_val self.button.set_active(get_val()) + self.button.set_sensitive(not readonly) def _on_toggle(self, obj): self.set_val(obj.get_active()) diff --git a/src/RelLib/_Note.py b/src/RelLib/_Note.py index ca307ff0c..cc80f7848 100644 --- a/src/RelLib/_Note.py +++ b/src/RelLib/_Note.py @@ -71,16 +71,16 @@ class Note(BasicPrimaryObject): """ Converts the object to a serialized tuple of data """ - return (self.handle,self.gramps_id,self.text,self.format, - self.type.serialize(),self.change, - self.marker.serialize(),self.private) + return (self.handle, self.gramps_id, self.text, self.format, + self.type.serialize(), self.change, self.marker.serialize(), + self.private) def unserialize(self, data): """ Converts a serialized tuple of data to an object """ - (self.handle,self.gramps_id,self.text,self.format, - the_type,self.change,the_marker,self.private) = data + (self.handle, self.gramps_id, self.text, self.format, + the_type, self.change, the_marker, self.private) = data self.marker.unserialize(the_marker) self.type.unserialize(the_type) diff --git a/src/glade/gramps.glade b/src/glade/gramps.glade index dd444b272..fe7bcbc31 100644 --- a/src/glade/gramps.glade +++ b/src/glade/gramps.glade @@ -15073,8 +15073,8 @@ Very High 6 True - 1 - 3 + 2 + 4 False 6 6 @@ -15082,7 +15082,51 @@ Very High True - Type + Type: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + False + True + True + + + 1 + 2 + 1 + 2 + fill + + + + + + True + ID: False False GTK_JUSTIFY_LEFT @@ -15108,15 +15152,64 @@ Very High - + + True + True + True + True + 0 + + True + + False + + + 1 + 2 + 0 + 1 + + + + + + + True + Marker: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 2 + 3 + 0 + 1 + fill + + + + + + True False True True - 1 - 2 + 3 + 4 0 1 fill @@ -15136,10 +15229,10 @@ Very High True - 2 - 3 - 0 - 1 + 3 + 4 + 1 + 2 fill