def _do_layout_(self): self._layout_buttons_() box = QVBoxLayout() box.setSpacing(0) box.addWidget(self.buttons_bar) box.addWidget(self.tree) self.setLayout(box)
def _do_layout_(self): box = QVBoxLayout() box.setSpacing(0) # box.setContentsMargins(0, 0, 0, 0) box.addWidget(self.buttons_bar) box.addWidget(self.list) self._layout_buttons_() self.setLayout(box)
class EditImageWindow(QMainWindow): on_saved = Signal() on_exit = Signal() editStyle = ''' QLineEdit { border-radius:10px; border: 1px solid gray; padding-left:5px; padding-right:5px} QLineEdit:focus { border: 1.5px solid lightblue; padding-left:5px; padding-right:5px} ''' def __init__(self, path): QMainWindow.__init__(self) self.path = path self.scene = ImageScene(imageUrl=path) self.view = ImageCanvas(self.scene) self.leftPanel = self.configureOverlyPanel(QWidget()) self.editLayout = QVBoxLayout() self.editLayout.setSpacing(0) self.leftPanel.setLayout(self.editLayout) self.leftPanel.setVisible(False) self.numberIter = 1 self.enabledOnSelection = [] self.do_layout() self.scene.selectionChanged.connect(self.update_enabled) self.scene.on_item_edit.connect(self.showProperties) def nextNumber(self): v = self.numberIter self.numberIter += 1 return v def update_enabled(self): sel = len(self.scene.selectedElements()) > 0 for button in self.enabledOnSelection: button.setEnabled(sel) def configureOverlyPanel(self, widget): widget.setStyleSheet(''' QWidget { background-color:white; border-radius:10px; } ''') # widget.setAutoFillBackground(True) # widget.setAttribute() from pyqode.qt.QtWidgets import QGraphicsDropShadowEffect effect = QGraphicsDropShadowEffect() effect.setBlurRadius(10) effect.setXOffset(0) effect.setYOffset(0) widget.setGraphicsEffect(effect) widget.setVisible(False) return widget def showProperties(self, item): for i in reversed(range(self.editLayout.count())): self.editLayout.itemAt(i).widget().setParent(None) self.leftPanel.setVisible(item is not None) if item is None: return # close = QPushButton('x') # close.clicked.connect(lambda: self.scene.emptyPress()) # l = QHBoxLayout() # l.addStretch(1) # l.addWidget(close) # w = QWidget() # w.setLayout(l) # self.editLayout.addWidget(w) from properties import PropertyWidget from widgets import horizontalSeparator, hoverActiveButton for p in item.properties(): rowW = PropertyWidget(item.properties(), p.name) rowW.edit.setStyleSheet(EditImageWindow.editStyle) rowW.edit.setMaximumWidth(80) self.editLayout.addWidget(rowW) if isinstance(item, RectSelectionItem): insetInput = QLineEdit() insetInput.setStyleSheet(EditImageWindow.editStyle) insetInput.setValidator(QIntValidator()) insetInput.setMaximumWidth(40) insetInput.setText('1') insetInput.setTextMargins(6, 0, 0, 0) rowLt = QHBoxLayout() bt = hoverActiveButton("Insert Insets") bt.clicked.connect( lambda: self.appendInsets(int(insetInput.text()), item)) rowLt.addWidget(insetInput) rowLt.addStretch(10) rowLt.addWidget(bt) panel = QWidget() panel.setLayout(rowLt) self.editLayout.addWidget(horizontalSeparator()) self.editLayout.addWidget(panel) def appendInsets(self, insets, item): p = item.pos() s = item.size item.setRect(p.x() - insets, p.y() - insets, s.width() + 2 * insets, s.height() + 2 * insets) 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 def do_layout(self): panel = QWidget() bar = self.layout_buttons() topBottom = QVBoxLayout() leftToRight = QHBoxLayout() leftToRight.addWidget(self.leftPanel) leftToRight.addStretch(10) topBottom.addStretch(1) topBottom.addLayout(leftToRight) topBottom.addStretch(1) self.view.setLayout(topBottom) lt = QVBoxLayout() lt.addWidget(bar) #lt.addLayout(leftToRight) lt.addWidget(self.view) panel.setLayout(lt) self.setCentralWidget(panel) def closeEvent(self, event): if len(self.scene.userItems) > 0: from pyqode.qt.QtWidgets import QMessageBox reply = QMessageBox.question(self, 'Save changes', "Do you want to save changes?", QMessageBox.Yes, QMessageBox.No) # QMessageBox.Cancel, if reply == QMessageBox.Yes: self.scene.renderToFile(self.path) self.on_saved.emit() elif reply == QMessageBox.Cancel: event.ignore() return self.on_exit.emit() event.accept()