From: Mark Wooding Date: Sat, 24 May 2014 13:00:03 +0000 (+0100) Subject: mon/tripemon.in: Highlight entry background when contents are invalid. X-Git-Tag: 1.0.0pre16~15 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/c739b22c601f2e4a0fa53eb59eac9c938b00027f mon/tripemon.in: Highlight entry background when contents are invalid. This shows up much better than the foreground. --- diff --git a/mon/tripemon.in b/mon/tripemon.in index 92ce33ed..42bad2b5 100644 --- a/mon/tripemon.in +++ b/mon/tripemon.in @@ -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): """