1
# Copyright 2005 Joe Wreschnig, Michael Urman
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as
5
# published by the Free Software Foundation
7
# $Id: entry.py 3197 2006-04-26 23:00:00Z piman $
13
class ValidatingEntry(gtk.Entry):
14
"""An entry with visual feedback as to whether it is valid or not.
15
The given validator function gets a string and returns True (green),
16
False (red), or a color string, or None (black).
18
parse.Query.is_valid_color mimicks the behavior of the search bar.
20
If the "Color search terms" option is off, the entry will not
23
def __init__(self, validator=None, *args):
24
super(ValidatingEntry, self).__init__(*args)
25
if validator: self.connect_object('changed', self.__color, validator)
27
def __color(self, validator):
28
if config.getboolean('browsers', 'color'):
29
value = validator(self.get_text())
30
if value is True: color = "dark green"
31
elif value is False: color = "red"
32
elif isinstance(value, str): color = value
35
if color and self.get_property('sensitive'):
36
self.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
38
self.modify_text(gtk.STATE_NORMAL, None)