Removal of redundant SourceRef and related modules. Minor consequent changes.

svn: r18516
This commit is contained in:
Tim G L Lyons
2011-11-27 17:49:25 +00:00
parent bafe7870c7
commit 26cb74474b
16 changed files with 19 additions and 906 deletions

View File

@@ -34,7 +34,6 @@ pkgdata_PYTHON = \
editreporef.py \
editsecondary.py \
editsource.py \
editsourceref.py \
editurl.py \
objectentries.py

View File

@@ -41,7 +41,6 @@ from editplace import EditPlace, DeletePlaceQuery
from editrepository import EditRepository, DeleteRepositoryQuery
from editreporef import EditRepoRef
from editsource import EditSource, DeleteSrcQuery
from editsourceref import EditSourceRef
from editurl import EditUrl
from editlink import EditLink

View File

@@ -43,8 +43,6 @@ pkgdata_PYTHON = \
repoembedlist.py \
reporefmodel.py \
sourcebackreflist.py \
sourceembedlist.py \
sourcerefmodel.py \
surnamemodel.py \
surnametab.py \
webembedlist.py \

View File

@@ -60,5 +60,4 @@ from placebackreflist import PlaceBackRefList
from repoembedlist import RepoEmbedList
from surnametab import SurnameTab
from sourcebackreflist import SourceBackRefList
from sourceembedlist import SourceEmbedList
from webembedlist import WebEmbedList

View File

@@ -1,230 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-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 classes
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS classes
#
#-------------------------------------------------------------------------
import gen.lib
from gui.dbguielement import DbGUIElement
from gui.selectors import SelectorFactory
import Errors
from DdTargets import DdTargets
from sourcerefmodel import SourceRefModel
from embeddedlist import EmbeddedList
#-------------------------------------------------------------------------
#
# SourceEmbedList
#
#-------------------------------------------------------------------------
class SourceEmbedList(EmbeddedList, DbGUIElement):
_HANDLE_COL = 4
_DND_TYPE = DdTargets.SOURCEREF
_DND_EXTRA = DdTargets.SOURCE_LINK
_MSG = {
'add' : _('Create and add a new source'),
'del' : _('Remove the existing source'),
'edit' : _('Edit the selected source'),
'share' : _('Add an existing source'),
'up' : _('Move the selected source upwards'),
'down' : _('Move the selected source downwards'),
}
#index = column in model. Value =
# (name, sortcol in model, width, markup/text, weigth_col
_column_names = [
(_('ID'), 0, 75, 0, -1),
(_('Title'), 1, 200, 0, -1),
(_('Author'), 2, 125, 0, -1),
(_('Page'), 3, 100, 0, -1),
]
def __init__(self, dbstate, uistate, track, obj):
self.obj = obj
EmbeddedList.__init__(self, dbstate, uistate, track, _('_Sources'),
SourceRefModel, share_button=True,
move_buttons=True)
DbGUIElement.__init__(self, dbstate.db)
self.callman.register_handles({'source': [sref.ref for sref
in self.obj.get_source_references()]})
def _connect_db_signals(self):
"""
Implement base class DbGUIElement method
"""
#note: source-rebuild closes the editors, so no need to connect to it
self.callman.register_callbacks(
{'source-delete': self.source_delete, # delete a source we track
'source-update': self.source_update, # change a source we track
})
self.callman.connect_all(keys=['source'])
def get_icon_name(self):
return 'gramps-source'
def get_data(self):
return self.obj.get_source_references()
def column_order(self):
return ((1, 0), (1, 1), (1, 2), (1, 3))
def add_button_clicked(self, obj):
from gui.editors import EditSourceRef
try:
sref = gen.lib.SourceRef()
src = gen.lib.Source()
EditSourceRef(
self.dbstate,
self.uistate,
self.track,
src,
sref,
self.object_added)
except Errors.WindowActiveError:
pass
def __blocked_text(self):
"""
Return the common text used when sourceref cannot be edited
"""
return _("This source reference cannot be edited at this time. "
"Either the associated source is already being edited "
"or another source reference that is associated with "
"the same source is being edited.\n\nTo edit this "
"source reference, you need to close the source.")
def share_button_clicked(self, obj):
from gui.editors import EditSourceRef
SelectSource = SelectorFactory('Source')
sel = SelectSource(self.dbstate,self.uistate,self.track)
src = sel.run()
if src:
try:
ref = gen.lib.SourceRef()
EditSourceRef(self.dbstate,
self.uistate,
self.track,
src,
ref,
self.object_added)
except Errors.WindowActiveError:
from QuestionDialog import WarningDialog
WarningDialog(_("Cannot share this reference"),
self.__blocked_text())
def edit_button_clicked(self, obj):
from gui.editors import EditSourceRef
sref = self.get_selected()
if sref:
src = self.dbstate.db.get_source_from_handle(sref.ref)
try:
EditSourceRef(self.dbstate, self.uistate, self.track,
src, sref, self.object_edited)
except Errors.WindowActiveError:
from QuestionDialog import WarningDialog
WarningDialog(_("Cannot edit this reference"),
self.__blocked_text())
def object_added(self, reference, primary):
"""
Callback from sourceref editor after adding a new reference (to a new
or an existing source).
Note that if it was to an existing source already present in the
sourcelist, then the source-update signal will also cause a rebuild
at that time.
"""
reference.ref = primary.handle
self.get_data().append(reference)
self.callman.register_handles({'source': [primary.handle]})
self.changed = True
self.rebuild()
def object_edited(self, refererence, primary):
"""
Callback from sourceref editor. If the source changes itself, also
the source-change signal will cause a rebuild.
This could be solved in the source editor if it only calls this
method in the case the sourceref part only changes.
"""
self.changed = True
self.rebuild()
def handle_extra_type(self, objtype, obj):
from gui.editors import EditSourceRef
sref = gen.lib.SourceRef()
src = self.dbstate.db.get_source_from_handle(obj)
try:
EditSourceRef(self.dbstate, self.uistate, self.track,
src, sref, self.object_added)
except Errors.WindowActiveError:
pass
def source_delete(self, del_src_handle_list):
"""
Outside of this tab source objects have been deleted. Check if tab
and object must be changed.
Note: delete of object will cause reference on database to be removed,
so this method need not do this
"""
rebuild = False
sourceref_list = self.get_data()
ref_handles = [sref.ref for sref in sourceref_list]
for handle in del_src_handle_list :
while 1:
pos = None
try :
pos = ref_handles.index(handle)
except ValueError :
break
if pos is not None:
#oeps, we need to remove this reference, and rebuild tab
del sourceref_list[pos]
del ref_handles[pos]
rebuild = True
if rebuild:
self.rebuild()
def source_update(self, upd_src_handle_list):
"""
Outside of this tab media objects have been changed. Check if tab
and object must be changed.
"""
ref_handles = [sref.ref for sref in self.get_data()]
for handle in upd_src_handle_list :
if handle in ref_handles:
self.rebuild()
break

View File

@@ -1,50 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-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$
#-------------------------------------------------------------------------
#
# GTK libraries
#
#-------------------------------------------------------------------------
import gtk
#-------------------------------------------------------------------------
#
# GRAMPS classes
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
#
# SourceRefModel
#
#-------------------------------------------------------------------------
class SourceRefModel(gtk.ListStore):
def __init__(self, sref_list, db):
gtk.ListStore.__init__(self, str, str, str, str, object)
self.db = db
for sref in sref_list:
src = self.db.get_source_from_handle(sref.get_reference_handle())
self.append(row=[src.gramps_id, src.title, src.author,
sref.page, sref, ])

View File

@@ -1,228 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# 2009 Gary Burton
# 2011 Michiel D. Nauta / MathieuMD
#
# 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 _
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import gen.lib
from gen.db import DbTxn
from glade import Glade
from displaytabs import (NoteTab, GalleryTab, SourceBackRefList,
DataEmbedList, RepoEmbedList)
from gui.widgets import (PrivacyButton, MonitoredEntry, MonitoredMenu,
MonitoredDate)
from editreference import RefTab, EditReference
#-------------------------------------------------------------------------
#
# EditSourceRef class
#
#-------------------------------------------------------------------------
class EditSourceRef(EditReference):
def __init__(self, state, uistate, track, source, source_ref, update):
EditReference.__init__(self, state, uistate, track, source,
source_ref, update)
def _local_init(self):
self.width_key = 'interface.event-ref-width'
self.height_key = 'interface.event-ref-height'
self.top = Glade()
self.set_window(self.top.toplevel,
self.top.get_object('source_title'),
_('Source Reference Editor'))
self.define_warn_box(self.top.get_object("warn_box"))
self.define_expander(self.top.get_object("src_expander"))
tblref = self.top.get_object('table67')
notebook = self.top.get_object('notebook_ref')
#recreate start page as GrampsTab
notebook.remove_page(0)
self.reftab = RefTab(self.dbstate, self.uistate, self.track,
_('General'), tblref)
tblref = self.top.get_object('table68')
notebook = self.top.get_object('notebook_src')
#recreate start page as GrampsTab
notebook.remove_page(0)
self.primtab = RefTab(self.dbstate, self.uistate, self.track,
_('General'), tblref)
def _post_init(self):
title = self.top.get_object('title')
volume = self.top.get_object('volume')
if not title.get_text_length():
title.grab_focus();
elif not volume.get_text_length():
volume.grab_focus();
def _connect_signals(self):
self.define_ok_button(self.top.get_object('ok'),self.ok_clicked)
self.define_cancel_button(self.top.get_object('cancel'))
self.define_help_button(self.top.get_object("help"))
def _connect_db_signals(self):
"""
Connect any signals that need to be connected.
Called by the init routine of the base class (_EditPrimary).
"""
self._add_db_signal('source-rebuild', self.close)
self._add_db_signal('source-delete', self.check_for_close)
#note: at the moment, a source cannot be updated while an editor with
# that source shown is open. So no need to connect to source-update
def _setup_fields(self):
self.ref_privacy = PrivacyButton(
self.top.get_object('privacy'), self.source_ref, self.db.readonly)
self.volume = MonitoredEntry(
self.top.get_object("volume"), self.source_ref.set_page,
self.source_ref.get_page, self.db.readonly)
self.gid = MonitoredEntry(
self.top.get_object('gid'), self.source.set_gramps_id,
self.source.get_gramps_id,self.db.readonly)
self.source_privacy = PrivacyButton(
self.top.get_object("private"),
self.source, self.db.readonly)
self.title = MonitoredEntry(
self.top.get_object('title'),
self.source.set_title,
self.source.get_title,
self.db.readonly)
self.abbrev = MonitoredEntry(
self.top.get_object('abbrev'), self.source.set_abbreviation,
self.source.get_abbreviation,self.db.readonly)
self.author = MonitoredEntry(
self.top.get_object('author'), self.source.set_author,
self.source.get_author,self.db.readonly)
self.pubinfo = MonitoredEntry(
self.top.get_object('pub_info'), self.source.set_publication_info,
self.source.get_publication_info,self.db.readonly)
self.type_mon = MonitoredMenu(
self.top.get_object('confidence'),
self.source_ref.set_confidence_level,
self.source_ref.get_confidence_level, [
(_('Very Low'), gen.lib.SourceRef.CONF_VERY_LOW),
(_('Low'), gen.lib.SourceRef.CONF_LOW),
(_('Normal'), gen.lib.SourceRef.CONF_NORMAL),
(_('High'), gen.lib.SourceRef.CONF_HIGH),
(_('Very High'), gen.lib.SourceRef.CONF_VERY_HIGH)],
self.db.readonly)
self.date = MonitoredDate(
self.top.get_object("date_entry"),
self.top.get_object("date_stat"),
self.source_ref.get_date_object(),
self.uistate,
self.track,
self.db.readonly)
def _create_tabbed_pages(self):
"""
Create the notebook tabs and inserts them into the main
window.
"""
notebook_src = self.top.get_object('notebook_src')
notebook_ref = self.top.get_object('notebook_ref')
self._add_tab(notebook_src, self.primtab)
self._add_tab(notebook_ref, self.reftab)
self.note_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.source.get_note_list(),
notetype=gen.lib.NoteType.SOURCE)
self._add_tab(notebook_src, self.note_tab)
self.track_ref_for_deletion("note_tab")
self.gallery_tab = GalleryTab(self.dbstate, self.uistate, self.track,
self.source.get_media_list())
self._add_tab(notebook_src, self.gallery_tab)
self.track_ref_for_deletion("gallery_tab")
self.data_tab = DataEmbedList(self.dbstate, self.uistate, self.track,
self.source)
self._add_tab(notebook_src, self.data_tab)
self.track_ref_for_deletion("data_tab")
self.repo_tab = RepoEmbedList(self.dbstate, self.uistate, self.track,
self.source.get_reporef_list())
self._add_tab(notebook_src, self.repo_tab)
self.track_ref_for_deletion("repo_tab")
self.srcref_list = SourceBackRefList(self.dbstate,self.uistate, self.track,
self.db.find_backlink_handles(self.source.handle),
self.enable_warnbox
)
self._add_tab(notebook_src, self.srcref_list)
self.track_ref_for_deletion("srcref_list")
self.comment_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.source_ref.get_note_list(),
notetype=gen.lib.NoteType.SOURCEREF)
self._add_tab(notebook_ref, self.comment_tab)
self.track_ref_for_deletion("comment_tab")
self._setup_notebook_tabs( notebook_src)
self._setup_notebook_tabs( notebook_ref)
def build_menu_names(self,sourceref):
if self.source:
source_name = self.source.get_title()
submenu_label = _('Source: %s') % source_name
else:
submenu_label = _('New Source')
return (_('Source Reference Editor'),submenu_label)
def ok_clicked(self, obj):
if self.source.handle:
with DbTxn(_("Modify Source"), self.db) as trans:
self.db.commit_source(self.source,trans)
else:
with DbTxn(_("Add Source"), self.db) as trans:
self.db.add_source(self.source,trans)
if self.update:
self.update(self.source_ref,self.source)
self.close()