def __init__(self, parent, session): QDialog.__init__(self, parent) self.setStyleSheet(''' QToolButton { border: 1px solid rgb(51, 122, 183); border-radius:5px; background:rgb(222, 222, 222); outline:0px; padding:10px; width: 80px; } QToolButton:hover { background:transparent; background:rgb(51, 122, 183); color:white} QToolButton:pressed { background:rgb(41, 100, 153); color:white } QToolButton:checked { background:rgb(41, 100, 153); color:white } ''') self.setWindowTitle('Choose Template') self.boxLt = QHBoxLayout() self.boxLt.setSpacing(20) self.buttons = {} self.selected = None nameLt = QHBoxLayout() self.nameInput = QLineEdit() self.nameInput.setValidator(FileExistValidator(session)) nameLt.addWidget(QLabel('File Name')) nameLt.addSpacing(10) nameLt.addWidget(self.nameInput) self.errorLabel = QLabel('File already exists, change name') self.errorLabel.setStyleSheet('color:red; font-size:8pt') self.errorLabel.hide() self.create = QPushButton('Create') self.create.setEnabled(False) self.create.clicked.connect(self.processCreation) blt = QHBoxLayout() blt.addStretch(0) blt.addWidget(self.create) lt = QVBoxLayout() lt.addLayout(nameLt) lt.addWidget(self.errorLabel) lt.addSpacing(20) lt.addLayout(self.boxLt) lt.addSpacing(20) lt.addLayout(blt) lt.setContentsMargins(50, 50, 50, 50) self.setLayout(lt) self.template_selected.connect(self.validateCreate) self.nameInput.textChanged.connect(self.validateCreate)
def layout_buttons(self): import icons panel = QWidget() panel.setObjectName('buttons-bar') add_rect = QPushButton() add_rect.setIcon(icons.get('rectangle')) add_rect.setToolTip('Add Rectangle') add_rect.clicked.connect(self.scene.addRectElement) add_ellipse = QPushButton() add_ellipse.setIcon(icons.get('ellipse')) add_ellipse.setToolTip('Add Ellipse') add_ellipse.clicked.connect(self.scene.addEllipseElement) add_number = QPushButton() add_number.setToolTip('Add number') add_number.setIcon(icons.get('add_number')) add_number.clicked.connect(lambda: self.scene.addNumberElement(self)) add_numbered_rect = QPushButton() add_numbered_rect.setToolTip('Add numbered rectangle') add_numbered_rect.setIcon(icons.get('add_numbered_rect')) add_numbered_rect.clicked.connect( lambda: self.scene.addNumberedRectElement(self)) duplicate_button = QPushButton() duplicate_button.setToolTip('Duplicate') duplicate_button.setIcon(icons.get('duplicate')) duplicate_button.setEnabled(False) duplicate_button.clicked.connect( lambda: self.scene.duplicateSelection()) self.enabledOnSelection.append(duplicate_button) delete_button = QPushButton() delete_button.setToolTip('Delete') delete_button.setIcon(self.style().standardIcon(QStyle.SP_TrashIcon)) delete_button.setEnabled(False) delete_button.clicked.connect(lambda: self.scene.deleteSelected()) self.enabledOnSelection.append(delete_button) spacing = QLineEdit() spacing.setText(str(self.scene.posConstraint.spacing)) spacing.setValidator(QIntValidator(bottom=0)) spacing.returnPressed.connect( lambda: self.scene.setSpacing(int(spacing.text()))) spacing.setMaximumWidth(30) xshift = QSpinBox() xshift.setValue(self.scene.posConstraint.xShift) xshift.valueChanged.connect(lambda v: self.scene.setXGridShift(v)) yshift = QSpinBox() yshift.setValue(self.scene.posConstraint.yShift) yshift.valueChanged.connect(lambda v: self.scene.setYGridShift(v)) lt = QHBoxLayout() lt.addWidget(add_rect) lt.addWidget(add_ellipse) lt.addWidget(add_number) lt.addWidget(add_numbered_rect) lt.addSpacing(20) lt.addWidget(duplicate_button) lt.addSpacing(20) lt.addWidget(delete_button) lt.addStretch() lt.addWidget(QLabel('Grid Spacing')) lt.addWidget(spacing) lt.addWidget(QLabel('X Grid Shift')) lt.addWidget(xshift) lt.addWidget(QLabel('Y Grid Shift')) lt.addWidget(yshift) panel.setLayout(lt) return panel