[hamster-applet/2_28_standalone] an entry with hint - a HintEntry
- From: Toms Baugis <tbaugis src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [hamster-applet/2_28_standalone] an entry with hint - a HintEntry
- Date: Wed, 18 Nov 2009 15:27:00 +0000 (UTC)
commit b50dfbbd1639311f1d715259e524ef68baf8c23b
Author: Toms Bauģis <toms baugis gmail com>
Date: Wed Nov 18 15:26:06 2009 +0000
an entry with hint - a HintEntry
hamster/widgets.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/hamster/widgets.py b/hamster/widgets.py
index af3611a..dbf316f 100644
--- a/hamster/widgets.py
+++ b/hamster/widgets.py
@@ -24,6 +24,57 @@ import calendar
import gobject
import re
+import pango
+
+
+class HintEntry(gtk.Entry):
+ """a gtk.Entry that displays greyed out hint in the box, while not focused"""
+ def __init__(self, hint, original_entry = None):
+ gtk.Entry.__init__(self)
+
+ self.hint = hint
+ self._set_hint()
+
+ self.connect('focus-in-event', self.on_focus_in)
+ self.connect('focus-out-event', self.on_focus_out)
+
+ if original_entry:
+ parent = original_entry.parent
+ parent.remove(original_entry)
+
+ self.set_name(original_entry.name)
+ parent.add(self)
+
+
+ self.show()
+
+ def _set_hint(self):
+ if self.get_text(): # don't mess with user entered text
+ return
+
+ self.modify_text(gtk.STATE_NORMAL, gtk.gdk.Color("gray"))
+ hint_font = pango.FontDescription(gtk.Style().font_desc.to_string())
+ hint_font.set_style(pango.STYLE_ITALIC)
+ self.modify_font(hint_font)
+
+ self.set_text(self.hint)
+
+ def _set_normal(self):
+ self.modify_text(gtk.STATE_NORMAL, gtk.Style().fg[gtk.STATE_NORMAL])
+ hint_font = pango.FontDescription(gtk.Style().font_desc.to_string())
+ self.modify_font(hint_font)
+
+ if self.get_text() == self.hint:
+ self.set_text("")
+
+ def on_focus_in(self, widget, event):
+ self._set_normal()
+
+ def on_focus_out(self, widget, event):
+ self._set_hint()
+
+
+
class DateInput(gtk.Entry):
""" a text entry widget with calendar popup"""
__gsignals__ = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]