* src/AddrEdit.py: More window management

* src/AttrEdit.py: More window management
* src/DisplayState.py: added push_message
* src/EditPerson.py: More window management
* src/ListBox.py: More window management
* src/NameEdit.py: More window management
* src/Navigation.py: More window management
* src/PeopleModel.py: More window management
* src/PersonView.py: More window management
* src/ViewManager.py: better handling of ui and action groups


svn: r5623
This commit is contained in:
Don Allingham 2005-12-23 05:35:32 +00:00
parent c30167137c
commit 04d0822569
11 changed files with 104 additions and 161 deletions

View File

@ -1,3 +1,15 @@
2005-12-22 Don Allingham <don@gramps-project.org>
* src/AddrEdit.py: More window management
* src/AttrEdit.py: More window management
* src/DisplayState.py: added push_message
* src/EditPerson.py: More window management
* src/ListBox.py: More window management
* src/NameEdit.py: More window management
* src/Navigation.py: More window management
* src/PeopleModel.py: More window management
* src/PersonView.py: More window management
* src/ViewManager.py: better handling of ui and action groups
2005-12-22 Alex Roitman <shura@gramps-project.org>
* test/RunAllTests.py: Change header.
* src/EventEdit.py: Fix build_ methods.

View File

@ -53,6 +53,7 @@ import RelLib
import Sources
import DateEdit
import DateHandler
import DisplayState
import Spell
from WindowUtils import GladeIf
@ -62,11 +63,11 @@ from WindowUtils import GladeIf
# AddressEditor class
#
#-------------------------------------------------------------------------
class AddressEditor:
class AddressEditor(DisplayState.ManagedWindow):
"""
Displays a dialog that allows the user to edit an address.
"""
def __init__(self,parent,addr,callback,parent_window=None):
def __init__(self, dbstate, uistate, track, addr, callback):
"""
Displays the dialog box.
@ -74,19 +75,15 @@ class AddressEditor:
addr - The address that is to be edited
"""
self.parent = parent
if addr:
if self.parent.child_windows.has_key(addr):
self.parent.child_windows[addr].present(None)
return
else:
self.win_key = addr
else:
self.win_key = self
self.db = self.parent.db
self.addr = addr
self.db = dbstate.db
self.uistate = uistate
self.dbstate = dbstate
self.callback = callback
self.child_windows = {}
self.addr = addr
DisplayState.ManagedWindow.__init__(self, uistate, track, addr)
if self.already_exist:
return
# Get the important widgets from the glade description
self.top = gtk.glade.XML(const.dialogFile, "addr_edit","gramps")
@ -151,9 +148,11 @@ class AddressEditor:
Utils.unbold_label(self.general_label)
self.addr_date_obj = Date.Date()
self.srcreflist = []
self.addr = RelLib.Address()
self.switch_page()
self.sourcetab = Sources.SourceTab(
self.dbstate, 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)
@ -164,57 +163,29 @@ class AddressEditor:
self.addr_date_obj, self.addr_start, date_stat, self.window)
self.gladeif.connect('addr_edit','delete_event',self.on_delete_event)
self.gladeif.connect('button122','clicked',self.close)
self.gladeif.connect('button122','clicked',self.close_window)
self.gladeif.connect('button121','clicked',self.ok_clicked)
okbtn = self.top.get_widget('button121')
okbtn.set_sensitive(not self.db.readonly)
self.gladeif.connect('button129','clicked',self.on_help_clicked)
self.gladeif.connect('notebook2','switch_page',self.on_switch_page)
if parent_window:
self.window.set_transient_for(parent_window)
self.add_itself_to_menu()
self.window.set_transient_for(self.parent_window)
self.window.show()
def on_delete_event(self,obj,b):
self.close_child_windows()
self.remove_itself_from_menu()
self.gladeif.close()
self.close()
gc.collect()
def close(self,obj):
self.close_child_windows()
self.remove_itself_from_menu()
def close_window(self,obj):
self.gladeif.close()
self.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 = _('Address')
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(_('Address 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 build_menu_names(self,obj):
return (_('Address'),_('Address Editor'))
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
@ -237,28 +208,23 @@ class AddressEditor:
format = self.preform.get_active()
priv = self.priv.get_active()
if self.addr == None:
self.addr = RelLib.Address()
self.parent.plist.append(self.addr)
self.addr.set_source_reference_list(self.srcreflist)
self.update(date_obj,street,city,state,country,postal,phone,note,format,priv)
self.callback(self.addr)
self.close(obj)
self.close_window(obj)
def check(self,get,set,data):
"""Compares a data item, updates if necessary, and sets the
parents lists_changed flag"""
if get() != data:
set(data)
self.parent.lists_changed = 1
def update(self,date_obj,street,city,state,country,postal,phone,note,format,priv):
"""Compares the data items, and updates if necessary"""
if not self.addr.get_date_object().is_equal(date_obj):
self.addr.set_date_object(date_obj)
self.parent.lists_changed = 1
self.check(self.addr.get_street,self.addr.set_street,street)
self.check(self.addr.get_country,self.addr.set_country,country)

View File

@ -56,6 +56,7 @@ import AutoComp
import RelLib
import Spell
import GrampsDisplay
import DisplayState
from QuestionDialog import WarningDialog
from WindowUtils import GladeIf
@ -65,12 +66,11 @@ from WindowUtils import GladeIf
# AttributeEditor class
#
#-------------------------------------------------------------------------
class AttributeEditor:
class AttributeEditor(DisplayState.ManagedWindow):
"""
Displays a dialog that allows the user to edit an attribute.
"""
def __init__(self, parent, attrib, title, data_list, callback,
parent_window=None):
def __init__(self, state, uistate, track, attrib, title, data_list, callback):
"""
Displays the dialog box.
@ -80,21 +80,18 @@ class AttributeEditor:
list - list of options for the pop down menu
"""
self.parent = parent
if attrib:
if self.parent.child_windows.has_key(attrib):
self.parent.child_windows[attrib].present(None)
return
else:
self.win_key = attrib
else:
self.win_key = self
self.db = self.parent.db
self.db = state.db
self.attrib = attrib
self.callback = callback
self.child_windows = {}
self.track = track
self.uistate = uistate
self.state = state
self.alist = data_list
DisplayState.ManagedWindow.__init__(self, uistate, track, attrib)
if self.already_exist:
return
self.top = gtk.glade.XML(const.dialogFile, "attr_edit","gramps")
self.slist = self.top.get_widget("slist")
self.value_field = self.top.get_widget("attr_value")
@ -121,6 +118,7 @@ class AttributeEditor:
self.srcreflist = []
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)
@ -132,7 +130,7 @@ class AttributeEditor:
l = self.top.get_widget("title")
Utils.set_titles(self.window,l,title,_('Attribute Editor'))
if attrib != None:
if attrib:
self.type_selector.set_values(attrib.get_type())
self.value_field.set_text(attrib.get_value())
self.priv.set_active(attrib.get_privacy())
@ -146,10 +144,12 @@ class AttributeEditor:
self.flowed.set_active(True)
else:
Utils.unbold_label(self.notes_label)
else:
self.attrib = RelLib.Attribute()
self.gladeif = GladeIf(self.top)
self.gladeif.connect('attr_edit','delete_event', self.on_delete_event)
self.gladeif.connect('button116', 'clicked', self.close)
self.gladeif.connect('button116', 'clicked', self.close_window)
self.gladeif.connect('button115', 'clicked', self.on_ok_clicked)
self.gladeif.connect('button127', 'clicked', self.on_help_clicked)
self.gladeif.connect('notebook', 'switch_page', self.on_switch_page)
@ -164,57 +164,30 @@ class AttributeEditor:
self.flowed.set_sensitive(False)
self.preform.set_sensitive(False)
if parent_window:
self.window.set_transient_for(parent_window)
self.add_itself_to_menu()
self.update_note_page()
self.window.set_transient_for(self.parent_window)
self.window.show()
def on_delete_event(self,obj,b):
self.close_child_windows()
self.remove_itself_from_menu()
self.gladeif.close()
self.close()
gc.collect()
def close(self,obj):
self.close_child_windows()
self.remove_itself_from_menu()
def close_window(self,obj):
self.gladeif.close()
self.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
if not self.attrib:
def build_menu_names(self, attrib):
if not attrib:
label = _("New Attribute")
else:
label = self.attrib.get_type()[1]
label = attrib.get_type()[1]
if not label.strip():
label = _("New Attribute")
label = "%s: %s" % (_('Attribute'),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(_('Attribute 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()
return (label, _('Attribute Editor'))
def on_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
@ -243,20 +216,16 @@ class AttributeEditor:
self.alist.append(attr_data[1])
self.alist.sort()
if self.attrib == None:
self.attrib = RelLib.Attribute()
self.parent.alist.append(self.attrib)
self.attrib.set_source_reference_list(self.srcreflist)
self.update(attr_data,value,note,format,priv)
self.callback(self.attrib)
self.close(obj)
self.close_window(obj)
def check(self,get,set,data):
"""Compares a data item, updates if necessary, and sets the
parents lists_changed flag"""
if get() != data:
set(data)
self.parent.lists_changed = 1
def update(self,attr_data,value,note,format,priv):
"""Compares the data items, and updates if necessary"""

View File

@ -132,7 +132,7 @@ class History(GrampsDb.GrampsDBCallback):
#
#-------------------------------------------------------------------------
_win_top = '<ui><menubar name="MenuBar"><menu name="WindowsMenu">'
_win_top = '<ui><menubar name="MenuBar"><menu action="WindowsMenu">'
_win_btm = '</menu></menubar></ui>'
DISABLED = -1
@ -464,6 +464,10 @@ class DisplayState(GrampsDb.GrampsDBCallback):
self.phistory = History()
self.gwm = GrampsWindowManager(uimanager)
def push_message(self, text):
self.status_text(text)
gobject.timeout_add(5000,self.modify_statusbar)
def modify_statusbar(self,active=None):
self.status.pop(self.status_id)
if self.dbstate.active == None:

View File

@ -313,7 +313,7 @@ class EditPerson(DisplayState.ManagedWindow):
self.person, self.addr_list, self.addr_label,
[addr_add_btn, addr_edit_btn, addr_delete_btn])
self.name_box = ListBox.NameListBox( state, uistate, self.track,
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])
@ -1030,6 +1030,10 @@ class EditPerson(DisplayState.ManagedWindow):
changed = False
name = self.person.get_primary_name()
for item in [ self.event_box, self.attr_box, self.addr_box,
self.name_box, self.url_box] :
if len(item.get_changed_objects()) > 0:
changed = True
#TODO#if self.complete.get_active() != self.person.get_complete_flag():
# changed = True
@ -1366,7 +1370,7 @@ class EditPerson(DisplayState.ManagedWindow):
self.pname.set_first_name(unicode(self.given.get_text()))
self.pname.set_title(unicode(self.title.get_text()))
NameEdit.NameEditor(self, self.pname, self.update_name, self.window)
NameEdit.NameEditor(self.state, self.uistate, self.track, self.pname, self)
def update_name(self,name):
self.write_primary_name()

View File

@ -265,16 +265,16 @@ class AttrListBox(ReorderListBox):
def add(self,obj):
"""Brings up the AttributeEditor for a new attribute"""
AttrEdit.AttributeEditor(state, uistate, None, self.name,
self.attr_dict,
AttrEdit.AttributeEditor(self.state, self.uistate, self.track,
None, self.name, self.attr_dict,
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(state,uistate, attr, self.name,
self.attr_dict,
AttrEdit.AttributeEditor(self.state, self.uistate, self.track,
attr, self.name, self.attr_dict,
self.edit_callback)
def display_data(self,attr):
@ -451,7 +451,7 @@ class EventListBox(ReorderListBox):
class NameListBox(ReorderListBox):
def __init__(self,state,uistate,track,person,obj,label,button_list):
def __init__(self, state, uistate, track, person, obj, label, button_list):
surnames = state.db.get_surname_list()
@ -499,14 +499,15 @@ class NameListBox(ReorderListBox):
self.data[index].set_suffix(value)
def add(self,obj):
NameEdit.NameEditor(self.state, self.uistate, None, self.track)
NameEdit.NameEditor(self.state, self.uistate, self.track,
None, self.edit_callback)
def update(self,obj):
store,node = self.list_model.get_selected()
if node:
NameEdit.NameEditor(self.state, self.uistate,
NameEdit.NameEditor(self.state, self.uistate, self.track,
self.list_model.get_object(node),
self.track)
self.edit_callback)
def display_data(self,name):
has_note = name.get_note()
@ -565,14 +566,14 @@ class AddressListBox(ReorderListBox):
self.data[index].set_country(value)
def add(self,obj):
AddrEdit.AddressEditor(self.state,self.uistate, None,
AddrEdit.AddressEditor(self.state, self.uistate, self.track, 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.state,self.uistate, item,
AddrEdit.AddressEditor(self.state, self.uistate, self.track, item,
self.edit_callback)
def display_data(self,item):

View File

@ -63,11 +63,12 @@ from WindowUtils import GladeIf
#-------------------------------------------------------------------------
class NameEditor(DisplayState.ManagedWindow):
def __init__(self,dbstate,uistate,name,track):
def __init__(self, dbstate, uistate, track, name, callback):
self.db = dbstate.db
self.uistate = uistate
self.state = dbstate
self.callback = callback
DisplayState.ManagedWindow.__init__(self, uistate, track, name)
if self.already_exist:
@ -101,6 +102,7 @@ class NameEditor(DisplayState.ManagedWindow):
else:
self.srcreflist = []
self.date_obj = Date.Date()
self.name = RelLib.Name()
self.date.set_text(DateHandler.displayer.display(self.date_obj))
@ -158,7 +160,7 @@ class NameEditor(DisplayState.ManagedWindow):
self.note_buffer = self.note_field.get_buffer()
self.gladeif.connect('name_edit','delete_event',self.on_delete_event)
self.gladeif.connect('button119','clicked',self.close)
self.gladeif.connect('button119','clicked',self.close_window)
self.gladeif.connect('button118','clicked',self.on_name_edit_ok_clicked)
okbtn = self.top.get_widget('button118')
okbtn.set_sensitive(not self.db.readonly)
@ -206,7 +208,8 @@ class NameEditor(DisplayState.ManagedWindow):
def build_menu_names(self,name):
if name:
submenu_label = _('%s: %s') % (_('Name',NameDisplay.displayer.display(name)))
ntext = NameDisplay.displayer.display_name(name)
submenu_label = _('%s: %s') % (_('Name'),ntext)
else:
submenu_label = _('New Name')
menu_label = _('Name Editor')
@ -234,10 +237,12 @@ class NameEditor(DisplayState.ManagedWindow):
def on_delete_event(self,*obj):
self.gladeif.close()
self.close()
gc.collect()
def close(self,*obj):
def close_window(self,*obj):
self.gladeif.close()
self.close()
self.window.destroy()
gc.collect()
@ -265,10 +270,6 @@ class NameEditor(DisplayState.ManagedWindow):
# if not mtype:
# mtype = "Also Known As"
if self.name == None:
self.name = RelLib.Name()
self.parent.nlist.append(self.name)
self.name.set_date_object(self.date_obj)
self.name.set_source_reference_list(self.srcreflist)
@ -278,20 +279,16 @@ class NameEditor(DisplayState.ManagedWindow):
if self.name.get_display_as() != self.display_as.get_active():
self.name.set_display_as(self.display_as.get_active())
self.parent.lists_changed = 1
prefix = unicode(self.prefix_field.get_text())
if self.name.get_surname_prefix() != prefix:
self.name.set_surname_prefix(prefix)
self.parent.lists_changed = 1
if self.name.get_sort_as() != self.sort_as.get_active():
self.name.set_sort_as(self.sort_as.get_active())
self.parent.lists_changed = 1
if not self.group_over.get_active():
self.name.set_group_as("")
self.parent.lists_changed = 1
elif self.name.get_group_as() != grp_as:
if grp_as not in self.db.get_name_group_keys():
from QuestionDialog import QuestionDialog2
@ -309,50 +306,39 @@ class NameEditor(DisplayState.ManagedWindow):
self.db.set_name_group_mapping(srn,grp_as)
else:
self.name.set_group_as(grp_as)
self.parent.lists_changed = 1
self.update_name(first,last,suffix,patronymic,title,the_type,note,format,priv)
self.parent.lists_changed = 1
self.close(obj)
self.callback(self.name)
self.close_window(obj)
def update_name(self,first,last,suffix,patronymic,title,the_type,note,format,priv):
if self.name.get_first_name() != first:
self.name.set_first_name(first)
self.parent.lists_changed = 1
if self.name.get_surname() != last:
self.name.set_surname(last)
self.parent.lists_changed = 1
if self.name.get_suffix() != suffix:
self.name.set_suffix(suffix)
self.parent.lists_changed = 1
if self.name.get_patronymic() != patronymic:
self.name.set_patronymic(patronymic)
self.parent.lists_changed = 1
if self.name.get_title() != title:
self.name.set_title(title)
self.parent.lists_changed = 1
if self.name.get_type() != the_type:
self.name.set_type(the_type)
self.parent.lists_changed = 1
if self.name.get_note() != note:
self.name.set_note(note)
self.parent.lists_changed = 1
if self.name.get_note_format() != format:
self.name.set_note_format(format)
self.parent.lists_changed = 1
if self.name.get_privacy() != priv:
self.name.set_privacy(priv)
self.parent.lists_changed = 1
def on_switch_page(self,obj,a,page):
start = self.note_buffer.get_start_iter()

View File

@ -65,8 +65,9 @@ class BaseNavigation:
"""
Enables the UI and action groups
"""
self.uistate.uimanager.insert_action_group(self.action_group, 1)
self.active = self.uistate.uimanager.add_ui_from_string(self.ui)
if self.active == DISABLED:
self.uistate.uimanager.insert_action_group(self.action_group, 1)
self.active = self.uistate.uimanager.add_ui_from_string(self.ui)
def build_item_name(self,handle):
"""
@ -81,9 +82,7 @@ class BaseNavigation:
"""
self.items = items
if self.active != DISABLED:
self.uistate.uimanager.remove_ui(self.active)
self.uistate.uimanager.remove_action_group(self.action_group)
self.disable()
data = map(lambda x: '<menuitem action="%s%02d"/>' % (self.title,x), range(0,len(items)))
self.ui = _top + "".join(data) + _btm

View File

@ -383,9 +383,9 @@ class PeopleModel(gtk.GenericTreeModel):
return cgi.escape(place_title)
for event_ref in data[_EVENT_COL]:
event = self.db.get_event_from_handle(event_ref.ref)
etype = event.get_type()[0]
if etype in [Event.BAPTISM, Event.CHRISTEN]:
event = self.db.get_event_from_handle(event_ref.ref)
place_handle = event.get_place_handle()
if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title()
@ -405,9 +405,9 @@ class PeopleModel(gtk.GenericTreeModel):
return cgi.escape(place_title)
for event_ref in data[_EVENT_COL]:
event = self.db.get_event_from_handle(event_ref.ref)
etype = event.get_type()[0]
if etype in [Event.BURIAL, Event.CREMATION]:
event = self.db.get_event_from_handle(event_ref.ref)
place_handle = event.get_place_handle()
if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title()

View File

@ -284,7 +284,7 @@ class PersonView(PageView.PersonNavView):
self.tree.scroll_to_cell(path,None,1,0.5,0)
except KeyError:
self.selection.unselect_all()
print "Person not currently available due to filter"
self.uistate.push_message(_("Active person not visible"))
self.dbstate.active = p
# disable the inactive flag

View File

@ -392,7 +392,7 @@ class ViewManager:
for mergeid in self.merge_ids:
self.uimanager.remove_ui(mergeid)
if self.active_page:
groups = self.active_page.get_actions()
for grp in groups:
@ -416,10 +416,12 @@ class ViewManager:
ui = self.active_page.ui_definition()
self.merge_ids = [self.uimanager.add_ui_from_string(ui)]
for ui in self.active_page.additional_ui_definitions():
mergeid = self.uimanager.add_ui_from_string(ui)
self.merge_ids.append(mergeid)
while gtk.events_pending():
gtk.main_iteration()
self.pages[num].change_page()
@ -717,7 +719,7 @@ class ViewManager:
self.bookmarks.add(self.active_person.get_handle())
name = NameDisplay.displayer.display(self.active_person)
self.status_text(_("%s has been bookmarked") % name)
gtk.timeout_add(5000,self.modify_statusbar)
gobject.timeout_add(5000,self.modify_statusbar)
else:
WarningDialog(_("Could Not Set a Bookmark"),
_("A bookmark could not be set because "