~ubuntu-branches/debian/squeeze/quodlibet/squeeze

« back to all changes in this revision

Viewing changes to qltk/entry.py

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2009-02-16 07:09:42 UTC
  • mfrom: (2.1.17 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090216070942-bd2iy1qva7fmpf4m
Upload to unstable now that Lenny has been released (woo!).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2005 Joe Wreschnig, Michael Urman
2
 
#
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
6
 
#
7
 
# $Id: entry.py 3197 2006-04-26 23:00:00Z piman $
8
 
 
9
 
import gtk
10
 
 
11
 
import config
12
 
 
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).
17
 
 
18
 
    parse.Query.is_valid_color mimicks the behavior of the search bar.
19
 
 
20
 
    If the "Color search terms" option is off, the entry will not
21
 
    change color."""
22
 
 
23
 
    def __init__(self, validator=None, *args):
24
 
        super(ValidatingEntry, self).__init__(*args)
25
 
        if validator: self.connect_object('changed', self.__color, validator)
26
 
 
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
33
 
            else: color = None
34
 
 
35
 
            if color and self.get_property('sensitive'):
36
 
                self.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
37
 
        else:
38
 
            self.modify_text(gtk.STATE_NORMAL, None)