summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErkin Bahceci <erkinbah@gmail.com>2008-10-18 16:48:55 -0500
committerErkin Bahceci <erkinbah@gmail.com>2008-10-18 16:48:55 -0500
commit31326c429868a9a1f4711d76d6d44120375234f9 (patch)
treea6bc240f3fd91d43d6ea2ffb20d22e16933bb3d9
parentc8a29645224baf39811d6f98d0d4868a703046f0 (diff)
downloadccsm-31326c429868a9a1f4711d76d6d44120375234f9.tar.gz
ccsm-31326c429868a9a1f4711d76d6d44120375234f9.tar.bz2
Speed up startup by loading icons in the background.
Plugin icons for all categories except the topmost three will be loaded in the background.
-rw-r--r--ccm/Utils.py37
-rw-r--r--ccm/Widgets.py28
2 files changed, 50 insertions, 15 deletions
diff --git a/ccm/Utils.py b/ccm/Utils.py
index 8f0231d..b6cec6a 100644
--- a/ccm/Utils.py
+++ b/ccm/Utils.py
@@ -63,12 +63,18 @@ def protect_markup_dict (dict_):
class Image (gtk.Image):
- def __init__ (self, name = None, type = ImageNone, size = 32):
+ def __init__ (self, name = None, type = ImageNone, size = 32,
+ useMissingImage = False):
gtk.Image.__init__ (self)
if not name:
return
+ if useMissingImage:
+ self.set_from_stock (gtk.STOCK_MISSING_IMAGE,
+ gtk.ICON_SIZE_LARGE_TOOLBAR)
+ return
+
try:
if type in (ImagePlugin, ImageCategory, ImageThemed):
pixbuf = None
@@ -220,14 +226,20 @@ class IdleSettingsParser:
self.Context = context
self.Main = main
self.PluginList = [p for p in self.Context.Plugins.items() if FilterPlugin(p[1])]
-
- gobject.timeout_add (200, self.Wait)
+ nCategories = len (main.MainPage.RightWidget._boxes)
+ self.CategoryLoadIconsList = range (3, nCategories) # Skip the first 3
+ print 'Loading icons...'
+
+ gobject.timeout_add (150, self.Wait)
def Wait(self):
if not self.PluginList:
return False
- gobject.idle_add (self.ParseSettings)
+ if len (self.CategoryLoadIconsList) == 0: # If we're done loading icons
+ gobject.idle_add (self.ParseSettings)
+ else:
+ gobject.idle_add (self.LoadCategoryIcons)
return False
@@ -244,6 +256,23 @@ class IdleSettingsParser:
return False
+ def LoadCategoryIcons(self):
+ from ccm.Widgets import PluginButton
+
+ catIndex = self.CategoryLoadIconsList[0]
+ pluginWindow = self.Main.MainPage.RightWidget
+ categoryBox = pluginWindow._boxes[catIndex]
+ for (pluginIndex, plugin) in enumerate (categoryBox.get_plugins()):
+ categoryBox._buttons[pluginIndex] = PluginButton (plugin)
+ categoryBox.rebuild_table (categoryBox._current_cols, True)
+ pluginWindow.connect_buttons (categoryBox)
+
+ self.CategoryLoadIconsList.remove (self.CategoryLoadIconsList[0])
+
+ gobject.timeout_add (150, self.Wait)
+
+ return False
+
# Updates all registered setting when they where changed through CompizConfig
class Updater:
diff --git a/ccm/Widgets.py b/ccm/Widgets.py
index 40a8c33..f42abc5 100644
--- a/ccm/Widgets.py
+++ b/ccm/Widgets.py
@@ -1372,11 +1372,11 @@ class PluginButton (gtk.HBox):
_plugin = None
- def __init__ (self, plugin):
+ def __init__ (self, plugin, useMissingImage = False):
gtk.HBox.__init__(self)
self._plugin = plugin
- image = Image (plugin.Name, ImagePlugin, size=32)
+ image = Image (plugin.Name, ImagePlugin, 32, useMissingImage)
label = Label (plugin.ShortDesc, 120)
label.connect ('style-set', self.style_set)
box = gtk.HBox ()
@@ -1465,7 +1465,7 @@ class CategoryBox(gtk.VBox):
_current_cols = 0
_current_plugins = 0
- def __init__ (self, context, name, plugins=None):
+ def __init__ (self, context, name, plugins=None, categoryIndex=0):
gtk.VBox.__init__ (self)
self.set_spacing (5)
@@ -1499,9 +1499,12 @@ class CategoryBox(gtk.VBox):
self._table = gtk.Table ()
self._table.set_border_width (10)
+ # load icons now only for the first 3 categories
+ dontLoadIcons = (categoryIndex >= 3);
+
self._buttons = []
for plugin in self._plugins:
- button = PluginButton(plugin)
+ button = PluginButton(plugin, dontLoadIcons)
self._buttons.append(button)
self._alignment = gtk.Alignment (0, 0, 1, 1)
@@ -1529,8 +1532,8 @@ class CategoryBox(gtk.VBox):
return bool(self._plugins)
- def rebuild_table (self, ncols):
- if (ncols == self._current_cols
+ def rebuild_table (self, ncols, force = False):
+ if (not force and ncols == self._current_cols
and len (self._plugins) == self._current_plugins):
return
self._current_cols = ncols
@@ -1604,12 +1607,10 @@ class PluginWindow(gtk.ScrolledWindow):
self._not_found_box = NotFoundBox ()
categories = sorted(self._categories, key=CategoryKeyFunc)
- for category in categories:
+ for (i, category) in enumerate(categories):
plugins = self._categories[category]
- category_box = CategoryBox(context, category, plugins)
- buttons = category_box.get_buttons ()
- for button in buttons:
- button.connect('clicked', self.show_plugin_page)
+ category_box = CategoryBox(context, category, plugins, i)
+ self.connect_buttons (category_box)
self._boxes.append (category_box)
self._box.pack_start (category_box, False, False)
@@ -1619,6 +1620,11 @@ class PluginWindow(gtk.ScrolledWindow):
viewport.add (self._box)
self.add (viewport)
+ def connect_buttons (self, category_box):
+ buttons = category_box.get_buttons ()
+ for button in buttons:
+ button.connect('clicked', self.show_plugin_page)
+
def set_viewport_style (self, widget, previous):
if self._style_block > 0:
return