Add a scale property to CanvasIcon.
Make Icon use gtk.Image icon-size. Patch by tannewt with some little tweaks.
This commit is contained in:
parent
de9e02b498
commit
34a1c81aa5
@ -25,7 +25,7 @@ class CanvasButton(hippo.CanvasButton):
|
|||||||
hippo.CanvasButton.__init__(self, text=label)
|
hippo.CanvasButton.__init__(self, text=label)
|
||||||
|
|
||||||
if icon_name:
|
if icon_name:
|
||||||
icon = Icon(icon_name, gtk.ICON_SIZE_BUTTON)
|
icon = Icon(icon_name,icon_size=gtk.ICON_SIZE_BUTTON)
|
||||||
self.props.widget.set_image(icon)
|
self.props.widget.set_image(icon)
|
||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
|
@ -142,6 +142,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
gobject.PARAM_READWRITE),
|
gobject.PARAM_READWRITE),
|
||||||
'size' : (int, None, None, 0, 1024, 0,
|
'size' : (int, None, None, 0, 1024, 0,
|
||||||
gobject.PARAM_READWRITE),
|
gobject.PARAM_READWRITE),
|
||||||
|
'scale' : (int, None, None, 0, 1024, 0,
|
||||||
|
gobject.PARAM_READWRITE),
|
||||||
'cache' : (bool, None, None, False,
|
'cache' : (bool, None, None, False,
|
||||||
gobject.PARAM_READWRITE),
|
gobject.PARAM_READWRITE),
|
||||||
'active' : (bool, None, None, True,
|
'active' : (bool, None, None, True,
|
||||||
@ -156,6 +158,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
self._buffers = {}
|
self._buffers = {}
|
||||||
self._cur_buffer = None
|
self._cur_buffer = None
|
||||||
self._size = 0
|
self._size = 0
|
||||||
|
self._scale = 0
|
||||||
self._fill_color = None
|
self._fill_color = None
|
||||||
self._stroke_color = None
|
self._stroke_color = None
|
||||||
self._icon_name = None
|
self._icon_name = None
|
||||||
@ -210,6 +213,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
self._clear_buffers()
|
self._clear_buffers()
|
||||||
self._size = value
|
self._size = value
|
||||||
self.emit_request_changed()
|
self.emit_request_changed()
|
||||||
|
elif pspec.name == 'scale':
|
||||||
|
if self._scale != value and not self._cache:
|
||||||
|
self._clear_buffers()
|
||||||
|
self._scale = value
|
||||||
|
self.emit_request_changed()
|
||||||
elif pspec.name == 'cache':
|
elif pspec.name == 'cache':
|
||||||
self._cache = value
|
self._cache = value
|
||||||
elif pspec.name == 'active':
|
elif pspec.name == 'active':
|
||||||
@ -277,6 +285,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
return self._active
|
return self._active
|
||||||
elif pspec.name == 'badge-name':
|
elif pspec.name == 'badge-name':
|
||||||
return self._badge_name
|
return self._badge_name
|
||||||
|
elif pspec.name == 'scale':
|
||||||
|
return self._scale
|
||||||
|
|
||||||
def _get_icon_size(self, handle):
|
def _get_icon_size(self, handle):
|
||||||
if handle:
|
if handle:
|
||||||
@ -286,9 +296,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
return [0, 0]
|
return [0, 0]
|
||||||
|
|
||||||
def _get_size(self, handle):
|
def _get_size(self, handle):
|
||||||
if self._size == 0:
|
|
||||||
width, height = self._get_icon_size(handle)
|
width, height = self._get_icon_size(handle)
|
||||||
else:
|
if self._scale != 0:
|
||||||
|
width = int(width * self._scale)
|
||||||
|
height = int(height * self._scale)
|
||||||
|
elif self._size != 0:
|
||||||
width = height = self._size
|
width = height = self._size
|
||||||
|
|
||||||
return [width, height]
|
return [width, height]
|
||||||
|
@ -34,17 +34,18 @@ class Icon(gtk.Image):
|
|||||||
gobject.PARAM_READWRITE)
|
gobject.PARAM_READWRITE)
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, size=gtk.ICON_SIZE_LARGE_TOOLBAR, **kwargs):
|
def __init__(self, name, **kwargs):
|
||||||
|
self._constructed = False
|
||||||
self._fill_color = None
|
self._fill_color = None
|
||||||
self._stroke_color = None
|
self._stroke_color = None
|
||||||
self._icon_name = name
|
self._icon_name = name
|
||||||
self._size = size
|
|
||||||
self._theme = gtk.icon_theme_get_default()
|
self._theme = gtk.icon_theme_get_default()
|
||||||
|
self._data = None
|
||||||
|
|
||||||
gobject.GObject.__init__(self, **kwargs)
|
gobject.GObject.__init__(self, **kwargs)
|
||||||
|
|
||||||
# If we have a non-styled-icon
|
self._constructed = True
|
||||||
if not self._fill_color and not self._stroke_color:
|
self._update_icon()
|
||||||
self._update_normal_icon()
|
|
||||||
|
|
||||||
def _get_pixbuf(self, data, width, height):
|
def _get_pixbuf(self, data, width, height):
|
||||||
loader = gtk.gdk.PixbufLoader('svg')
|
loader = gtk.gdk.PixbufLoader('svg')
|
||||||
@ -77,9 +78,12 @@ class Icon(gtk.Image):
|
|||||||
source.set_state(gtk.STATE_INSENSITIVE)
|
source.set_state(gtk.STATE_INSENSITIVE)
|
||||||
icon_set.add_source(source)
|
icon_set.add_source(source)
|
||||||
|
|
||||||
self.set_from_icon_set(icon_set, self._size)
|
self.set_from_icon_set(icon_set, self.props.icon_size)
|
||||||
|
|
||||||
def _update_icon(self):
|
def _update_icon(self):
|
||||||
|
if not self._constructed:
|
||||||
|
return
|
||||||
|
|
||||||
if not self._fill_color and not self._stroke_color:
|
if not self._fill_color and not self._stroke_color:
|
||||||
self._update_normal_icon()
|
self._update_normal_icon()
|
||||||
return
|
return
|
||||||
@ -100,12 +104,12 @@ class Icon(gtk.Image):
|
|||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
# Redraw pixbuf
|
# Redraw pixbuf
|
||||||
[w, h] = gtk.icon_size_lookup(self._size)
|
[w, h] = gtk.icon_size_lookup(self.props.icon_size)
|
||||||
pixbuf = self._get_pixbuf(self._data, w, h)
|
pixbuf = self._get_pixbuf(self._data, w, h)
|
||||||
self.set_from_pixbuf(pixbuf)
|
self.set_from_pixbuf(pixbuf)
|
||||||
|
|
||||||
def _get_real_name(self, name):
|
def _get_real_name(self, name):
|
||||||
info = self._theme.lookup_icon(name, self._size, 0)
|
info = self._theme.lookup_icon(name, self.props.icon_size, 0)
|
||||||
if not info:
|
if not info:
|
||||||
raise ValueError("Icon '" + name + "' not found.")
|
raise ValueError("Icon '" + name + "' not found.")
|
||||||
fname = info.get_filename()
|
fname = info.get_filename()
|
||||||
@ -122,9 +126,16 @@ class Icon(gtk.Image):
|
|||||||
elif pspec.name == 'stroke-color':
|
elif pspec.name == 'stroke-color':
|
||||||
self._stroke_color = value
|
self._stroke_color = value
|
||||||
self._update_icon()
|
self._update_icon()
|
||||||
|
elif pspec.name == 'icon-size':
|
||||||
|
gtk.Image.do_set_property(self, pspec, value)
|
||||||
|
self._update_icon()
|
||||||
|
else:
|
||||||
|
gtk.Image.do_set_property(self, pspec, value)
|
||||||
|
|
||||||
def do_get_property(self, pspec):
|
def do_get_property(self, pspec):
|
||||||
if pspec.name == 'fill-color':
|
if pspec.name == 'fill-color':
|
||||||
return self._fill_color
|
return self._fill_color
|
||||||
elif pspec.name == 'stroke-color':
|
elif pspec.name == 'stroke-color':
|
||||||
return self._stroke_color
|
return self._stroke_color
|
||||||
|
else:
|
||||||
|
return gtk.Image.do_get_property(self, pspec)
|
||||||
|
@ -22,7 +22,7 @@ class MenuItem(gtk.ImageMenuItem):
|
|||||||
def __init__(self, text_label, icon_name=None):
|
def __init__(self, text_label, icon_name=None):
|
||||||
gtk.ImageMenuItem.__init__(self, text_label)
|
gtk.ImageMenuItem.__init__(self, text_label)
|
||||||
if icon_name:
|
if icon_name:
|
||||||
icon = Icon(icon_name, gtk.ICON_SIZE_MENU)
|
icon = Icon(icon_name,icon_size=gtk.ICON_SIZE_MENU)
|
||||||
self.set_image(icon)
|
self.set_image(icon)
|
||||||
icon.show()
|
icon.show()
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ class ToolButton(gtk.ToolButton):
|
|||||||
def __init__(self, icon_name=None):
|
def __init__(self, icon_name=None):
|
||||||
gtk.ToolButton.__init__(self)
|
gtk.ToolButton.__init__(self)
|
||||||
self._palette = None
|
self._palette = None
|
||||||
|
if icon_name:
|
||||||
self.set_icon(icon_name)
|
self.set_icon(icon_name)
|
||||||
self.connect('clicked', self._button_clicked_cb)
|
self.connect('clicked', self._button_clicked_cb)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user