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.
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
4 years ago
|
from PyQt5 import QtWidgets
|
||
|
from PyQt5.QtCore import Qt
|
||
|
from PyQt5.QtGui import QStandardItem, QStandardItemModel
|
||
|
|
||
|
from ArtNet.gui.dialogs.presence_selection_dialog.presence_selection_dialog import Ui_presence_selection_dialog
|
||
|
|
||
|
|
||
|
class PresenceSelectDialog(QtWidgets.QDialog):
|
||
|
|
||
|
def __init__(self, parent=None):
|
||
|
super().__init__(parent)
|
||
|
self.parent = parent
|
||
|
self.ui = Ui_presence_selection_dialog()
|
||
|
self.ui.setupUi(self)
|
||
|
|
||
|
self.__curr_presence: list = None
|
||
|
self.__curr_search_result: list = None
|
||
|
|
||
|
self.ui.presence_name_search_line.textChanged.connect(self.on_search_change)
|
||
|
self.ui.presence_domain_search_line.textChanged.connect(self.on_search_change)
|
||
|
|
||
|
def set_search_result_list(self, result: list):
|
||
|
self.__curr_search_result = result
|
||
|
item_model = QStandardItemModel(self.ui.presence_search_list)
|
||
|
|
||
|
for presence in result:
|
||
|
item = QStandardItem(presence)
|
||
|
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
|
||
|
item.setData(Qt.Unchecked, Qt.CheckStateRole)
|
||
|
|
||
|
if self.__curr_presence is not None:
|
||
|
curr_presence = self.__curr_presence[0] + ":" + self.__curr_presence[1]
|
||
|
if presence == curr_presence:
|
||
|
item.setCheckState(Qt.Checked)
|
||
|
|
||
|
item_model.appendRow(item)
|
||
|
|
||
|
item_model.itemChanged.connect(self.on_search_presence_item_changed)
|
||
|
self.ui.presence_search_list.setModel(item_model)
|
||
|
|
||
|
def on_search_change(self):
|
||
|
name = self.ui.presence_name_search_line.text()
|
||
|
domain = self.ui.presence_domain_search_line.text()
|
||
|
|
||
|
if len(name) == 0 and len(domain) == 0: # nothing to search for
|
||
|
self.set_search_result_list([])
|
||
|
return
|
||
|
presences = self.parent.parent.get_authors(name, domain)
|
||
|
|
||
|
result = []
|
||
|
for ID, desc in presences:
|
||
|
result.append(ID+":"+desc)
|
||
|
|
||
|
self.set_search_result_list(result)
|
||
|
|
||
|
def on_search_presence_item_changed(self, item: QStandardItem):
|
||
|
name, domain = item.text().split(":")
|
||
|
if item.checkState() == Qt.Checked:
|
||
|
self.__curr_presence = self.parent.parent.get_presence(name, domain)
|
||
|
if self.__curr_presence is not None:
|
||
|
self.__curr_presence = self.__curr_presence[0] # unpack from list
|
||
|
elif item.checkState() == Qt.Unchecked:
|
||
|
self.__curr_presence = None
|
||
|
self.set_search_result_list(self.__curr_search_result)
|
||
|
|
||
|
def exec_(self) -> list:
|
||
|
if super(PresenceSelectDialog, self).exec_() == QtWidgets.QDialog.Rejected:
|
||
|
return None
|
||
|
|
||
|
return self.__curr_presence
|