Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorReinier Heeres <reinier@heeres.eu>2007-11-22 16:04:58 (GMT)
committer Reinier Heeres <reinier@heeres.eu>2007-11-22 16:04:58 (GMT)
commitacd0bec92f85b8c9ecada0c54576a9e5f24145ec (patch)
treee294472837c39350c07c31403c7c2cb28261512b /lib
parent188a68ba1f0d9b5ce060232d20c185c4226f2e21 (diff)
Proper clear icon in Mesh view and journal, #4311
Diffstat (limited to 'lib')
-rw-r--r--lib/sugar/_sugarext.defs2
-rw-r--r--lib/sugar/graphics/iconentry.py64
2 files changed, 64 insertions, 2 deletions
diff --git a/lib/sugar/_sugarext.defs b/lib/sugar/_sugarext.defs
index 151bc92..1c9812e 100644
--- a/lib/sugar/_sugarext.defs
+++ b/lib/sugar/_sugarext.defs
@@ -119,7 +119,7 @@
(return-type "none")
(parameters
'("SexyIconEntryPosition" "position")
- '("GtkImage*" "icon")
+ '("GtkImage*" "icon" (null-ok))
)
)
diff --git a/lib/sugar/graphics/iconentry.py b/lib/sugar/graphics/iconentry.py
index 5bd8714..6990eea 100644
--- a/lib/sugar/graphics/iconentry.py
+++ b/lib/sugar/graphics/iconentry.py
@@ -19,16 +19,37 @@ import gtk
from sugar import _sugarext
+from sugar.graphics.icon import _SVGLoader
+import sugar.profile
+
ICON_ENTRY_PRIMARY = _sugarext.ICON_ENTRY_PRIMARY
ICON_ENTRY_SECONDARY = _sugarext.ICON_ENTRY_SECONDARY
class IconEntry(_sugarext.IconEntry):
+
+ def __init__(self):
+ _sugarext.IconEntry.__init__(self)
+
+ self._clear_icon = None
+ self._clear_shown = False
+
+ self.connect('key_press_event', self._keypress_event_cb)
+
def set_icon_from_name(self, position, name):
icon_theme = gtk.icon_theme_get_default()
icon_info = icon_theme.lookup_icon(name,
gtk.ICON_SIZE_SMALL_TOOLBAR,
0)
- pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.get_filename())
+
+ if icon_info.get_filename().endswith('.svg'):
+ loader = _SVGLoader()
+ color = sugar.profile.get_color()
+ entities = {'fill_color': color.get_fill_color(),
+ 'stroke_color': color.get_stroke_color()}
+ handle = loader.load(icon_info.get_filename(), entities, None)
+ pixbuf = handle.get_pixbuf()
+ else:
+ pixbuf = gtk.gdk.pixbuf_new_from_file(icon_info.get_filename())
del icon_info
image = gtk.Image()
@@ -43,3 +64,44 @@ class IconEntry(_sugarext.IconEntry):
'stock, not %r.' % image.get_storage_type())
_sugarext.IconEntry.set_icon(self, position, image)
+ def remove_icon(self, position):
+ _sugarext.IconEntry.set_icon(self, position, None)
+
+ def add_clear_button(self):
+ if self.props.text != "":
+ self.show_clear_button()
+ else:
+ self.hide_clear_button()
+
+ self.connect('icon-pressed', self._icon_pressed_cb)
+ self.connect('changed', self._changed_cb)
+
+ def show_clear_button(self):
+ if not self._clear_shown:
+ self.set_icon_from_name(ICON_ENTRY_SECONDARY,
+ 'dialog-cancel')
+ self._clear_shown = True
+
+ def hide_clear_button(self):
+ if self._clear_shown:
+ self.remove_icon(ICON_ENTRY_SECONDARY)
+ self._clear_shown = False
+
+ def _keypress_event_cb(self, widget, event):
+ keyval = gtk.gdk.keyval_name(event.keyval)
+ if keyval == 'Escape':
+ self.props.text = ''
+ return True
+ return False
+
+ def _icon_pressed_cb(self, entru, icon_pos, button):
+ if icon_pos == ICON_ENTRY_SECONDARY:
+ self.set_text('')
+ self.hide_clear_button()
+
+ def _changed_cb(self, icon_entry):
+ if not self.props.text:
+ self.hide_clear_button()
+ else:
+ self.show_clear_button()
+