[gedit-latex] Fix toolbar (stock) icons
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-latex] Fix toolbar (stock) icons
- Date: Fri, 24 Jun 2011 01:23:01 +0000 (UTC)
commit dc61c88c735e51b665c336217a3dbb229c3547e0
Author: John Stowers <john stowers gmail com>
Date: Fri Jun 24 12:27:47 2011 +1200
Fix toolbar (stock) icons
latex/base/__init__.py | 3 +++
latex/base/decorators.py | 5 +++--
latex/util.py | 37 ++++++++++++-------------------------
3 files changed, 18 insertions(+), 27 deletions(-)
---
diff --git a/latex/base/__init__.py b/latex/base/__init__.py
index bbdbff8..fcd4e88 100644
--- a/latex/base/__init__.py
+++ b/latex/base/__init__.py
@@ -195,6 +195,9 @@ class Action(object):
extensions = [None] # a list of file extensions for which this action should be enabled
# [None] indicates that this action is to be enabled for all extensions
+
+ def __init__(self, *args, **kwargs):
+ pass
def hook(self, action_group, window_context):
"""
diff --git a/latex/base/decorators.py b/latex/base/decorators.py
index 447f4f8..e8ab7d4 100644
--- a/latex/base/decorators.py
+++ b/latex/base/decorators.py
@@ -38,7 +38,6 @@ from ..preferences import Preferences, IPreferencesMonitor
# TODO: maybe create ActionDelegate for GeditWindowDecorator
-
class GeditWindowDecorator(IPreferencesMonitor):
"""
This class
@@ -128,6 +127,8 @@ class GeditWindowDecorator(IPreferencesMonitor):
"""
self._ui_manager = self._window.get_ui_manager()
self._action_group = Gtk.ActionGroup("LaTeXPluginActions")
+ self._icon_factory = Gtk.IconFactory()
+ self._icon_factory.add_default()
# create action instances, hook them and build up some
# hash tables
@@ -136,7 +137,7 @@ class GeditWindowDecorator(IPreferencesMonitor):
self._action_extensions = {} # extension -> action names
for clazz in ACTIONS:
- action = clazz()
+ action = clazz(icon_factory=self._icon_factory)
action.hook(self._action_group, self._window_context)
self._action_objects[clazz.__name__] = action
diff --git a/latex/util.py b/latex/util.py
index 4ce2898..c83e76a 100644
--- a/latex/util.py
+++ b/latex/util.py
@@ -191,7 +191,7 @@ class GladeInterface(object):
from uuid import uuid1
-from gi.repository import Gdk
+from gi.repository import Gtk, Gdk
from base import Action
@@ -203,6 +203,11 @@ class IconAction(Action):
The subclass must provide a field 'icon'.
"""
+
+ __stock_id = None
+
+ def __init__(self, *args, **kwargs):
+ self.__icon_factory = kwargs["icon_factory"]
@property
def icon(self):
@@ -215,34 +220,16 @@ class IconAction(Action):
#
# generate a new stock id
#
-
- # TODO: do we have to create the stock id every time?
-
self.__stock_id = str(uuid1())
-
- # see http://article.gmane.org/gmane.comp.gnome.gtk%2B.python/5119
-
- # TODO: what is this strange construct for?
- stock_items = (
- ((self.__stock_id, "", 0, 0, "")),
- )
-
- # Gtk.stock_add(stock_items)
-
- factory = Gtk.IconFactory()
- factory.add_default()
-
- # TODO: use IconSource, the Pixbuf is just fallback
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.icon.path)
-
- icon_set = Gtk.IconSet.new_from_pixbuf(pixbuf)
-
- # factory.add(self.__stock_id, icon_set)
-
+ self.__icon_factory.add(
+ self.__stock_id,
+ Gtk.IconSet.new_from_pixbuf(
+ GdkPixbuf.Pixbuf.new_from_file(self.icon.path)))
+
@property
def stock_id(self):
if self.icon:
- if not "__stock_id" in dir(self):
+ if not self.__stock_id:
self.__init_stock_id()
return self.__stock_id
else:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]