2006-03-05 04:36:10 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2009-02-08 04:24:16 +05:30
|
|
|
# 2009 Gary Burton
|
2006-03-05 04:36:10 +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
|
|
|
|
#
|
|
|
|
|
2008-01-22 14:47:46 +05:30
|
|
|
# $Id$
|
2006-03-05 04:36:10 +05:30
|
|
|
|
2008-02-19 01:37:09 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
2006-03-05 04:36:10 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-01 09:29:42 +05:30
|
|
|
import ManagedWindow
|
2009-12-16 11:41:06 +05:30
|
|
|
from displaytabs import GrampsTab
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2009-08-05 16:02:05 +05:30
|
|
|
from gui.dbguielement import DbGUIElement
|
2006-03-05 04:36:10 +05:30
|
|
|
|
2007-12-20 19:19:41 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Classes
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class RefTab(GrampsTab):
|
|
|
|
"""
|
|
|
|
This class provides a simple tabpage for use on EditReference
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate, track, name, widget):
|
|
|
|
"""
|
|
|
|
@param dbstate: The database state. Contains a reference to
|
|
|
|
the database, along with other state information. The GrampsTab
|
|
|
|
uses this to access the database and to pass to and created
|
|
|
|
child windows (such as edit dialogs).
|
|
|
|
@type dbstate: DbState
|
|
|
|
@param uistate: The UI state. Used primarily to pass to any created
|
|
|
|
subwindows.
|
|
|
|
@type uistate: DisplayState
|
|
|
|
@param track: The window tracking mechanism used to manage windows.
|
|
|
|
This is only used to pass to generted child windows.
|
|
|
|
@type track: list
|
|
|
|
@param name: Notebook label name
|
|
|
|
@type name: str/unicode
|
|
|
|
@param widget: widget to be shown in the tab
|
|
|
|
@type widge: gtk widget
|
|
|
|
"""
|
|
|
|
GrampsTab.__init__(self, dbstate, uistate, track, name)
|
|
|
|
eventbox = gtk.EventBox()
|
|
|
|
eventbox.add(widget)
|
|
|
|
self.pack_start(eventbox)
|
|
|
|
self._set_label(show_image=False)
|
|
|
|
widget.connect('key_press_event', self.key_pressed)
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
def is_empty(self):
|
|
|
|
"""
|
|
|
|
Override base class
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2006-03-05 04:36:10 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# EditReference class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-08-05 16:02:05 +05:30
|
|
|
class EditReference(ManagedWindow.ManagedWindow, DbGUIElement):
|
2006-11-26 10:09:34 +05:30
|
|
|
|
2006-03-05 04:36:10 +05:30
|
|
|
def __init__(self, state, uistate, track, source, source_ref, update):
|
|
|
|
self.db = state.db
|
|
|
|
self.dbstate = state
|
|
|
|
self.uistate = uistate
|
|
|
|
self.source_ref = source_ref
|
|
|
|
self.source = source
|
|
|
|
self.source_added = False
|
|
|
|
self.update = update
|
|
|
|
self.warn_box = None
|
2009-08-05 16:02:05 +05:30
|
|
|
self.__tabs = []
|
2006-03-05 04:36:10 +05:30
|
|
|
|
2006-04-01 09:29:42 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track, source_ref)
|
2009-08-05 16:02:05 +05:30
|
|
|
DbGUIElement.__init__(self, self.db)
|
2006-03-05 04:36:10 +05:30
|
|
|
|
|
|
|
self._local_init()
|
2006-11-26 10:09:34 +05:30
|
|
|
self._set_size()
|
2006-03-05 04:36:10 +05:30
|
|
|
self._create_tabbed_pages()
|
|
|
|
self._setup_fields()
|
|
|
|
self._connect_signals()
|
|
|
|
self.show()
|
|
|
|
self._post_init()
|
|
|
|
|
|
|
|
def _local_init(self):
|
|
|
|
"""
|
|
|
|
Derived class should do any pre-window initalization in this task.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def define_warn_box(self,box):
|
|
|
|
self.warn_box = box
|
|
|
|
|
2006-04-21 04:02:17 +05:30
|
|
|
def enable_warnbox(self):
|
2006-04-28 06:03:44 +05:30
|
|
|
self.warn_box.show()
|
2006-03-05 04:36:10 +05:30
|
|
|
|
|
|
|
def define_expander(self,expander):
|
|
|
|
expander.set_expanded(True)
|
|
|
|
|
|
|
|
def _post_init(self):
|
|
|
|
"""
|
|
|
|
Derived class should do any post-window initalization in this task.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
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-12-20 19:19:41 +05:30
|
|
|
child.set_parent_notebook(notebook)
|
2008-02-16 04:08:47 +05:30
|
|
|
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)
|
2007-02-18 23:38:26 +05:30
|
|
|
|
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)
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _add_tab(self, notebook,page):
|
2009-08-05 16:02:05 +05:30
|
|
|
self.__tabs.append(page)
|
2007-01-16 12:42:10 +05:30
|
|
|
notebook.insert_page(page, page.get_tab_widget())
|
2008-02-16 04:08:47 +05:30
|
|
|
page.label.set_use_underline(True)
|
2006-03-05 04:36:10 +05:30
|
|
|
return page
|
|
|
|
|
|
|
|
def _connect_signals(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _setup_fields(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _create_tabbed_pages(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def build_window_key(self,sourceref):
|
2007-08-29 18:20:37 +05:30
|
|
|
#the window key for managedwindow identification. No need to return None
|
|
|
|
if self.source and self.source.get_handle():
|
2006-03-05 04:36:10 +05:30
|
|
|
return self.source.get_handle()
|
|
|
|
else:
|
|
|
|
return id(self)
|
|
|
|
|
2006-10-09 08:15:05 +05:30
|
|
|
def define_ok_button(self, button, function):
|
2006-03-05 04:36:10 +05:30
|
|
|
button.connect('clicked',function)
|
|
|
|
button.set_sensitive(not self.db.readonly)
|
|
|
|
|
2006-10-09 08:15:05 +05:30
|
|
|
def define_cancel_button(self, button):
|
|
|
|
button.connect('clicked',self.close_and_cancel)
|
|
|
|
|
|
|
|
def close_and_cancel(self, obj):
|
|
|
|
self._cleanup_on_exit()
|
|
|
|
self.close(obj)
|
2006-03-05 04:36:10 +05:30
|
|
|
|
2009-08-05 16:02:05 +05:30
|
|
|
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.source.get_handle() in handles:
|
|
|
|
self.close()
|
|
|
|
|
2008-04-05 19:47:15 +05:30
|
|
|
def define_help_button(self, button, webpage='', section=''):
|
2006-04-22 08:53:57 +05:30
|
|
|
import GrampsDisplay
|
2008-04-05 19:47:15 +05:30
|
|
|
button.connect('clicked', lambda x: GrampsDisplay.help(webpage,
|
2008-02-15 17:10:17 +05:30
|
|
|
section))
|
2007-03-19 09:49:49 +05:30
|
|
|
button.set_sensitive(True)
|
2006-03-05 04:36:10 +05:30
|
|
|
|
|
|
|
def _cleanup_on_exit(self):
|
|
|
|
pass
|
|
|
|
|
2006-04-24 04:13:36 +05:30
|
|
|
def close(self,*obj):
|
2009-08-05 16:02:05 +05:30
|
|
|
self._cleanup_db_connects()
|
2006-04-24 04:13:36 +05:30
|
|
|
ManagedWindow.ManagedWindow.close(self)
|
2009-08-05 16:02:05 +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 [tab for tab in self.__tabs if hasattr(tab, 'callman')]:
|
|
|
|
tab._cleanup_callbacks()
|