Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadatabox cleanup #2476

Merged
merged 29 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6c83732
MetadataBox: use self as parent of QtGui.QAction actions
zas May 17, 2024
e9f90e6
lookup_tags() -> _lookup_tags()
zas May 17, 2024
bb8091c
get_file_lookup() -> _get_file_lookup()
zas May 17, 2024
74eb110
open_link() -> _open_link()
zas May 17, 2024
c945991
copy/paste_value() -> _copy/_paste_value()
zas May 17, 2024
385bd3c
update_clipboard() -> _update_clipboard()
zas May 17, 2024
903d3dc
edit_tag() -> _edit_tag()
zas May 17, 2024
a106bc9
edit_selected_tag() -> _edit_selected_tag()
zas May 17, 2024
02d191d
toggle_changes_first() -> _toggle_changes_first()
zas May 17, 2024
d1a9f0d
set_tag_values() -> _set_tag_values()
zas May 17, 2024
901acc9
remove_tag() -> _remove_tag()
zas May 17, 2024
8e53ebb
tag_is_(removable|editable)() -> _tag_is_(removable|editable)()
zas May 17, 2024
0396808
remove_selected_tags(): no need to check if tag is removable, as the …
zas May 17, 2024
888df23
selected_tags() -> _selected_tags()
zas May 17, 2024
7a620f0
_selected_tags(): make it a generator
zas May 17, 2024
953bdbc
set_item_value() -> _set_item_value()
zas May 17, 2024
94ff51e
Drop _lookup_tags() in favor of new _lookup_tag(tag)
zas May 17, 2024
6a1d568
Test if methods listed in MetadataBox.LOOKUP_TAGS are valid FileLooku…
zas May 17, 2024
1d06036
Use named columns instead of numerical values
zas May 17, 2024
6157063
name -> tag (as we iterate among tags)
zas May 17, 2024
6ed7802
Use if/continue instead of filter(lambda...), more readable
zas May 17, 2024
f82c5ac
Use self.tag_diff after it was set to result
zas May 17, 2024
43a1103
Minor code redundancy reduction
zas May 17, 2024
4e1ff55
Consistency: we use tag instead of name everywhere else in the file
zas May 17, 2024
be261bb
_update_items(): regroup code per column
zas May 17, 2024
138996d
Use a namedtuple for display values, with fields text and is_grouped
zas May 17, 2024
a095e31
different -> is_grouped
zas May 17, 2024
14db96d
Add two helper functions to toggle between grouped and normal values
zas May 17, 2024
72c7c60
Variables orig_tags and new_tags aren't needed, drop keys() as it's t…
zas May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions picard/ui/edittagdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, window, tag):
self.metadata_box = window.metadata_box
self.tag = tag
self.modified_tags = {}
self.different = False
self.is_grouped = False
self.default_tags = sorted(
set(list(TAG_NAMES.keys()) + self.metadata_box.tag_diff.tag_names))
if len(self.metadata_box.files) == 1:
Expand Down Expand Up @@ -162,12 +162,15 @@ def add_or_edit_value(self):
else:
self.add_value()

def _group(self, is_grouped):
self.is_grouped = is_grouped
self.ui.add_value.setEnabled(not is_grouped)

def remove_value(self):
value_list = self.value_list
row = value_list.currentRow()
if row == 0 and self.different:
self.different = False
self.ui.add_value.setEnabled(True)
if row == 0 and self.is_grouped:
self._group(False)
value_list.takeItem(row)

def on_rows_inserted(self, parent, first, last):
Expand Down Expand Up @@ -240,36 +243,42 @@ def tag_changed(self, tag):
values = self.modified_tags.get(self.tag, None)
if values is None:
new_tags = self.metadata_box.tag_diff.new
display_value, self.different = new_tags.display_value(self.tag)
values = [display_value] if self.different else new_tags[self.tag]
self.ui.add_value.setEnabled(not self.different)
display_value = new_tags.display_value(self.tag)
if display_value.is_grouped:
# grouped values have a special text, which isn't a valid tag value
values = [display_value.text]
self._group(True)
else:
# normal tag values
values = new_tags[self.tag]
self._group(False)

self.value_list.model().rowsInserted.disconnect(self.on_rows_inserted)
self._add_value_items(values)
self.value_list.model().rowsInserted.connect(self.on_rows_inserted)
self.value_list.setCurrentItem(self.value_list.item(0), QtCore.QItemSelectionModel.SelectionFlag.SelectCurrent)
tag_names.editTextChanged.connect(self.tag_changed)

def _set_item_style(self, item):
font = item.font()
font.setItalic(self.is_grouped)
item.setFont(font)

def _add_value_items(self, values):
values = [v for v in values if v] or [""]
for value in values:
item = QtWidgets.QListWidgetItem(value)
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsEditable | QtCore.Qt.ItemFlag.ItemIsDragEnabled)
font = item.font()
font.setItalic(self.different)
item.setFont(font)
self._set_item_style(item)
self.value_list.addItem(item)

def value_edited(self, item):
row = self.value_list.row(item)
value = item.text()
if row == 0 and self.different:
if row == 0 and self.is_grouped:
self.modified_tags[self.tag] = [value]
self.different = False
font = item.font()
font.setItalic(False)
item.setFont(font)
self.ui.add_value.setEnabled(True)
self._group(False)
self._set_item_style(item)
else:
self._modified_tag()[row] = value
# add tags to the completer model once they get values
Expand Down
Loading
Loading