~moovida-developers/moovida/account_video_intro

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/pigment/widgets/input.py

  • Committer: Olivier Tilloy
  • Date: 2009-08-19 11:51:34 UTC
  • mfrom: (1486.1.4 text_entry_default)
  • Revision ID: olivier@fluendo.com-20090819115134-qun148qsvlu2qfi5
Optional instructions text in the TextEntry widget.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    If the C{password_char} attribute is set to anything else than C{None}, its
38
38
    value will be used to display obfuscated contents (password mode).
39
39
 
40
 
    @ivar content:         the content of the entry
41
 
    @type content:         C{unicode}
42
 
    @ivar password_char:   an optional character to display instead of the real
43
 
                           contents, or C{None} (the default)
44
 
    @type password_char:   C{unicode}
45
 
    @ivar obfuscate_delay: delay in seconds before obfuscating the last
46
 
                           character entered when in password mode
47
 
    @type obfuscate_delay: C{float}
48
 
    @ivar label:           the text widget that displays the contents
49
 
    @type label:           L{elisa.plugins.pigment.graph.text.Text}
 
40
    The entry can display an optional instruction text when empty to give the
 
41
    user a hint on what she is expected to enter.
 
42
 
 
43
    @ivar content:            the content of the entry
 
44
    @type content:            C{unicode}
 
45
    @ivar instructions:       optional text to display when the entry is empty
 
46
    @type instructions:       C{unicode}
 
47
    @ivar password_char:      an optional character to display instead of the
 
48
                              real contents, or C{None} (the default)
 
49
    @type password_char:      C{unicode}
 
50
    @ivar obfuscate_delay:    delay in seconds before obfuscating the last
 
51
                              character entered when in password mode
 
52
    @type obfuscate_delay:    C{float}
 
53
    @ivar label:              the text widget that displays the contents
 
54
    @type label:              L{elisa.plugins.pigment.graph.text.Text}
 
55
    @ivar instructions_label: the text widget that displays the instructions
 
56
    @type instructions_label: L{elisa.plugins.pigment.graph.text.Text}
50
57
    """
51
58
 
52
59
    __gsignals__ = {'content-changed': (gobject.SIGNAL_RUN_LAST, 
78
85
        self.add(self.label)
79
86
        # FIXME: not pretty
80
87
        self._connect_mouse_events(self.label)
 
88
        # Text widget for optional instructions
 
89
        self.instructions_label = Text()
 
90
        self.instructions_label.visible = False
 
91
        self.add(self.instructions_label)
81
92
 
82
93
    def _set_label(self, old_content):
83
94
        self._cancel_pending_obfuscation()
95
106
        value = value or u''
96
107
        if self._content != value:
97
108
            old_content = self._content
 
109
            if not old_content:
 
110
                # Some content entered, hide the optional instructions
 
111
                self.label.visible = True
 
112
                self.instructions_label.visible = False
98
113
            self._content = value
99
114
            self._set_label(old_content)
 
115
            if not value:
 
116
                # Content has been cleared, display the optional instructions
 
117
                self.label.visible = False
 
118
                self.instructions_label.visible = True
100
119
            self.emit('content-changed')
101
120
 
102
121
    content = property(content__get, content__set)
103
122
 
 
123
    def instructions__get(self):
 
124
        return self.instructions_label.label
 
125
 
 
126
    def instructions__set(self, value):
 
127
        self.instructions_label.label = value or u''
 
128
        if not self._content:
 
129
            self.label.visible = False
 
130
            self.instructions_label.visible = True
 
131
 
 
132
    instructions = property(instructions__get, instructions__set)
 
133
 
104
134
    def _cancel_pending_obfuscation(self):
105
135
        if self._pending_obfuscation is not None:
106
136
            if not self._pending_obfuscation.called:
146
176
    def _demo_widget(cls, *args, **kwargs):
147
177
        widget = cls()
148
178
        widget.size = (100.0, 10.0)
149
 
        widget.content = "Type in something..."
 
179
        widget.instructions = "Type in something..."
150
180
        widget.visible = True
151
181
        return widget
152
182