Skip to content

Commit fcde2dc

Browse files
committed
[MovieTagger]
- define flags at once to avoid multiple calls of functions - use list comprehension
1 parent 5373f9e commit fcde2dc

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

movietagger/src/plugin.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,11 @@ def updateAllTagList(self):
139139
xtmp.extend(ml.tags)
140140
self.usedTags = xtmp
141141

142-
e = []+self.pretags
143-
testlist = []
144-
for i in ml.tags:
145-
try:
146-
self.pretags.index(i)
147-
except ValueError:
148-
e.append(i)
149-
142+
e = self.pretags + [ x for x in ml.tags if x not in self.pretags ]
143+
150144
taglist = []
151145
for i in e:
152-
taglist.append((i, self.isUsedTag(i), self.isUserTag(i), self.isPreTag(i) ))
146+
taglist.append(self.getFlags(i))
153147
taglist.sort()
154148
self["aTaglist"].setList(taglist)
155149

@@ -237,26 +231,15 @@ def clearAllTags(self,yesno):
237231
self.updateCurrentTagList()
238232
self.updateAllTagList()
239233

240-
def isUsedTag(self,tag):
241-
try:
242-
self.usedTags.index(tag)
243-
return True
244-
except ValueError:
245-
return False
246-
247-
def isPreTag(self,tag):
248-
try:
249-
self.pretags.index(tag)
250-
return True
251-
except ValueError:
252-
return False
253-
254-
def isUserTag(self,tag):
255-
if self.isPreTag(tag) is False and self.isUsedTag(tag) is True:
256-
return True
257-
else:
258-
return False
259-
234+
def getFlags(self, tag):
235+
usedTags = tag in self.usedTags
236+
preTags = tag in self.pretags
237+
print usedTags, preTags
238+
userTags = False
239+
if not preTags and usedTags:
240+
userTags = True
241+
return (tag, usedTags, preTags, userTags )
242+
260243
def keyRed(self):
261244
if self.currList is self["cTaglist"]:
262245
print "removing Tag", self["cTaglist"].getCurrent()[0]
@@ -362,7 +345,6 @@ def buildTagMenuListEntry(self, tagName, isUsedTag=False, isUserTag=False, isPre
362345
if isPreTag:
363346
res.append((eListboxPythonMultiContent.TYPE_TEXT,self.xIndicatorOffset+(2*self.xIndicatorWidth),0,self.xIndicatorWidth,self.componentItemHeight,1,RT_HALIGN_CENTER|RT_VALIGN_CENTER, "X",self.preTagColor))
364347

365-
print "res", res
366348
return res
367349

368350
def postWidgetCreate(self, instance):

0 commit comments

Comments
 (0)