gramps/src/gui/editors/editattribute.py

171 lines
5.8 KiB
Python
Raw Normal View History

2002-10-20 14:25:16 +00:00
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# 2009 Gary Burton
2002-10-20 14:25:16 +00:00
#
# 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$
2002-10-20 14:25:16 +00:00
"""
2006-03-03 00:29:52 +00:00
The EditAttribute module provides the AttributeEditor class. This provides a
2004-02-20 01:15:37 +00:00
mechanism for the user to edit attribute information.
2002-10-20 14:25:16 +00:00
"""
2005-03-08 17:25:09 +00:00
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
2005-03-08 17:25:09 +00:00
2002-10-20 14:25:16 +00:00
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
2002-10-20 14:25:16 +00:00
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
from editsecondary import EditSecondary
from gen.lib import NoteType
from glade import Glade
from displaytabs import SourceEmbedList, NoteTab
from gui.widgets import MonitoredEntry, PrivacyButton, MonitoredDataType
2002-10-20 14:25:16 +00:00
#-------------------------------------------------------------------------
#
2006-03-03 00:29:52 +00:00
# EditAttribute class
2002-10-20 14:25:16 +00:00
#
#-------------------------------------------------------------------------
2006-03-04 06:34:48 +00:00
class EditAttribute(EditSecondary):
2002-10-20 14:25:16 +00:00
"""
Displays a dialog that allows the user to edit an attribute.
"""
def __init__(self, state, uistate, track, attrib, title, data_list, callback):
2002-10-20 14:25:16 +00:00
"""
Displays the dialog box.
parent - The class that called the Address editor.
attrib - The attribute that is to be edited
title - The title of the dialog box
list - list of options for the pop down menu
"""
self.alist = data_list
2006-03-04 06:34:48 +00:00
EditSecondary.__init__(self, state, uistate, track, attrib, callback)
def _local_init(self):
self.width_key = 'interface.attribute-width'
self.height_key = 'interface.attribute-height'
self.top = Glade()
self.set_window(self.top.toplevel,
self.top.get_object('title'),
_('Attribute Editor'))
def _connect_signals(self):
self.define_cancel_button(self.top.get_object('cancel'))
self.define_help_button(self.top.get_object('help'))
self.define_ok_button(self.top.get_object('ok'),self.save)
def _setup_fields(self):
self.value_field = MonitoredEntry(
self.top.get_object("attr_value"),
self.obj.set_value, self.obj.get_value,
self.db.readonly)
self.priv = PrivacyButton(
self.top.get_object("private"),
self.obj, self.db.readonly)
2006-04-21 18:15:23 +00:00
self.type_selector = MonitoredDataType(
self.top.get_object("attr_menu"),
self.obj.set_type,
self.obj.get_type,
self.db.readonly,
custom_values=self.alist
)
def _create_tabbed_pages(self):
notebook = gtk.Notebook()
2010-11-01 20:48:29 +00:00
self.srcref_list = SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj)
self._add_tab(notebook, self.srcref_list)
self.track_ref_for_deletion("srcref_list")
2010-11-01 20:48:29 +00:00
self.note_tab = NoteTab(self.dbstate, self.uistate, self.track,
self.obj.get_note_list(),
2010-11-01 20:48:29 +00:00
notetype = NoteType.ATTRIBUTE)
self._add_tab(notebook, self.note_tab)
self.track_ref_for_deletion("note_tab")
self._setup_notebook_tabs( notebook)
notebook.show_all()
self.top.get_object('vbox').pack_start(notebook,True)
2006-04-22 03:23:57 +00:00
def build_menu_names(self, attrib):
if not attrib:
2004-02-20 01:15:37 +00:00
label = _("New Attribute")
else:
2006-04-21 18:15:23 +00:00
label = str(attrib.get_type())
2004-02-20 01:15:37 +00:00
if not label.strip():
label = _("New Attribute")
label = "%s: %s" % (_('Attribute'),label)
return (label, _('Attribute Editor'))
2004-02-20 01:15:37 +00:00
def save(self,*obj):
2002-10-20 14:25:16 +00:00
"""
Called when the OK button is pressed. Gets data from the
form and updates the Attribute data structure.
"""
t = self.obj.get_type()
if t.is_custom() and str(t) == '':
from QuestionDialog import ErrorDialog
ErrorDialog(
_("Cannot save attribute"),
_("The attribute type cannot be empty"))
return
if self.callback:
self.callback(self.obj)
2006-04-23 22:43:36 +00:00
self.close()
#-------------------------------------------------------------------------
#
# EditAttribute class
#
#-------------------------------------------------------------------------
class EditFamilyAttribute(EditAttribute):
"""
Displays a dialog that allows the user to edit an attribute.
"""
def __init__(self, state, uistate, track, attrib, title, data_list, callback):
"""
Displays the dialog box.
parent - The class that called the Address editor.
attrib - The attribute that is to be edited
title - The title of the dialog box
list - list of options for the pop down menu
"""
EditAttribute.__init__(self, state, uistate, track, attrib, title,
data_list, callback)