2006-03-01 10:39:01 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
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$
|
|
|
|
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2007-08-31 01:19:04 +05:30
|
|
|
import gtk
|
2006-03-01 10:39:01 +05:30
|
|
|
|
2006-04-01 09:29:42 +05:30
|
|
|
import ManagedWindow
|
2006-03-01 10:39:01 +05:30
|
|
|
import DateHandler
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer
|
2006-03-03 05:40:52 +05:30
|
|
|
import Config
|
2006-03-01 10:39:01 +05:30
|
|
|
import GrampsDisplay
|
|
|
|
from QuestionDialog import SaveDialog
|
|
|
|
|
2006-04-01 09:29:42 +05:30
|
|
|
class EditPrimary(ManagedWindow.ManagedWindow):
|
2006-03-01 10:39:01 +05:30
|
|
|
|
2007-08-31 01:19:04 +05:30
|
|
|
QR_CATEGORY = -1
|
|
|
|
|
2006-03-01 10:39:01 +05:30
|
|
|
def __init__(self, state, uistate, track, obj, get_from_handle, callback=None):
|
|
|
|
"""Creates an edit window. Associates a person with the window."""
|
|
|
|
|
|
|
|
self.dp = DateHandler.parser
|
|
|
|
self.dd = DateHandler.displayer
|
2007-06-28 11:11:40 +05:30
|
|
|
self.nd = 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.signal_keys = []
|
2007-04-08 09:54:38 +05:30
|
|
|
self.ok_button = None
|
2006-03-01 10:39:01 +05:30
|
|
|
self.get_from_handle = get_from_handle
|
2007-08-31 01:19:04 +05:30
|
|
|
self.contexteventbox = None
|
2006-03-01 10:39:01 +05:30
|
|
|
|
2006-04-01 09:29:42 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track, obj)
|
2006-03-01 10:39:01 +05:30
|
|
|
|
|
|
|
self._local_init()
|
|
|
|
|
|
|
|
self._create_tabbed_pages()
|
|
|
|
self._setup_fields()
|
|
|
|
self._connect_signals()
|
|
|
|
self.show()
|
2006-03-02 10:02:37 +05:30
|
|
|
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 _add_db_signal(self, name, callback):
|
|
|
|
self.signal_keys.append(self.db.connect(name,callback))
|
|
|
|
|
|
|
|
def _connect_signals(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _setup_fields(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _create_tabbed_pages(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)
|
2007-02-17 02:50:36 +05:30
|
|
|
|
2007-01-16 12:42:10 +05:30
|
|
|
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)
|
2007-02-17 02:50:36 +05:30
|
|
|
label.connect('drag_motion',
|
|
|
|
self._switch_page_on_dnd,
|
|
|
|
notebook,
|
|
|
|
page_no)
|
|
|
|
|
2007-01-16 12:42:10 +05:30
|
|
|
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)
|
|
|
|
|
2006-03-01 10:39:01 +05:30
|
|
|
def _add_tab(self,notebook,page):
|
2007-01-16 12:42:10 +05:30
|
|
|
notebook.insert_page(page, page.get_tab_widget())
|
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
|
|
|
|
|
2007-04-08 09:54:38 +05:30
|
|
|
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):
|
2006-04-24 04:13:36 +05:30
|
|
|
button.connect('clicked',self.close)
|
2006-03-01 10:39:01 +05:30
|
|
|
|
|
|
|
def define_help_button(self,button,tag):
|
|
|
|
button.connect('clicked', lambda x: GrampsDisplay.help(tag))
|
|
|
|
|
2006-04-24 04:13:36 +05:30
|
|
|
def _do_close(self,*obj):
|
2006-03-01 10:39:01 +05:30
|
|
|
for key in self.signal_keys:
|
|
|
|
self.db.disconnect(key)
|
|
|
|
self._cleanup_on_exit()
|
2006-04-24 04:13:36 +05:30
|
|
|
ManagedWindow.ManagedWindow.close(self)
|
2006-03-01 10:39:01 +05:30
|
|
|
|
2006-04-24 04:13:36 +05:30
|
|
|
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"""
|
2006-04-25 02:34:01 +05:30
|
|
|
if not Config.get(Config.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):
|
|
|
|
return None
|
|
|
|
|
2006-03-01 10:39:01 +05:30
|
|
|
def data_has_changed(self):
|
2006-04-21 08:29:15 +05:30
|
|
|
|
2006-03-01 10:39:01 +05:30
|
|
|
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):
|
|
|
|
pass
|
2007-08-31 01:19:04 +05:30
|
|
|
|
|
|
|
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.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
|
|
|
|
|