gramps/src/gui/editors/editprimary.py

330 lines
11 KiB
Python
Raw Normal View History

2006-03-01 10:39:01 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
* src/TreeViews/_PersonTreeView.py: Use name_displayer. * src/ReportBase/_ReportUtils.py: Use name_displayer. * src/ReportBase/_CommandLineReport.py: Use name_displayer. * src/ReportBase/_BareReportDialog.py: Use name_displayer. * src/PluginUtils/_Tool.py: Use name_displayer. * src/plugins/TimeLine.py: Use name_displayer. * src/plugins/RelCalc.py: Use name_displayer. * src/plugins/ReadGrdb.py: Use name_displayer. * src/plugins/NarrativeWeb.py: Use name_displayer. * src/plugins/IndivComplete.py: Use name_displayer. * src/plugins/GraphViz.py: Use name_displayer. * src/plugins/FindDupes.py: Use name_displayer. * src/plugins/FamilyGroup.py: Use name_displayer. * src/plugins/DetDescendantReport.py: Use name_displayer. * src/plugins/DetAncestralReport.py: Use name_displayer. * src/plugins/DesGraph.py: Use name_displayer. * src/plugins/DescendReport.py: Use name_displayer. * src/plugins/DescendChart.py: Use name_displayer. * src/plugins/Check.py: Use name_displayer. * src/plugins/Ancestors.py: Use name_displayer. * src/plugins/AncestorReport.py: Use name_displayer. * src/plugins/AncestorChart2.py: Use name_displayer. * src/ObjectSelector/_PersonTreeFrame.py: Use name_displayer. * src/ObjectSelector/_PersonFrame.py: Use name_displayer. * src/Merge/_MergePerson.py: Use name_displayer. * src/GrampsDbUtils/_WriteGedcom.py: Use name_displayer. * src/GrampsDbUtils/_ReadXML.py: Use name_displayer. * src/GrampsDbUtils/_GedcomParse.py: Use name_displayer. * src/FilterEditor/_ShowResults.py: Use name_displayer. * src/FilterEditor/_EditRule.py: Use name_displayer. * src/Editors/_EditPrimary.py: Use name_displayer. * src/Editors/_EditPersonRef.py: Use name_displayer. * src/Editors/_EditPerson.py: Use name_displayer. * src/Editors/_EditName.py: Use name_displayer. * src/Editors/_EditLdsOrd.py: Use name_displayer. * src/Editors/_EditFamily.py: Use name_displayer. * src/DisplayTabs/_PersonRefModel.py: Use name_displayer. * src/DisplayTabs/_NameModel.py: Use name_displayer. * src/DisplayTabs/_ChildModel.py: Use name_displayer. * src/DisplayTabs/_BackRefModel.py: Use name_displayer. * src/DisplayModels/_PeopleModel.py: Use name_displayer. * src/DisplayModels/_FamilyModel.py: Use name_displayer. * src/DataViews/_PersonView.py: Use name_displayer. * src/DataViews/_RelationView.py: Use name_displayer. * src/DataViews/_PedigreeView.py: Use name_displayer. * src/Utils.py: Use name_displayer. * src/SubstKeywords.py: Use name_displayer. * src/Sort.py: Use name_displayer. * src/Reorder.py: Use name_displayer. * src/PageView.py (BookMarkView.add_bookmark): Use name_displayer. * src/Navigation.py: Use name_displayer. * src/DisplayState.py: Use name_displayer. * src/GrampsCfg.py: Use name_displayer. * src/Bookmarks.py (Bookmarks.make_label): Use name_displayer. * src/GrampsDb/Makefile.am (pkgdata_PYTHON): Ship new files. * src/Makefile.am (gdir_PYTHON): Ship ProgressDialog.py svn: r8680
2007-06-28 11:11:40 +05:30
# Copyright (C) 2000-2007 Donald N. Allingham
# 2009 Gary Burton
2006-03-01 10:39:01 +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
#
# $Id$
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
import gtk
2006-03-01 10:39:01 +05:30
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
2006-04-01 09:29:42 +05:30
import ManagedWindow
2006-03-01 10:39:01 +05:30
import DateHandler
from gen.display.name import displayer as name_displayer
import config
2006-03-01 10:39:01 +05:30
import GrampsDisplay
from QuestionDialog import SaveDialog
import gen.lib
from gui.dbguielement import DbGUIElement
2006-03-01 10:39:01 +05:30
class EditPrimary(ManagedWindow.ManagedWindow, DbGUIElement):
2006-03-01 10:39:01 +05:30
QR_CATEGORY = -1
def __init__(self, state, uistate, track, obj, get_from_handle,
get_from_gramps_id, callback=None):
"""
Create an edit window.
Associate a person with the window.
"""
2006-03-01 10:39:01 +05:30
self.dp = DateHandler.parser
self.dd = DateHandler.displayer
self.name_displayer = name_displayer
2006-03-01 10:39:01 +05:30
self.obj = obj
self.dbstate = state
self.uistate = uistate
self.db = state.db
self.callback = callback
self.ok_button = None
2006-03-01 10:39:01 +05:30
self.get_from_handle = get_from_handle
self.get_from_gramps_id = get_from_gramps_id
self.contexteventbox = None
self.__tabs = []
2006-03-01 10:39:01 +05:30
2006-04-01 09:29:42 +05:30
ManagedWindow.ManagedWindow.__init__(self, uistate, track, obj)
DbGUIElement.__init__(self, self.db)
2006-03-01 10:39:01 +05:30
self._local_init()
self._set_size()
2006-03-01 10:39:01 +05:30
self._create_tabbed_pages()
self._setup_fields()
self._connect_signals()
#if the database is changed, all info shown is invalid and the window
# should close
self.dbstate_connect_key = self.dbstate.connect('database-changed',
self._do_close)
2006-03-01 10:39:01 +05:30
self.show()
self._post_init()
2006-03-01 10:39:01 +05:30
def _local_init(self):
"""
Derived class should do any pre-window initalization in this task.
"""
pass
def _post_init(self):
"""
Derived class should do any post-window initalization in this task.
"""
pass
def _setup_fields(self):
pass
def _create_tabbed_pages(self):
pass
def _connect_signals(self):
pass
def build_window_key(self, obj):
2006-04-20 10:29:04 +05:30
if obj and obj.get_handle():
2006-03-01 10:39:01 +05:30
return obj.get_handle()
else:
return id(self)
def _setup_notebook_tabs(self, notebook):
for child in notebook.get_children():
label = notebook.get_tab_label(child)
page_no = notebook.page_num(child)
label.drag_dest_set(0, [], 0)
label.connect('drag_motion',
self._switch_page_on_dnd,
notebook,
page_no)
child.set_parent_notebook(notebook)
notebook.connect('key-press-event', self.key_pressed, notebook)
def key_pressed(self, obj, event, notebook):
"""
Handles the key being pressed on the notebook, pass to key press of
current page.
"""
pag = notebook.get_current_page()
if not pag == -1:
notebook.get_nth_page(pag).key_pressed(obj, event)
def _switch_page_on_dnd(self, widget, context, x, y, time, notebook,
page_no):
if notebook.get_current_page() != page_no:
notebook.set_current_page(page_no)
def _add_tab(self, notebook, page):
self.__tabs.append(page)
notebook.insert_page(page, page.get_tab_widget())
page.label.set_use_underline(True)
2006-03-01 10:39:01 +05:30
return page
def _cleanup_on_exit(self):
pass
2006-04-01 01:16:41 +05:30
def object_is_empty(self):
return cmp(self.obj.serialize()[1:],
self.empty_object().serialize()[1:]) == 0
def define_ok_button(self, button, function):
self.ok_button = button
button.connect('clicked', function)
2006-03-01 10:39:01 +05:30
button.set_sensitive(not self.db.readonly)
def define_cancel_button(self, button):
button.connect('clicked', self.close)
2006-03-01 10:39:01 +05:30
def define_help_button(self, button, webpage='', section=''):
button.connect('clicked', lambda x: GrampsDisplay.help(webpage,
section))
2006-03-01 10:39:01 +05:30
def _do_close(self, *obj):
self._cleanup_db_connects()
self.dbstate.disconnect(self.dbstate_connect_key)
2006-03-01 10:39:01 +05:30
self._cleanup_on_exit()
2006-04-24 04:13:36 +05:30
ManagedWindow.ManagedWindow.close(self)
2006-03-01 10:39:01 +05:30
def _cleanup_db_connects(self):
"""
All connects that happened to signals of the db must be removed on
closed. This implies two things:
1. The connects on the main view must be disconnected
2. Connects done in subelements must be disconnected
"""
#cleanup callbackmanager of this editor
self._cleanup_callbacks()
for tab in self.__tabs:
if hasattr(tab, 'callman'):
tab._cleanup_callbacks()
def check_for_close(self, handles):
"""
Callback method for delete signals.
If there is a delete signal of the primary object we are editing, the
editor (and all child windows spawned) should be closed
"""
if self.obj.get_handle() in handles:
self._do_close()
def close(self, *obj):
2006-03-01 10:39:01 +05:30
"""If the data has changed, give the user a chance to cancel
the close window"""
if not config.get('interface.dont-ask') and self.data_has_changed():
2006-03-01 10:39:01 +05:30
SaveDialog(
_('Save Changes?'),
_('If you close without saving, the changes you '
'have made will be lost'),
2006-04-24 04:13:36 +05:30
self._do_close,
2006-03-01 10:39:01 +05:30
self.save)
return True
else:
2006-04-24 04:13:36 +05:30
self._do_close()
2006-03-01 10:39:01 +05:30
return False
2006-04-01 01:16:41 +05:30
def empty_object(self):
#empty_object should be overridden in base class and will throw an
#exception if it is not because self.empty_object().serialize() is
#called and PrimaryObject does not implement serialize(). See
#BaseObject.serialize()
return gen.lib.PrimaryObject
2006-04-01 01:16:41 +05:30
2006-03-01 10:39:01 +05:30
def data_has_changed(self):
if self.db.readonly:
return False
elif self.obj.handle:
orig = self.get_from_handle(self.obj.handle)
2006-03-09 08:37:41 +05:30
if orig:
2006-04-01 01:16:41 +05:30
cmp_obj = orig
2006-03-09 08:37:41 +05:30
else:
2006-04-01 01:16:41 +05:30
cmp_obj = self.empty_object()
return cmp(cmp_obj.serialize()[1:],
self.obj.serialize()[1:]) != 0
2006-03-01 10:39:01 +05:30
else:
2006-04-01 01:16:41 +05:30
cmp_obj = self.empty_object()
return cmp(cmp_obj.serialize()[1:],
self.obj.serialize()[1:]) != 0
2006-03-01 10:39:01 +05:30
def save(self, *obj):
2006-03-01 10:39:01 +05:30
pass
def set_contexteventbox(self, eventbox):
"""Set the contextbox that grabs button presses if not grabbed
by overlying widgets.
"""
self.contexteventbox = eventbox
self.contexteventbox.connect('button-press-event',
self._contextmenu_button_press)
def _contextmenu_button_press(self, obj, event) :
"""
Button press event that is caught when a mousebutton has been
pressed while on contexteventbox
It opens a context menu with possible actions
"""
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3 :
if self.obj.get_handle() == 0 :
return False
#build the possible popup menu
self._build_popup_ui()
#set or unset sensitivity in popup
self._post_build_popup_ui()
menu = self.popupmanager.get_widget('/Popup')
if menu:
menu.popup(None, None, None, event.button, event.time)
return True
return False
def _build_popup_ui(self):
"""
Create actions and ui of context menu
"""
from QuickReports import create_quickreport_menu
self.popupmanager = gtk.UIManager()
#add custom actions
(ui_top, action_groups) = self._top_contextmenu()
for action in action_groups :
self.popupmanager.insert_action_group(action, -1)
#see which quick reports are available now:
ui_qr = ''
if self.QR_CATEGORY > -1 :
(ui_qr, reportactions) = create_quickreport_menu(self.QR_CATEGORY,
self.dbstate, self.uistate,
self.obj.get_handle())
self.report_action = gtk.ActionGroup("/PersonReport")
self.report_action.add_actions(reportactions)
self.report_action.set_visible(True)
self.popupmanager.insert_action_group(self.report_action, -1)
popupui = '''
<ui>
<popup name="Popup">''' + ui_top + '''
<separator/>''' + ui_qr + '''
</popup>
</ui>'''
self.popupmanager.add_ui_from_string(popupui)
def _top_contextmenu(self):
"""
Derived class can create a ui with menuitems and corresponding list of
actiongroups
"""
return "", []
def _post_build_popup_ui(self):
"""
Derived class should do extra actions here on the menu
"""
pass
2008-02-11 02:54:50 +05:30
def _uses_duplicate_id(self):
"""
Check whether a changed or added GRAMPS ID already exists in the DB.
Return True if a duplicate GRAMPS ID has been detected.
2008-02-11 02:54:50 +05:30
"""
original = self.get_from_handle(self.obj.get_handle())
if original and original.get_gramps_id() == self.obj.get_gramps_id():
return (False, 0)
else:
idval = self.obj.get_gramps_id()
if self.get_from_gramps_id(idval):
return (True, idval)
return (False, 0)