from PyQt5.QtWidgets import QVBoxLayout, QWidget, QSizePolicy, QGroupBox, QSpinBox, QHBoxLayout, QLineEdit, QComboBox, \ QPushButton from utils import MODULES class VLayout(QVBoxLayout): def __init__(self, margin=3, spacing=3): super().__init__() if isinstance(margin, int): self.setContentsMargins(margin, margin, margin, margin) elif isinstance(margin, list): self.setContentsMargins(margin[0], margin[1], margin[2], margin[3]) self.setSpacing(spacing) def addWidgets(self, widgets): for w in widgets: self.addWidget(w) def addSpacer(self): spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.addWidget(spacer) class HLayout(QHBoxLayout): def __init__(self, margin=3, spacing=3): super().__init__() if isinstance(margin, int): self.setContentsMargins(margin, margin, margin, margin) elif isinstance(margin, list): self.setContentsMargins(margin[0], margin[1], margin[2], margin[3]) self.setSpacing(spacing) def addWidgets(self, widgets): for w in widgets: self.addWidget(w) def addSpacer(self): spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.addWidget(spacer) class GroupBoxV(QGroupBox): def __init__(self, title, margin=3, spacing=3, *args, **kwargs): super(GroupBoxV, self).__init__(*args, **kwargs) self.setTitle(title) layout = VLayout() layout.setSpacing(spacing) if isinstance(margin, int): layout.setContentsMargins(margin, margin, margin, margin) elif isinstance(margin, list): layout.setContentsMargins(margin[0], margin[1], margin[2], margin[3]) self.setLayout(layout) def addWidget(self, w): self.layout().addWidget(w) def addWidgets(self, widgets): for w in widgets: self.layout().addWidget(w) def addLayout(self, w): self.layout().addLayout(w) class GroupBoxH(QGroupBox): def __init__(self, title, margin=None, spacing=None, *args, **kwargs): super(GroupBoxH, self).__init__(title) self.setLayout(HLayout()) def addWidget(self, w): self.layout().addWidget(w) def addWidgets(self, widgets): for w in widgets: self.layout().addWidget(w) def addLayout(self, w): self.layout().addLayout(w) class SpinBox(QSpinBox): def __init__(self, *args, **kwargs): super(SpinBox, self).__init__(*args, **kwargs) self.setButtonSymbols(self.NoButtons) self.setMinimum(kwargs.get('minimum', 1)) self.setMaximum(kwargs.get('maximum', 65535)) class Password(QLineEdit): def __init__(self): super(Password, self).__init__() self.setEchoMode(QLineEdit.Password) class Modules(QComboBox): def __init__(self): super(Modules, self).__init__() for id, name in MODULES.items(): self.addItem(name, id) class TemplateComboBox(QComboBox): def __init__(self): super(TemplateComboBox, self).__init__() self.setEditable(True) class ActionButton(QPushButton): def __init__(self, label, color): super(ActionButton, self).__init__(label) self.setMinimumHeight(50) self.setStyleSheet(f'background-color: {color};') self.setSizePolicy(QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed))