100 lines
3.0 KiB
Python
100 lines
3.0 KiB
Python
import traceback
|
|
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.QtGui import QPixmap
|
|
from PyQt6.QtCore import Qt, QAbstractListModel
|
|
|
|
from dialogs import ErrorPopup, ListDialog
|
|
|
|
import os, sys, json
|
|
|
|
# settings widgets
|
|
|
|
class SettingBox(QFrame):
|
|
def __init__(self, parent, name, description = None):
|
|
super().__init__(parent)
|
|
self.setObjectName("settingbox")
|
|
self.name = name
|
|
|
|
self.layout = QVBoxLayout()
|
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
|
self.setLayout(self.layout)
|
|
|
|
self.label = QLabel(name, self)
|
|
self.label.setObjectName("settinglabel")
|
|
self.layout.addWidget(self.label)
|
|
|
|
if description:
|
|
self.description = QLabel(description, self)
|
|
self.layout.addWidget(self.description)
|
|
|
|
def AddSetting(self, setting):
|
|
self.layout.addWidget(setting)
|
|
|
|
class SettingButton(QFrame):
|
|
def __init__(self, parent, text, description = None):
|
|
super().__init__(parent)
|
|
self.setObjectName("settingbutton")
|
|
self.description = None
|
|
|
|
self.layout = QHBoxLayout()
|
|
self.layout.setContentsMargins(0, 0, 0, 0)
|
|
self.setLayout(self.layout)
|
|
|
|
self.button = QPushButton("Button", self)
|
|
self.layout.addWidget(self.button)
|
|
self.button.setFixedWidth(100)
|
|
|
|
self.setting_info_base = QWidget()
|
|
self.setting_info = QVBoxLayout(self.setting_info_base)
|
|
self.setting_info.setContentsMargins(0, 0, 0, 0)
|
|
self.layout.addWidget(self.setting_info_base)
|
|
|
|
self.label = QLabel(text, self)
|
|
self.label.setObjectName("settinglabel")
|
|
self.setting_info.addWidget(self.label)
|
|
|
|
if description:
|
|
self.description = QLabel(description, self)
|
|
self.setting_info.addWidget(self.description)
|
|
|
|
def SetText(self, text):
|
|
self.label.setText(text)
|
|
|
|
def SetDescription(self, text):
|
|
# check the type of the description
|
|
if type(text) == bool:
|
|
text = str(text)
|
|
if type(text) == list:
|
|
text = "\n".join(text)
|
|
if type(text) == dict:
|
|
text = json.dumps(text, indent=4)
|
|
if type(text) == traceback.FrameSummary:
|
|
text = traceback.format_tb(text)
|
|
|
|
if not self.description:
|
|
self.description = QLabel(text, self)
|
|
self.setting_info.addWidget(self.description)
|
|
|
|
if self.description:
|
|
self.description.setText(text)
|
|
|
|
def GetButton(self):
|
|
return self.button
|
|
|
|
def SetButtonText(self, text):
|
|
self.button.setText(text)
|
|
|
|
def SetButtonPressed(self, func):
|
|
self.button.clicked.connect(func)
|
|
|
|
def SetButtonWidth(self, width):
|
|
self.button.setFixedWidth(width)
|