Skip to content

Commit

Permalink
Introduce TreeItem.update_colums_text() and reduce code redundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed May 6, 2024
1 parent a5fb09f commit 261f2fa
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,14 @@ def sortkey(self, column):
self._sortkeys[column] = sortkey
return sortkey

def update_colums_text(self, color=None, bgcolor=None):
for i, column in enumerate(MainPanel.columns):
self.setText(i, self.obj.column(column.key))
if color is not None:
self.setForeground(i, color)
if bgcolor is not None:
self.setBackground(i, bgcolor)


class ClusterItem(TreeItem):

Expand All @@ -988,8 +996,7 @@ def __init__(self, *args):
self.setIcon(MainPanel.TITLE_COLUMN, ClusterItem.icon_dir)

def update(self, update_selection=True):
for i, column in enumerate(MainPanel.columns):
self.setText(i, self.obj.column(column.key))
self.update_colums_text()
album = self.obj.related_album
if self.obj.special and album and album.loaded:
album.item.update(update_tracks=False)
Expand Down Expand Up @@ -1076,8 +1083,7 @@ def update(self, update_tracks=True, update_selection=True):
else:
self.setIcon(MainPanel.TITLE_COLUMN, AlbumItem.icon_cd)
self.setToolTip(MainPanel.TITLE_COLUMN, _("Album unchanged"))
for i, column in enumerate(MainPanel.columns):
self.setText(i, album.column(column.key))
self.update_colums_text()
if selection_changed and update_selection:
TreeItem.window.update_selection(new_selection=False)
# Workaround for PICARD-1446: Expand/collapse indicator for the release
Expand Down Expand Up @@ -1163,10 +1169,7 @@ def update(self, update_album=True, update_files=True, update_selection=True):
else:
self.setIcon(MainPanel.TITLE_COLUMN, icon)
self.setToolTip(MainPanel.TITLE_COLUMN, icon_tooltip)
for i, column in enumerate(MainPanel.columns):
self.setText(i, track.column(column.key))
self.setForeground(i, color)
self.setBackground(i, bgcolor)
self.update_colums_text(color=color, bgcolor=bgcolor)
if update_selection and self.isSelected():
TreeItem.window.update_selection(new_selection=False)
if update_album:
Expand All @@ -1185,10 +1188,7 @@ def update(self, update_track=True, update_selection=True):
self.setIcon(MainPanel.FINGERPRINT_COLUMN, fingerprint_icon)
color = FileItem.file_colors[file.state]
bgcolor = get_match_color(file.similarity, TreeItem.base_color)
for i, column in enumerate(MainPanel.columns):
self.setText(i, file.column(column.key))
self.setForeground(i, color)
self.setBackground(i, bgcolor)
self.update_colums_text(color=color, bgcolor=bgcolor)
if update_selection and self.isSelected():
TreeItem.window.update_selection(new_selection=False)
parent = self.parent()
Expand Down

0 comments on commit 261f2fa

Please sign in to comment.