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.

147 lines
6.0 KiB
Python

from PyQt5 import QtWidgets
from PyQt5.QtGui import QStandardItem, QStandardItemModel
from PyQt5.QtCore import Qt
from ArtNet.gui.dockers.presence.presence_docker import Ui_presence_docker
from ArtNet.gui.dialogs.presence_modify_dialog.presence_mod_dialog import PresenceModDialog
from ArtNet.gui.dialogs.presence_selection_dialog.presence_select_dialog import PresenceSelectDialog
class PresenceDocker(QtWidgets.QFrame):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
self.ui = Ui_presence_docker()
self.ui.setupUi(self)
self.ui.name_line.textChanged.connect(self.on_search_bar_change)
self.ui.domain_line.textChanged.connect(self.on_search_bar_change)
self.ui.create_presence_button.clicked.connect(self.on_create_presence_clicked)
self.ui.edit_presence_button.clicked.connect(self.on_edit_presence_clicked)
self.ui.delete_presence_button.clicked.connect(self.on_delete_presence_clicked)
self.on_search_bar_change()
def set_presence_list(self, presences: list):
item_model = QStandardItemModel(self.ui.search_author_list)
for name, domain in presences:
item = QStandardItem(name+":"+domain)
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole)
item_model.appendRow(item)
if (name, domain) in self.parent.get_current_presences():
item.setCheckState(Qt.Checked)
item_model.itemChanged.connect(self.on_presence_item_change)
self.ui.search_author_list.setModel(item_model)
def set_selected_presences_list(self, presences: list):
item_model = QStandardItemModel(self.ui.selected_presence_list)
for name, domain in presences:
item = QStandardItem(name + ":" + domain)
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
item.setData(Qt.Unchecked, Qt.CheckStateRole)
if domain == "(Not in Database)":
continue
item_model.appendRow(item)
if (name, domain) in self.parent.get_current_presences():
item.setCheckState(Qt.Checked)
item_model.itemChanged.connect(self.on_selected_presence_item_change)
self.ui.selected_presence_list.setModel(item_model)
def on_search_bar_change(self):
authors = self.parent.get_authors(self.ui.name_line.text(), self.ui.domain_line.text())
self.set_presence_list(authors)
def on_presence_item_change(self, item: QStandardItem):
if item.checkState() == Qt.Checked:
s = item.text().split(":")
s = (s[0], s[1])
if self.parent.get_current_presences() is None:
self.parent.set_current_presences([s])
self.set_selected_presences_list([s])
else:
self.parent.set_current_presences(self.parent.get_current_presences() + [s])
self.set_selected_presences_list(self.parent.get_current_presences())
elif item.checkState() == Qt.Unchecked:
presences = self.parent.get_current_presences()
if presences is None:
return
s = item.text().split(":")
s = (s[0], s[1])
presences.remove(s)
self.parent.set_current_presences(presences)
self.set_selected_presences_list(presences)
def on_selected_presence_item_change(self, item: QStandardItem):
item_presence = item.text().split(":")
item_presence = (item_presence[0], item_presence[1])
if item.checkState() == Qt.Unchecked:
presences = self.parent.get_current_presences()
presences.remove(item_presence)
self.parent.set_current_presences(presences)
self.set_selected_presences_list(presences)
self.on_search_bar_change()
def on_create_presence_clicked(self):
dialog = PresenceModDialog(self, edit_presence=False)
data = dialog.exec_()
if data is None: # canceled?
self.on_search_bar_change()
return
self.parent.create_presence(name=data["name"], domain=data["domain"], artist=data["artist"],
link=data["link"])
self.on_search_bar_change()
def on_edit_presence_clicked(self):
select_dialog = PresenceSelectDialog(self)
selected_presence = select_dialog.exec_()
if selected_presence is None:
return
dialog = PresenceModDialog(self, edit_presence=True)
dialog.ui.presence_name_line.setText(selected_presence[0])
dialog.ui.presence_domain_line.setText(selected_presence[1])
if len(selected_presence) > 2:
if len(selected_presence) >= 4:
if selected_presence[3] is not None:
dialog.ui.presence_link_list.setText(selected_presence[3])
artist = self.parent.get_artists(selected_presence[2])[0]
dialog.curr_artist = artist
dialog.set_artist_selected_list(dialog.curr_artist)
data = dialog.exec_()
if data is None:
self.on_search_bar_change()
return
self.parent.create_presence(name=data["name"], domain=data["domain"], artist=data["artist"], link=data["link"])
self.parent.set_temporary_status_message("Saved Presence {0}:{1} Artist:{2} link:{3} to DB!"
.format(data["name"], data["domain"], data["artist"], data["link"]),
3000)
self.on_search_bar_change()
def on_delete_presence_clicked(self):
print("Clicked delete presence button!")
select_dialog = PresenceSelectDialog(self)
selected_presence = select_dialog.exec_()
if selected_presence is None:
self.on_search_bar_change()
return
self.parent.remove_presence(selected_presence[0], selected_presence[1])
self.on_search_bar_change()