34
34
from collections import (
35
35
Counter ,
36
36
defaultdict ,
37
+ namedtuple ,
37
38
)
38
39
from functools import partial
39
40
@@ -83,6 +84,9 @@ class TagStatus:
83
84
READONLY = 32
84
85
85
86
87
+ TagCounterDisplayValue = namedtuple ('TagCounterDisplayValue' , ('text' , 'is_grouped' ))
88
+
89
+
86
90
class TagCounter (dict ):
87
91
88
92
__slots__ = ('parent' , 'counts' , 'different' )
@@ -109,17 +113,22 @@ def display_value(self, tag):
109
113
missing = self .parent .objects - count
110
114
111
115
if tag in self .different :
112
- return (ngettext ("(different across %d item)" , "(different across %d items)" , count ) % count , True )
116
+ text = ngettext ("(different across %d item)" , "(different across %d items)" , count ) % count
117
+ is_grouped = True
113
118
else :
114
119
if tag == '~length' :
115
120
msg = format_time (self .get (tag , 0 ))
116
121
else :
117
122
msg = MULTI_VALUED_JOINER .join (self [tag ])
118
123
119
124
if count > 0 and missing > 0 :
120
- return (msg + " " + (ngettext ("(missing from %d item)" , "(missing from %d items)" , missing ) % missing ), True )
125
+ text = msg + " " + (ngettext ("(missing from %d item)" , "(missing from %d items)" , missing ) % missing )
126
+ is_grouped = True
121
127
else :
122
- return (msg , False )
128
+ text = msg
129
+ is_grouped = False
130
+
131
+ return TagCounterDisplayValue (text , is_grouped )
123
132
124
133
125
134
class TagDiff (object ):
@@ -714,11 +723,11 @@ def _update_items(self, result=None, error=None):
714
723
self .setRowHeight (i , self .sizeHintForRow (i ))
715
724
716
725
def _set_item_value (self , item , tags , tag ):
717
- text , italic = tags .display_value (tag )
726
+ display_value = tags .display_value (tag )
718
727
item .setData (QtCore .Qt .ItemDataRole .UserRole , tag )
719
- item .setText (text )
728
+ item .setText (display_value . text )
720
729
font = item .font ()
721
- font .setItalic (italic )
730
+ font .setItalic (display_value . is_grouped )
722
731
item .setFont (font )
723
732
724
733
@restore_method
0 commit comments