Skip to content

Commit

Permalink
Merge pull request #2414 from zas/alternative_versions_tooltip
Browse files Browse the repository at this point in the history
PICARD-2863: Add a tooltip with additional disambiguation to release versions menu
  • Loading branch information
zas authored Apr 19, 2024
2 parents 5368e69 + 93b7101 commit 05ddd5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 11 additions & 1 deletion picard/releasegroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
'catnum': N_("Cat No"),
}
# additional keys displayed only for disambiguation
VERSIONS_EXTRA_HEADINGS = {
'packaging': N_("Packaging"),
'barcode': N_("Barcode"),
'disambiguation': N_("Disambiguation"),
}
VERSIONS_EXTRA_KEYS = ('packaging', 'barcode', 'disambiguation')


Expand Down Expand Up @@ -85,7 +90,7 @@ def prepare_releases_for_versions(releases):
'catnum': ', '.join(set(catnums)),
'tracks': tracks,
'barcode': node.get('barcode', '') or _('[no barcode]'),
'packaging': node.get('packaging', '') or '??',
'packaging': pgettext_attributes('release_packaging', node.get('packaging', '') or '??'),
'disambiguation': node.get('disambiguation', ''),
'_disambiguate_name': list(),
'totaltracks': sum(m['track-count'] for m in node['media']),
Expand Down Expand Up @@ -141,12 +146,17 @@ def _parse_versions(self, document):
for release in versions[name]:
dis = " / ".join(filter(None, uniqify(release['_disambiguate_name'])))
disname = name if not dis else name + ' / ' + dis
extra = "\n".join(
"%s: %s" % (_(VERSIONS_EXTRA_HEADINGS[k]), release[k])
for k in VERSIONS_EXTRA_KEYS if release[k]
)
version = {
'id': release['id'],
'name': disname.replace("&", "&&"),
'totaltracks': release['totaltracks'],
'countries': release['countries'],
'formats': release['formats'],
'extra': extra,
}
self.versions.append(version)

Expand Down
7 changes: 5 additions & 2 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def contextMenuEvent(self, event):

if isinstance(obj, Album) and not isinstance(obj, NatAlbum) and obj.loaded:
releases_menu = QtWidgets.QMenu(_("&Other versions"), menu)
releases_menu.setToolTipsVisible(True)
menu.addSeparator()
menu.addMenu(releases_menu)
loading = releases_menu.addAction(_("Loading…"))
Expand Down Expand Up @@ -584,17 +585,19 @@ def _add_other_versions():
formatmatch = ORDER_AFTER
group = (trackmatch, countrymatch, formatmatch)
# order by group, name, and id on push
heappush(alternatives, (group, version['name'], version['id']))
heappush(alternatives, (group, version['name'], version['id'], version['extra']))

prev_group = None
while alternatives:
group, action_text, release_id = heappop(alternatives)
group, action_text, release_id, extra = heappop(alternatives)
if group != prev_group:
if prev_group is not None:
releases_menu.addSeparator()
prev_group = group
action = releases_menu.addAction(action_text)
action.setCheckable(True)
if extra:
action.setToolTip(extra)
if obj.id == release_id:
action.setChecked(True)
action.triggered.connect(partial(obj.switch_release_version, release_id))
Expand Down

0 comments on commit 05ddd5f

Please sign in to comment.