[kupfer: 32/41] Remove art/icon-list and use only plugin-installed icons
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer: 32/41] Remove art/icon-list and use only plugin-installed icons
- Date: Tue, 26 Apr 2011 17:15:29 +0000 (UTC)
commit 12638981cea664f9d427a73faf0e5cee15b84211
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Tue Apr 26 18:45:48 2011 +0200
Remove art/icon-list and use only plugin-installed icons
Also, plugin-installed icons default to being skipped if they conflict
with an already themed icon (from the normal theme). The plugin can add
the special flag ``!override`` to each line in the icon-list to request
the icon always to be installed.
Moving object.svg and objects.svg into the ``core`` plugin, and now we
only install the kupfer-object icon when it's not provided by the icon
theme.
data/art/icon-list | 5 --
data/wscript_build | 1 -
kupfer/core/plugins.py | 20 ++++-----
kupfer/icons.py | 52 +++++++++++++-------------
{data/art => kupfer/plugin/core}/COPYING | 0
kupfer/plugin/core/icon-list | 3 +
{data/art => kupfer/plugin/core}/object.svg | 0
{data/art => kupfer/plugin/core}/objects.svg | 0
kupfer/plugin/qsicons/icon-list | 10 ++--
9 files changed, 43 insertions(+), 48 deletions(-)
---
diff --git a/data/wscript_build b/data/wscript_build
index 0939f90..30dcda2 100644
--- a/data/wscript_build
+++ b/data/wscript_build
@@ -3,6 +3,5 @@ bld.install_files("${DATADIR}/kupfer", "defaults.cfg")
bld.install_files("${DATADIR}/kupfer", bld.path.ant_glob("*.ui"))
# install all pure data files
-bld.install_files("${DATADIR}/kupfer/art", bld.path.ant_glob("art/*"))
bld.install_files("${DATADIR}/kupfer/searchplugins",
bld.path.ant_glob("searchplugins/*"))
diff --git a/kupfer/core/plugins.py b/kupfer/core/plugins.py
index 93808b0..1ddd3e8 100644
--- a/kupfer/core/plugins.py
+++ b/kupfer/core/plugins.py
@@ -352,18 +352,16 @@ def _load_icons(plugin_name):
try:
icon_file = pkgutil.get_data(modname, PLUGIN_ICON_FILE)
- except IOError, exc:
- pretty.print_debug(__name__, type(exc).__name__, exc)
- return
-
- for line in icon_file.splitlines():
- # ignore '#'-comments
- if line.startswith("#") or not line.strip():
- continue
- icon_name, basename = (i.strip() for i in line.split("\t", 1))
- icon_data = pkgutil.get_data(modname, basename)
- icons.load_plugin_icon(plugin_name, icon_name, icon_data)
+ except IOError as exc:
+ if exc.errno != 2:
+ pretty.print_exc(__name__)
+ else:
+ # no icon-list exists, let is pass silently
+ return
+ def get_icon_data(basename):
+ return pkgutil.get_data(modname, basename)
+ icons.parse_load_icon_list(icon_file, get_icon_data, plugin_name)
def initialize_plugin(plugin_name):
"""Initialize plugin.
diff --git a/kupfer/icons.py b/kupfer/icons.py
index 7e2ea95..af41403 100644
--- a/kupfer/icons.py
+++ b/kupfer/icons.py
@@ -43,39 +43,39 @@ _default_theme.connect("changed", _icon_theme_changed)
_local_theme = gtk.IconTheme()
_local_theme.set_search_path([])
-def load_kupfer_icons(scheduler):
- """Load in kupfer icons from installed files"""
- ilist = "art/icon-list"
- ilist_file_path = config.get_data_file(ilist)
- # parse icon list file
- ifile = open(ilist_file_path, "r")
- for line in ifile:
+def parse_load_icon_list(icon_list_data, get_data_func, plugin_name=None):
+ """
+ @icon_list_data: A bytestring whose lines identify icons
+ @get_data_func: A function to return the data for a relative filename
+ @plugin_name: plugin id, if applicable
+ """
+ for line in icon_list_data.splitlines():
# ignore '#'-comments
- if line.startswith("#"):
+ if line.startswith("#") or not line.strip():
continue
- icon_name, basename, size = (i.strip() for i in line.split("\t", 2))
- size = int(size)
- icon_path = config.get_data_file(os.path.join("art", basename))
- if not icon_path:
- pretty.print_info(__name__, "Icon", basename,icon_path,"not found")
+ fields = map(str.strip, line.split('\t'))
+ if len(fields) < 2:
continue
- if (icon_name in kupfer_locally_installed_names or
- _default_theme.has_icon(icon_name)):
- pretty.print_debug(__name__, "Skipping existing", icon_name)
- continue
- pixbuf = pixbuf_new_from_file_at_size(icon_path, size,size)
- gtk.icon_theme_add_builtin_icon(icon_name, size, pixbuf)
- kupfer_locally_installed_names.add(icon_name)
- pretty.print_debug(__name__, "Loading icon", icon_name, "at", size,
- "from", icon_path)
+ icon_name, basename = fields[:2]
+ override = ('!override' in fields)
+ def wrap_get_data():
+ return get_data_func(basename)
+ load_icon_from_func(plugin_name, icon_name, wrap_get_data, override)
-scheduler.GetScheduler().connect("after-display", load_kupfer_icons)
+def load_icon_from_func(plugin_name, icon_name, get_data_func, override=False):
+ """
+ Load icon from @icon_data into the name @icon_name
-def load_plugin_icon(plugin_name, icon_name, icon_data):
- "Load icon from @icon_data into the name @icon_name"
- if icon_name in kupfer_locally_installed_names:
+ @get_data_func: function to retrieve the data if needed
+ @override: override the icon theme
+ """
+ if not override and icon_name in kupfer_locally_installed_names:
pretty.print_debug(__name__, "Skipping existing", icon_name)
return
+ if not override and _default_theme.has_icon(icon_name):
+ pretty.print_debug(__name__, "Skipping themed icon", icon_name)
+ return
+ icon_data = get_data_func()
for size in (SMALL_SZ, LARGE_SZ):
pixbuf = get_pixbuf_from_data(icon_data, size, size)
gtk.icon_theme_add_builtin_icon(icon_name, size, pixbuf)
diff --git a/data/art/COPYING b/kupfer/plugin/core/COPYING
similarity index 100%
rename from data/art/COPYING
rename to kupfer/plugin/core/COPYING
diff --git a/kupfer/plugin/core/icon-list b/kupfer/plugin/core/icon-list
new file mode 100644
index 0000000..1811eb7
--- /dev/null
+++ b/kupfer/plugin/core/icon-list
@@ -0,0 +1,3 @@
+# IconName File
+kupfer-object object.svg
+kupfer-object-multiple objects.svg
diff --git a/data/art/object.svg b/kupfer/plugin/core/object.svg
similarity index 100%
rename from data/art/object.svg
rename to kupfer/plugin/core/object.svg
diff --git a/data/art/objects.svg b/kupfer/plugin/core/objects.svg
similarity index 100%
rename from data/art/objects.svg
rename to kupfer/plugin/core/objects.svg
diff --git a/kupfer/plugin/qsicons/icon-list b/kupfer/plugin/qsicons/icon-list
index f959af5..2767447 100644
--- a/kupfer/plugin/qsicons/icon-list
+++ b/kupfer/plugin/qsicons/icon-list
@@ -1,6 +1,6 @@
# ID File
-kupfer-launch Rocket.png
-kupfer-object Object.png
-kupfer-object-multiple Object.png
-kupfer-execute Action.png
-kupfer-catalog Find.png
+kupfer-launch Rocket.png !override
+kupfer-object Object.png !override
+kupfer-object-multiple Object.png !override
+kupfer-execute Action.png !override
+kupfer-catalog Find.png !override
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]