From 72d064f5b58ad39870164cc6d35970a5db7bc62e Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 23 Feb 2006 03:13:15 +0000 Subject: [PATCH] * src/EditPlace.py: use monitored widgets * src/EditSource.py: use monitored widgets * src/EventEdit.py: use monitored widgets * src/GrampsWidgets.py: start of monitored place * src/GrampsDb/_GrampsDbBase.py: monitor place changes svn: r5975 --- ChangeLog | 7 ++ src/EditPlace.py | 146 +++++++++++++++------------------- src/EditSource.py | 146 +++++++++++++++------------------- src/EventEdit.py | 131 ++++++++++++------------------ src/GrampsDb/_GrampsDbBase.py | 26 ++++++ src/GrampsWidgets.py | 22 +++++ 6 files changed, 231 insertions(+), 247 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e350c994..ad2d0b8a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-02-22 Don Allingham + * src/EditPlace.py: use monitored widgets + * src/EditSource.py: use monitored widgets + * src/EventEdit.py: use monitored widgets + * src/GrampsWidgets.py: start of monitored place + * src/GrampsDb/_GrampsDbBase.py: monitor place changes + 2006-02-22 Alex Roitman * src/EditSourceRef.py (__init__): Typos. * src/DisplayTabs.py (GalleryTab.add_button_clicked): Typos. diff --git a/src/EditPlace.py b/src/EditPlace.py index ca7ff9eea..e8610f2b2 100644 --- a/src/EditPlace.py +++ b/src/EditPlace.py @@ -58,8 +58,8 @@ import RelLib import ListModel from DdTargets import DdTargets -from WindowUtils import GladeIf from DisplayTabs import * +from GrampsWidgets import * #------------------------------------------------------------------------- # @@ -72,81 +72,84 @@ class EditPlace(DisplayState.ManagedWindow): self.dbstate = dbstate self.uistate = uistate - self.ref_not_loaded = place and place.get_handle() - self.idle = None + DisplayState.ManagedWindow.__init__(self, uistate, track, place) + self.name_display = NameDisplay.displayer.display self.place = place self.db = dbstate.db - self.path = dbstate.db.get_save_path() - self.not_loaded = True - self.model = None # becomes the model for back references. - self.lists_changed = 0 self.top = gtk.glade.XML(const.gladeFile,"placeEditor","gramps") - self.gladeif = GladeIf(self.top) self.window = self.top.get_widget("placeEditor") title_label = self.top.get_widget('title') Utils.set_titles(self.window,title_label,_('Place Editor')) - mode = not self.dbstate.db.readonly - self.title = self.top.get_widget("place_title") - self.title.set_editable(mode) - self.city = self.top.get_widget("city") - self.city.set_editable(mode) - self.parish = self.top.get_widget("parish") - self.parish.set_editable(mode) - self.county = self.top.get_widget("county") - self.county.set_editable(mode) - self.state = self.top.get_widget("state") - self.state.set_editable(mode) - self.phone = self.top.get_widget("phone") - self.phone.set_editable(mode) - self.postal = self.top.get_widget("postal") - self.postal.set_editable(mode) - self.country = self.top.get_widget("country") - self.country.set_editable(mode) - self.longitude = self.top.get_widget("longitude") - self.longitude.set_editable(mode) - self.latitude = self.top.get_widget("latitude") - self.latitude.set_editable(mode) - self.top.get_widget('changed').set_text(place.get_change_display()) - self.title.set_text(place.get_title()) - mloc = place.get_main_location() - self.city.set_text(mloc.get_city()) - self.county.set_text(mloc.get_county()) - self.state.set_text(mloc.get_state()) - self.phone.set_text(mloc.get_phone()) - self.postal.set_text(mloc.get_postal_code()) - self.parish.set_text(mloc.get_parish()) - self.country.set_text(mloc.get_country()) - self.longitude.set_text(place.get_longitude()) - self.latitude.set_text(place.get_latitude()) - self.plist = self.top.get_widget("refinfo") - self.notebook = self.top.get_widget('notebook3') - self.gladeif.connect('placeEditor', 'delete_event', self.on_delete_event) - self.gladeif.connect('button127', 'clicked', self.close) - self.gladeif.connect('ok', 'clicked', self.on_place_apply_clicked) - self.gladeif.connect('button135', 'clicked', self.on_help_clicked) - - DisplayState.ManagedWindow.__init__(self, uistate, track, place) - - if self.place.get_handle() == None or self.dbstate.db.readonly: - self.top.get_widget("add_photo").set_sensitive(0) - self.top.get_widget("delete_photo").set_sensitive(0) - - self.top.get_widget('ok').set_sensitive(not self.db.readonly) - self._create_tabbed_pages() + self._setup_fields() + self._connect_signals() self.show() self.pdmap = {} self.build_pdmap() + + def _connect_signals(self): + self.top.get_widget('placeEditor').connect('delete_event', self.delete_event) + self.top.get_widget('button127').connect('clicked', self.close) + self.top.get_widget('button135').connect('clicked', self.help_clicked) + ok = self.top.get_widget('ok') + ok.connect('clicked', self.apply_clicked) + ok.set_sensitive(not self.db.readonly) + + def _setup_fields(self): + mloc = self.place.get_main_location() + + self.title = MonitoredEntry( + self.top.get_widget("place_title"), + self.place.set_title, self.place.get_title, + self.db.readonly) + + self.city = MonitoredEntry( + self.top.get_widget("city"), + mloc.set_city, mloc.get_city, self.db.readonly) + + self.parish = MonitoredEntry( + self.top.get_widget("parish"), + mloc.set_parish, mloc.get_parish, self.db.readonly) + + self.county = MonitoredEntry( + self.top.get_widget("county"), + mloc.set_county, mloc.get_county, self.db.readonly) + + self.state = MonitoredEntry( + self.top.get_widget("state"), + mloc.set_state, mloc.get_state, self.db.readonly) + + self.phone = MonitoredEntry( + self.top.get_widget("phone"), + mloc.set_phone, mloc.get_phone, self.db.readonly) + + self.postal = MonitoredEntry( + self.top.get_widget("postal"), + mloc.set_postal_code, mloc.get_postal_code, self.db.readonly) + + self.country = MonitoredEntry( + self.top.get_widget("country"), + mloc.set_country, mloc.get_county, self.db.readonly) + + self.longitude = MonitoredEntry( + self.top.get_widget("longitude"), + self.place.set_longitude, self.place.get_longitude, + self.db.readonly) + + self.latitude = MonitoredEntry( + self.top.get_widget("latitude"), + self.place.set_latitude, self.place.get_latitude, + self.db.readonly) def build_window_key(self,place): @@ -201,18 +204,14 @@ class EditPlace(DisplayState.ManagedWindow): self.dbstate,self.uistate,self.track, self.db.find_backlink_handles(self.place.handle))) - def on_delete_event(self,obj,b): - self.gladeif.close() + def delete_event(self,obj,b): self.close() def close_window(self,obj): - self.gladeif.close() self.close() self.window.destroy() - if self.idle != None: - gobject.source_remove(self.idle) - def on_help_clicked(self,obj): + def help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-plc') @@ -225,15 +224,9 @@ class EditPlace(DisplayState.ManagedWindow): cnum = cnum + 1 tree.append_column(column) - def set(self,field,getf,setf): - text = unicode(field.get_text()) - if text != getf(): - setf(text) - - def on_place_apply_clicked(self,obj): + def apply_clicked(self,obj): - mloc = self.place.get_main_location() - title = self.title.get_text() + title = self.place.get_title() if self.pdmap.has_key(title) and self.pdmap[title] != self.place.handle: import QuestionDialog QuestionDialog.ErrorDialog( @@ -243,19 +236,6 @@ class EditPlace(DisplayState.ManagedWindow): "another place")) return - self.set(self.city,mloc.get_city,mloc.set_city) - self.set(self.parish,mloc.get_parish,mloc.set_parish) - self.set(self.state,mloc.get_state,mloc.set_state) - self.set(self.phone,mloc.get_phone,mloc.set_phone) - self.set(self.postal,mloc.get_postal_code,mloc.set_postal_code) - self.set(self.county,mloc.get_county,mloc.set_county) - self.set(self.country,mloc.get_country,mloc.set_country) - self.set(self.title,self.place.get_title,self.place.set_title) - self.set(self.longitude,self.place.get_longitude, - self.place.set_longitude) - self.set(self.latitude,self.place.get_latitude, - self.place.set_latitude) - trans = self.db.transaction_begin() if self.place.get_handle(): self.db.commit_place(self.place,trans) diff --git a/src/EditSource.py b/src/EditSource.py index fb5ec84b9..e9e0992cf 100644 --- a/src/EditSource.py +++ b/src/EditSource.py @@ -56,6 +56,7 @@ import DisplayState from DisplayTabs import * from WindowUtils import GladeIf +from GrampsWidgets import * #------------------------------------------------------------------------- # @@ -184,83 +185,83 @@ class EditSource(DisplayState.ManagedWindow): if source: self.source = source - self.ref_not_loaded = 1 else: self.source = RelLib.Source() - self.ref_not_loaded = 0 - self.path = self.db.get_save_path() - self.not_loaded = 1 - self.lists_changed = 0 - mode = not self.db.readonly + self.glade = gtk.glade.XML(const.gladeFile,"sourceEditor","gramps") + self.window = self.glade.get_widget("sourceEditor") - self.top_window = gtk.glade.XML(const.gladeFile,"sourceEditor","gramps") - self.window = self.top_window.get_widget("sourceEditor") - self.gladeif = GladeIf(self.top_window) - - Utils.set_titles(self.window,self.top_window.get_widget('title'), + Utils.set_titles(self.window,self.glade.get_widget('title'), _('Source Editor')) - - self.author = self.top_window.get_widget("author") - self.pubinfo = self.top_window.get_widget("pubinfo") - self.abbrev = self.top_window.get_widget("abbrev") - self.cancel = self.top_window.get_widget('cancel') - self.ok = self.top_window.get_widget('ok') - - self.vbox = self.top_window.get_widget('vbox') - - self.refinfo = self.top_window.get_widget("refinfo") - - self.title = self.top_window.get_widget("source_title") - self.title.set_text(source.get_title()) - self.title.set_editable(mode) - self.author.set_text(source.get_author()) - self.author.set_editable(mode) - self.pubinfo.set_text(source.get_publication_info()) - self.pubinfo.set_editable(mode) - self.abbrev.set_text(source.get_abbreviation()) - self.abbrev.set_editable(mode) - - self.ok.set_sensitive(not self.db.readonly) - self.cancel.connect('clicked', self.close_window) - self.ok.connect('clicked', self.apply_clicked) + + self.vbox = self.glade.get_widget('vbox') self.notebook = gtk.Notebook() self.notebook.show() self.vbox.pack_start(self.notebook,True) - self.load_data() - + self._create_tabbed_pages() + self._setup_fields() + self._connect_signals() self.show() - def load_data(self): - self.note_tab = NoteTab( - self.dbstate, self.uistate, self.track, self.source.get_note_object()) - self.gallery_tab = GalleryTab( - self.dbstate, self.uistate, self.track, self.source.get_media_list()) - self.data_tab = DataEmbedList( - self.dbstate, self.uistate, self.track, self.source) - self.repo_tab = RepoEmbedList( - self.dbstate, self.uistate, self.track, self.source.get_reporef_list()) - self.backref_tab = SourceBackRefList( + def _connect_signals(self): + self.glade.get_widget('cancel').connect('clicked', self.close_window) + + ok = self.glade.get_widget('ok') + ok.set_sensitive(not self.db.readonly) + ok.connect('clicked', self.apply_clicked) + + def _setup_fields(self): + self.author = MonitoredEntry( + self.glade.get_widget("author"), + self.source.set_author, + self.source.get_author, + self.db.readonly) + + self.pubinfo = MonitoredEntry( + self.glade.get_widget("pubinfo"), + self.source.set_publication_info, + self.source.get_publication_info, + self.db.readonly) + + self.abbrev = MonitoredEntry( + self.glade.get_widget("abbrev"), + self.source.set_abbreviation, + self.source.get_abbreviation, + self.db.readonly) + + self.title = MonitoredEntry( + self.glade.get_widget("source_title"), + self.source.set_title, + self.source.get_title, + self.db.readonly) + + def _add_page(self,page): + self.notebook.insert_page(page) + self.notebook.set_tab_label(page,page.get_tab_widget()) + return page + + def _create_tabbed_pages(self): + self.note_tab = self._add_page(NoteTab( self.dbstate, self.uistate, self.track, - self.db.find_backlink_handles(self.source.handle)) + self.source.get_note_object())) + + self.gallery_tab = self._add_page(GalleryTab( + self.dbstate, self.uistate, self.track, + self.source.get_media_list())) + + self.data_tab = self._add_page(DataEmbedList( + self.dbstate, self.uistate, self.track, self.source)) + + self.repo_tab = self._add_page(RepoEmbedList( + self.dbstate, self.uistate, self.track, + self.source.get_reporef_list())) + + self.backref_tab = self._add_page(SourceBackRefList( + self.dbstate, self.uistate, self.track, + self.db.find_backlink_handles(self.source.handle))) - self.notebook.insert_page(self.note_tab) - self.notebook.set_tab_label(self.note_tab,self.note_tab.get_tab_widget()) - - self.notebook.insert_page(self.data_tab) - self.notebook.set_tab_label(self.data_tab,self.data_tab.get_tab_widget()) - - self.notebook.insert_page(self.gallery_tab) - self.notebook.set_tab_label(self.gallery_tab,self.gallery_tab.get_tab_widget()) - - self.notebook.insert_page(self.repo_tab) - self.notebook.set_tab_label(self.repo_tab,self.repo_tab.get_tab_widget()) - - self.notebook.insert_page(self.backref_tab) - self.notebook.set_tab_label(self.backref_tab,self.backref_tab.get_tab_widget()) - self.notebook.show_all() def build_window_key(self,source): @@ -278,7 +279,6 @@ class EditSource(DisplayState.ManagedWindow): def on_delete_event(self,obj,b): self.backref_tab.close() - self.gladeif.close() def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" @@ -286,28 +286,10 @@ class EditSource(DisplayState.ManagedWindow): def close_window(self,obj): self.backref_tab.close() - self.gladeif.close() self.close() def apply_clicked(self,obj): - title = unicode(self.title.get_text()) - author = unicode(self.author.get_text()) - pubinfo = unicode(self.pubinfo.get_text()) - abbrev = unicode(self.abbrev.get_text()) - - if author != self.source.get_author(): - self.source.set_author(author) - - if title != self.source.get_title(): - self.source.set_title(title) - - if pubinfo != self.source.get_publication_info(): - self.source.set_publication_info(pubinfo) - - if abbrev != self.source.get_abbreviation(): - self.source.set_abbreviation(abbrev) - trans = self.db.transaction_begin() if self.source.get_handle() == None: self.db.add_source(self.source,trans) diff --git a/src/EventEdit.py b/src/EventEdit.py index 035931208..91f8edd2f 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -45,19 +45,15 @@ import gtk.glade # gramps modules # #------------------------------------------------------------------------- -import Sources -import Witness import const import Utils import AutoComp import RelLib -from DateHandler import parser as _dp, displayer as _dd import DateEdit import GrampsDisplay import DisplayState from QuestionDialog import WarningDialog, ErrorDialog -from WindowUtils import GladeIf from DisplayTabs import * from GrampsWidgets import * @@ -105,16 +101,11 @@ class EventEditor(DisplayState.ManagedWindow): self.track = track self.callback = callback - read_only = self.db.readonly - noedit = self.db.readonly self.event = event self.path = self.db.get_save_path() self.plist = [] self.pmap = {} - self.dp = _dp - self.dd = _dd - DisplayState.ManagedWindow.__init__(self, uistate, self.track, event) if self.already_exist: return @@ -123,15 +114,10 @@ class EventEditor(DisplayState.ManagedWindow): title = self.db.get_place_from_handle(key).get_title() self.pmap[title] = key - if event: - self.srcreflist = self.event.get_source_references() - self.date = RelLib.Date(self.event.get_date_object()) - else: - self.srcreflist = [] - self.date = RelLib.Date(None) + if not event: + self.event = RelLib.Event() self.top = gtk.glade.XML(const.gladeFile, "event_edit","gramps") - self.gladeif = GladeIf(self.top) self.window = self.top.get_widget("event_edit") title_label = self.top.get_widget('title') @@ -141,64 +127,57 @@ class EventEditor(DisplayState.ManagedWindow): _('Event Editor')) self.place_field = self.top.get_widget("eventPlace") - self.place_field.set_editable(not noedit) - self.cause_field = self.top.get_widget("eventCause") - self.cause_monitor = MonitoredEntry(self.cause_field,self.event.set_cause, - self.event.get_cause, noedit) - self.date_field = self.top.get_widget("eventDate") - self.date_field.set_editable(not noedit) - self.descr_field = MonitoredEntry(self.top.get_widget("event_description"), - self.event.set_description, - self.event.get_description, noedit) - self.event_menu = self.top.get_widget("personal_events") - self.priv = PrivacyButton(self.top.get_widget("private"),self.event) - self.priv.set_sensitive(not noedit) - self.ok = self.top.get_widget('ok') - - self.ok.set_sensitive(not noedit) - - if read_only or noedit: - self.event_menu.set_sensitive(False) - self.date_field.grab_focus() + self.place_field.set_editable(not self.db.readonly) - if event: - defval = event.get_type()[0] + place_handle = event.get_place_handle() + if not place_handle: + place_name = u"" else: - defval = None - - self.type_selector = AutoComp.StandardCustomSelector( - total_events, self.event_menu, - RelLib.Event.CUSTOM, defval) - - AutoComp.fill_entry(self.place_field,self.pmap.keys()) - - if event != None: - place_handle = event.get_place_handle() - if not place_handle: - place_name = u"" - else: - place_name = self.db.get_place_from_handle(place_handle).get_title() - self.place_field.set_text(place_name) - - self.date_field.set_text(_dd.display(self.date)) - - else: - event = RelLib.Event() - date_stat = self.top.get_widget("date_stat") - date_stat.set_sensitive(not self.db.readonly) - self.date_check = DateEdit.DateEdit(self.date, - self.date_field, - date_stat, - self.window) - - self.gladeif.connect('button111','clicked',self.close_window) - self.gladeif.connect('ok','clicked',self.on_event_edit_ok_clicked) - self.gladeif.connect('button126','clicked',self.on_help_clicked) + place_name = self.db.get_place_from_handle(place_handle).get_title() + self.place_field.set_text(place_name) self._create_tabbed_pages() - + self._setup_fields() + self._connect_signals() self.show() + def _connect_signals(self): + self.top.get_widget('button111').connect('clicked',self.close_window) + self.top.get_widget('button126').connect('clicked',self.on_help_clicked) + + ok = self.top.get_widget('ok') + ok.set_sensitive(not self.db.readonly) + ok.connect('clicked',self.on_event_edit_ok_clicked) + + def _setup_fields(self): + self.cause_monitor = MonitoredEntry( + self.top.get_widget("eventCause"), + self.event.set_cause, + self.event.get_cause, self.db.readonly) + + self.descr_field = MonitoredEntry( + self.top.get_widget("event_description"), + self.event.set_description, + self.event.get_description, self.db.readonly) + + + self.priv = PrivacyButton( + self.top.get_widget("private"), + self.event, self.db.readonly) + + self.event_menu = MonitoredType( + self.top.get_widget("personal_events"), + self.event.set_type, + self.event.get_type, + dict(total_events), + RelLib.Event.CUSTOM) + + self.date_field = MonitoredDate( + self.top.get_widget("eventDate"), + self.top.get_widget("date_stat"), + self.event.get_date_object(), + self.window, self.db.readonly) + def _add_page(self,page): self.notebook.insert_page(page) self.notebook.set_tab_label(page,page.get_tab_widget()) @@ -246,11 +225,9 @@ class EventEditor(DisplayState.ManagedWindow): return id(self) def on_delete_event(self,obj,b): - self.gladeif.close() self.close() def close_window(self,obj): - self.gladeif.close() self.close() self.window.destroy() @@ -260,12 +237,9 @@ class EventEditor(DisplayState.ManagedWindow): def on_event_edit_ok_clicked(self,obj): - event_data = self.type_selector.get_values() eplace_obj = get_place(self.place_field,self.pmap,self.db) - self.update_event(event_data,self.date,eplace_obj) - - print self.event, self.event.handle + self.update_event(eplace_obj) if self.event.handle == None: trans = self.db.transaction_begin() @@ -282,7 +256,7 @@ class EventEditor(DisplayState.ManagedWindow): self.callback(self.event) self.close(obj) - def update_event(self,the_type,date,place): + def update_event(self,place): # FIXME: commented because we no longer have parent if place: if self.event.get_place_handle() != place.get_handle(): @@ -291,13 +265,6 @@ class EventEditor(DisplayState.ManagedWindow): if self.event.get_place_handle(): self.event.set_place_handle("") - if self.event.get_type() != the_type: - self.event.set_type(the_type) - - dobj = self.event.get_date_object() - if not dobj.is_equal(date): - self.event.set_date_object(date) - def commit(self,event,trans): self.db.commit_event(event,trans) diff --git a/src/GrampsDb/_GrampsDbBase.py b/src/GrampsDb/_GrampsDbBase.py index f3ffe4df9..52a59221d 100644 --- a/src/GrampsDb/_GrampsDbBase.py +++ b/src/GrampsDb/_GrampsDbBase.py @@ -1991,6 +1991,28 @@ class DbState(GrampsDBCallback): self.db = GrampsDbBase() self.open = False self.active = None + self.places = {} + + def _place_rebuild(self): + self.places.clear() + cursor = self.db.get_place_cursor() + data = cursor.next() + while data: + if data[1][2]: + self.places[data[1][2]] = data[0] + data = cursor.next() + cursor.close() + + def _place_add(self,handle): + place = self.db.get_place_from_handle(handle) + self.places[place.get_title()] = handle + + def _place_update(self,handle): + place = self.db.get_place_from_handle(handle) + self.places[handle] = place.get_title() + + def _place_delete(self,handle): + del self.places[handle] def change_active_person(self,person): self.active = person @@ -2009,6 +2031,10 @@ class DbState(GrampsDBCallback): def change_database(self,db): self.db.close() self.db = db + self.db.connect('place-add',self._place_add) + self.db.connect('place-update',self._place_update) + self.db.connect('place-delete',self._place_delete) + self.db.connect('place-rebuild',self._place_rebuild) self.active = None self.open = True self.emit('database-changed',(self.db,)) diff --git a/src/GrampsWidgets.py b/src/GrampsWidgets.py index 2fade5568..5b4267a93 100644 --- a/src/GrampsWidgets.py +++ b/src/GrampsWidgets.py @@ -334,3 +334,25 @@ class MonitoredDate: field.set_text(DateHandler.displayer.display(self.date)) +class MonitoredPlace: + + def __init__(self,obj,set_val,get_val,mapping,custom): + self.set_val = set_val + self.get_val = get_val + + self.obj = obj + + val = get_val() + if val: + default = val[0] + else: + default = None + + self.sel = AutoComp.StandardCustomSelector( + mapping, obj, custom, default) + + self.obj.connect('changed', self.on_change) + + def on_change(self, obj): + self.set_val(self.sel.get_values()) +