Proper clear icon in Mesh view and journal, #4311
This commit is contained in:
parent
188a68ba1f
commit
acd0bec92f
@ -119,7 +119,7 @@
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("SexyIconEntryPosition" "position")
|
||||
'("GtkImage*" "icon")
|
||||
'("GtkImage*" "icon" (null-ok))
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user