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.
114 lines
4.5 KiB
Python
114 lines
4.5 KiB
Python
import logging
|
|
|
|
from PyQt5 import QtWidgets
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtGui import QStandardItem, QStandardItemModel
|
|
|
|
from ArtNet.gui.dialogs.collection_select_dialog.collection_select_dialog import Ui_Dialog
|
|
|
|
from ArtNet.gui.dialogs.collection_modify_dialog.collection_dialog import CollectionModDialog
|
|
|
|
|
|
class CollectionSelectDialog(QtWidgets.QDialog):
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.parent = parent
|
|
|
|
self.__curr_searched_collections: list = None
|
|
self.curr_collections = list()
|
|
|
|
self.ui = Ui_Dialog()
|
|
self.ui.setupUi(self)
|
|
|
|
self.setWindowTitle("Select a Collection")
|
|
|
|
self.ui.collection_name_line.textChanged.connect(self.on_search_params_changed)
|
|
self.ui.presence_name_line.textChanged.connect(self.on_search_params_changed)
|
|
self.ui.presence_domain_line.textChanged.connect(self.on_search_params_changed)
|
|
self.ui.art_name_line.textChanged.connect(self.on_search_params_changed)
|
|
|
|
self.ui.create_collection_button.clicked.connect(self.on_create_collection_clicked)
|
|
self.ui.edit_collection_button.clicked.connect(self.on_edit_collection_clicked)
|
|
self.ui.delete_collection_button.clicked.connect(self.on_delete_collection_clicked)
|
|
|
|
def exec_(self, already_selected_collections: list) -> list:
|
|
self.curr_collections = already_selected_collections
|
|
self.on_search_params_changed()
|
|
if super(CollectionSelectDialog, self).exec_() == QtWidgets.QDialog.Rejected:
|
|
return None
|
|
|
|
logging.debug(f"Finished collection selection dialog! User chose collections: {self.curr_collections}")
|
|
return self.curr_collections
|
|
|
|
def set_collection_search_result(self, collections: list):
|
|
"""
|
|
Set the collections in the list
|
|
:param collections:
|
|
:return:
|
|
"""
|
|
item_model = QStandardItemModel(self.ui.collection_list)
|
|
|
|
self.__curr_searched_collections = list()
|
|
for collection in collections:
|
|
coll_id, coll_name, coll_desc, _, _, _, _ = collection
|
|
collection_string = f"#{coll_id}:{coll_name}"
|
|
self.__curr_searched_collections.append(collection)
|
|
|
|
item = QStandardItem(collection_string)
|
|
flags = Qt.ItemIsEnabled
|
|
flags |= Qt.ItemIsUserCheckable
|
|
item.setFlags(flags)
|
|
|
|
item.setData(Qt.Unchecked, Qt.CheckStateRole)
|
|
if self.curr_collections is not None and coll_id in [coll_id for coll_id, coll_name in self.curr_collections]:
|
|
item.setCheckState(Qt.Checked)
|
|
|
|
item_model.appendRow(item)
|
|
|
|
item_model.itemChanged.connect(self.on_collection_search_item_changed)
|
|
self.ui.collection_list.setModel(item_model)
|
|
|
|
# callback methods
|
|
|
|
def on_collection_search_item_changed(self, item: QStandardItem):
|
|
coll_id = int(item.text().split(":")[0].split("#")[1])
|
|
coll_name = item.text().split(":")[1]
|
|
|
|
if item.checkState() == Qt.Checked:
|
|
self.curr_collections.append((coll_id, coll_name))
|
|
else: # unchecked
|
|
self.curr_collections.remove((coll_id, coll_name))
|
|
self.set_collection_search_result(self.__curr_searched_collections) # unchecks previously checked collections
|
|
|
|
def on_search_params_changed(self):
|
|
coll_name = self.ui.collection_name_line.text()
|
|
pr_name = self.ui.presence_name_line.text()
|
|
pr_domain = self.ui.presence_domain_line.text()
|
|
art_title = self.ui.art_name_line.text()
|
|
|
|
result = self.parent.search_collections(collection_name=coll_name, presence_name=pr_name,
|
|
presence_domain=pr_domain,
|
|
art_name=art_title)
|
|
|
|
self.set_collection_search_result(result)
|
|
|
|
def on_create_collection_clicked(self):
|
|
logging.info("Clicked on create collection button!")
|
|
dialog = CollectionModDialog(self, edit_collection=True, db_connection=self.parent.main.db_connection)
|
|
collection_data = dialog.exec_()
|
|
if collection_data is None:
|
|
return
|
|
|
|
self.parent.create_collection(collection_data["name"],
|
|
collection_data["description"])
|
|
self.on_search_params_changed()
|
|
|
|
def on_edit_collection_clicked(self):
|
|
logging.info("Clicked on edit collection button!")
|
|
raise NotImplementedError # TODO
|
|
|
|
def on_delete_collection_clicked(self):
|
|
logging.info("Clicked on delete collection button!")
|
|
raise NotImplementedError # TODO
|