1 from PyQt4 import QtGui, QtCore
2
3 from camelot.core.utils import ugettext as _
4 from camelot.admin.object_admin import ObjectAdmin
5 from camelot.view.controls.editors.one2manyeditor import One2ManyEditor
6 from user_translatable_label import UserTranslatableLabel
7
9 """Helper class representing a field attribute's name and its value"""
13
14 - class Admin(ObjectAdmin):
18
20 """A Label widget used to display the name of a field on a form.
21 This label provides the user with the possibility to change the translation
22 of the label and review its field attributes.
23 """
24
25 - def __init__(self, field_name, text, field_attributes, admin, parent=None):
26 """
27 :param field_name: the name of the field
28 :param text: user translatable string to be used as field label
29 :param field_attributes: the field attributes associated with the field for which
30 this is a label
31 :param admin: the admin of the object of the field
32 """
33 super(FieldLabel, self).__init__(text, parent)
34 show_field_attributes_action = QtGui.QAction(_('View attributes'), self)
35 self.connect(show_field_attributes_action, QtCore.SIGNAL('triggered()'), self.show_field_attributes)
36 self.addAction(show_field_attributes_action)
37 self._field_name = field_name
38 self._admin = admin
39 self._field_attributes = field_attributes
40
42 import inspect
43
44 def attribute_value_to_string(key, value):
45 if inspect.isclass(value):
46 return value.__name__
47 return unicode(value)
48
49 return [Attribute(key,attribute_value_to_string(key, value)) for key,value in self._field_attributes.items()]
50
71
72 dialog = FieldAttributesDialog(self._field_name, self)
73 dialog.exec_()
74