from PyQt5 import QtWidgets from PyQt5.QtCore import Qt from ArtNet.gui.dialogs.artist_modify_dialog.artist_modify_dialog import Ui_Artist_Mod_Dialog class ArtistModDialog(QtWidgets.QDialog): def __init__(self, parent=None, create_artist: bool = False): super().__init__(parent) self.parent = parent self.ui = Ui_Artist_Mod_Dialog() self.ui.setupUi(self) self.data = {"id": None, "description": None} if not create_artist: self.set_available_artists(self.parent.parent.parent.get_all_artists()) else: self.ui.id_list = QtWidgets.QLineEdit(self) self.ui.id_spinbox.setParent(None) self.ui.id_spinbox.destroy() self.ui.id_layout.addWidget(self.ui.id_list) self.ui.description_line.textChanged.connect(self.on_description_changed) def set_available_artists(self, artists: list): if artists is None: self.ui.id_spinbox.setParent(None) self.ui.id_spinbox.destroy() self.ui.id_label.setText("Artist ID (auto-generated)") return self.ui.id_spinbox.setMinimum(0) self.ui.id_spinbox.setMaximum(len(artists)) self.ui.id_spinbox.valueChanged.connect(self.on_id_spinbox_changed) def on_id_spinbox_changed(self): id = self.ui.id_spinbox.value() artist = self.parent.parent.parent.get_artist(id) if len(artist) != 0: self.ui.description_line.setText(artist[0][1]) else: self.ui.description_line.setText("Warning! unknown Artist ID!") self.data["id"] = id def on_description_changed(self): self.data["description"] = self.ui.description_line.text() def exec_(self): result = super(ArtistModDialog, self).exec_() if result == QtWidgets.QDialog.Rejected: return None return self.data