Music-Library/dialogs.py
2024-04-15 13:21:43 +00:00

113 lines
3.8 KiB
Python

from PyQt6.QtWidgets import (
QApplication, QMainWindow, QLabel, QPushButton,
QWidget, QFrame, QSplitter, QStackedWidget, QListWidget, QListWidgetItem,
QGraphicsScene, QGraphicsView, QGraphicsPixmapItem,
QLayout, QScrollArea, QVBoxLayout, QHBoxLayout,
QDialog, QFileDialog
)
from PyQt6.QtCore import Qt
class SimpleHeader(QFrame):
def __init__(self, parent) -> None:
super().__init__(parent)
self.setObjectName("SimpleHeader")
self.setStyleSheet("#SimpleHeader { border: 1px solid #00000000; border-bottom-color: #444; }")
self.parent = parent
self.setFixedHeight(24)
self.label = QLabel("Simple Header", self)
self.label.move(12, 0)
self.label.resize( self.width() - 24, 24)
def resizeEvent(self, event):
self.label.resize( self.width() - 24, 24)
self.resize(self.parent.width(), 24 )
def setLabel(self, text):
self.label.setText(text)
class ErrorPopup(QDialog):
def __init__(self, parent, message, trace, CanIgnore=True, buttonLayout=0) -> None:
super().__init__(parent)
self.parent = parent
self.message = message
self.trace = trace
self.canTerminate = CanIgnore
self.setWindowTitle("Error")
self.setGeometry(000, 150, 600, 300)
# reset styles
# self.setStyleSheet("")
# self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)
self.setWindowModality(Qt.WindowModality.WindowModal)
self.header = SimpleHeader(self)
self.header.setLabel(self.message)
self.header.move(0, 0)
# self.label = QLabel(self.message, self)
# self.label.move(12, 0)
# self.label.resize( self.width() - 24, 24)
self.trace = QLabel(self.trace, self)
self.trace.move(12, 24)
self.trace.resize( self.width() - 24, 24)
match buttonLayout:
case 0:
pass
self.ignore = QPushButton(CanIgnore and "Ignore" or "Critical Error", self)
self.ignore.move(12, self.height() - 36)
self.ignore.resize( self.width() - 24, 24)
self.ignore.clicked.connect(self.close)
self.ignore.setDisabled(not CanIgnore)
self.btn_terminate = QPushButton("Terminate", self)
self.btn_terminate.move(12, self.height() - 60)
self.btn_terminate.resize( self.width() - 24, 24)
self.btn_terminate.clicked.connect(self.terminate)
def resizeEvent(self, event):
# self.move(int(self.parent.width()/2) - int(self.width()/2), int(self.parent.height()/2) - int(self.height()/2))
self.header.resize( self.width(), 24)
self.trace.resize( self.width() - 24, self.height() - 60)
self.ignore.move(12, self.height() - 36)
self.ignore.resize( int(self.width()/2) - 24, 24)
self.btn_terminate.move(int(self.width()/2) + 12, self.height() - 36)
self.btn_terminate.resize( int(self.width()/2) - 24, 24)
def close(self):
super().close()
def terminate(self):
self.parent.close()
super().close()
exit(1)
# on window close
def closeEvent(self, event):
if self.canTerminate:
self.close()
else:
self.terminate()
class ListDialog(QDialog):
def __init__(self, parent = None, dialogHeader = None, header = None, data = None):
super(ListDialog, self).__init__(parent)
self.setWindowTitle(dialogHeader)
layout = QVBoxLayout()
layout.addWidget(QLabel(header))
# scroll area
scroll = QScrollArea()
widget = QWidget()
widget.setLayout(QVBoxLayout())
layout.addWidget(scroll)
self.setLayout(layout)
for item in data:
widget.layout().addWidget(QLabel(item))
scroll.setWidget(widget)
self.exec()