* src/EditPerson.py: Call child editors with new arguments.

* src/EventEdit.py: Use new window management.
* src/ListBox.py: Use new arguments.
* src/PersonView.py: Add track argument to EditPerson.


svn: r5547
This commit is contained in:
Alex Roitman 2005-12-14 06:54:02 +00:00
parent c416e79e3a
commit 7f98e3bc35
6 changed files with 139 additions and 110 deletions

View File

@ -1,5 +1,9 @@
2005-12-13 Alex Roitman <shura@gramps-project.org>
* src/DisplayState.py: Correct and add comments.
* src/EditPerson.py: Call child editors with new arguments.
* src/EventEdit.py: Use new window management.
* src/ListBox.py: Use new arguments.
* src/PersonView.py: Add track argument to EditPerson.
2005-12-13 Don Allingham <don@gramps-project.org>
* src/EditPerson.py: fix after merge

View File

@ -164,6 +164,7 @@ class GrampsWindowManager:
def get_item_from_track(self,track):
# Recursively find an item given track sequence
item = self.window_tree
print "track", track
for index in track:
item = item[index]
return item
@ -173,35 +174,33 @@ class GrampsWindowManager:
# Return None if the ID is not found
return self.id2item.get(item_id,None)
def close_item(self,track):
def close_track(self,track):
# This is called when item needs to be closed
# Closes all its children and then removes the item from the tree.
print "1", track
item = self.get_item_from_track(track)
last_item = self.close_item_recursively(item)
# now we have the only surviving item from possibly a huge
# nested group of items
if last_item.window_id:
del self.id2item[last_item.window_id]
last_item.window.destroy()
self.close_item(item)
# This only needs to be run once for the highest level point
# to remove.
self.remove_item(track)
def close_item_recursively(self,item):
def close_item(self,item):
# This function calls children's close_item() method
# to let the children go away cleanly. Then it returns
# the actual window item to later remove from dictionary
# and delete.
# to let the children go away cleanly.
if type(item) == list:
# If this item is a branch
# close the children except for the first one
for sub_item in item[1:]:
self.close_item(sub_item)
# return the first child
the_item = item[0]
last_item = item[0]
else:
# This item is a leaf -- no children to close
# return itself
the_item = item
return the_item
last_item = item
if last_item.window_id:
del self.id2item[last_item.window_id]
last_item.window.destroy()
def remove_item(self,track):
# We need the whole gymnastics below because our item
@ -225,6 +224,8 @@ class GrampsWindowManager:
if item.window_id:
self.id2item[item.window_id] = item
print "Adding: Track:", track
# Make sure we have a track
parent_item = self.get_item_from_track(track)
assert type(parent_item) == list or track == [], \
@ -322,7 +323,7 @@ class ManagedWindow:
Takes care of closing children and removing itself from menu.
"""
self.uistate.gwm.close_item(self.track)
self.uistate.gwm.close_track(self.track)
def present(self):
"""

View File

@ -96,7 +96,7 @@ class EditPerson(DisplayState.ManagedWindow):
use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic
def __init__(self,state,uistate,person,callback=None):
def __init__(self,state,uistate,track,person,callback=None):
"""Creates an edit window. Associates a person with the window."""
self.dp = DateHandler.parser
@ -113,6 +113,7 @@ class EditPerson(DisplayState.ManagedWindow):
if self.already_exist:
return
print "EditPerson added: track:", self.track
self.state = state
self.uistate = uistate
self.retval = const.UPDATE_PERSON
@ -309,24 +310,24 @@ class EditPerson(DisplayState.ManagedWindow):
Utils.bold_label(self.gallery_label)
# event display
self.event_box = ListBox.EventListBox(
self, self.person, self.event_list, self.events_label,
self.event_box = ListBox.EventListBox( state, uistate, self.track,
self.person, self.event_list, self.events_label,
[event_add_btn,event_edit_btn,event_delete_btn,event_sel_btn])
self.attr_box = ListBox.AttrListBox(
self, self.person, self.attr_list, self.attr_label,
self.attr_box = ListBox.AttrListBox( state, uistate, self.track,
self.person, self.attr_list, self.attr_label,
[attr_add_btn, attr_edit_btn, attr_delete_btn])
self.addr_box = ListBox.AddressListBox(
self, self.person, self.addr_list, self.addr_label,
self.addr_box = ListBox.AddressListBox( state, uistate, self.track,
self.person, self.addr_list, self.addr_label,
[addr_add_btn, addr_edit_btn, addr_delete_btn])
self.name_box = ListBox.NameListBox(
self, self.person, self.name_list, self.names_label,
self.name_box = ListBox.NameListBox( state, uistate, self.track,
self.person, self.name_list, self.names_label,
[name_add_btn, name_edit_btn, name_delete_btn])
self.url_box = ListBox.UrlListBox(
self, self.person, self.web_list, self.inet_label,
self.url_box = ListBox.UrlListBox( state, uistate, self.track,
self.person, self.web_list, self.inet_label,
[web_add_btn, web_edit_btn, web_delete_btn])
self.place_list = self.pdmap.keys()

View File

@ -55,6 +55,7 @@ import ImageSelect
import DateEdit
import Spell
import GrampsDisplay
import DisplayState
from QuestionDialog import WarningDialog, ErrorDialog
from WindowUtils import GladeIf
@ -435,23 +436,30 @@ class EventEditor:
# EventRefEditor class
#
#-------------------------------------------------------------------------
class EventRefEditor:
def __init__(self, event, event_ref, referent, database, update, parent):
self.db = database
self.parent = parent
class EventRefEditor(DisplayState.ManagedWindow):
def __init__(self, state, uistate, track,
event, event_ref, referent, update):
self.db = state.db
self.state = state
self.uistate = uistate
self.referent = referent
if self.parent.__dict__.has_key('child_windows'):
self.win_parent = self.parent
else:
self.win_parent = self.parent.parent
#if self.parent.__dict__.has_key('child_windows'):
# self.win_parent = self.parent
#else:
# self.win_parent = self.parent.parent
if event_ref:
if self.win_parent.child_windows.has_key(event_ref):
self.win_parent.child_windows[event_ref].present(None)
return
else:
self.win_key = event_ref
win_key = event_ref
else:
self.win_key = self
win_key = self
submenu_label =_('Event Reference')
menu_label = _('Event Reference Editor')
DisplayState.ManagedWindow.__init__(
self, uistate, track, win_key, submenu_label, menu_label)
if self.already_exist:
return
self.update = update
self.event_ref = event_ref
self.event = event
@ -592,21 +600,23 @@ class EventRefEditor:
if self.event.get_media_list():
Utils.bold_label(self.gallery_label)
self.add_itself_to_menu()
try:
self.window.set_transient_for(self.parent.window)
except AttributeError:
pass
#self.add_itself_to_menu()
#try:
# self.window.set_transient_for(self.parent.window)
#except AttributeError:
# pass
self.window.show()
print "added track:", self.track
def on_delete_event(self,obj,b):
self.close_child_windows()
self.remove_itself_from_menu()
#self.close_child_windows()
#self.remove_itself_from_menu()
self.close()
def close(self,obj):
self.close_child_windows()
self.remove_itself_from_menu()
self.window.destroy()
# def close(self,obj):
# self.close_child_windows()
# self.remove_itself_from_menu()
# self.window.destroy()
def close_child_windows(self):
for child_window in self.child_windows.values():
@ -633,8 +643,8 @@ class EventRefEditor:
self.winsmenu.destroy()
self.parent_menu_item.destroy()
def present(self,obj):
self.window.present()
# def present(self,obj):
# self.window.present()
def on_help_clicked(self,obj):
pass

View File

@ -65,17 +65,20 @@ class ListBox:
The primary argument is either Person or Family object.
"""
def __init__(self, parent, primary, obj, label, button_list, titles):
def __init__(self, state, uistate, track,
primary, obj, label, button_list, titles):
self.primary = primary
if self.primary.__class__.__name__ == 'Person':
self.name = NameDisplay.displayer.display(primary)
elif self.primary.__class__.__name__ == 'Family':
self.name = Utils.family_name(primary,parent.db)
self.name = Utils.family_name(primary,state.db)
else:
self.name = ""
self.label = label
self.db = parent.db
self.parent = parent
self.db = state.db
self.state = state
self.uistate = uistate
self.track = track
self.list_model = ListModel(
obj, titles, self.select_row, self.update)
self.blist = button_list
@ -170,9 +173,11 @@ class ListBox:
class ReorderListBox(ListBox):
def __init__(self,parent,primary,obj,label,button_list,evalues, dnd_type):
def __init__(self,state,uistate,track,
primary,obj,label,button_list,evalues, dnd_type):
ListBox.__init__(self,parent,primary,obj,label,button_list,evalues)
ListBox.__init__(self,state,uistate,track,
primary,obj,label,button_list,evalues)
self.dnd_type = dnd_type
@ -218,7 +223,8 @@ class ReorderListBox(ListBox):
class AttrListBox(ReorderListBox):
def __init__(self, parent, primary, obj, label, button_list):
def __init__(self, state, uistate, track,
primary, obj, label, button_list):
if primary.__class__.__name__ == 'Person':
self.attr_dict = Utils.personal_attributes
@ -239,7 +245,8 @@ class AttrListBox(ReorderListBox):
]
self.data = primary.get_attribute_list()[:]
ListBox.__init__(self, parent, primary, obj, label,
ListBox.__init__(self, state, uistate, track,
primary, obj, label,
button_list, titles)
self.attr_name_map,self.attr_val_map = self.build_maps(
@ -258,17 +265,17 @@ class AttrListBox(ReorderListBox):
def add(self,obj):
"""Brings up the AttributeEditor for a new attribute"""
AttrEdit.AttributeEditor(self.parent, None, self.name,
AttrEdit.AttributeEditor(state, uistate, None, self.name,
self.attr_dict,
self.edit_callback,self.parent.window)
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
attr = self.list_model.get_object(node)
AttrEdit.AttributeEditor(self.parent, attr, self.name,
AttrEdit.AttributeEditor(state,uistate, attr, self.name,
self.attr_dict,
self.edit_callback,self.parent.window)
self.edit_callback)
def display_data(self,attr):
has_note = attr.get_note()
@ -287,20 +294,23 @@ class EventListBox(ReorderListBox):
titles = ['Event', 'Description','Date','Place','Source','Note']
def __init__(self,parent,primary,obj,label,button_list):
def __init__(self,state,uistate,track,primary,obj,label,button_list):
self.data = []
self.primary = primary
self.parent = parent
self.state = state
self.uistate = uistate
if self.primary.__class__.__name__ == 'Person':
birth_ref = primary.get_birth_ref()
death_ref = primary.get_death_ref()
if birth_ref:
self.data.append((birth_ref,
parent.db.get_event_from_handle(birth_ref.ref)))
self.data.append(
(birth_ref,state.db.get_event_from_handle(birth_ref.ref)))
if death_ref:
self.data.append((death_ref,
parent.db.get_event_from_handle(death_ref.ref)))
self.data.append(
(death_ref,
state.db.get_event_from_handle(death_ref.ref))
)
self.ev_dict = Utils.personal_events
self.role_dict = Utils.event_roles
elif self.primary.__class__.__name__ == 'Family':
@ -309,7 +319,7 @@ class EventListBox(ReorderListBox):
for event_ref in primary.get_event_ref_list():
self.data.append((event_ref,
parent.db.get_event_from_handle(event_ref.ref)))
state.db.get_event_from_handle(event_ref.ref)))
ev_custom_str = self.ev_dict[RelLib.Event.CUSTOM]
eventnames = filter(lambda x: x != ev_custom_str,
@ -321,8 +331,8 @@ class EventListBox(ReorderListBox):
self.role_dict.values())
self.place_dict = {}
for handle in self.parent.db.get_place_handles():
title = self.parent.db.get_place_from_handle(handle).get_title()
for handle in self.state.db.get_place_handles():
title = self.state.db.get_place_from_handle(handle).get_title()
self.place_dict[title] = handle
placenames = self.place_dict.keys()
placenames.sort(locale.strcoll)
@ -338,7 +348,8 @@ class EventListBox(ReorderListBox):
(_('Note'), NOSORT, 50, TOGGLE, None, None),
]
ReorderListBox.__init__(self, parent, primary, obj, label,
ReorderListBox.__init__(self, state, uistate, track,
primary, obj, label,
button_list, evalues, DdTargets.EVENT)
self.ev_name_map,self.ev_val_map = self.build_maps(
@ -371,13 +382,13 @@ class EventListBox(ReorderListBox):
return
handle = self.place_dict.get(value,None)
if handle:
place = self.parent.db.get_place_from_handle(handle)
place = self.state.db.get_place_from_handle(handle)
else:
place = RelLib.Place()
place.set_title(value)
trans = self.parent.db.transaction_begin()
self.parent.db.add_place(place,trans)
self.parent.db.transaction_commit(trans,_("Add Place"))
trans = self.state.db.transaction_begin()
self.state.db.add_place(place,trans)
self.state.db.transaction_commit(trans,_("Add Place"))
handle = place.get_handle()
self.data[index][1].set_place_handle(handle)
@ -389,8 +400,8 @@ class EventListBox(ReorderListBox):
def add(self,obj):
"""Brings up the EventEditor for a new event"""
EventEdit.EventRefEditor(None,None,self.primary,self.parent.db,
self.edit_callback,self.parent)
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
None,None,self.primary,self.edit_callback)
def select(self,obj):
"""
@ -398,20 +409,21 @@ class EventListBox(ReorderListBox):
"""
# select existing event
import SelectEvent
sel_event = SelectEvent.SelectEvent(self.db,_('Select Event'),
self.parent.window)
sel_event = SelectEvent.SelectEvent(self.state.db,_('Select Event'))
event = sel_event.run()
if event:
EventEdit.EventRefEditor(event,None,self.primary,self.parent.db,
self.edit_callback,self.parent)
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
event,None,self.primary,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if not node:
return
event_ref,event = self.list_model.get_object(node)
EventEdit.EventRefEditor(event,event_ref,self.primary,self.parent.db,
self.edit_callback,self.parent)
EventEdit.EventRefEditor(self.state,self.uistate,self.track,
event,event_ref,self.primary,
self.edit_callback)
def display_data(self,event_tuple):
(event_ref, event) = event_tuple
@ -439,9 +451,9 @@ class EventListBox(ReorderListBox):
class NameListBox(ReorderListBox):
def __init__(self,parent,person,obj,label,button_list):
def __init__(self,state,uistate,track,person,obj,label,button_list):
surnames = parent.db.get_surname_list()
surnames = state.db.get_surname_list()
custom_str = Utils.name_types[RelLib.Name.CUSTOM]
types = filter(lambda x: x != custom_str, Utils.name_types.values())
@ -459,7 +471,8 @@ class NameListBox(ReorderListBox):
]
self.data = person.get_alternate_names()[:]
ReorderListBox.__init__(self, parent, person, obj, label,
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.NAME)
self.name_name_map,self.name_val_map = self.build_maps(
@ -486,14 +499,14 @@ class NameListBox(ReorderListBox):
self.data[index].set_suffix(value)
def add(self,obj):
NameEdit.NameEditor(self.parent, None, self.edit_callback,
self.parent.window)
NameEdit.NameEditor(self.state, self.uistate, None, self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
NameEdit.NameEditor(self.parent, self.list_model.get_object(node),
self.edit_callback, self.parent.window)
NameEdit.NameEditor(self.state, self.uistate,
self.list_model.get_object(node),
self.edit_callback)
def display_data(self,name):
has_note = name.get_note()
@ -518,7 +531,7 @@ class NameListBox(ReorderListBox):
class AddressListBox(ReorderListBox):
def __init__(self,parent,person,obj,label,button_list):
def __init__(self,state,uistate,track,person,obj,label,button_list):
titles = [
# Title Sort Col Size, Type
@ -532,7 +545,8 @@ class AddressListBox(ReorderListBox):
]
self.data = person.get_address_list()[:]
ReorderListBox.__init__(self, parent, person, obj, label,
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.ADDRESS)
def set_date(self,index,value):
@ -551,15 +565,15 @@ class AddressListBox(ReorderListBox):
self.data[index].set_country(value)
def add(self,obj):
AddrEdit.AddressEditor(self.parent, None, self.edit_callback,
self.parent.window)
AddrEdit.AddressEditor(self.state,self.uistate, None,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
item = self.list_model.get_object(node)
AddrEdit.AddressEditor(self.parent, item,
self.edit_callback, self.parent.window)
AddrEdit.AddressEditor(self.state,self.uistate, item,
self.edit_callback)
def display_data(self,item):
has_note = item.get_note()
@ -578,7 +592,7 @@ class AddressListBox(ReorderListBox):
class UrlListBox(ReorderListBox):
def __init__(self,parent,person,obj,label,button_list):
def __init__(self,state,uistate,track,person,obj,label,button_list):
titles = [
# Title Sort Col Size, Type
@ -586,7 +600,8 @@ class UrlListBox(ReorderListBox):
(_('Description'), NOSORT, 100, TEXT, None, self.set_description),
]
self.data = person.get_url_list()[:]
ReorderListBox.__init__(self, parent, person, obj, label,
ReorderListBox.__init__(self, state, uistate, track,
person, obj, label,
button_list, titles, DdTargets.URL)
def set_path(self,index,value):
@ -596,17 +611,15 @@ class UrlListBox(ReorderListBox):
self.data[index].set_description(value)
def add(self,obj):
UrlEdit.UrlEditor(self.parent, self.name, None,
self.edit_callback, self.parent.window)
UrlEdit.UrlEditor(self.state, self.uistate, self.name, None,
self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
UrlEdit.UrlEditor(self.parent, self.name,
UrlEdit.UrlEditor(self.state, self.uistate, self.name,
self.list_model.get_object(node),
self.edit_callback, self.window)
def display_data(self,url):
return [url.get_path(), url.get_description()]

View File

@ -449,11 +449,11 @@ class PersonView(PageView.PersonNavView):
def add(self,obj):
person = RelLib.Person()
EditPerson.EditPerson(self.dbstate, self.uistate, person)
EditPerson.EditPerson(self.dbstate, self.uistate, [], person)
def edit(self,obj):
if self.dbstate.active:
EditPerson.EditPerson(self.dbstate, self.uistate, self.dbstate.active)
EditPerson.EditPerson(self.dbstate, self.uistate, [], self.dbstate.active)
def remove(self,obj):
mlist = self.get_selected_objects()
@ -736,7 +736,7 @@ class PersonView(PageView.PersonNavView):
handle = self.first_selected()
person = self.dbstate.db.get_person_from_handle(handle)
if person:
EditPerson.EditPerson(self.dbstate, self.uistate,person)
EditPerson.EditPerson(self.dbstate, self.uistate, [], person)
return True
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
menu = self.uistate.uimanager.get_widget('/Popup')