fixed weight

This commit is contained in:
Andreas Preikschat 2011-04-12 23:01:27 +02:00
parent b7a1554abd
commit c683300385
1 changed files with 9 additions and 7 deletions

View File

@ -154,10 +154,13 @@ class CategoryList(object):
return False return False
def append(self, name, actions=None): def append(self, name, actions=None):
weight = 0
if len(self.categories) > 0:
weight = self.categories[-1].weight + 1
if actions: if actions:
self.add(name, actions=actions) self.add(name, weight, actions)
else: else:
self.add(name) self.add(name, weight)
def add(self, name, weight=0, actions=None): def add(self, name, weight=0, actions=None):
category = ActionCategory(name, weight) category = ActionCategory(name, weight)
@ -168,7 +171,7 @@ class CategoryList(object):
else: else:
category.actions.append(action) category.actions.append(action)
self.categories.append(category) self.categories.append(category)
self.categories.sort(key=lambda cat: cat.weight, reverse=True) self.categories.sort(key=lambda cat: cat.weight)
def remove(self, name): def remove(self, name):
for category in self.categories: for category in self.categories:
@ -270,8 +273,7 @@ class ActionList(object):
for category in self.categories: for category in self.categories:
if category.name == name: if category.name == name:
category.weight = weight category.weight = weight
self.categories.categories.sort( self.categories.categories.sort(key=lambda cat: cat.weight)
key=lambda cat: cat.weight, reverse=True)
return return
self.categories.add(name, weight) self.categories.add(name, weight)
@ -280,5 +282,5 @@ class CategoryOrder(object):
""" """
An enumeration class for category weights. An enumeration class for category weights.
""" """
standardMenu = 100 standardMenu = -20
standardToolbar = 90 standardToolbar = -10