[alacarte] NainWindow: Refactor loadItems/loadMenu



commit 91c7dc8889f60e5d3b21f3aaff23290061443d61
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Jun 1 01:41:11 2012 -0400

    NainWindow: Refactor loadItems/loadMenu
    
    Make these methods more competent and less messy

 Alacarte/MainWindow.py |   35 ++++++++++++++++-------------------
 Alacarte/util.py       |    4 +++-
 2 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py
index 2e81de7..fcec157 100644
--- a/Alacarte/MainWindow.py
+++ b/Alacarte/MainWindow.py
@@ -218,10 +218,10 @@ class MainWindow(object):
             iters[depth] = self.menu_store.append(None, (icon, cgi.escape(parent.get_name()), parent))
         depth += 1
         for menu, show in self.editor.getMenus(parent):
-            if show:
-                name = cgi.escape(menu.get_name())
-            else:
-                name = '<small><i>' + cgi.escape(menu.get_name()) + '</i></small>'
+            name = cgi.escape(menu.get_name())
+            if not show:
+                name = "<small><i>%s</i></small>" % (name,)
+
             icon = util.getIcon(menu)
             iters[depth] = self.menu_store.append(iters[depth-1], (icon, name, menu))
             self.loadMenu(iters, menu, depth)
@@ -230,23 +230,20 @@ class MainWindow(object):
     def loadItems(self, menu, menu_path):
         self.item_store.clear()
         for item, show in self.editor.getItems(menu):
-            menu_icon = None
-            if isinstance(item, GMenu.TreeSeparator):
-                name = '---'
-                icon = None
+            icon = util.getIcon(item)
+            if isinstance(item, GMenu.TreeDirectory):
+                name = item.get_name()
             elif isinstance(item, GMenu.TreeEntry):
-                app_info = item.get_app_info()
-                if show:
-                    name = cgi.escape(app_info.get_display_name())
-                else:
-                    name = '<small><i>' + cgi.escape(app_info.get_display_name()) + '</i></small>'
-                icon = util.getIcon(item)
+                name = item.get_app_info().get_display_name()
+            elif isinstance(item, GMenu.Separator):
+                name = '---'
             else:
-                if show:
-                    name = cgi.escape(item.get_name())
-                else:
-                    name = '<small><i>' + cgi.escape(item.get_name()) + '</i></small>'
-                icon = util.getIcon(item)
+                assert False, 'should not be reached'
+
+            name = cgi.escape(name)
+            if not show:
+                name = "<small><i>%s</i></small>" % (name,)
+
             self.item_store.append((show, icon, name, item))
 
     #this is a little timeout callback to insert new items after
diff --git a/Alacarte/util.py b/Alacarte/util.py
index cc7d136..93c2372 100644
--- a/Alacarte/util.py
+++ b/Alacarte/util.py
@@ -135,9 +135,11 @@ def getIcon(item):
 
     if isinstance(item, GMenu.TreeDirectory):
         gicon = item.get_icon()
-    else:
+    elif isinstance(item, GMenu.TreeEntry):
         app_info = item.get_app_info()
         gicon = app_info.get_icon()
+    else:
+        return None
 
     if gicon is None:
         return None



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]