* src/DisplayState.py: Factor out recursive action function.

* src/EditPerson.py: Use person handle to identify the window.
* src/EventEdit.py: Use more descriptive menu label.


svn: r5605
This commit is contained in:
Alex Roitman 2005-12-21 19:48:18 +00:00
parent aa4f1c7ed4
commit e51ee68d69
4 changed files with 43 additions and 32 deletions

View File

@ -8,6 +8,10 @@
Recursively walk the items under a given item and lower the track Recursively walk the items under a given item and lower the track
entry. entry.
* src/DisplayState.py: Factor out recursive action function.
* src/EditPerson.py: Use person handle to identify the window.
* src/EventEdit.py: Use more descriptive menu label.
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk> 2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
* src/EditSource.py: fixed small mistake in display_references * src/EditSource.py: fixed small mistake in display_references

View File

@ -201,30 +201,35 @@ class GrampsWindowManager:
def close_track(self,track): def close_track(self,track):
# This is called when item needs to be closed # This is called when item needs to be closed
# Closes all its children and then removes the item from the tree. # Closes all its children and then removes the item from the tree.
#print "1", track
item = self.get_item_from_track(track) item = self.get_item_from_track(track)
self.close_item(item) self.recursive_action(item,self.close_item)
# This only needs to be run once for the highest level point # This only needs to be run once for the highest level point
# to remove. # to remove.
self.remove_item(track) self.remove_item(track)
def close_item(self,item): def recursive_action(self,item,func,*args):
# This function calls children's close_item() method # This function recursively calls itself over the child items
# to let the children go away cleanly. # starting with the given item.
# Eventualy, every non-list item (leaf) will be reached
# and the func(item,*args) will be called on that item.
if type(item) == list: if type(item) == list:
# If this item is a branch # If this item is a branch
# close the children except for the first one # close the children except for the first one
for sub_item in item[1:]: for sub_item in item[1:]:
self.close_item(sub_item) self.recursive_action(sub_item,func,*args)
# return the first child # return the first child
last_item = item[0] last_item = item[0]
else: else:
# This item is a leaf -- no children to close # This item is a leaf -- no children to close
# return itself # return itself
last_item = item last_item = item
if last_item.window_id: func(last_item,*args)
del self.id2item[last_item.window_id]
last_item.window.destroy() def close_item(self,item,*args):
# Given an item, close its window and remove it's ID from the dict
if item.window_id:
del self.id2item[item.window_id]
item.window.destroy()
def remove_item(self,track): def remove_item(self,track):
# We need the whole gymnastics below because our item # We need the whole gymnastics below because our item
@ -242,25 +247,15 @@ class GrampsWindowManager:
# so that it's track is down by one on this level # so that it's track is down by one on this level
for ix in range(child_in_parent,len(parent_item)): for ix in range(child_in_parent,len(parent_item)):
item = parent_item[ix] item = parent_item[ix]
self.move_item_down(item,len(track)-1) self.recursive_action(item,self.move_item_down,len(track)-1)
# Rebuild menu # Rebuild menu
self.build_windows_menu() self.build_windows_menu()
def move_item_down(self,item,index): def move_item_down(self,item,*args):
# This function calls children's move_item_down() method # Given an item and an index, adjust the item's track
# to subtract 1 from the children's track component given by index. # by subtracting 1 from that index's level
if type(item) == list: index = args[0]
# If this item is a branch item.track[index] -= 1
# move down the children except for the first one
for sub_item in item[1:]:
self.move_item_down(sub_item,index)
# return the first child
last_item = item[0]
else:
# This item is a leaf -- no children to move down
# return itself
last_item = item
last_item.track[index] -= 1
def add_item(self,track,item): def add_item(self,track,item):
# if the item is identifiable then we need to remember # if the item is identifiable then we need to remember

View File

@ -107,8 +107,15 @@ class EditPerson(DisplayState.ManagedWindow):
if not win_menu_label.strip(): if not win_menu_label.strip():
win_menu_label = _("New Person") 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__( DisplayState.ManagedWindow.__init__(
self, uistate, [], self, win_menu_label, _('Edit Person')) self, uistate, [], win_key, win_menu_label, _('Edit Person'))
if self.already_exist: if self.already_exist:
return return
@ -118,11 +125,6 @@ class EditPerson(DisplayState.ManagedWindow):
self.uistate = uistate self.uistate = uistate
self.retval = const.UPDATE_PERSON self.retval = const.UPDATE_PERSON
if person:
self.orig_handle = person.get_handle()
else:
self.orig_handle = ""
# UGLY HACK to refresh person object from handle if that exists # UGLY HACK to refresh person object from handle if that exists
# done to ensure that the person object is not stale, as it could # done to ensure that the person object is not stale, as it could
# have been changed by something external (merge, tool, etc). # have been changed by something external (merge, tool, etc).

View File

@ -451,7 +451,17 @@ class EventRefEditor(DisplayState.ManagedWindow):
win_key = event_ref win_key = event_ref
else: else:
win_key = self win_key = self
submenu_label =_('Event Reference') 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') menu_label = _('Event Reference Editor')
DisplayState.ManagedWindow.__init__( DisplayState.ManagedWindow.__init__(