2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2003 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
# $Id: AttrEdit.py,v 1.22 2003/12/17 16:06:35 rshura Exp $
24
The AttrEdit module provides the AddressEditor class. This provides a
25
mechanism for the user to edit address information.
28
__author__ = "Donald N. Allingham"
29
__version__ = "$Revision: 1.22 $"
31
#-------------------------------------------------------------------------
35
#-------------------------------------------------------------------------
39
#-------------------------------------------------------------------------
43
#-------------------------------------------------------------------------
49
from QuestionDialog import WarningDialog
51
from gettext import gettext as _
53
#-------------------------------------------------------------------------
55
# AttributeEditor class
57
#-------------------------------------------------------------------------
58
class AttributeEditor:
60
Displays a dialog that allows the user to edit an attribute.
62
def __init__(self,parent,attrib,title,list,callback,parent_window=None):
64
Displays the dialog box.
66
parent - The class that called the Address editor.
67
attrib - The attribute that is to be edited
68
title - The title of the dialog box
69
list - list of options for the pop down menu
73
self.db = self.parent.db
75
self.top = gtk.glade.XML(const.dialogFile, "attr_edit","gramps")
76
self.type_field = self.top.get_widget("attr_type")
77
self.slist = self.top.get_widget("slist")
78
self.value_field = self.top.get_widget("attr_value")
79
self.note_field = self.top.get_widget("attr_note")
80
self.attrib_menu = self.top.get_widget("attr_menu")
81
self.source_field = self.top.get_widget("attr_source")
82
self.priv = self.top.get_widget("priv")
83
self.sources_label = self.top.get_widget("sourcesAttr")
84
self.notes_label = self.top.get_widget("noteAttr")
85
self.flowed = self.top.get_widget("attr_flowed")
86
self.preform = self.top.get_widget("attr_preform")
87
self.callback = callback
90
self.window = self.top.get_widget("attr_edit")
93
self.srcreflist = self.attrib.getSourceRefList()
97
self.sourcetab = Sources.SourceTab(self.srcreflist,self,self.top,
98
self.window, self.slist,
99
self.top.get_widget('add_src'),
100
self.top.get_widget('edit_src'),
101
self.top.get_widget('del_src'))
104
title = _("Attribute Editor")
106
title = _("Attribute Editor for %s") % title
107
l = self.top.get_widget("title")
108
Utils.set_titles(self.window,l,title,_('Attribute Editor'))
110
AutoComp.AutoCombo(self.attrib_menu,list)
113
self.type_field.set_text(attrib.getType())
114
self.value_field.set_text(attrib.getValue())
115
self.priv.set_active(attrib.getPrivacy())
118
self.note_field.get_buffer().set_text(attrib.getNote())
119
Utils.bold_label(self.notes_label)
120
if attrib.getNoteFormat() == 1:
121
self.preform.set_active(1)
123
self.flowed.set_active(1)
125
self.top.signal_autoconnect({
126
"on_add_src_clicked" : self.add_source,
127
"on_del_src_clicked" : self.del_source,
128
"on_help_attr_clicked" : self.on_help_clicked,
129
"on_switch_page" : self.on_switch_page
133
self.window.set_transient_for(parent_window)
134
self.val = self.window.run()
135
if self.val == gtk.RESPONSE_OK:
137
self.window.destroy()
139
def on_help_clicked(self,obj):
140
"""Display the relevant portion of GRAMPS manual"""
141
gnome.help_display('gramps-manual','gramps-edit-complete')
142
self.val = self.window.run()
144
def add_source(self,obj):
147
def del_source(self,obj):
150
def on_ok_clicked(self):
152
Called when the OK button is pressed. Gets data from the
153
form and updates the Attribute data structure.
155
type = unicode(self.type_field.get_text())
156
value = unicode(self.value_field.get_text())
158
buf = self.note_field.get_buffer()
159
note = unicode(buf.get_text(buf.get_start_iter(),buf.get_end_iter(),gtk.FALSE))
160
format = self.preform.get_active()
161
priv = self.priv.get_active()
163
if not type in self.alist:
164
WarningDialog(_('New attribute type created'),
165
_('The "%s" attribute type has been added to this database.\n'
166
'It will now appear in the attribute menus for this database') % type)
167
self.alist.append(type)
170
if self.attrib == None:
171
self.attrib = RelLib.Attribute()
172
self.parent.alist.append(self.attrib)
174
self.attrib.setSourceRefList(self.srcreflist)
175
self.update(type,value,note,format,priv)
176
self.callback(self.attrib)
178
def check(self,get,set,data):
179
"""Compares a data item, updates if necessary, and sets the
180
parents lists_changed flag"""
183
self.parent.lists_changed = 1
185
def update(self,type,value,note,format,priv):
186
"""Compares the data items, and updates if necessary"""
187
ntype = const.save_pattr(type)
188
self.check(self.attrib.getType,self.attrib.setType,ntype)
189
self.check(self.attrib.getValue,self.attrib.setValue,value)
190
self.check(self.attrib.getNote,self.attrib.setNote,note)
191
self.check(self.attrib.getNoteFormat,self.attrib.setNoteFormat,format)
192
self.check(self.attrib.getPrivacy,self.attrib.setPrivacy,priv)
194
def on_switch_page(self,obj,a,page):
195
buf = self.note_field.get_buffer()
196
text = unicode(buf.get_text(buf.get_start_iter(),buf.get_end_iter(),gtk.FALSE))
198
Utils.bold_label(self.notes_label)
200
Utils.unbold_label(self.notes_label)