From 66556116d0f2f8514495c6aa1f32ed264dd4a2a1 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 22 Dec 2005 23:43:32 +0000 Subject: [PATCH] * src/EditPerson.py: window management improvements * src/EditPlace.py: window management improvements * src/EditSource.py: window management improvements * src/EventEdit.py: window management improvements * src/EventView.py: window management improvements * src/ListBox.py: window management improvements * src/NameEdit.py: window management improvements * src/SourceView.py: window management improvements * src/Sources.py: window management improvements svn: r5618 --- gramps2/ChangeLog | 12 +++ gramps2/src/DisplayState.py | 28 +++++-- gramps2/src/EditPerson.py | 38 +++++---- gramps2/src/EditPlace.py | 23 ++++-- gramps2/src/EditSource.py | 117 ++++++++++----------------- gramps2/src/EventEdit.py | 131 +++++++++++------------------- gramps2/src/EventView.py | 4 +- gramps2/src/ListBox.py | 4 +- gramps2/src/NameEdit.py | 79 ++++++------------ gramps2/src/SourceView.py | 6 +- gramps2/src/Sources.py | 154 +++++++++++------------------------- 11 files changed, 236 insertions(+), 360 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index ccd68f2d8..c0b4a4bc1 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,15 @@ +2005-12-22 Don Allingham + * src/DisplayState.py: window management improvements + * src/EditPerson.py: window management improvements + * src/EditPlace.py: window management improvements + * src/EditSource.py: window management improvements + * src/EventEdit.py: window management improvements + * src/EventView.py: window management improvements + * src/ListBox.py: window management improvements + * src/NameEdit.py: window management improvements + * src/SourceView.py: window management improvements + * src/Sources.py: window management improvements + 2005-12-22 Richard Taylor * src/ImageSelect.py: changed display_refs to use find_backlink_handles and updated GlobalMediaProperties to use new UI model. diff --git a/gramps2/src/DisplayState.py b/gramps2/src/DisplayState.py index 7993015b2..0396df925 100644 --- a/gramps2/src/DisplayState.py +++ b/gramps2/src/DisplayState.py @@ -356,14 +356,14 @@ class ManagedWindow: event, and presenting itself when selected or attempted to create again. """ - def __init__(self,uistate,track,window_key,submenu_label,menu_label): + def __init__(self,uistate,track,obj): """ Create child windows and add itself to menu, if not there already. - + The usage from derived classes is envisioned as follows: - - + + import DisplayState class SomeWindowClass(DisplayState.ManagedWindow): def __init__(self,uistate,dbstate,track): @@ -378,11 +378,21 @@ class ManagedWindow: menu_label) if self.already_exist: return - + # Proceed with the class. ... - + """ + + window_key = self.build_window_key(obj) + + menu_info = self.build_menu_names(obj) + if not menu_info: + menu_info = ('Undefined Menu','Undefined Submenu') + + menu_label = menu_info[0] + submenu_label = menu_info[1] + if uistate.gwm.get_item_from_id(window_key): uistate.gwm.get_item_from_id(window_key).present() self.already_exist = True @@ -414,6 +424,12 @@ class ManagedWindow: # On the top level: we use gramps top window self.parent_window = self.uistate.window + def build_menu_names(self,obj): + return None + + def build_window_key(self,obj): + return self + def close(self,obj=None,obj2=None): """ Close itself. diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index a3a32db47..27920a8d9 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -95,7 +95,7 @@ _use_patronymic = [ class EditPerson(DisplayState.ManagedWindow): use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic - + def __init__(self,state,uistate,track,person,callback=None): """Creates an edit window. Associates a person with the window.""" @@ -103,24 +103,16 @@ class EditPerson(DisplayState.ManagedWindow): self.dd = DateHandler.displayer self.nd = NameDisplay.displayer - win_menu_label = self.nd.display(person) - if not win_menu_label.strip(): - win_menu_label = _("New Person") - if person: self.orig_handle = person.get_handle() - win_key = self.orig_handle else: self.orig_handle = "" - win_key = self - DisplayState.ManagedWindow.__init__( - self, uistate, [], win_key, win_menu_label, _('Edit Person')) + DisplayState.ManagedWindow.__init__(self, uistate, [], person) if self.already_exist: return - print "EditPerson added: track:", self.track self.state = state self.uistate = uistate self.retval = const.UPDATE_PERSON @@ -132,9 +124,6 @@ class EditPerson(DisplayState.ManagedWindow): person = self.state.db.get_person_from_handle(self.orig_handle) self.person = person self.orig_surname = self.person.get_primary_name().get_group_name() - #if self.parent_window.child_windows.has_key(self.orig_handle): - # self.parent_window.child_windows[self.orig_handle].present(None) - # return self.db = self.state.db self.callback = callback self.child_windows = {} @@ -435,7 +424,7 @@ class EditPerson(DisplayState.ManagedWindow): # self.gladeif.connect("button130", "clicked", self.on_ldsseal_note_clicked) - self.sourcetab = Sources.SourceTab( + self.sourcetab = Sources.SourceTab(self.state, self.uistate, self.track, self.srcreflist, self, self.top, self.window, self.slist, self.top.get_widget('add_src'), self.top.get_widget('edit_src'), self.top.get_widget('del_src'), self.db.readonly) @@ -461,6 +450,18 @@ class EditPerson(DisplayState.ManagedWindow): widget.set_sensitive(not self.db.readonly) self.window.show() + def build_menu_names(self,person): + win_menu_label = self.nd.display(person) + if not win_menu_label.strip(): + win_menu_label = _("New Person") + return (win_menu_label,_('Edit Person')) + + def build_window_key(self,obj): + if obj: + win_key = obj.get_handle() + else: + win_key = self + def set_list_dnd(self,obj, get, begin, receive): obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [DdTargets.NAME.target()], gtk.gdk.ACTION_COPY) @@ -1371,7 +1372,8 @@ class EditPerson(DisplayState.ManagedWindow): self.write_primary_name() def on_ldsbap_source_clicked(self,obj): - Sources.SourceSelector(self.lds_baptism.get_source_references(), + Sources.SourceSelector(self.state, self.uistate, self.track, + self.lds_baptism.get_source_references(), self,self.update_ldsbap_list) def update_ldsbap_list(self,list): @@ -1383,7 +1385,8 @@ class EditPerson(DisplayState.ManagedWindow): readonly=self.db.readonly) def on_ldsendow_source_clicked(self,obj): - Sources.SourceSelector(self.lds_endowment.get_source_references(), + Sources.SourceSelector(self.state, self.uitstate, self.track, + self.lds_endowment.get_source_references(), self,self.set_ldsendow_list) def set_ldsendow_list(self,list): @@ -1395,7 +1398,8 @@ class EditPerson(DisplayState.ManagedWindow): readonly=self.db.readonly) def on_ldsseal_source_clicked(self,obj): - Sources.SourceSelector(self.lds_sealing.get_source_references(), + Sources.SourceSelector(self.state, self.uistate, self.track, + self.lds_sealing.get_source_references(), self,self.lds_seal_list) def lds_seal_list(self,list): diff --git a/gramps2/src/EditPlace.py b/gramps2/src/EditPlace.py index 0c557084c..939b3a76b 100644 --- a/gramps2/src/EditPlace.py +++ b/gramps2/src/EditPlace.py @@ -67,9 +67,10 @@ from WindowUtils import GladeIf #------------------------------------------------------------------------- class EditPlace(DisplayState.ManagedWindow): - def __init__(self,place,dbstate,uistate): + def __init__(self,place,dbstate,uistate,trace=[]): self.dbstate = dbstate self.uistate = uistate + self.trace = [] self.ref_not_loaded = place and place.get_handle() self.idle = None @@ -218,6 +219,7 @@ class EditPlace(DisplayState.ManagedWindow): self.gladeif.connect('del_url', 'clicked', self.on_delete_url_clicked) self.sourcetab = Sources.SourceTab( + self.state, self.ui_state, self.track, self.srcreflist,self, self.top_window,self.top,self.slist, self.top_window.get_widget('add_src'), @@ -249,12 +251,8 @@ class EditPlace(DisplayState.ManagedWindow): self.top_window.get_widget('ok').set_sensitive(not self.db.readonly) self.top.show() - win_menu_label = place.get_title() - if not win_menu_label.strip(): - win_menu_label = _("New Place") - DisplayState.ManagedWindow.__init__( - self, uistate, [], self, win_menu_label, _('Edit Place')) + DisplayState.ManagedWindow.__init__(self, uistate, [], place) self.pdmap = {} self.build_pdmap() @@ -265,6 +263,18 @@ class EditPlace(DisplayState.ManagedWindow): self.idle = gobject.idle_add(self.display_references) self.ref_not_loaded = False + def build_window_key(self,place): + if place: + return place.get_handle() + else: + return self + + def build_menu_names(self,place): + win_menu_label = place.get_title() + if not win_menu_label.strip(): + win_menu_label = _("New Place") + return (win_menu_label, _('Edit Place')) + def build_pdmap(self): self.pdmap.clear() cursor = self.db.get_place_cursor() @@ -278,7 +288,6 @@ class EditPlace(DisplayState.ManagedWindow): def on_delete_event(self,obj,b): self.gladeif.close() self.glry.close() - self.remove_itself_from_menu() gc.collect() def close(self,obj): diff --git a/gramps2/src/EditSource.py b/gramps2/src/EditSource.py index 654d71c9f..45e2a46a1 100644 --- a/gramps2/src/EditSource.py +++ b/gramps2/src/EditSource.py @@ -53,6 +53,8 @@ import NameDisplay import RepositoryRefEdit import Spell import GrampsDisplay +import DisplayState + from WindowUtils import GladeIf #------------------------------------------------------------------------- @@ -168,30 +170,26 @@ class ReposRefListView: return self._widget.get_selection() -class EditSource: +class EditSource(DisplayState.ManagedWindow): - def __init__(self,source,dbstate,uistate,readonly=False): + def __init__(self,dbstate,uistate,track,source,readonly=False): self.dbstate = dbstate - if source: - self.source = source - else: - self.source = RelLib.Source() - if self.source.get_handle(): - self.ref_not_loaded = 1 - else: - self.ref_not_loaded = 0 + self.track = track + self.uistate = uistate + self.db = dbstate.db self.idle = None self.name_display = NameDisplay.displayer.display -# if source: -# if parent and self.parent.child_windows.has_key(source.get_handle()): -# self.parent.child_windows[source.get_handle()].present(None) -# return -# else: -# self.win_key = source.get_handle() -# else: -# self.win_key = self -# self.child_windows = {} + + DisplayState.ManagedWindow.__init__(self, uistate, self.track, self.source) + + 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 @@ -199,17 +197,17 @@ class EditSource: mode = not self.db.readonly self.top_window = gtk.glade.XML(const.gladeFile,"sourceEditor","gramps") - self.top = self.top_window.get_widget("sourceEditor") + self.window = self.top_window.get_widget("sourceEditor") self.gladeif = GladeIf(self.top_window) - Utils.set_titles(self.top,self.top_window.get_widget('title'), + Utils.set_titles(self.window,self.top_window.get_widget('title'), _('Source Editor')) plwidget = self.top_window.get_widget("iconlist") self.gallery = ImageSelect.Gallery(source, self.db.commit_place, self.path, plwidget, - self.db, self, self.top) + self.db, self, self.window) self.author = self.top_window.get_widget("author") self.pubinfo = self.top_window.get_widget("pubinfo") self.abbrev = self.top_window.get_widget("abbrev") @@ -318,26 +316,34 @@ class EditSource: else: Utils.unbold_label(self.data_label) -# if parent_window: -# self.top.set_transient_for(parent_window) - self.top_window.get_widget('ok').set_sensitive(not self.db.readonly) -# if parent_window: -# self.top.set_transient_for(parent_window) -# self.add_itself_to_menu() - self.top.show() + self.window.set_transient_for(self.parent_window) + self.window.show() self.model = None # This will hold the model for backreferences once it is complete. if self.ref_not_loaded: self.ref_not_loaded = 0 - Utils.temp_label(self.refs_label,self.top) + Utils.temp_label(self.refs_label,self.window) self.cursor_type = None self.idle = gobject.idle_add(self.display_references) self.data_sel = self.datalist.get_selection() + def build_window_key(self,source): + if source: + return source.get_handle() + else: + return self + + def build_menu_names(self,source): + if source: + label = "Edit Source" + else: + label = "New Source" + return (label, _('Source Editor')) + def on_add_data_clicked(self,widget): node = self.data_model.append(row=['','']) self.data_sel.select_iter(node) @@ -392,51 +398,12 @@ class EditSource: def close(self,obj): self.gallery.close() - self.close_child_windows() - self.remove_itself_from_menu() self.gladeif.close() - self.top.destroy() + self.window.destroy() if self.idle != None: gobject.source_remove(self.idle) gc.collect() - def close_child_windows(self): - return - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def add_itself_to_menu(self): - return - self.parent.child_windows[self.win_key] = self - if not self.source: - label = _("New Source") - else: - label = self.source.get_title() - if not label.strip(): - label = _("New Source") - label = "%s: %s" % (_('Source'),label) - self.parent_menu_item = gtk.MenuItem(label) - self.parent_menu_item.set_submenu(gtk.Menu()) - self.parent_menu_item.show() - self.parent.winsmenu.append(self.parent_menu_item) - self.winsmenu = self.parent_menu_item.get_submenu() - self.menu_item = gtk.MenuItem(_('Source Editor')) - self.menu_item.connect("activate",self.present) - self.menu_item.show() - self.winsmenu.append(self.menu_item) - - def remove_itself_from_menu(self): - return - del self.parent.child_windows[self.win_key] - self.menu_item.destroy() - self.winsmenu.destroy() - self.parent_menu_item.destroy() - - def present(self,obj): - return - self.top.present() - def button_press(self,obj): data = self.model.get_selected_objects() if not data: @@ -556,9 +523,9 @@ class EditSource: return True if self.any_refs: - Utils.bold_label(self.refs_label,self.top) + Utils.bold_label(self.refs_label,self.window) else: - Utils.unbold_label(self.refs_label,self.top) + Utils.unbold_label(self.refs_label,self.window) self.ref_not_loaded = 0 self.backlink_generator = None @@ -629,7 +596,7 @@ class EditSource: self.gallery.load_images() elif page == 3 and self.ref_not_loaded: self.ref_not_loaded = 0 - Utils.temp_label(self.refs_label,self.top) + Utils.temp_label(self.refs_label,self.window) self.idle = gobject.idle_add(self.display_references) text = unicode( self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), @@ -637,9 +604,9 @@ class EditSource: False) ) if text: - Utils.bold_label(self.notes_label,self.top) + Utils.bold_label(self.notes_label,self.window) else: - Utils.unbold_label(self.notes_label,self.top) + Utils.unbold_label(self.notes_label,self.window) def update_repositories(self, repos_ref): """Make the repository list reflect the change or addition of repos_ref""" diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index c2a803f8e..986ae5227 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -95,23 +95,17 @@ def get_place(field,pmap,db): # EventEditor class # #------------------------------------------------------------------------- -class EventEditor: +class EventEditor(DisplayState.ManagedWindow): - def __init__(self,event,dbstate,uistate): - #self.parent = parent + def __init__(self,event,dbstate,uistate,track=[]): self.db = dbstate.db + self.uistate = uistate + self.dbstate = dbstate + self.track = track + read_only = self.db.readonly noedit = self.db.readonly -# if event: -# if self.parent.child_windows.has_key(event.get_handle()): -# self.parent.child_windows[event.get_handle()].present(None) -# return -# else: -# self.win_key = event.get_handle() -# else: -# self.win_key = self self.event = event -# self.child_windows = {} self.path = self.db.get_save_path() self.plist = [] self.pmap = {} @@ -119,6 +113,10 @@ class EventEditor: self.dp = _dp self.dd = _dd + DisplayState.ManagedWindow.__init__(self, uistate, [], event) + if self.already_exist: + return + # build list for menu ## values = sets.Set(elist) ## values.union(self.get_event_names()) @@ -184,7 +182,7 @@ class EventEditor: del_src = self.top.get_widget('del_src') del_src.set_sensitive(not noedit) - self.sourcetab = Sources.SourceTab( + self.sourcetab = Sources.SourceTab(self.dbstate, self.uistate, self.track, self.srcreflist, self, self.top, self.window, self.slist, add_src, self.top.get_widget('edit_src'), del_src, self.db.readonly) @@ -263,70 +261,33 @@ class EventEditor: Utils.bold_label(self.general_label) -# try: -# self.window.set_transient_for(self.parent.window) -# except AttributeError: -# pass -# self.add_itself_to_menu() + self.window.set_transient_for(self.parent_window) self.window.show() + def build_menu_names(self,event): + if event: + win_menu_label = event.get_type()[1] + if not win_menu_label.strip(): + win_menu_label = _("New Place") + return (win_menu_label,_('Edit Place')) + + def build_window_key(self,obj): + if obj: + win_key = obj.get_handle() + else: + win_key = self + def on_delete_event(self,obj,b): self.gladeif.close() self.gallery.close() - self.close_child_windows() - self.remove_itself_from_menu() gc.collect() def close(self,obj): self.gladeif.close() self.gallery.close() - self.close_child_windows() - self.remove_itself_from_menu() self.window.destroy() gc.collect() - def close_child_windows(self): - return - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def add_itself_to_menu(self): - return - self.parent.child_windows[self.win_key] = self - if not self.event: - label = _("New Event") - else: - (val,strval) = self.event.get_type() - if val == RelLib.Event.CUSTOM: - label = strval - else: - label = total_events[val] - if not label.strip(): - label = _("New Event") - label = "%s: %s" % (_('Event'),label) - self.parent_menu_item = gtk.MenuItem(label) - self.parent_menu_item.set_submenu(gtk.Menu()) - self.parent_menu_item.show() - self.parent.winsmenu.append(self.parent_menu_item) - self.winsmenu = self.parent_menu_item.get_submenu() - self.menu_item = gtk.MenuItem(_('Event Editor')) - self.menu_item.connect("activate",self.present) - self.menu_item.show() - self.winsmenu.append(self.menu_item) - - def remove_itself_from_menu(self): - return - if self.window: - del self.parent.child_windows[self.win_key] - self.menu_item.destroy() - self.winsmenu.destroy() - self.parent_menu_item.destroy() - - def present(self,obj): - return - self.window.present() - def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-ev') @@ -443,33 +404,14 @@ class EventRefEditor(DisplayState.ManagedWindow): self.state = state self.uistate = uistate self.referent = referent - if event_ref: - win_key = event_ref - else: - win_key = self - if event: - if event.get_type()[0] == RelLib.Event.CUSTOM: - event_name = event.get_type()[1] - else: - try: - event_name = Utils.personal_events[event.get_type()[0]] - except: - event_name = Utils.family_events[event.get_type()[0]] - submenu_label = _('Event: %s') % event_name - else: - submenu_label = _('New Event') - menu_label = _('Event Reference Editor') - - DisplayState.ManagedWindow.__init__( - self, uistate, track, win_key, submenu_label, menu_label) + DisplayState.ManagedWindow.__init__(self, uistate, track, event_ref) if self.already_exist: return self.update = update self.event_ref = event_ref self.event = event - self.child_windows = {} self.pmap = {} for key in self.db.get_place_handles(): @@ -570,6 +512,7 @@ class EventRefEditor(DisplayState.ManagedWindow): self.srcreflist = self.event.get_source_references() self.sourcetab = Sources.SourceTab( + self.state, self.uistate, self.track, self.srcreflist, self, self.top, self.window, self.slist, add_src, self.top.get_widget('eer_edit_src'), del_src, self.db.readonly) @@ -609,6 +552,26 @@ class EventRefEditor(DisplayState.ManagedWindow): self.window.set_transient_for(self.parent_window) self.window.show() + def build_menu_names(self,event): + if event: + if event.get_type()[0] == RelLib.Event.CUSTOM: + event_name = event.get_type()[1] + else: + try: + event_name = Utils.personal_events[event.get_type()[0]] + except: + event_name = Utils.family_events[event.get_type()[0]] + submenu_label = _('Event: %s') % event_name + else: + submenu_label = _('New Event') + menu_label = _('Event Reference Editor') + + def build_window_key(self,event): + if event: + return event.get_handle() + else: + return self + def on_help_clicked(self,obj): pass diff --git a/gramps2/src/EventView.py b/gramps2/src/EventView.py index b0f074259..f428240d4 100644 --- a/gramps2/src/EventView.py +++ b/gramps2/src/EventView.py @@ -111,10 +111,10 @@ class EventView(PageView.ListView): def on_double_click(self,obj,event): handle = self.first_selected() the_event = self.dbstate.db.get_event_from_handle(handle) - EventEdit.EventEditor(the_event,self.dbstate, self.uistate) + EventEdit.EventEditor(the_event,self.dbstate, self.uistate, []) def add(self,obj): - EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate) + EventEdit.EventEditor(RelLib.Event(),self.dbstate, self.uistate, []) def remove(self,obj): for event_handle in self.selected_handles(): diff --git a/gramps2/src/ListBox.py b/gramps2/src/ListBox.py index 1fcaa630b..4e3083e6a 100644 --- a/gramps2/src/ListBox.py +++ b/gramps2/src/ListBox.py @@ -499,14 +499,14 @@ class NameListBox(ReorderListBox): self.data[index].set_suffix(value) def add(self,obj): - NameEdit.NameEditor(self.state, self.uistate, None, self.edit_callback) + NameEdit.NameEditor(self.state, self.uistate, None, self.track) def update(self,obj): store,node = self.list_model.get_selected() if node: NameEdit.NameEditor(self.state, self.uistate, self.list_model.get_object(node), - self.edit_callback) + self.track) def display_data(self,name): has_note = name.get_note() diff --git a/gramps2/src/NameEdit.py b/gramps2/src/NameEdit.py index be3769c75..7a922c454 100644 --- a/gramps2/src/NameEdit.py +++ b/gramps2/src/NameEdit.py @@ -52,6 +52,7 @@ import DateEdit import DateHandler import Spell import GrampsDisplay +import DisplayState from WindowUtils import GladeIf @@ -60,23 +61,19 @@ from WindowUtils import GladeIf # NameEditor class # #------------------------------------------------------------------------- -class NameEditor: +class NameEditor(DisplayState.ManagedWindow): - def __init__(self,parent,name,callback,parent_window=None): + def __init__(self,dbstate,uistate,name,track): + + self.db = dbstate.db + self.uistate = uistate + self.state = dbstate + + DisplayState.ManagedWindow.__init__(self, uistate, track, name) + if self.already_exist: + return - self.parent = parent - self.db = self.parent.db - if name: - if self.parent.child_windows.has_key(name): - self.parent.child_windows[name].present(None) - return - else: - self.win_key = name - else: - self.win_key = self self.name = name - self.callback = callback - self.child_windows = {} self.top = gtk.glade.XML(const.dialogFile, "name_edit","gramps") self.gladeif = GladeIf(self.top) self.window = self.top.get_widget("name_edit") @@ -113,7 +110,7 @@ class NameEditor: self.date_obj, self.date, date_stat, self.window) - AutoComp.fill_combo(self.combo,self.parent.db.get_surname_list()) + AutoComp.fill_combo(self.combo,self.db.get_surname_list()) self.surname_field = self.combo.get_child() self.prefix_field = self.top.get_widget("alt_prefix") self.prefix_field.set_editable(not self.db.readonly) @@ -153,6 +150,7 @@ class NameEditor: Utils.set_titles(self.window, alt_title, tmsg, _('Name Editor')) self.sourcetab = Sources.SourceTab( + self.state, self.uistate, self.track, self.srcreflist, self, self.top, self.window, self.slist, self.top.get_widget('add_src'), self.top.get_widget('edit_src'), self.top.get_widget('del_src'), self.db.readonly) @@ -201,12 +199,19 @@ class NameEditor: Utils.unbold_label(self.sources_label) Utils.unbold_label(self.general_label) - if parent_window: - self.window.set_transient_for(parent_window) self.surname_field.connect('changed',self.update_group_as) - self.add_itself_to_menu() + + self.window.set_transient_for(self.parent_window) self.window.show() + def build_menu_names(self,name): + if name: + submenu_label = _('%s: %s') % (_('Name',NameDisplay.displayer.display(name))) + else: + submenu_label = _('New Name') + menu_label = _('Name Editor') + return (menu_label,submenu_label) + def update_group_as(self,obj): if not self.group_over.get_active(): if self.name and self.name.get_group_as() != self.name.get_surname(): @@ -229,50 +234,13 @@ class NameEditor: def on_delete_event(self,*obj): self.gladeif.close() - self.close_child_windows() - self.remove_itself_from_menu() gc.collect() def close(self,*obj): self.gladeif.close() - self.close_child_windows() - self.remove_itself_from_menu() self.window.destroy() gc.collect() - def close_child_windows(self): - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def add_itself_to_menu(self): - self.parent.child_windows[self.win_key] = self - if not self.name: - label = _("New Name") - else: - label = self.name.get_name() - if not label.strip(): - label = _("New Name") - label = "%s: %s" % (_('Alternate Name'),label) - self.parent_menu_item = gtk.MenuItem(label) - self.parent_menu_item.set_submenu(gtk.Menu()) - self.parent_menu_item.show() - self.parent.winsmenu.append(self.parent_menu_item) - self.winsmenu = self.parent_menu_item.get_submenu() - self.menu_item = gtk.MenuItem(_('Name Editor')) - self.menu_item.connect("activate",self.present) - self.menu_item.show() - self.winsmenu.append(self.menu_item) - - def remove_itself_from_menu(self): - del self.parent.child_windows[self.win_key] - self.menu_item.destroy() - self.winsmenu.destroy() - self.parent_menu_item.destroy() - - def present(self,*obj): - self.window.present() - def on_help_clicked(self,*obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-an') @@ -346,7 +314,6 @@ class NameEditor: self.update_name(first,last,suffix,patronymic,title,the_type,note,format,priv) self.parent.lists_changed = 1 - self.callback(self.name) self.close(obj) def update_name(self,first,last,suffix,patronymic,title,the_type,note,format,priv): diff --git a/gramps2/src/SourceView.py b/gramps2/src/SourceView.py index b3c64700a..91029969d 100644 --- a/gramps2/src/SourceView.py +++ b/gramps2/src/SourceView.py @@ -110,10 +110,10 @@ class SourceView(PageView.ListView): def on_double_click(self,obj,event): handle = self.first_selected() source = self.dbstate.db.get_source_from_handle(handle) - EditSource.EditSource(source,self.dbstate, self.uistate) + EditSource.EditSource(self.dbstate, self.uistate, [], source) def add(self,obj): - EditSource.EditSource(RelLib.Source(),self.dbstate, self.uistate) + EditSource.EditSource(self.dbstate, self.uistate, [], RelLib.Source()) def remove(self,obj): for event_handle in self.selected_handles(): @@ -151,5 +151,5 @@ class SourceView(PageView.ListView): for handle in mlist: source = self.dbstate.db.get_source_from_handle(handle) - EditSource.EditSource(source, self.dbstate, self.uistate) + EditSource.EditSource(self.dbstate, self.uistate, [], source) diff --git a/gramps2/src/Sources.py b/gramps2/src/Sources.py index f1de20ce1..e1bb2e488 100644 --- a/gramps2/src/Sources.py +++ b/gramps2/src/Sources.py @@ -52,6 +52,7 @@ import DateEdit import DateHandler import GrampsDisplay import Spell +import DisplayState from DdTargets import DdTargets from WindowUtils import GladeIf @@ -62,21 +63,27 @@ from WindowUtils import GladeIf # #------------------------------------------------------------------------- -class SourceSelector: - def __init__(self,srclist,parent,update=None): - self.db = parent.db - self.parent = parent +class SourceSelector(DisplayState.ManagedWindow): + def __init__(self,state,uistate,track,srclist,parent,update=None): + self.db = state.db + self.state = state + self.uistate = uistate + self.track = track + if srclist: - if self.parent.child_windows.has_key(id(srclist)): - self.parent.child_windows[id(srclist)].present(None) - return - else: - self.win_key = id(srclist) + win_key = id(srclist) else: - self.win_key = self + win_key = self + + + submenu_label = _('Source') + + DisplayState.ManagedWindow.__init__( + self, uistate, self.track, win_key, submenu_label, + _('Source Selector')) + self.orig = srclist self.list = [] - self.child_windows = {} for s in self.orig: self.list.append(RelLib.SourceRef(s)) self.update=update @@ -130,44 +137,13 @@ class SourceSelector: def on_delete_event(self,obj,b): self.gladeif.close() - self.close_child_windows() - self.remove_itself_from_menu() gc.collect() def close(self,obj): - self.close_child_windows() - self.remove_itself_from_menu() self.gladeif.close() self.window.destroy() gc.collect() - def close_child_windows(self): - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def add_itself_to_menu(self): - self.parent.child_windows[self.win_key] = self - label = _('Source Reference') - self.parent_menu_item = gtk.MenuItem(label) - self.parent_menu_item.set_submenu(gtk.Menu()) - self.parent_menu_item.show() - self.parent.winsmenu.append(self.parent_menu_item) - self.winsmenu = self.parent_menu_item.get_submenu() - self.menu_item = gtk.MenuItem(_('Reference Selector')) - self.menu_item.connect("activate",self.present) - self.menu_item.show() - self.winsmenu.append(self.menu_item) - - def remove_itself_from_menu(self): - del self.parent.child_windows[self.win_key] - self.menu_item.destroy() - self.winsmenu.destroy() - self.parent_menu_item.destroy() - - def present(self,obj): - self.window.present() - def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('gramps-edit-complete') @@ -229,10 +205,13 @@ class SourceSelector: # #------------------------------------------------------------------------- class SourceTab: - def __init__(self, srclist, parent, top, window, clist, add_btn, - edit_btn, del_btn, readonly=False): + def __init__(self, state, uistate, track, srclist, parent, top, window, + clist, add_btn, edit_btn, del_btn, readonly=False): - self.db = parent.db + self.db = state.db + self.state = state + self.uistate = uistate + self.track = track self.parent = parent self.list = srclist self.top = top @@ -340,11 +319,11 @@ class SourceTab: if node: col = store.get_path(node) src = self.list[col[0]] - SourceEditor(src,self.db,self.update_clist,self) + SourceEditor(self.state, self.uistate, self.track, src, self.update_clist) def add_src_clicked(self,obj): src = RelLib.SourceRef() - SourceEditor(src,self.db,self.add_ref,self) + SourceEditor(self.state, self.uistate, self.track, src, self.add_ref) def del_src_clicked(self,obj): (store,node) = self.selection.get_selected() @@ -359,32 +338,30 @@ class SourceTab: # SourceEditor # #------------------------------------------------------------------------- -class SourceEditor: +class SourceEditor(DisplayState.ManagedWindow): - def __init__(self, srcref, database, update, parent): + def __init__(self, state, uistate, track, srcref, update): - self.db = database - self.parent = parent - if self.parent.__dict__.has_key('child_windows'): - self.win_parent = self.parent - else: - self.win_parent = self.parent.parent + self.db = state.db + self.state = state + self.track = track + self.uistate = uistate if srcref: - if self.win_parent.child_windows.has_key(srcref): - self.win_parent.child_windows[srcref].present(None) - return - else: - self.win_key = srcref + submenu_label = _('Source Reference') else: - self.win_key = self + submenu_label = _('New Source Reference') + + DisplayState.ManagedWindow.__init__( + self, uistate, self.track, srcref, submenu_label, + _('Source Reference Editor')) + self.update = update self.source_ref = srcref - self.child_windows = {} self.showSource = gtk.glade.XML(const.srcselFile, "sourceDisplay","gramps") - self.sourceDisplay = self.get_widget("sourceDisplay") + self.window = self.get_widget("sourceDisplay") - Utils.set_titles(self.sourceDisplay, + Utils.set_titles(self.window, self.showSource.get_widget('title'), _('Source Information')) @@ -433,7 +410,7 @@ class SourceEditor: date_stat.set_sensitive(not self.db.readonly) self.date_check = DateEdit.DateEdit( self.date_obj, self.date_entry_field, - date_stat, self.sourceDisplay) + date_stat, self.window) self.spage = self.get_widget("spage") self.spage.set_editable(not self.db.readonly) @@ -446,61 +423,22 @@ class SourceEditor: self.draw(self.active_source,fresh=True) self.set_button() - if self.parent: - self.sourceDisplay.set_transient_for(self.parent.window) - self.add_itself_to_menu() + self.window.set_transient_for(self.parent_window) self.db.connect('source-add', self.rebuild_menu) - self.sourceDisplay.show() + self.window.show() def rebuild_menu(self,handle_list): self.build_source_menu(handle_list[0]) def on_delete_event(self,obj,b): - self.close_child_windows() - self.remove_itself_from_menu() self.gladeif.close() gc.collect() def close(self,obj): - self.close_child_windows() - self.remove_itself_from_menu() self.gladeif.close() - self.sourceDisplay.destroy() + self.window.destroy() gc.collect() - def close_child_windows(self): - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def add_itself_to_menu(self): - self.win_parent.child_windows[self.win_key] = self - if self.active_source: - label = self.active_source.get_title() - else: - label = _("New Source") - if not label.strip(): - label = _("New Source") - label = "%s: %s" % (_('Source Reference'),label) - self.parent_menu_item = gtk.MenuItem(label) - self.parent_menu_item.set_submenu(gtk.Menu()) - self.parent_menu_item.show() - self.win_parent.winsmenu.append(self.parent_menu_item) - self.winsmenu = self.parent_menu_item.get_submenu() - self.menu_item = gtk.MenuItem(_('Source Information')) - self.menu_item.connect("activate",self.present) - self.menu_item.show() - self.winsmenu.append(self.menu_item) - - def remove_itself_from_menu(self): - del self.win_parent.child_windows[self.win_key] - self.menu_item.destroy() - self.winsmenu.destroy() - self.parent_menu_item.destroy() - - def present(self,obj): - self.sourceDisplay.present() - def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" GrampsDisplay.help('adv-si') @@ -609,4 +547,4 @@ class SourceEditor: def add_src_clicked(self,obj): import EditSource - EditSource.EditSource(RelLib.Source(),self.db, self) + EditSource.EditSource(self.state, self.uistate, self.track, RelLib.Source())