2005-08-11 05:23:24 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2005-08-11 05:23:24 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
"""
|
|
|
|
Base history navigation class. Builds the action group and ui for the
|
|
|
|
uimanager. Changes to the associated history objects are tracked. When
|
|
|
|
the history changes, the UI XML string and the action groups are updated.
|
2005-08-11 05:23:24 +05:30
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------
|
2005-08-11 05:23:24 +05:30
|
|
|
import gtk
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
DISABLED = -1
|
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
#-------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# UI Manager XML code
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
_top = [
|
|
|
|
'<ui>'
|
|
|
|
'<menubar name="MenuBar">'
|
|
|
|
'<menu action="GoMenu">'
|
|
|
|
'<placeholder name="CommonHistory">'
|
|
|
|
]
|
|
|
|
|
|
|
|
_btm = [
|
|
|
|
'</placeholder>'
|
|
|
|
'</menu>'
|
|
|
|
'</menubar>'
|
|
|
|
'</ui>'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
class BaseNavigation:
|
|
|
|
"""
|
|
|
|
Base history navigation class. Builds the action group and ui for the
|
|
|
|
uimanager. Changes to the associated history objects are tracked. When
|
|
|
|
the history changes, the UI XML string and the action groups are updated.
|
|
|
|
|
|
|
|
Import variables:
|
|
|
|
|
|
|
|
self.title - name used for Action group name and Actions
|
|
|
|
self.ui - XML string used to build menu items for UIManager
|
|
|
|
self.action_group - associate action group for selecting items
|
|
|
|
self.active - merge ID for the action group. DISABLED if not active
|
|
|
|
self.items - history handles associated with the menu
|
|
|
|
self.func - array of functions to take action based off of.
|
|
|
|
|
|
|
|
"""
|
In .:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* src/Filters/_SearchBar.py (SearchBar.__init__): Take dbstate as
a constructor argument; (SearchBar.apply_filter): pass dbstate.
* src/PageView.py (BookMarkView.add_bookmark,
PersonNavView.jumpto, PersonNavView.fwd_clicked,
PersonNavView.back_clicked, ListView.build_widget): Pass dbstate.
* src/Navigation.py (BaseNavigation.__init__,
PersonNavigation.__init__): Take dbstate as a constructor argument;
(PersonNavigation.build_item_name): properly access dbstate.
* src/DisplayState.py (__init__): Do not take dbstate as a
constructor argument; Do not connect dbstate signal here (moved to
ViewManager);
(display_relationship,push_message,modify_statusbar): Make dbstate
an argument.
* src/plugins/Checkpoint.py (run_tool): Pass dbstate.
* src/ViewManager.py (_build_main_window): Do not pass dbstate to
uistate DisplayState constructor; connect dbstate signal handler;
pass dbstate to Navigation; (keypress): Pass dbstate;
(statusbar_key_update): Pass dbstate;
(do_load_plugins): Pass dbstate;
(ViewManager.add_bookmark): Pass dbstate.
* src/DataViews/_RelationView.py (shade_update): Pass dbstate.
* src/DataViews/_PersonView.py (build_widget,_goto,
key_goto_home_person, key_edit_selected_person): Pass dbstate.
* src/Filters/Makefile.am (pkgdata_PYTHON): Remove obsolete file.
* src/Filters/__init__.py: Remove importing obsolete module.
* src/Filters/_FilterWidget.py: Remove obsolete module.
In po:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* POTFILES.in: Remove obsolete file.
svn: r7104
2006-08-01 10:01:10 +05:30
|
|
|
def __init__(self, dbstate, uistate, history, title):
|
2005-08-11 05:23:24 +05:30
|
|
|
self.title = title
|
2006-04-07 10:02:43 +05:30
|
|
|
self.ui = "".join(_top) + "".join(_btm)
|
In .:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* src/Filters/_SearchBar.py (SearchBar.__init__): Take dbstate as
a constructor argument; (SearchBar.apply_filter): pass dbstate.
* src/PageView.py (BookMarkView.add_bookmark,
PersonNavView.jumpto, PersonNavView.fwd_clicked,
PersonNavView.back_clicked, ListView.build_widget): Pass dbstate.
* src/Navigation.py (BaseNavigation.__init__,
PersonNavigation.__init__): Take dbstate as a constructor argument;
(PersonNavigation.build_item_name): properly access dbstate.
* src/DisplayState.py (__init__): Do not take dbstate as a
constructor argument; Do not connect dbstate signal here (moved to
ViewManager);
(display_relationship,push_message,modify_statusbar): Make dbstate
an argument.
* src/plugins/Checkpoint.py (run_tool): Pass dbstate.
* src/ViewManager.py (_build_main_window): Do not pass dbstate to
uistate DisplayState constructor; connect dbstate signal handler;
pass dbstate to Navigation; (keypress): Pass dbstate;
(statusbar_key_update): Pass dbstate;
(do_load_plugins): Pass dbstate;
(ViewManager.add_bookmark): Pass dbstate.
* src/DataViews/_RelationView.py (shade_update): Pass dbstate.
* src/DataViews/_PersonView.py (build_widget,_goto,
key_goto_home_person, key_edit_selected_person): Pass dbstate.
* src/Filters/Makefile.am (pkgdata_PYTHON): Remove obsolete file.
* src/Filters/__init__.py: Remove importing obsolete module.
* src/Filters/_FilterWidget.py: Remove obsolete module.
In po:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* POTFILES.in: Remove obsolete file.
svn: r7104
2006-08-01 10:01:10 +05:30
|
|
|
self.dbstate = dbstate
|
2006-02-10 11:06:32 +05:30
|
|
|
self.uistate = uistate
|
2005-08-11 05:23:24 +05:30
|
|
|
self.action_group = gtk.ActionGroup(self.title)
|
|
|
|
self.active = DISABLED
|
|
|
|
self.items = []
|
2006-04-07 10:02:43 +05:30
|
|
|
self.func = []
|
2006-02-10 11:06:32 +05:30
|
|
|
self.history = history
|
|
|
|
|
|
|
|
def clear(self):
|
2006-04-07 10:02:43 +05:30
|
|
|
"""
|
|
|
|
Clears out the specified history
|
|
|
|
"""
|
2006-02-10 11:06:32 +05:30
|
|
|
self.history.clear()
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
def disable(self):
|
|
|
|
"""
|
|
|
|
Removes the UI and action groups if the navigation is enabled
|
|
|
|
"""
|
|
|
|
if self.active != DISABLED:
|
|
|
|
self.uistate.uimanager.remove_ui(self.active)
|
|
|
|
self.uistate.uimanager.remove_action_group(self.action_group)
|
|
|
|
self.active = DISABLED
|
|
|
|
|
|
|
|
def enable(self):
|
|
|
|
"""
|
|
|
|
Enables the UI and action groups
|
|
|
|
"""
|
2005-12-23 11:05:32 +05:30
|
|
|
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)
|
2006-04-27 03:45:22 +05:30
|
|
|
self.uistate.uimanager.ensure_update()
|
2005-08-11 05:23:24 +05:30
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
def build_item_name(self, handle):
|
2005-08-11 05:23:24 +05:30
|
|
|
"""
|
|
|
|
Builds a string from the passed handle. Must be overridden by the
|
|
|
|
derrived class.
|
|
|
|
"""
|
|
|
|
return "ERROR"
|
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
def update_menu(self, items):
|
2005-08-11 05:23:24 +05:30
|
|
|
"""
|
|
|
|
Builds the UI and action group.
|
|
|
|
"""
|
|
|
|
self.items = items
|
2005-12-23 11:05:32 +05:30
|
|
|
self.disable()
|
2006-04-07 10:02:43 +05:30
|
|
|
menu_len = min(len(items), 10)
|
|
|
|
entry = '<menuitem action="%s%02d"/>'
|
|
|
|
|
|
|
|
data = [ entry % (self.title, index) for index in range(0, menu_len) ]
|
|
|
|
self.ui = "".join(_top) + "".join(data) + "".join(_btm)
|
2005-08-11 05:23:24 +05:30
|
|
|
self.action_group = gtk.ActionGroup(self.title)
|
|
|
|
data = []
|
|
|
|
index = 0
|
2006-01-06 10:38:51 +05:30
|
|
|
|
|
|
|
mitems = items[:]
|
|
|
|
mitems.reverse()
|
|
|
|
for item in mitems[:10]:
|
2005-08-11 05:23:24 +05:30
|
|
|
name = self.build_item_name(item)
|
2006-04-07 10:02:43 +05:30
|
|
|
func = self.func[index]
|
|
|
|
data.append(('%s%02d'%(self.title, index), None, name,
|
|
|
|
"<alt>%d" % index, None, func))
|
2006-01-06 10:38:51 +05:30
|
|
|
index += 1
|
|
|
|
|
2005-08-11 05:23:24 +05:30
|
|
|
self.action_group.add_actions(data)
|
2006-01-06 10:38:51 +05:30
|
|
|
self.enable()
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
|
|
|
|
class PersonNavigation(BaseNavigation):
|
|
|
|
"""
|
|
|
|
Builds a navigation item for the Person class.
|
|
|
|
"""
|
In .:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* src/Filters/_SearchBar.py (SearchBar.__init__): Take dbstate as
a constructor argument; (SearchBar.apply_filter): pass dbstate.
* src/PageView.py (BookMarkView.add_bookmark,
PersonNavView.jumpto, PersonNavView.fwd_clicked,
PersonNavView.back_clicked, ListView.build_widget): Pass dbstate.
* src/Navigation.py (BaseNavigation.__init__,
PersonNavigation.__init__): Take dbstate as a constructor argument;
(PersonNavigation.build_item_name): properly access dbstate.
* src/DisplayState.py (__init__): Do not take dbstate as a
constructor argument; Do not connect dbstate signal here (moved to
ViewManager);
(display_relationship,push_message,modify_statusbar): Make dbstate
an argument.
* src/plugins/Checkpoint.py (run_tool): Pass dbstate.
* src/ViewManager.py (_build_main_window): Do not pass dbstate to
uistate DisplayState constructor; connect dbstate signal handler;
pass dbstate to Navigation; (keypress): Pass dbstate;
(statusbar_key_update): Pass dbstate;
(do_load_plugins): Pass dbstate;
(ViewManager.add_bookmark): Pass dbstate.
* src/DataViews/_RelationView.py (shade_update): Pass dbstate.
* src/DataViews/_PersonView.py (build_widget,_goto,
key_goto_home_person, key_edit_selected_person): Pass dbstate.
* src/Filters/Makefile.am (pkgdata_PYTHON): Remove obsolete file.
* src/Filters/__init__.py: Remove importing obsolete module.
* src/Filters/_FilterWidget.py: Remove obsolete module.
In po:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* POTFILES.in: Remove obsolete file.
svn: r7104
2006-08-01 10:01:10 +05:30
|
|
|
def __init__(self, dbstate, uistate):
|
2005-08-11 05:23:24 +05:30
|
|
|
"""
|
|
|
|
Associates the functions with the associated items. Builds the function
|
|
|
|
array so that there are unique functions for each possible index (0-9)
|
|
|
|
The callback simply calls change_active_handle
|
|
|
|
"""
|
In .:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* src/Filters/_SearchBar.py (SearchBar.__init__): Take dbstate as
a constructor argument; (SearchBar.apply_filter): pass dbstate.
* src/PageView.py (BookMarkView.add_bookmark,
PersonNavView.jumpto, PersonNavView.fwd_clicked,
PersonNavView.back_clicked, ListView.build_widget): Pass dbstate.
* src/Navigation.py (BaseNavigation.__init__,
PersonNavigation.__init__): Take dbstate as a constructor argument;
(PersonNavigation.build_item_name): properly access dbstate.
* src/DisplayState.py (__init__): Do not take dbstate as a
constructor argument; Do not connect dbstate signal here (moved to
ViewManager);
(display_relationship,push_message,modify_statusbar): Make dbstate
an argument.
* src/plugins/Checkpoint.py (run_tool): Pass dbstate.
* src/ViewManager.py (_build_main_window): Do not pass dbstate to
uistate DisplayState constructor; connect dbstate signal handler;
pass dbstate to Navigation; (keypress): Pass dbstate;
(statusbar_key_update): Pass dbstate;
(do_load_plugins): Pass dbstate;
(ViewManager.add_bookmark): Pass dbstate.
* src/DataViews/_RelationView.py (shade_update): Pass dbstate.
* src/DataViews/_PersonView.py (build_widget,_goto,
key_goto_home_person, key_edit_selected_person): Pass dbstate.
* src/Filters/Makefile.am (pkgdata_PYTHON): Remove obsolete file.
* src/Filters/__init__.py: Remove importing obsolete module.
* src/Filters/_FilterWidget.py: Remove obsolete module.
In po:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* POTFILES.in: Remove obsolete file.
svn: r7104
2006-08-01 10:01:10 +05:30
|
|
|
BaseNavigation.__init__(self, dbstate, uistate,
|
|
|
|
uistate.phistory, 'PersonHistory')
|
|
|
|
fcn_ptr = self.dbstate.change_active_handle
|
2006-04-07 10:02:43 +05:30
|
|
|
|
|
|
|
self.func = [ generate(fcn_ptr, self.items, index) \
|
|
|
|
for index in range(0, 10) ]
|
2005-08-11 05:23:24 +05:30
|
|
|
|
|
|
|
def build_item_name(self, item):
|
|
|
|
"""
|
|
|
|
Builds a name in the format of 'NAME [GRAMPSID]'
|
|
|
|
"""
|
In .:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* src/Filters/_SearchBar.py (SearchBar.__init__): Take dbstate as
a constructor argument; (SearchBar.apply_filter): pass dbstate.
* src/PageView.py (BookMarkView.add_bookmark,
PersonNavView.jumpto, PersonNavView.fwd_clicked,
PersonNavView.back_clicked, ListView.build_widget): Pass dbstate.
* src/Navigation.py (BaseNavigation.__init__,
PersonNavigation.__init__): Take dbstate as a constructor argument;
(PersonNavigation.build_item_name): properly access dbstate.
* src/DisplayState.py (__init__): Do not take dbstate as a
constructor argument; Do not connect dbstate signal here (moved to
ViewManager);
(display_relationship,push_message,modify_statusbar): Make dbstate
an argument.
* src/plugins/Checkpoint.py (run_tool): Pass dbstate.
* src/ViewManager.py (_build_main_window): Do not pass dbstate to
uistate DisplayState constructor; connect dbstate signal handler;
pass dbstate to Navigation; (keypress): Pass dbstate;
(statusbar_key_update): Pass dbstate;
(do_load_plugins): Pass dbstate;
(ViewManager.add_bookmark): Pass dbstate.
* src/DataViews/_RelationView.py (shade_update): Pass dbstate.
* src/DataViews/_PersonView.py (build_widget,_goto,
key_goto_home_person, key_edit_selected_person): Pass dbstate.
* src/Filters/Makefile.am (pkgdata_PYTHON): Remove obsolete file.
* src/Filters/__init__.py: Remove importing obsolete module.
* src/Filters/_FilterWidget.py: Remove obsolete module.
In po:
2006-07-31 Alex Roitman <shura@gramps-project.org>
* POTFILES.in: Remove obsolete file.
svn: r7104
2006-08-01 10:01:10 +05:30
|
|
|
person = self.dbstate.db.get_person_from_handle(item)
|
2007-06-28 11:11:40 +05:30
|
|
|
return "%s [%s]" % (name_displayer.display(person),
|
2005-08-12 22:58:22 +05:30
|
|
|
person.gramps_id)
|
2005-08-11 05:23:24 +05:30
|
|
|
|
2006-04-07 10:02:43 +05:30
|
|
|
def generate(func, items, index):
|
|
|
|
"""
|
|
|
|
Generates a callback function based off the passed arguments
|
|
|
|
"""
|
|
|
|
return lambda x: func(items[index])
|