Skip to content

Commit 138996d

Browse files
committed
Use a namedtuple for display values, with fields text and is_grouped
- it makes things a bit clearer - it will be easier to add new fields
1 parent be261bb commit 138996d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

picard/ui/edittagdialog.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,17 @@ def tag_changed(self, tag):
240240
values = self.modified_tags.get(self.tag, None)
241241
if values is None:
242242
new_tags = self.metadata_box.tag_diff.new
243-
display_value, self.different = new_tags.display_value(self.tag)
244-
values = [display_value] if self.different else new_tags[self.tag]
245-
self.ui.add_value.setEnabled(not self.different)
243+
display_value = new_tags.display_value(self.tag)
244+
if display_value.is_grouped:
245+
# grouped values have a special text, which isn't a valid tag value
246+
self.different = True
247+
values = [display_value.text]
248+
self.ui.add_value.setEnabled(False)
249+
else:
250+
# normal tag values
251+
self.different = False
252+
values = new_tags[self.tag]
253+
self.ui.add_value.setEnabled(True)
246254

247255
self.value_list.model().rowsInserted.disconnect(self.on_rows_inserted)
248256
self._add_value_items(values)

picard/ui/metadatabox.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from collections import (
3535
Counter,
3636
defaultdict,
37+
namedtuple,
3738
)
3839
from functools import partial
3940

@@ -83,6 +84,9 @@ class TagStatus:
8384
READONLY = 32
8485

8586

87+
TagCounterDisplayValue = namedtuple('TagCounterDisplayValue', ('text', 'is_grouped'))
88+
89+
8690
class TagCounter(dict):
8791

8892
__slots__ = ('parent', 'counts', 'different')
@@ -109,17 +113,22 @@ def display_value(self, tag):
109113
missing = self.parent.objects - count
110114

111115
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
113118
else:
114119
if tag == '~length':
115120
msg = format_time(self.get(tag, 0))
116121
else:
117122
msg = MULTI_VALUED_JOINER.join(self[tag])
118123

119124
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
121127
else:
122-
return (msg, False)
128+
text = msg
129+
is_grouped = False
130+
131+
return TagCounterDisplayValue(text, is_grouped)
123132

124133

125134
class TagDiff(object):
@@ -714,11 +723,11 @@ def _update_items(self, result=None, error=None):
714723
self.setRowHeight(i, self.sizeHintForRow(i))
715724

716725
def _set_item_value(self, item, tags, tag):
717-
text, italic = tags.display_value(tag)
726+
display_value = tags.display_value(tag)
718727
item.setData(QtCore.Qt.ItemDataRole.UserRole, tag)
719-
item.setText(text)
728+
item.setText(display_value.text)
720729
font = item.font()
721-
font.setItalic(italic)
730+
font.setItalic(display_value.is_grouped)
722731
item.setFont(font)
723732

724733
@restore_method

0 commit comments

Comments
 (0)