~rosco2/ubuntu/wily/gramps/bug-1492304

« back to all changes in this revision

Viewing changes to src/AttrEdit.py

  • Committer: Bazaar Package Importer
  • Author(s): James A. Treacy
  • Date: 2004-06-16 16:53:36 UTC
  • Revision ID: james.westby@ubuntu.com-20040616165336-kjzczqef4gnxrn2b
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Gramps - a GTK+/GNOME based genealogy program
 
3
#
 
4
# Copyright (C) 2000-2003  Donald N. Allingham
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
 
 
21
# $Id: AttrEdit.py,v 1.22 2003/12/17 16:06:35 rshura Exp $ 
 
22
 
 
23
"""
 
24
The AttrEdit module provides the AddressEditor class. This provides a
 
25
mechanism for the user to edit address information.
 
26
"""
 
27
 
 
28
__author__ = "Donald N. Allingham"
 
29
__version__ = "$Revision: 1.22 $"
 
30
 
 
31
#-------------------------------------------------------------------------
 
32
#
 
33
# GTK/Gnome modules
 
34
#
 
35
#-------------------------------------------------------------------------
 
36
import gtk.glade
 
37
import gnome
 
38
 
 
39
#-------------------------------------------------------------------------
 
40
#
 
41
# gramps modules
 
42
#
 
43
#-------------------------------------------------------------------------
 
44
import const
 
45
import Utils
 
46
import Sources
 
47
import AutoComp
 
48
import RelLib
 
49
from QuestionDialog import WarningDialog
 
50
 
 
51
from gettext import gettext as _
 
52
 
 
53
#-------------------------------------------------------------------------
 
54
#
 
55
# AttributeEditor class
 
56
#
 
57
#-------------------------------------------------------------------------
 
58
class AttributeEditor:
 
59
    """
 
60
    Displays a dialog that allows the user to edit an attribute.
 
61
    """
 
62
    def __init__(self,parent,attrib,title,list,callback,parent_window=None):
 
63
        """
 
64
        Displays the dialog box.
 
65
 
 
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
 
70
        """
 
71
 
 
72
        self.parent = parent
 
73
        self.db = self.parent.db
 
74
        self.attrib = attrib
 
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
 
88
        self.alist = list
 
89
 
 
90
        self.window = self.top.get_widget("attr_edit")
 
91
        
 
92
        if attrib:
 
93
            self.srcreflist = self.attrib.getSourceRefList()
 
94
        else:
 
95
            self.srcreflist = []
 
96
 
 
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'))
 
102
 
 
103
        if title == ", ":
 
104
            title = _("Attribute Editor")
 
105
        else:
 
106
            title = _("Attribute Editor for %s") % title
 
107
        l = self.top.get_widget("title")
 
108
        Utils.set_titles(self.window,l,title,_('Attribute Editor'))
 
109
 
 
110
        AutoComp.AutoCombo(self.attrib_menu,list)
 
111
 
 
112
        if attrib != None:
 
113
            self.type_field.set_text(attrib.getType())
 
114
            self.value_field.set_text(attrib.getValue())
 
115
            self.priv.set_active(attrib.getPrivacy())
 
116
 
 
117
            if attrib.getNote():
 
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)
 
122
                else:
 
123
                    self.flowed.set_active(1)
 
124
 
 
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
 
130
            })
 
131
 
 
132
        if parent_window:
 
133
            self.window.set_transient_for(parent_window)
 
134
        self.val = self.window.run()
 
135
        if self.val == gtk.RESPONSE_OK:
 
136
            self.on_ok_clicked()
 
137
        self.window.destroy()
 
138
 
 
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()
 
143
 
 
144
    def add_source(self,obj):
 
145
        pass
 
146
 
 
147
    def del_source(self,obj):
 
148
        pass
 
149
 
 
150
    def on_ok_clicked(self):
 
151
        """
 
152
        Called when the OK button is pressed. Gets data from the
 
153
        form and updates the Attribute data structure.
 
154
        """
 
155
        type = unicode(self.type_field.get_text())
 
156
        value = unicode(self.value_field.get_text())
 
157
 
 
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()
 
162
 
 
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)
 
168
            self.alist.sort()
 
169
 
 
170
        if self.attrib == None:
 
171
            self.attrib = RelLib.Attribute()
 
172
            self.parent.alist.append(self.attrib)
 
173
 
 
174
        self.attrib.setSourceRefList(self.srcreflist)
 
175
        self.update(type,value,note,format,priv)
 
176
        self.callback(self.attrib)
 
177
 
 
178
    def check(self,get,set,data):
 
179
        """Compares a data item, updates if necessary, and sets the
 
180
        parents lists_changed flag"""
 
181
        if get() != data:
 
182
            set(data)
 
183
            self.parent.lists_changed = 1
 
184
            
 
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)
 
193
 
 
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))
 
197
        if text:
 
198
            Utils.bold_label(self.notes_label)
 
199
        else:
 
200
            Utils.unbold_label(self.notes_label)