chiark / gitweb /
mon/tripemon.in: Highlight entry background when contents are invalid.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 24 May 2014 13:00:03 +0000 (14:00 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 20 Jul 2014 00:42:30 +0000 (01:42 +0100)
This shows up much better than the foreground.

mon/tripemon.in

index 92ce33ed868de05f68ad5f78fdbd4eaf0b1f858d..42bad2b5d22d97b0e7fb53c7b48f42df937e9399 100644 (file)
@@ -689,7 +689,7 @@ class MyScrolledWindow (G.ScrolledWindow):
 rx_num = RX.compile(r'^[-+]?\d+$')
 
 ## The colour red.
-c_red = GDK.color_parse('red')
+c_red = GDK.color_parse('#ff6666')
 
 class ValidationError (Exception):
   """Raised by ValidatingEntry.get_text() if the text isn't valid."""
@@ -712,27 +712,26 @@ class ValidatingEntry (G.Entry):
     characters (ish).  Other arguments are passed to Entry.
     """
     G.Entry.__init__(me, *arg, **kw)
-    me.connect("changed", me.check)
+    me.connect("changed", me._check)
+    me.connect("state-changed", me._check)
     if callable(valid):
       me.validate = valid
     else:
       me.validate = RX.compile(valid).match
     me.ensure_style()
-    me.c_ok = me.get_style().text[G.STATE_NORMAL]
-    me.c_bad = c_red
     if size != -1: me.set_width_chars(size)
     me.set_activates_default(True)
     me.set_text(text)
-    me.check()
+    me._check()
 
-  def check(me, *hunoz):
+  def _check(me, *hunoz):
     """Check the current text and update validp and the text colour."""
     if me.validate(G.Entry.get_text(me)):
       me.validp = True
-      me.modify_text(G.STATE_NORMAL, me.c_ok)
+      me.modify_base(G.STATE_NORMAL, None)
     else:
       me.validp = False
-      me.modify_text(G.STATE_NORMAL, me.c_bad)
+      me.modify_base(G.STATE_NORMAL, me.is_sensitive() and c_red or None)
 
   def get_text(me):
     """