From f63b72f734b33f446f1e8a9f3055d6698cf31a05 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 19 Aug 2005 22:10:35 +0000 Subject: [PATCH] * src/DisplayState.py: fixe some window management syntax errros * src/PageView.py: enable double click to edit * src/EditPerson.py: tried to enable window management * src/PersonView.py: make more compatible with base class svn: r5114 --- ChangeLog | 6 ++ src/DisplayState.py | 25 ++++--- src/EditPerson.py | 64 ++++++------------ src/PageView.py | 2 +- src/PersonView.py | 156 +++++++++++++++++++++----------------------- 5 files changed, 119 insertions(+), 134 deletions(-) diff --git a/ChangeLog b/ChangeLog index 268670154..132a21938 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-08-19 Don Allingham + * src/DisplayState.py: fixe some window management syntax errros + * src/PageView.py: enable double click to edit + * src/EditPerson.py: tried to enable window management + * src/PersonView.py: make more compatible with base class + 2005-08-19 Richard Taylor * src/EventEditor.py: hacked about to make add work at least. diff --git a/src/DisplayState.py b/src/DisplayState.py index a3911b88c..721292c50 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -93,8 +93,11 @@ class History(GrampsDBCallback.GrampsDBCallback): self.history.append(person_handle) if person_handle not in self.mhistory: self.mhistory.append(person_handle) - self.emit('menu-changed',(self.mhistory,)) + else: + self.mhistory.remove(person_handle) + self.mhistory.push(person_handle) self.index += 1 + self.emit('menu-changed',(self.mhistory,)) self.emit('changed',(self.history,)) def forward(self,step=1): @@ -154,12 +157,12 @@ class GrampsWindowManager: self.close_item_recursively(sub_item) else: if item.window_id: - del self.id2item[window_id] + del self.id2item[item.window_id] item.window.destroy() def add_item(self,node,item): if item.window_id: - self.id2item[window_id] = item + self.id2item[item.window_id] = item parent_item = self.get_item_from_node(node) assert type(parent_item) == list or node == [], \ @@ -172,6 +175,7 @@ class GrampsWindowManager: new_item = item parent_item.append(new_item) new_node = node + [len(parent_item) + 1] + self.build_windows_menu() return new_node def remove_node(self,node): @@ -179,18 +183,21 @@ class GrampsWindowManager: child_in_parent = node[-1:][0] item = self.get_item_from_node(parent_node) item.pop(child_in_parent) + self.build_windows_menu() def call_back_factory(self,item): if type(item) != list: def f(obj): - if item.window_id and self.get_window_from_id(window_id): - self.get_window_from_id(window__id).present() + if item.window_id and self.get_window_from_id(item.window_id): + self.get_window_from_id(item.window_id).present() else: def f(obj): pass return f - def built_windows_menu(self): + def build_windows_menu(self): + print self.window_tree + print self.id2item pass #------------------------------------------------------------------------- @@ -235,12 +242,12 @@ class ManagedWindow: ... """ - if uistate.gwm.get_window_from_id(window_id): - uistate.gwm.get_window_from_id(window_id).present() + if uistate.gwm.get_window_from_id(window_key): + uistate.gwm.get_window_from_id(window_key).present() self.already_exist = True else: self.already_exist = False - self.window_id = window_id + self.window_id = window_key self.submenu_label = submenu_label self.menu_label = menu_label self.uistate = uistate diff --git a/src/EditPerson.py b/src/EditPerson.py index 958db0d1c..164294a10 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -62,6 +62,7 @@ import NameDisplay import NameEdit import NoteEdit import Spell +import DisplayState from QuestionDialog import WarningDialog, ErrorDialog, SaveDialog, QuestionDialog2 @@ -86,21 +87,36 @@ _use_patronymic = [ # EditPerson class # #------------------------------------------------------------------------- -class EditPerson: +class EditPerson(DisplayState.ManagedWindow): use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic def __init__(self,state,uistate,person,callback=None): """Creates an edit window. Associates a person with the window.""" + self.dp = DateHandler.parser + 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") + + DisplayState.ManagedWindow.__init__( + self, uistate, [], self, win_menu_label, _('Edit Person')) + + if self.already_exist: + return + self.state = state self.uistate = uistate self.retval = const.UPDATE_PERSON - self.dp = DateHandler.parser - self.dd = DateHandler.displayer - self.nd = NameDisplay.displayer - self.orig_handle = person.get_handle() + if person: + self.orig_handle = person.get_handle() + else: + self.orig_handle = "" + # UGLY HACK to refresh person object from handle if that exists # done to ensure that the person object is not stale, as it could # have been changed by something external (merge, tool, etc). @@ -336,7 +352,6 @@ class EditPerson: self.url_box.redraw() self.get_widget("notebook").set_current_page(0) self.surname.grab_focus() - self.add_itself_to_winsmenu() if self.db.readonly: for i in ["ok", "aka_add", "aka_del", "event_add", "event_del", @@ -446,43 +461,6 @@ class EditPerson: ImageSelect.LocalMediaProperties(ph,obj.get_path(),self, self.window) - def close_child_windows(self): - for child_window in self.child_windows.values(): - child_window.close(None) - self.child_windows = {} - - def close(self): - #self.gallery.close() - self.close_child_windows() - self.remove_itself_from_winsmenu() - self.window.destroy() - - def add_itself_to_winsmenu(self): -## self.parent_window.child_windows[self.orig_handle] = self -## win_menu_label = self.name_display.display(self.person) -## if not win_menu_label.strip(): -## win_menu_label = _("New Person") -## self.win_menu_item = gtk.MenuItem(win_menu_label) -## self.win_menu_item.set_submenu(gtk.Menu()) -## self.win_menu_item.show() -## self.uistate.winsmenu.append(self.win_menu_item) -## self.winsmenu = self.win_menu_item.get_submenu() -## self.menu_item = gtk.MenuItem(_('Edit Person')) -## self.menu_item.connect("activate",self.present) -## self.menu_item.show() -## self.winsmenu.append(self.menu_item) - return - - def remove_itself_from_winsmenu(self): - return - del self.parent_window.child_windows[self.orig_handle] - self.menu_item.destroy() - self.winsmenu.destroy() - self.win_menu_item.destroy() - - def present(self,obj): - self.window.present() - def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" gnome.help_display('gramps-manual','gramps-edit-complete') diff --git a/src/PageView.py b/src/PageView.py index 6448d9db6..38b799865 100644 --- a/src/PageView.py +++ b/src/PageView.py @@ -398,7 +398,7 @@ class ListView(PageView): def button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: - self.double_click(obj,event) + self.edit(obj) return True elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: menu = self.uistate.uimanager.get_widget('/Popup') diff --git a/src/PersonView.py b/src/PersonView.py index d1f78f6d6..d09256c40 100644 --- a/src/PersonView.py +++ b/src/PersonView.py @@ -75,7 +75,8 @@ class PersonView(PageView.PersonNavView): self.inactive = False dbstate.connect('database-changed',self.change_db) dbstate.connect('active-changed',self.goto_active_person) - + self.handle_col = len(column_names)+2 + def change_page(self): self.on_filter_name_changed(None) @@ -140,15 +141,15 @@ class PersonView(PageView.PersonNavView): self.filter_text.set_sensitive(False) - self.person_tree = gtk.TreeView() - self.person_tree.set_rules_hint(True) - self.person_tree.set_headers_visible(True) - self.person_tree.connect('key-press-event',self.key_press) + self.tree = gtk.TreeView() + self.tree.set_rules_hint(True) + self.tree.set_headers_visible(True) + self.tree.connect('key-press-event',self.key_press) scrollwindow = gtk.ScrolledWindow() scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_shadow_type(gtk.SHADOW_ETCHED_IN) - scrollwindow.add(self.person_tree) + scrollwindow.add(self.tree) self.vbox.pack_start(self.filterbar,False) self.vbox.pack_start(scrollwindow,True) @@ -158,15 +159,15 @@ class PersonView(PageView.PersonNavView): self.columns = [] self.build_columns() - self.person_tree.connect('button-press-event', self.on_button_press) - self.person_tree.connect('drag_data_get', self.person_drag_data_get) + self.tree.connect('button-press-event', self.button_press) + self.tree.connect('drag_data_get', self.drag_data_get) - self.person_selection = self.person_tree.get_selection() - self.person_selection.set_mode(gtk.SELECTION_MULTIPLE) - self.person_selection.connect('changed',self.row_changed) + self.selection = self.tree.get_selection() + self.selection.set_mode(gtk.SELECTION_MULTIPLE) + self.selection.connect('changed',self.row_changed) - self.vbox.set_focus_chain([self.person_tree, self.filter_list, + self.vbox.set_focus_chain([self.tree, self.filter_list, self.filter_text, self.filter_invert, self.filter_button]) @@ -268,20 +269,20 @@ class PersonView(PageView.PersonNavView): # select the active person in the person view p = self.dbstate.active try: - path = self.person_model.on_get_path(p.get_handle()) + path = self.model.on_get_path(p.get_handle()) group_name = p.get_primary_name().get_group_name() top_name = self.dbstate.db.get_name_group_mapping(group_name) - top_path = self.person_model.on_get_path(top_name) - self.person_tree.expand_row(top_path,0) + top_path = self.model.on_get_path(top_name) + self.tree.expand_row(top_path,0) - current = self.person_model.on_get_iter(path) - selected = self.person_selection.path_is_selected(path) + current = self.model.on_get_iter(path) + selected = self.selection.path_is_selected(path) if current != p.get_handle() or not selected: - self.person_selection.unselect_all() - self.person_selection.select_path(path) - self.person_tree.scroll_to_cell(path,None,1,0.5,0) + self.selection.unselect_all() + self.selection.select_path(path) + self.tree.scroll_to_cell(path,None,1,0.5,0) except KeyError: - self.person_selection.unselect_all() + self.selection.unselect_all() print "Person not currently available due to filter" self.dbstate.active = p @@ -430,12 +431,12 @@ class PersonView(PageView.PersonNavView): Creates a new PeopleModel instance. Essentially creates a complete rebuild of the data. """ - self.person_model = PeopleModel.PeopleModel( + self.model = PeopleModel.PeopleModel( self.dbstate.db, self.DataFilter, self.filter_invert.get_active()) - self.person_tree.set_model(self.person_model) + self.tree.set_model(self.model) - if self.person_model.tooltip_column != None: - self.tooltips = TreeTips.TreeTips(self.person_tree,self.person_model.tooltip_column,True) + if self.model.tooltip_column != None: + self.tooltips = TreeTips.TreeTips(self.tree,self.model.tooltip_column,True) def filter_toggle(self,obj): @@ -525,7 +526,7 @@ class PersonView(PageView.PersonNavView): def build_columns(self): for column in self.columns: - self.person_tree.remove_column(column) + self.tree.remove_column(column) column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0) column.set_resizable(True) @@ -533,7 +534,7 @@ class PersonView(PageView.PersonNavView): #column.connect('clicked',self.sort_clicked) column.set_min_width(225) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) - self.person_tree.append_column(column) + self.tree.append_column(column) self.columns = [column] for pair in self.dbstate.db.get_person_column_order(): @@ -545,7 +546,7 @@ class PersonView(PageView.PersonNavView): column.set_min_width(60) column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY) self.columns.append(column) - self.person_tree.append_column(column) + self.tree.append_column(column) def row_changed(self,obj): """Called with a row is changed. Check the selected objects from @@ -562,23 +563,16 @@ class PersonView(PageView.PersonNavView): self.dbstate.change_active_person(None) if len(selected_ids) == 1: - self.person_tree.drag_source_set(BUTTON1_MASK, + self.tree.drag_source_set(BUTTON1_MASK, [DdTargets.PERSON_LINK.target()], ACTION_COPY) elif len(selected_ids) > 1: - self.person_tree.drag_source_set(BUTTON1_MASK, + self.tree.drag_source_set(BUTTON1_MASK, [DdTargets.PERSON_LINK_LIST.target()], ACTION_COPY) self.uistate.modify_statusbar() - def on_button_press(self,obj,event): - if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: - menu = self.uistate.uimanager.get_widget('/Popup') - menu.popup(None,None,None,event.button,event.time) - return True - return False - - def person_drag_data_get(self, widget, context, sel_data, info, time): + def drag_data_get(self, widget, context, sel_data, info, time): selected_ids = self.get_selected_objects() if len(selected_ids) == 1: @@ -600,45 +594,45 @@ class PersonView(PageView.PersonNavView): for node in handle_list: person = self.dbstate.db.get_person_from_handle(node) top = person.get_primary_name().get_group_name() - self.person_model.rebuild_data(self.DataFilter) - if not self.person_model.is_visable(node): + self.model.rebuild_data(self.DataFilter) + if not self.model.is_visable(node): continue - if (not self.person_model.sname_sub.has_key(top) or - len(self.person_model.sname_sub[top]) == 1): - path = self.person_model.on_get_path(top) - pnode = self.person_model.get_iter(path) - self.person_model.row_inserted(path,pnode) - path = self.person_model.on_get_path(node) - pnode = self.person_model.get_iter(path) - self.person_model.row_inserted(path,pnode) + if (not self.model.sname_sub.has_key(top) or + len(self.model.sname_sub[top]) == 1): + path = self.model.on_get_path(top) + pnode = self.model.get_iter(path) + self.model.row_inserted(path,pnode) + path = self.model.on_get_path(node) + pnode = self.model.get_iter(path) + self.model.row_inserted(path,pnode) def person_removed(self,handle_list): for node in handle_list: person = self.dbstate.db.get_person_from_handle(node) - if not self.person_model.is_visable(node): + if not self.model.is_visable(node): continue top = person.get_primary_name().get_group_name() - mylist = self.person_model.sname_sub.get(top,[]) + mylist = self.model.sname_sub.get(top,[]) if mylist: try: - path = self.person_model.on_get_path(node) - self.person_model.row_deleted(path) + path = self.model.on_get_path(node) + self.model.row_deleted(path) if len(mylist) == 1: - path = self.person_model.on_get_path(top) - self.person_model.row_deleted(path) + path = self.model.on_get_path(top) + self.model.row_deleted(path) except KeyError: pass - self.person_model.rebuild_data(self.DataFilter,skip=node) + self.model.rebuild_data(self.DataFilter,skip=node) def person_updated(self,handle_list): for node in handle_list: person = self.dbstate.db.get_person_from_handle(node) try: - oldpath = self.person_model.iter2path[node] + oldpath = self.model.iter2path[node] except: return - pathval = self.person_model.on_get_path(node) - pnode = self.person_model.get_iter(pathval) + pathval = self.model.on_get_path(node) + pnode = self.model.get_iter(pathval) # calculate the new data @@ -649,46 +643,46 @@ class PersonView(PageView.PersonNavView): surname = self.dbstate.db.get_name_group_mapping(base) if oldpath[0] == surname: - self.person_model.build_sub_entry(surname) + self.model.build_sub_entry(surname) else: - self.person_model.calculate_data(self.DataFilter) + self.model.calculate_data(self.DataFilter) # find the path of the person in the new data build - newpath = self.person_model.temp_iter2path[node] + newpath = self.model.temp_iter2path[node] # if paths same, just issue row changed signal if oldpath == newpath: - self.person_model.row_changed(pathval,pnode) + self.model.row_changed(pathval,pnode) else: # paths different, get the new surname list - mylist = self.person_model.temp_sname_sub.get(oldpath[0],[]) - path = self.person_model.on_get_path(node) + mylist = self.model.temp_sname_sub.get(oldpath[0],[]) + path = self.model.on_get_path(node) # delete original - self.person_model.row_deleted(pathval) + self.model.row_deleted(pathval) # delete top node of original if necessar if len(mylist)==0: - self.person_model.row_deleted(pathval[0]) + self.model.row_deleted(pathval[0]) # determine if we need to insert a new top node', - insert = not self.person_model.sname_sub.has_key(newpath[0]) + insert = not self.model.sname_sub.has_key(newpath[0]) # assign new data - self.person_model.assign_data() + self.model.assign_data() # insert new row if needed if insert: - path = self.person_model.on_get_path(newpath[0]) - pnode = self.person_model.get_iter(path) - self.person_model.row_inserted(path,pnode) + path = self.model.on_get_path(newpath[0]) + pnode = self.model.get_iter(path) + self.model.row_inserted(path,pnode) # insert new person - path = self.person_model.on_get_path(node) - pnode = self.person_model.get_iter(path) - self.person_model.row_inserted(path,pnode) + path = self.model.on_get_path(node) + pnode = self.model.get_iter(path) + self.model.row_inserted(path,pnode) self.goto_active_person() @@ -712,22 +706,22 @@ class PersonView(PageView.PersonNavView): self.uistate.modify_statusbar() def get_selected_objects(self): - (mode,paths) = self.person_selection.get_selected_rows() + (mode,paths) = self.selection.get_selected_rows() mlist = [] for path in paths: - node = self.person_model.on_get_iter(path) - mlist.append(self.person_model.on_get_value(node, PeopleModel.COLUMN_INT_ID)) + node = self.model.on_get_iter(path) + mlist.append(self.model.on_get_value(node, PeopleModel.COLUMN_INT_ID)) return mlist def remove_from_person_list(self,person): """Remove the selected person from the list. A person object is expected, not an ID""" - path = self.person_model.on_get_path(person.get_handle()) + path = self.model.on_get_path(person.get_handle()) (col,row) = path if row > 0: - self.person_selection.select_path((col,row-1)) - elif row == 0 and self.person_model.on_get_iter(path): - self.person_selection.select_path(path) + self.selection.select_path((col,row-1)) + elif row == 0 and self.model.on_get_iter(path): + self.selection.select_path(path) def button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: