~ubuntu-branches/ubuntu/trusty/gramps/trusty-proposed

« back to all changes in this revision

Viewing changes to src/gui/editors/editattribute.py

  • Committer: Package Import Robot
  • Author(s): Ross Gammon
  • Date: 2014-02-03 17:28:04 UTC
  • mfrom: (39.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140203172804-76y7nwxiw92zhlnj
Tags: 4.0.3+dfsg-1
* New upstream release (Closes: #720858)
* To-do notes improved and made persistent (Closes: #680692)
* Applied patch to setup.py to fix resource path problem
* Applied patch to disable the optional HTML View & prevent a crash
* Remove sourceless javascript files (Closes: #736436)
* Gramps uses Bat Mitzva internally (Closes: #502532)

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-2006  Donald N. Allingham
5
 
#               2009       Gary Burton
6
 
# Copyright (C) 2011       Tim G L Lyons
7
 
#
8
 
# This program is free software; you can redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as published by
10
 
# the Free Software Foundation; either version 2 of the License, or
11
 
# (at your option) any later version.
12
 
#
13
 
# This program is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with this program; if not, write to the Free Software
20
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
#
22
 
 
23
 
# $Id: editattribute.py 18548 2011-12-04 17:09:17Z kulath $ 
24
 
 
25
 
"""
26
 
The EditAttribute module provides the AttributeEditor class. This provides a
27
 
mechanism for the user to edit attribute information.
28
 
"""
29
 
 
30
 
#-------------------------------------------------------------------------
31
 
#
32
 
# Python modules
33
 
#
34
 
#-------------------------------------------------------------------------
35
 
from gen.ggettext import gettext as _
36
 
 
37
 
#-------------------------------------------------------------------------
38
 
#
39
 
# GTK/Gnome modules
40
 
#
41
 
#-------------------------------------------------------------------------
42
 
import gtk
43
 
 
44
 
#-------------------------------------------------------------------------
45
 
#
46
 
# gramps modules
47
 
#
48
 
#-------------------------------------------------------------------------
49
 
from editsecondary import EditSecondary
50
 
from gen.lib import NoteType
51
 
from glade import Glade
52
 
from displaytabs import CitationEmbedList, NoteTab
53
 
from gui.widgets import MonitoredEntry, PrivacyButton, MonitoredDataType
54
 
 
55
 
#-------------------------------------------------------------------------
56
 
#
57
 
# EditAttribute class
58
 
#
59
 
#-------------------------------------------------------------------------
60
 
class EditAttribute(EditSecondary):
61
 
    """
62
 
    Displays a dialog that allows the user to edit an attribute.
63
 
    """
64
 
 
65
 
    def __init__(self, state, uistate, track, attrib, title, data_list, callback):
66
 
        """
67
 
        Displays the dialog box.
68
 
 
69
 
        parent - The class that called the Address editor.
70
 
        attrib - The attribute that is to be edited
71
 
        title - The title of the dialog box
72
 
        list - list of options for the pop down menu
73
 
        """
74
 
        self.alist = data_list
75
 
        EditSecondary.__init__(self, state, uistate, track, attrib, callback)
76
 
 
77
 
    def _local_init(self):
78
 
        self.width_key = 'interface.attribute-width'
79
 
        self.height_key = 'interface.attribute-height'
80
 
        self.top = Glade()
81
 
        
82
 
        self.set_window(self.top.toplevel,
83
 
                        self.top.get_object('title'),
84
 
                        _('Attribute Editor'))
85
 
 
86
 
    def _connect_signals(self):
87
 
        self.define_cancel_button(self.top.get_object('cancel'))
88
 
        self.define_help_button(self.top.get_object('help'))
89
 
        self.define_ok_button(self.top.get_object('ok'),self.save)
90
 
 
91
 
    def _setup_fields(self):
92
 
        self.value_field = MonitoredEntry(
93
 
            self.top.get_object("attr_value"),
94
 
            self.obj.set_value, self.obj.get_value,
95
 
            self.db.readonly)
96
 
        
97
 
        self.priv = PrivacyButton(
98
 
            self.top.get_object("private"),
99
 
            self.obj, self.db.readonly)
100
 
 
101
 
        self.type_selector = MonitoredDataType(
102
 
            self.top.get_object("attr_menu"),
103
 
            self.obj.set_type,
104
 
            self.obj.get_type,
105
 
            self.db.readonly,
106
 
            custom_values=self.alist
107
 
            )
108
 
 
109
 
    def _create_tabbed_pages(self):
110
 
        notebook = gtk.Notebook()
111
 
        self.srcref_list = CitationEmbedList(self.dbstate,
112
 
                                             self.uistate,
113
 
                                             self.track,
114
 
                                             self.obj.get_citation_list())
115
 
        self._add_tab(notebook, self.srcref_list)
116
 
        self.track_ref_for_deletion("srcref_list")
117
 
        
118
 
        self.note_tab = NoteTab(self.dbstate, self.uistate, self.track,
119
 
                    self.obj.get_note_list(),
120
 
                    notetype = NoteType.ATTRIBUTE)
121
 
        self._add_tab(notebook, self.note_tab)
122
 
        self.track_ref_for_deletion("note_tab")
123
 
        
124
 
        self._setup_notebook_tabs( notebook)
125
 
        notebook.show_all()
126
 
        self.top.get_object('vbox').pack_start(notebook,True)
127
 
        
128
 
    def build_menu_names(self, attrib):
129
 
        if not attrib:
130
 
            label = _("New Attribute")
131
 
        else:
132
 
            label = str(attrib.get_type())
133
 
        if not label.strip():
134
 
            label = _("New Attribute")
135
 
        label = "%s: %s" % (_('Attribute'),label)
136
 
        return (label, _('Attribute Editor'))
137
 
 
138
 
    def save(self,*obj):
139
 
        """
140
 
        Called when the OK button is pressed. Gets data from the
141
 
        form and updates the Attribute data structure.
142
 
        """
143
 
        t = self.obj.get_type()
144
 
        
145
 
        if t.is_custom() and str(t) == '':
146
 
            from QuestionDialog import ErrorDialog
147
 
            ErrorDialog(
148
 
                _("Cannot save attribute"),
149
 
                _("The attribute type cannot be empty"))
150
 
            return
151
 
        if self.callback:
152
 
            self.callback(self.obj)
153
 
        self.close()
154
 
 
155
 
#-------------------------------------------------------------------------
156
 
#
157
 
# EditAttribute class
158
 
#
159
 
#-------------------------------------------------------------------------
160
 
class EditFamilyAttribute(EditAttribute):
161
 
    """
162
 
    Displays a dialog that allows the user to edit an attribute.
163
 
    """
164
 
    def __init__(self, state, uistate, track, attrib, title, data_list, callback):
165
 
        """
166
 
        Displays the dialog box.
167
 
 
168
 
        parent - The class that called the Address editor.
169
 
        attrib - The attribute that is to be edited
170
 
        title - The title of the dialog box
171
 
        list - list of options for the pop down menu
172
 
        """
173
 
        EditAttribute.__init__(self, state, uistate, track, attrib, title,
174
 
                               data_list, callback)