You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.6 KiB
Python
123 lines
3.6 KiB
Python
from PyQt5 import QtWidgets
|
|
from PyQt5.QtGui import QStandardItemModel, QStandardItem
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from ArtNet.gui.dialogs.tag_import_dialog.tag_import_dialog import Ui_Dialog
|
|
|
|
|
|
class TagImportDialog(QtWidgets.QDialog):
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent=parent)
|
|
self.parent = parent
|
|
self.ui = Ui_Dialog()
|
|
self.ui.setupUi(self)
|
|
self.ui.import_all_button.clicked.connect(self.on_import_all_clicked)
|
|
self.ui.remove_all_button.clicked.connect(self.on_remove_all_clicked)
|
|
|
|
self.to_import = []
|
|
self.not_import = []
|
|
|
|
self.data = dict()
|
|
|
|
def set_import_tag_list(self, tags: list):
|
|
"""
|
|
Set the tags in the imported list
|
|
:param tags:
|
|
:return:
|
|
"""
|
|
set_checked = True
|
|
item_model = QStandardItemModel(self.ui.import_list)
|
|
self.data = tags
|
|
|
|
for tag in tags:
|
|
item = QStandardItem(tag)
|
|
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
|
|
item.setData(Qt.Unchecked, Qt.CheckStateRole)
|
|
if set_checked:
|
|
item.setCheckState(Qt.Checked)
|
|
|
|
item_model.appendRow(item)
|
|
|
|
item_model.itemChanged.connect(self.on_import_item_changed)
|
|
self.ui.import_list.setModel(item_model)
|
|
|
|
def set_detected_artists(self, artists: list):
|
|
"""
|
|
Set the label for detected artists
|
|
:param artists:
|
|
:return:
|
|
"""
|
|
s = ""
|
|
for artist in artists:
|
|
s += artist + " | "
|
|
s = s[:-3]
|
|
|
|
self.ui.detected_artists_label.setText(s)
|
|
|
|
def set_used_link(self, link: str):
|
|
"""
|
|
Set the label to display the predicted link
|
|
:param link:
|
|
:return:
|
|
"""
|
|
self.ui.used_link_label.setText(link)
|
|
|
|
def set_ignore_tag_list(self, tags: list):
|
|
"""
|
|
Set the tags in the ignore list
|
|
:param tags:
|
|
:return:
|
|
"""
|
|
set_checked = False
|
|
item_model = QStandardItemModel(self.ui.ignored_list)
|
|
|
|
for tag in tags:
|
|
item = QStandardItem(tag)
|
|
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
|
|
item.setData(Qt.Unchecked, Qt.CheckStateRole)
|
|
if set_checked:
|
|
item.setCheckState(Qt.Checked)
|
|
|
|
item_model.appendRow(item)
|
|
|
|
item_model.itemChanged.connect(self.on_ignore_item_changed)
|
|
self.ui.ignored_list.setModel(item_model)
|
|
|
|
def on_ignore_item_changed(self, item: QStandardItem):
|
|
if item.checkState() == Qt.Checked:
|
|
tag = item.text()
|
|
self.to_import.append(tag)
|
|
self.not_import.remove(tag)
|
|
|
|
self.set_import_tag_list(self.to_import)
|
|
self.set_ignore_tag_list(self.not_import)
|
|
|
|
def on_import_item_changed(self, item: QStandardItem):
|
|
if item.checkState() == Qt.Unchecked:
|
|
tag = item.text()
|
|
self.to_import.remove(tag)
|
|
self.not_import.append(tag)
|
|
|
|
self.set_import_tag_list(self.to_import)
|
|
self.set_ignore_tag_list(self.not_import)
|
|
|
|
def on_import_all_clicked(self):
|
|
self.to_import += self.not_import
|
|
self.not_import = []
|
|
|
|
self.set_import_tag_list(self.to_import)
|
|
self.set_ignore_tag_list(self.not_import)
|
|
|
|
def on_remove_all_clicked(self):
|
|
self.not_import += self.to_import
|
|
self.to_import = []
|
|
|
|
self.set_import_tag_list(self.to_import)
|
|
self.set_ignore_tag_list(self.not_import)
|
|
|
|
def exec_(self) -> int:
|
|
if super(TagImportDialog, self).exec_() == QtWidgets.QDialog.Rejected:
|
|
return None
|
|
return self.data
|