Handle category additions/removals one by one

This commit is contained in:
Clement Lefebvre 2013-11-25 16:06:22 +00:00
parent d8372a6846
commit 55160de553
2 changed files with 38 additions and 27 deletions

View File

@ -1632,7 +1632,6 @@ class pluginclass( object ):
if not found: if not found:
addedCategories.append(item) addedCategories.append(item)
key = 0
for item in self.categoryList: for item in self.categoryList:
found = False found = False
for item2 in newCategoryList: for item2 in newCategoryList:
@ -1640,27 +1639,34 @@ class pluginclass( object ):
found = True found = True
break break
if not found: if not found:
removedCategories.append( key ) removedCategories.append( item )
else:
key += 1
if self.showcategoryicons == True: if self.showcategoryicons == True:
categoryIconSize = self.iconSize categoryIconSize = self.iconSize
else: else:
categoryIconSize = 0 categoryIconSize = 0
for key in removedCategories: for item in removedCategories:
self.categoryList[key]["button"].destroy() try:
del self.categoryList[key] button = item["button"]
self.categoryList.remove(item)
button.destroy()
del item
except Exception, e:
print e
if addedCategories: if addedCategories:
sortedCategoryList = [] sortedCategoryList = []
for item in self.categoryList: for item in self.categoryList:
try:
self.categoriesBox.remove( item["button"] ) self.categoriesBox.remove( item["button"] )
sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) ) sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) )
except Exception, e:
print e
# Create new category buttons and add the to the list # Create new category buttons and add the to the list
for item in addedCategories: for item in addedCategories:
try:
item["button"] = CategoryButton( item["icon"], categoryIconSize, [ item["name"] ], item["filter"] ) item["button"] = CategoryButton( item["icon"], categoryIconSize, [ item["name"] ], item["filter"] )
self.mintMenuWin.setTooltip( item["button"], item["tooltip"] ) self.mintMenuWin.setTooltip( item["button"], item["tooltip"] )
@ -1677,10 +1683,16 @@ class pluginclass( object ):
self.categoryList.append( item ) self.categoryList.append( item )
sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) ) sortedCategoryList.append( ( str(item["index"]) + item["name"], item["button"] ) )
except Exception, e:
print e
sortedCategoryList.sort() sortedCategoryList.sort()
for item in sortedCategoryList: for item in sortedCategoryList:
try:
self.categoriesBox.pack_start( item[1], False, False, 0 ) self.categoriesBox.pack_start( item[1], False, False, 0 )
except Exception, e:
print e
# Find added and removed applications add update the application list # Find added and removed applications add update the application list

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from gi.repository import Gtk, GdkPixbuf, Gdk, GLib from gi.repository import Gtk, Gdk, GLib
from gi.repository import Pango from gi.repository import Pango
#import matedesktop
from gi.repository import GObject from gi.repository import GObject
import os.path import os.path
import shutil import shutil