gramps/src/PageView.py

930 lines
31 KiB
Python
Raw Normal View History

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2006 Donald N. Allingham
#
# 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
#
# $Id$
#----------------------------------------------------------------
#
# python
#
#----------------------------------------------------------------
from gettext import gettext as _
import cPickle as pickle
#----------------------------------------------------------------
#
# gtk
#
#----------------------------------------------------------------
import gtk
import pango
from gtk.gdk import ACTION_COPY, BUTTON1_MASK
#----------------------------------------------------------------
#
# GRAMPS
#
#----------------------------------------------------------------
2006-05-10 21:38:56 +05:30
import Config
import TreeTips
2006-04-27 03:18:13 +05:30
import Bookmarks
import Errors
2006-05-10 21:38:56 +05:30
from Filters import SearchBar
import const
2005-08-11 05:23:24 +05:30
NAVIGATION_NONE = -1
NAVIGATION_PERSON = 0
EMPTY_SEARCH = (0, '', False)
2005-08-12 08:05:27 +05:30
#----------------------------------------------------------------
#
# PageView
#
#----------------------------------------------------------------
class PageView:
def __init__(self, title, dbstate, uistate):
self.title = title
2005-08-11 05:23:24 +05:30
self.dbstate = dbstate
self.uistate = uistate
self.action_list = []
self.action_toggle_list = []
self.action_group = None
self.additional_action_groups = []
2005-08-11 05:23:24 +05:30
self.additional_uis = []
self.widget = None
self.model = None
2005-08-11 05:23:24 +05:30
self.ui = '<ui></ui>'
2006-05-18 20:07:24 +05:30
self.dbstate.connect('no-database',self.disable_action_group)
2005-08-11 05:23:24 +05:30
self.dbstate.connect('database-changed',self.enable_action_group)
self.dirty = True
self.active = False
self.handle_col = 0
self.selection = None
def call_function(self, key):
self.func_list.get(key)()
def post(self):
pass
def set_active(self):
self.active = True
if self.dirty:
self.uistate.set_busy_cursor(True)
self.build_tree()
self.uistate.set_busy_cursor(False)
def set_inactive(self):
self.active = False
def build_tree(self):
pass
2005-08-11 05:23:24 +05:30
def navigation_type(self):
return NAVIGATION_NONE
def ui_definition(self):
return self.ui
def additional_ui_definitions(self):
return self.additional_uis
def disable_action_group(self):
if self.action_group:
self.action_group.set_visible(False)
def enable_action_group(self,obj):
if self.action_group:
self.action_group.set_visible(True)
def get_stock(self):
2006-05-18 20:07:24 +05:30
try:
return gtk.STOCK_MEDIA_MISSING
except AttributeError:
return gtk.STOCK_MISSING_IMAGE
def get_title(self):
return self.title
def get_display(self):
if not self.widget:
self.widget = self.build_widget()
return self.widget
def build_widget(self):
assert False
def define_actions(self):
assert False
def _build_action_group(self):
self.action_group = gtk.ActionGroup(self.title)
if len(self.action_list) > 0:
self.action_group.add_actions(self.action_list)
if len(self.action_toggle_list) > 0:
self.action_group.add_toggle_actions(self.action_toggle_list)
2005-08-12 08:05:27 +05:30
def add_action(self, name, stock_icon, label, accel=None, tip=None,
callback=None):
self.action_list.append((name,stock_icon,label,accel,tip,callback))
2005-08-12 08:05:27 +05:30
def add_toggle_action(self, name, stock_icon, label, accel=None,
tip=None, callback=None, value=False):
self.action_toggle_list.append((name,stock_icon,label,accel,
tip,callback,value))
def get_actions(self):
if not self.action_group:
self._build_action_group()
return [self.action_group] + self.additional_action_groups
def add_action_group(self,group):
self.additional_action_groups.append(group)
2005-08-11 05:23:24 +05:30
2005-08-11 22:49:03 +05:30
def change_page(self):
self.uistate.clear_filter_results()
2005-08-12 03:43:44 +05:30
def edit(self,obj):
pass
def remove(self,obj):
pass
def add(self,obj):
pass
2005-08-12 03:43:44 +05:30
def key_press(self,obj,event):
#act if no modifier, and allow Num Lock as MOD2_MASK
if not event.state or event.state in (gtk.gdk.MOD2_MASK,):
if event.keyval in (gtk.keysyms.Return, gtk.keysyms.KP_Enter):
self.edit(obj)
return True
2005-08-12 03:43:44 +05:30
return False
2005-08-12 08:05:27 +05:30
def blist(self,store,path,iter,sel_list):
handle = store.get_value(iter,self.handle_col)
sel_list.append(handle)
def selected_handles(self):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
return mlist
def first_selected(self):
mlist = []
self.selection.selected_foreach(self.blist,mlist)
if mlist:
return mlist[0]
else:
return None
2006-04-27 03:18:13 +05:30
class BookMarkView(PageView):
def __init__(self, title, state, uistate, bookmarks, bm_type):
PageView.__init__(self, title, state, uistate)
self.bm_type = bm_type
self.setup_bookmarks(bookmarks)
def goto_handle(self, obj):
pass
2006-04-27 03:18:13 +05:30
def setup_bookmarks(self, bookmarks):
self.bookmarks = self.bm_type(
self.dbstate, self.uistate, bookmarks, self.goto_handle)
2006-04-27 03:18:13 +05:30
def add_bookmark(self, obj):
from BasicUtils import NameDisplay
2006-04-27 03:18:13 +05:30
if self.dbstate.active:
self.bookmarks.add(self.dbstate.active.get_handle())
name = NameDisplay.displayer.display(self.dbstate.active)
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.uistate.push_message(self.dbstate,
_("%s has been bookmarked") % name)
2006-04-27 03:18:13 +05:30
else:
from QuestionDialog import WarningDialog
WarningDialog(
_("Could Not Set a Bookmark"),
_("A bookmark could not be set because "
"no one was selected."))
def set_active(self):
PageView.set_active(self)
self.bookmarks.display()
def set_inactive(self):
PageView.set_inactive(self)
self.bookmarks.undisplay()
def edit_bookmarks(self, obj):
self.bookmarks.edit()
def enable_action_group(self, obj):
PageView.enable_action_group(self, obj)
def disable_action_group(self):
2006-04-27 03:18:13 +05:30
PageView.disable_action_group(self)
def define_actions(self):
self.book_action = gtk.ActionGroup(self.title + '/Bookmark')
self.book_action.add_actions([
('AddBook','gramps-bookmark-new', _('_Add bookmark'),'<control>d',None,
2006-04-27 03:18:13 +05:30
self.add_bookmark),
('EditBook','gramps-bookmark-edit', _('_Edit bookmarks'),'<control>b',None,
2006-04-27 03:18:13 +05:30
self.edit_bookmarks),
])
self.add_action_group(self.book_action)
2005-08-12 08:05:27 +05:30
#----------------------------------------------------------------
#
# PersonNavView
#
#----------------------------------------------------------------
2006-04-27 03:18:13 +05:30
class PersonNavView(BookMarkView):
2005-08-12 08:05:27 +05:30
def __init__(self,title,dbstate,uistate, callback=None):
2006-04-27 03:18:13 +05:30
BookMarkView.__init__(self, title, dbstate, uistate,
dbstate.db.get_bookmarks(),
Bookmarks.Bookmarks)
2005-08-11 22:49:03 +05:30
def navigation_type(self):
return NAVIGATION_PERSON
def define_actions(self):
# add the Forward action group to handle the Forward button
2006-04-27 03:18:13 +05:30
BookMarkView.define_actions(self)
2005-08-11 22:49:03 +05:30
self.fwd_action = gtk.ActionGroup(self.title + '/Forward')
self.fwd_action.add_actions([
2006-05-02 11:24:26 +05:30
('Forward',gtk.STOCK_GO_FORWARD,_("_Forward"),
"<ALT>Right", _("Go to the next person in the history"),
self.fwd_clicked)
2005-08-11 22:49:03 +05:30
])
# add the Backward action group to handle the Forward button
self.back_action = gtk.ActionGroup(self.title + '/Backward')
self.back_action.add_actions([
('Back',gtk.STOCK_GO_BACK,_("_Back"),
"<ALT>Left", _("Go to the previous person in the history"),
self.back_clicked)
2005-08-11 22:49:03 +05:30
])
2005-08-11 05:23:24 +05:30
self.add_action('HomePerson', gtk.STOCK_HOME, _("_Home"),
accel="<Alt>Home",
tip=_("Go to the default person"), callback=self.home)
self.add_action('FilterEdit', None, _('Person Filter Editor'),
callback=self.filter_editor)
self.other_action = gtk.ActionGroup(self.title + '/PersonOther')
self.other_action.add_actions([
('SetActive', gtk.STOCK_HOME, _("Set _Home Person"), None,
None, self.set_default_person),
])
2005-08-11 22:49:03 +05:30
self.add_action_group(self.back_action)
self.add_action_group(self.fwd_action)
self.add_action_group(self.other_action)
2005-08-11 22:49:03 +05:30
def disable_action_group(self):
"""
Normally, this would not be overridden from the base class. However,
in this case, we have additional action groups that need to be
handled correctly.
"""
2006-04-27 03:18:13 +05:30
BookMarkView.disable_action_group(self)
2005-08-11 22:49:03 +05:30
self.fwd_action.set_visible(False)
self.back_action.set_visible(False)
def enable_action_group(self,obj):
"""
Normally, this would not be overridden from the base class. However,
in this case, we have additional action groups that need to be
handled correctly.
"""
2006-04-27 03:18:13 +05:30
BookMarkView.enable_action_group(self,obj)
2005-08-11 22:49:03 +05:30
self.fwd_action.set_visible(True)
self.back_action.set_visible(True)
hobj = self.uistate.phistory
self.fwd_action.set_sensitive(not hobj.at_end())
self.back_action.set_sensitive(not hobj.at_front())
def set_default_person(self,obj):
active = self.dbstate.active
if active:
self.dbstate.db.set_default_person_handle(active.get_handle())
2005-08-11 22:49:03 +05:30
def home(self,obj):
defperson = self.dbstate.db.get_default_person()
if defperson:
self.dbstate.change_active_person(defperson)
def jump(self):
dialog = gtk.Dialog(_('Jump to by GRAMPS ID'),None,
gtk.DIALOG_NO_SEPARATOR)
dialog.set_border_width(12)
label = gtk.Label('<span weight="bold" size="larger">%s</span>' % _('Jump to by GRAMPS ID'))
label.set_use_markup(True)
dialog.vbox.add(label)
dialog.vbox.set_spacing(10)
dialog.vbox.set_border_width(12)
hbox = gtk.HBox()
hbox.pack_start(gtk.Label("%s: " % _('ID')),False)
text = gtk.Entry()
text.set_activates_default(True)
hbox.pack_start(text,False)
dialog.vbox.pack_start(hbox,False)
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_JUMP_TO, gtk.RESPONSE_OK)
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.vbox.show_all()
if dialog.run() == gtk.RESPONSE_OK:
gid = text.get_text()
person = self.dbstate.db.get_person_from_gramps_id(gid)
if person:
self.dbstate.change_active_person(person)
else:
self.uistate.push_message(
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,
_("Error: %s is not a valid GRAMPS ID") % gid)
dialog.destroy()
def filter_editor(self,obj):
from FilterEditor import FilterEditor
try:
FilterEditor('Person',const.custom_filters,
self.dbstate,self.uistate)
except Errors.WindowActiveError:
pass
2005-08-11 22:49:03 +05:30
def fwd_clicked(self,obj,step=1):
hobj = self.uistate.phistory
hobj.lock = True
if not hobj.at_end():
try:
handle = hobj.forward()
self.dbstate.change_active_handle(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
self.uistate.modify_statusbar(self.dbstate)
2005-08-11 22:49:03 +05:30
hobj.mhistory.append(hobj.history[hobj.index])
self.fwd_action.set_sensitive(not hobj.at_end())
self.back_action.set_sensitive(True)
except:
hobj.clear()
self.fwd_action.set_sensitive(False)
self.back_action.set_sensitive(False)
else:
self.fwd_action.set_sensitive(False)
self.back_action.set_sensitive(True)
hobj.lock = False
def back_clicked(self,obj,step=1):
hobj = self.uistate.phistory
hobj.lock = True
if not hobj.at_front():
try:
handle = hobj.back()
self.active = self.dbstate.db.get_person_from_handle(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
self.uistate.modify_statusbar(self.dbstate)
2005-08-11 22:49:03 +05:30
self.dbstate.change_active_handle(handle)
hobj.mhistory.append(hobj.history[hobj.index])
self.back_action.set_sensitive(not hobj.at_front())
self.fwd_action.set_sensitive(True)
except:
hobj.clear()
self.fwd_action.set_sensitive(False)
self.back_action.set_sensitive(False)
else:
self.back_action.set_sensitive(False)
self.fwd_action.set_sensitive(True)
hobj.lock = False
def handle_history(self, handle):
"""
Updates the person history information
"""
hobj = self.uistate.phistory
if handle and not hobj.lock:
hobj.push(handle)
self.fwd_action.set_sensitive(not hobj.at_end())
self.back_action.set_sensitive(not hobj.at_front())
def change_page(self):
hobj = self.uistate.phistory
self.fwd_action.set_sensitive(not hobj.at_end())
self.back_action.set_sensitive(not hobj.at_front())
self.other_action.set_sensitive(not self.dbstate.db.readonly)
2005-08-12 03:43:44 +05:30
2005-08-12 08:05:27 +05:30
#----------------------------------------------------------------
#
# ListView
#
#----------------------------------------------------------------
2006-04-27 03:18:13 +05:30
class ListView(BookMarkView):
2005-08-12 03:43:44 +05:30
ADD_MSG = ""
EDIT_MSG = ""
DEL_MSG = ""
2005-08-12 03:43:44 +05:30
def __init__(self, title, dbstate, uistate, columns, handle_col,
make_model, signal_map, get_bookmarks, bm_type,
multiple=False, filter_class=None):
2006-04-27 03:18:13 +05:30
BookMarkView.__init__(self, title, dbstate, uistate,
get_bookmarks, bm_type)
self.filter_class = filter_class
2005-08-12 03:43:44 +05:30
self.renderer = gtk.CellRendererText()
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
2005-08-12 03:43:44 +05:30
self.sort_col = 0
self.columns = []
self.colinfo = columns
self.handle_col = handle_col
self.make_model = make_model
self.signal_map = signal_map
self.multiple_selection = multiple
self.generic_filter = None
2005-08-12 03:43:44 +05:30
dbstate.connect('database-changed',self.change_db)
def build_filter_container(self, box, filter_class):
self.filter_sidebar = filter_class(self.dbstate, self.uistate,
self.filter_clicked)
self.filter_pane = self.filter_sidebar.get_widget()
hpaned = gtk.HBox()
hpaned.pack_start(self.vbox, True, True)
hpaned.pack_end(self.filter_pane, False, False)
self.filter_toggle(None, None, None, None)
return hpaned
def filter_toggle(self, client, cnxn_id, entry, data):
if Config.get(Config.FILTER):
self.search_bar.hide()
self.filter_pane.show()
active = True
else:
self.search_bar.show()
self.filter_pane.hide()
active = False
def post(self):
if self.filter_class:
if Config.get(Config.FILTER):
self.search_bar.hide()
self.filter_pane.show()
else:
self.search_bar.show()
self.filter_pane.hide()
def filter_clicked(self):
self.generic_filter = self.filter_sidebar.get_filter()
self.build_tree()
2006-04-27 03:18:13 +05:30
def add_bookmark(self, obj):
mlist = []
self.selection.selected_foreach(self.blist, mlist)
if mlist:
self.bookmarks.add(mlist[0])
else:
from QuestionDialog import WarningDialog
WarningDialog(
_("Could Not Set a Bookmark"),
_("A bookmark could not be set because "
"nothing was selected."))
def jump(self):
dialog = gtk.Dialog(_('Jump to by GRAMPS ID'),None,
gtk.DIALOG_NO_SEPARATOR)
dialog.set_border_width(12)
label = gtk.Label('<span weight="bold" size="larger">%s</span>' % _('Jump to by GRAMPS ID'))
label.set_use_markup(True)
dialog.vbox.add(label)
dialog.vbox.set_spacing(10)
dialog.vbox.set_border_width(12)
hbox = gtk.HBox()
hbox.pack_start(gtk.Label("%s: " % _('ID')),False)
text = gtk.Entry()
text.set_activates_default(True)
hbox.pack_start(text,False)
dialog.vbox.pack_start(hbox,False)
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_JUMP_TO, gtk.RESPONSE_OK)
dialog.set_default_response(gtk.RESPONSE_OK)
dialog.vbox.show_all()
if dialog.run() == gtk.RESPONSE_OK:
gid = text.get_text()
handle = self.get_handle_from_gramps_id(gid)
if handle:
self.goto_handle(handle)
else:
self.uistate.push_message(
self.dbstate,
_("Error: %s is not a valid GRAMPS ID") % gid)
dialog.destroy()
def drag_info(self):
return None
2006-03-27 10:36:10 +05:30
def drag_begin(self, widget, *data):
widget.drag_source_set_icon_stock(self.get_stock())
2005-08-12 08:05:27 +05:30
def column_order(self):
assert False
2005-08-12 03:43:44 +05:30
def build_widget(self):
"""
Builds the interface and returns a gtk.Container type that
contains the interface. This containter will be inserted into
a gtk.Notebook page.
"""
self.vbox = gtk.VBox()
self.vbox.set_border_width(4)
self.vbox.set_spacing(4)
self.search_bar = SearchBar(self.dbstate,self.uistate,
self.search_build_tree)
2006-05-10 21:38:56 +05:30
filter_box = self.search_bar.build()
2005-08-12 03:43:44 +05:30
self.list = gtk.TreeView()
self.list.set_rules_hint(True)
self.list.set_headers_visible(True)
self.list.set_headers_clickable(True)
self.list.set_fixed_height_mode(True)
2005-08-12 08:05:27 +05:30
self.list.connect('button-press-event',self.button_press)
2005-08-12 03:43:44 +05:30
self.list.connect('key-press-event',self.key_press)
if self.drag_info():
self.list.connect('drag_data_get', self.drag_data_get)
2006-03-27 10:36:10 +05:30
self.list.connect('drag_begin', self.drag_begin)
2005-08-12 03:43:44 +05:30
scrollwindow = gtk.ScrolledWindow()
scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrollwindow.set_shadow_type(gtk.SHADOW_ETCHED_IN)
scrollwindow.add(self.list)
self.vbox.pack_start(filter_box,False)
self.vbox.pack_start(scrollwindow,True)
2005-08-12 03:43:44 +05:30
self.renderer = gtk.CellRendererText()
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
2005-08-12 03:43:44 +05:30
self.inactive = False
self.columns = []
self.build_columns()
self.selection = self.list.get_selection()
if self.multiple_selection:
self.selection.set_mode(gtk.SELECTION_MULTIPLE)
self.selection.connect('changed',self.row_changed)
2005-08-12 03:43:44 +05:30
self.setup_filter()
if self.filter_class:
return self.build_filter_container(self.vbox, self.filter_class)
else:
return self.vbox
2005-08-12 03:43:44 +05:30
def search_build_tree(self):
self.build_tree()
def row_changed(self,obj):
"""Called with a row is changed. Check the selected objects from
the person_tree to get the IDs of the selected objects. Set the
active person to the first person in the list. If no one is
selected, set the active person to None"""
if self.drag_info():
selected_ids = self.selected_handles()
if len(selected_ids) == 1:
self.list.drag_source_set(BUTTON1_MASK,
[self.drag_info().target()],
ACTION_COPY)
def drag_data_get(self, widget, context, sel_data, info, time):
selected_ids = self.selected_handles()
if selected_ids:
data = (self.drag_info().drag_type, id(self), selected_ids[0], 0)
sel_data.set(sel_data.target, 8 ,pickle.dumps(data))
def setup_filter(self):
"""
Builds the default filters and add them to the filter menu.
"""
2006-05-10 21:38:56 +05:30
cols = []
for pair in [pair for pair in self.column_order() if pair[0]]:
2006-05-11 02:26:22 +05:30
cols.append((self.colinfo[pair[1]],pair[1]))
2006-05-10 21:38:56 +05:30
self.search_bar.setup_filter(cols)
def goto_handle(self, handle):
if not self.dbstate.active or self.inactive:
return
# mark inactive to prevent recusion
self.inactive = True
# select the active person in the person view
try:
path = self.model.on_get_path(handle)
self.selection.unselect_all()
self.selection.select_path(path)
self.list.scroll_to_cell(path,None,1,0.5,0)
except KeyError:
self.selection.unselect_all()
# disable the inactive flag
self.inactive = False
2005-08-12 03:43:44 +05:30
def column_clicked(self,obj,data):
if self.sort_col != data:
order = gtk.SORT_ASCENDING
else:
if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING
or not self.columns[data].get_sort_indicator()):
2005-08-12 03:43:44 +05:30
order = gtk.SORT_ASCENDING
else:
order = gtk.SORT_DESCENDING
2005-08-12 03:43:44 +05:30
self.sort_col = data
handle = self.first_selected()
2006-05-10 21:38:56 +05:30
if Config.get(Config.FILTER):
search = EMPTY_SEARCH
2006-05-10 21:38:56 +05:30
else:
search = (False,self.search_bar.get_value())
2006-05-10 21:38:56 +05:30
self.model = self.make_model(self.dbstate.db, self.sort_col, order,
search=search,
sort_map=self.column_order())
2005-08-12 03:43:44 +05:30
self.list.set_model(self.model)
2006-05-18 20:07:24 +05:30
colmap = self.column_order()
2005-08-12 03:43:44 +05:30
if handle:
path = self.model.on_get_path(handle)
self.selection.select_path(path)
self.list.scroll_to_cell(path,None,1,0.5,0)
for i in xrange(len(self.columns)):
enable_sort_flag = (i==self.sort_col)
self.columns[i].set_sort_indicator(enable_sort_flag)
2005-08-12 03:43:44 +05:30
self.columns[self.sort_col].set_sort_order(order)
2005-08-12 03:43:44 +05:30
def build_columns(self):
for column in self.columns:
self.list.remove_column(column)
self.columns = []
index = 0
for pair in [pair for pair in self.column_order() if pair[0]]:
2005-08-12 03:43:44 +05:30
name = self.colinfo[pair[1]]
if self.model and self.model.__dict__.has_key('marker_color_column'):
mcol = self.model.marker_color_column
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1],
foreground=mcol)
else:
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
2005-08-12 03:43:44 +05:30
column.connect('clicked',self.column_clicked,index)
column.set_resizable(True)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(pair[2])
2005-08-12 03:43:44 +05:30
column.set_clickable(True)
self.columns.append(column)
self.list.append_column(column)
index += 1
2005-08-12 03:43:44 +05:30
def build_tree(self):
if self.active:
2006-05-10 21:38:56 +05:30
if Config.get(Config.FILTER):
filter_info = (True, self.generic_filter)
2006-05-10 21:38:56 +05:30
else:
filter_info = (False, self.search_bar.get_value())
2006-05-10 21:38:56 +05:30
self.model = self.make_model(self.dbstate.db,self.sort_col,
search=filter_info)
self.list.set_model(self.model)
self.selection = self.list.get_selection()
if const.use_tips and self.model.tooltip_column != None:
self.tooltips = TreeTips.TreeTips(
self.list, self.model.tooltip_column, True)
self.dirty = False
self.uistate.show_filter_results(self.dbstate,
self.model.displayed,
self.model.total)
else:
self.dirty = True
def filter_toggle_action(self,obj):
if obj.get_active():
self.search_bar.hide()
self.filter_pane.show()
active = True
else:
self.search_bar.show()
self.filter_pane.hide()
active = False
Config.set(Config.FILTER, active)
self.build_tree()
def filter_editor(self,obj):
from FilterEditor import FilterEditor
try:
FilterEditor(self.FILTER_TYPE ,const.custom_filters,
self.dbstate, self.uistate)
except Errors.WindowActiveError:
pass
2005-08-12 03:43:44 +05:30
def change_db(self,db):
for sig in self.signal_map:
db.connect(sig, self.signal_map[sig])
2006-05-10 21:38:56 +05:30
2005-08-12 03:43:44 +05:30
self.build_columns()
2006-04-27 03:18:13 +05:30
self.bookmarks.update_bookmarks(self.get_bookmarks())
if self.active:
self.build_tree()
2006-04-27 03:18:13 +05:30
self.bookmarks.redraw()
else:
self.dirty = True
2005-08-12 03:43:44 +05:30
def row_add(self,handle_list):
if self.active:
for handle in handle_list:
self.model.add_row_by_handle(handle)
else:
self.dirty = True
2005-08-12 03:43:44 +05:30
def row_update(self,handle_list):
if self.model:
self.model.prev_handle = None
if self.active:
for handle in handle_list:
self.model.update_row_by_handle(handle)
else:
self.dirty = True
2005-08-12 03:43:44 +05:30
def row_delete(self,handle_list):
if self.active:
for handle in handle_list:
self.model.delete_row_by_handle(handle)
else:
self.dirty = True
2005-08-12 03:43:44 +05:30
def define_actions(self):
"""
Required define_actions function for PageView. Builds the action
group information required. We extend beyond the normal here,
since we want to have more than one action group for the PersonView.
Most PageViews really won't care about this.
"""
2006-04-27 03:18:13 +05:30
BookMarkView.define_actions(self)
2005-08-12 03:43:44 +05:30
self.edit_action = gtk.ActionGroup(self.title + '/ChangeOrder')
self.edit_action.add_actions([
('Add', gtk.STOCK_ADD, _("_Add"), "<control>Insert",
self.ADD_MSG, self.add),
('Remove', gtk.STOCK_REMOVE, _("_Remove"), "<control>Delete",
self.DEL_MSG, self.remove),
('ColumnEdit', gtk.STOCK_PROPERTIES, _('_Column Editor'),
None, None, self.column_editor),
('ExportTab', None, _('Export view'), None, None, self.export),
])
self.add_action_group(self.edit_action)
self.add_action('Edit', gtk.STOCK_EDIT, _("_Edit"),
accel="<control>Return",
tip=self.EDIT_MSG,
callback=self.edit)
self.add_toggle_action('Filter', None, _('_Filter'),
callback=self.filter_toggle_action)
2005-08-12 03:43:44 +05:30
def column_editor(self,obj):
pass
2005-08-12 08:05:27 +05:30
def button_press(self,obj,event):
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
self.edit(obj)
2005-08-12 08:05:27 +05:30
return True
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
menu = self.uistate.uimanager.get_widget('/Popup')
if menu:
menu.popup(None,None,None,event.button,event.time)
return True
2005-08-12 08:05:27 +05:30
return False
2005-08-12 03:43:44 +05:30
def key_press(self,obj,event):
if not event.state or event.state in (gtk.gdk.MOD2_MASK,):
if event.keyval in (gtk.keysyms.Return, gtk.keysyms.KP_Enter):
self.edit(obj)
return True
2005-08-12 03:43:44 +05:30
return False
2005-08-12 08:05:27 +05:30
def double_click(self,obj,event):
return False
def change_page(self):
if self.model:
self.uistate.show_filter_results(self.dbstate,
self.model.displayed,
self.model.total)
self.edit_action.set_sensitive(not self.dbstate.db.readonly)
2006-04-27 03:18:13 +05:30
def key_delete(self):
self.remove(None)
def export(self, obj):
chooser = gtk.FileChooserDialog(
_("Export view as spreadsheet"),
self.uistate.window,
gtk.FILE_CHOOSER_ACTION_SAVE,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_do_overwrite_confirmation(True)
combobox = gtk.combo_box_new_text()
label = gtk.Label(_("Format:"))
label.set_alignment(1.0, 0.5)
box = gtk.HBox()
box.pack_start(label, True, True, padding=12)
box.pack_start(combobox, False, False)
combobox.append_text(_('CSV'))
2007-02-06 10:55:27 +05:30
combobox.append_text(_('Open Document Spreadsheet'))
combobox.set_active(0)
box.show_all()
chooser.set_extra_widget(box)
while True:
value = chooser.run()
fn = chooser.get_filename()
fl = combobox.get_active()
if value == gtk.RESPONSE_OK:
if fn:
chooser.destroy()
break
else:
chooser.destroy()
return
self.write_tabbed_file(fn, fl)
def write_tabbed_file(self, name, type):
if type == 0:
from CSVTab import CSVTab as tabgen
else:
from ODSTab import ODSTab as tabgen
data_cols = [pair[1] for pair in self.column_order() if pair[0]]
column_names = [self.colinfo[i] for i in data_cols]
o = tabgen(len(column_names))
o.open(name)
o.start_page()
o.start_row()
for name in column_names:
o.write_cell(name)
o.end_row()
for row in self.model:
o.start_row()
for index in data_cols:
o.write_cell(row[index])
o.end_row()
o.end_page()
o.close()