def __init__(self, label="Color:", initialRgbColor=None, initialRgbColorF=None, contentsMargins=(0, 0, 0, 0), parent=None, labelWeight=1, colorWeight=1, colorWidth=None): """Initialize variables :param label: The name of the label, usually "Color:" :type label: str :param initialRgbColor: The initial rgb color in 0-255 ranges, overridden if there's a initialRgbColorF value :type initialRgbColor: tuple :param initialRgbColorF: The initial rgb color in 0-1.0 ranges, if None defaults to initialRgbColor values :type initialRgbColorF: tuple :param parent: the widget parent :type parent: class """ super(labelColorBtn, self).__init__(parent=parent) self.layout = HBoxLayout(parent=None, margins=utils.marginsDpiScale(*contentsMargins), spacing=utils.dpiScale(uiconstants.SPACING)) self.layout.addWidget(QtWidgets.QLabel(label, parent=self), labelWeight) self.colorPickerBtn = QtWidgets.QPushButton("", parent=self) # use initialRgbColor (255 range) or initialRgbColorF (float range 0-1) # if no color given then default to red self.storedRgbColor = initialRgbColor or tuple([i * 255 for i in initialRgbColorF]) or tuple([255, 0, 0]) self.colorPickerBtn.setStyleSheet("background-color: rgb{}".format(str(self.storedRgbColor))) if colorWidth: self.colorPickerBtn.setFixedWidth(colorWidth) self.layout.addWidget(self.colorPickerBtn, colorWeight) self.setLayout(self.layout) self.connections()
def __init__(self, parent=None): super(ArrayAttributeView, self).__init__(parent) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) sliceLayout = QtWidgets.QHBoxLayout() layout.addLayout(sliceLayout) sliceLayout.addWidget(QtWidgets.QLabel("Slice:")) self._lineEdit = _SliceLineEdit() self._lineEdit.setPlaceholderText('e.g.: "0:5000", "::-1"') sliceLayout.addWidget(self._lineEdit) self._arrayAttrModel = _ArrayAttributeModel() self._listView = QtWidgets.QListView() self._listView.setUniformItemSizes(True) self._listView.setViewMode(QtWidgets.QListView.ListMode) self._listView.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self._listView.setModel(self._arrayAttrModel) layout.addWidget(self._listView) self._lineEdit.SliceChanged.connect(self._arrayAttrModel.SetSlice) self._SetupContextMenu()
def buildTitleFrame(self): """Builds the title part of the layout with a QFrame widget """ # main dark grey qframe self.titleFrame = frame.QFrame(parent=self) self.setFrameColor(self.color) self.titleFrame.setContentsMargins(4, 0, 4, 0) # the horizontal layout self.horizontalLayout = QtWidgets.QHBoxLayout(self.titleFrame) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) # the icon and title and spacer self.iconButton = QtWidgets.QToolButton(parent=self) if self.collapsed: self.iconButton.setIcon(self._collapsedIcon) else: self.iconButton.setIcon(self._expandIcon) self.titleLabel = QtWidgets.QLabel(self.title, parent=self) self.titleLabel.setStyleSheet("font: bold;") self.titleLabel.setContentsMargins(0, 0, 0, 0) spacerItem = QtWidgets.QSpacerItem(10, 10, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) # add to horizontal layout self.horizontalLayout.addWidget(self.iconButton) self.horizontalLayout.addWidget(self.titleLabel) self.horizontalLayout.addItem(spacerItem) self.titleFrame.setFixedHeight(self.titleFrame.sizeHint().height()) self.setMinimumSize(self.titleFrame.sizeHint().width(), self.titleFrame.sizeHint().height())
def __init__(self, label, matrix, min, max, parent=None): """ :param label: the matrix widget label :type label: str :param matrix: a list of lists the lenght of each nested list is equal to the column length of the matrix for example if we're dealing with a 4x4 matrix then its a length of 4, 3x3 is 3 etc :type matrix: list(list(float)) :param: min: a list of floats, each float is min for each vector :type min: list(float) :param: max: a list of floats, each float is max for each vector :type max: list(float) :param parent: :type parent: """ super(Matrix, self).__init__(parent=parent) self.mainLayout = QtWidgets.QGridLayout(self) self.mainLayout.setContentsMargins(2, 2, 2, 2) self.mainLayout.setSpacing(uiconstants.SPACING) self.label = QtWidgets.QLabel(label, parent=self) spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) self.mainLayout.addWidget(self.label, 0, 0) self.mainLayout.addItem(spacerItem, 1, 0) self._widgets = OrderedDict() axislabels = ("X", "Y", "Z") for i, c in enumerate(matrix): vec = VectorSpinBox(label="", value=c, min=min[i], max=max[i], axis=axislabels, parent=self) self.mainLayout.addWidget(vec, i, 1) self._widgets[i] = vec self.setLayout(self.mainLayout)
def _initUi(self): self.mainLayout = QtWidgets.QVBoxLayout() self.setLayout(self.mainLayout) topSpacer = QtWidgets.QSpacerItem(20, 52, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) bottomSpacer = QtWidgets.QSpacerItem(20, 52, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) leftSpacer = QtWidgets.QSpacerItem(20, 52, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) rightSpacer = QtWidgets.QSpacerItem(20, 52, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) # label to hold the thumbnail image self.imageLabel = QtWidgets.QLabel(parent=self) self.imageLabel.hide() # camera icon self.iconLayout = QtWidgets.QHBoxLayout() self.cameraBtn = _CameraButton(parent=self) self.iconLayout.addItem(leftSpacer) self.iconLayout.addWidget(self.cameraBtn) self.iconLayout.addItem(rightSpacer) # add the items self.mainLayout.addItem(topSpacer) self.mainLayout.addLayout(self.iconLayout) self.mainLayout.addItem(bottomSpacer) self.cameraBtn.clicked.connect(self.onCameraButtonClicked)
def _initUi(self): parent = self.parent() self.frame = QtWidgets.QFrame(parent) self.iconWidget = QtWidgets.QLabel(parent) self.iconWidget.setFixedWidth(29) self.label = _ExtendedQLabel(self._label, parent) self.optionBox = QtWidgets.QToolButton(parent) self.iconWidget.setFixedWidth(29) self.label.clicked.connect(self.triggered.emit) self.optionBox.clicked.connect(self.optionBoxTriggered.emit)
def vlineEdit(labelName, parent, enabled=True): layout = QtWidgets.QVBoxLayout() label = QtWidgets.QLabel(labelName, parent=parent) edit = QtWidgets.QLineEdit(parent=parent) edit.setEnabled(enabled) layout.addWidget(label) layout.addWidget(edit) layout.setContentsMargins(2, 2, 2, 2) layout.setSpacing(1) return label, edit, layout
def addLabelFromConstructed(self): """Add a label with the current text in constructed. """ label = QtWidgets.QLabel(self.constructed) label.setOpenExternalLinks(True) label.setWordWrap(True) label.setFont(self.font) self.constructed = "" self._widgets.append(label)
def __init__(self, label, widget, parent=None): super(AttributeItemWidget, self).__init__(parent=parent) layout = QtWidgets.QFormLayout() layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) label = QtWidgets.QLabel(label, parent=self) widget.setParent(self) layout.addWidget(label) layout.addWidget(widget) self.setLayout(layout)
def _setupFilter(self): self.searchBoxLabel = QtWidgets.QLabel("Search By: ", parent=self) self.searchHeaderBox = QtWidgets.QComboBox(parent=self) self.refreshBtn = QtWidgets.QToolButton(parent=self) self.refreshBtn.setIcon(iconlib.icon("reload")) self.searchFrame = QtWidgets.QFrame(parent=self) self.searchFrame.setFrameShape(QtWidgets.QFrame.NoFrame) self.searchFrame.setFrameShadow(QtWidgets.QFrame.Plain) self.searchLayout = QtWidgets.QHBoxLayout(self) self.searchLayout.setContentsMargins(2, 2, 2, 2) self.searchClearBtn = QtWidgets.QPushButton("Clear", parent=self) self.searchLabel = QtWidgets.QLabel("Search", parent=self) self.searchEdit = QtWidgets.QLineEdit(self) self.searchFrame.setLayout(self.searchLayout) self.searchLayout.addWidget(self.refreshBtn) self.searchLayout.addWidget(self.searchBoxLabel) self.searchLayout.addWidget(self.searchHeaderBox) self.searchLayout.addWidget(self.searchLabel) self.searchLayout.addWidget(self.searchEdit) self.searchLayout.addWidget(self.searchClearBtn) self.mainLayout.addWidget(self.searchFrame)
def __init__(self, label="", parent=None): """ :type parent: QtWidgets.QMenu """ QtWidgets.QWidgetAction.__init__(self, parent) self.widget = frame.QFrame(parent) self.label = QtWidgets.QLabel(label, self.widget) self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self.widget) self._slider.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.valueChanged = self._slider.valueChanged
def Label(name, parent, toolTip=""): """One liner for labels and tooltip :param name: name of the text label :type name: str :param parent: the qt parent :type parent: class :param toolTip: the tool tip message on mouse over hover, extra info :type toolTip: str :return lbl: the QT QLabel widget :rtype lbl: QWidget.QLabel """ lbl = QtWidgets.QLabel(name, parent=parent) lbl.setToolTip(toolTip) return lbl
def __init__(self, label, value, min, max, axis, parent=None, step=0.1, setDecimals=2): """Creates a double spinbox for axis and lays them out in a horizontal layout We give access to each spinbox with a property eg. self.x which returns the float value :param label: the label for the vector eg. translate, if the label is None or "" then it will be excluded :type label: str :param value: n floats corresponding with axis param :type value: tuple(float) :param min: the min value for all three elements of the vector :type min: float :param max: the max value for all three elements of the vector :type max: float :param axis: every axis which will have a doubleSpinBox eg. [X,Y,Z] or [X,Y,Z,W] :type axis: list :param parent: the widget parent :type parent: QtWidget :param step: the step amount while clicking on the spin box or keyboard up/down :type step: float """ super(VectorSpinBox, self).__init__(parent=parent) self.mainLayout = HBoxLayout(parent, (2, 2, 2, 2), uiconstants.SREG) if label: self.label = QtWidgets.QLabel(label, parent=self) self.mainLayout.addWidget(self.label) self._widgets = OrderedDict() # todo: STYLESHEET needs to be in stylesheet and prefs # rgb(27, 27, 27) is the QLineEdit/QDoubleSpinBox color # images will need to be added and tweaked for hover states and press borderSize = utils.dpiScale(3) styleSheet = "QDoubleSpinBox {0} border: {2}px solid rgb(27, 27, 27); " \ "border-radius: 0px; {1}".format("{", "}", borderSize) for i, v in enumerate(axis): box = QtWidgets.QDoubleSpinBox(self) box.setSingleStep(step) box.setObjectName("".join([label, v])) box.setRange(min, max) box.setValue(value[i]) box.setDecimals(setDecimals) box.valueChanged.connect(self.onValueChanged) box.setStyleSheet(styleSheet) self._widgets[v] = box self.mainLayout.addWidget(box) self.setLayout(self.mainLayout)
def __init__(self, widget, width=450, height=50, iconSize=40, parent=None, showOnInitialize=False, stylesheet="", popupRelease=QtCore.Qt.Key_Control, showAtCursor=True): super(ExpandedTooltipPopup, self).__init__(None, width, height, "", parent, showOnInitialize) self.layout = QtWidgets.QVBoxLayout(self) self.font = QtGui.QFont("sans") self.titleFont = QtGui.QFont("sans") # Maybe should link this with the stylesheets self.iconColour = self.ETT_ICONCOLOUR self.themeColour = self.ETT_THEMECOLOUR self.linkColour = self.ETT_LINKCOLOUR self.popupKey = popupRelease self.iconSize = iconSize self.frameLayout = QtWidgets.QVBoxLayout() self.titleLayout = QtWidgets.QHBoxLayout() self.frame = QtWidgets.QFrame(self) self.titleLabel = QtWidgets.QLabel(self) self.tooltipIcon = None # type: QtCore.QIcon self.widget = widget if stylesheet != "": self.setStyleSheet(stylesheet) self.initUi() self.show() if showAtCursor: self.move(QtGui.QCursor.pos()) self.setStyle(self.style())
def initUi(self): compStackToolbarLayout = QtWidgets.QHBoxLayout() compStackToolbarLayout.addWidget(self.stackSearchEdit) # Toolbar buttons self.expandBtn.setIcon(self._expandIcon) self.expandBtn.setIconSize(QtCore.QSize(12, 12)) self.collapseBtn.setIcon(self._collapseIcon) self.collapseBtn.setIconSize(QtCore.QSize(10, 10)) size = QtCore.QSize(self.collapseBtn.sizeHint().width(), 20) # Temporary size till we get icons here self.collapseBtn.setFixedSize(size) self.expandBtn.setFixedSize(size) # Add buttons and search to toolbar compStackToolbarLayout.addSpacing(1) compStackToolbarLayout.addWidget(self.collapseBtn) compStackToolbarLayout.addWidget(self.expandBtn) compStackToolbarLayout.setStretchFactor(self.stackSearchEdit, 1) compStackToolbarLayout.setContentsMargins(0, 0, 0, 0) compStackToolbarLayout.setSpacing(1) compStackToolbar = QtWidgets.QWidget(parent=self) compStackToolbar.setLayout(compStackToolbarLayout) mainLayout = QtWidgets.QVBoxLayout() if self.text != "": mainLayout.addWidget(QtWidgets.QLabel(self.text)) if not self.showToolbar: compStackToolbar.hide() mainLayout.addWidget(compStackToolbar) mainLayout.addWidget(self.stackTableWgt) self.setLayout(mainLayout)
def __init__(self, label, value, axis=("x", "y", "z"), parent=None, toolTip="", inputMode="float", labelRatio=1, editRatio=1, spacing=uiconstants.SREG): """A label with multiple QLineEdits (text boxes), no spin boxes usually for x y z numeric input use inputMode="float" to restrict the data entry to decimal numbers :param label: the label for the vector eg. translate, if the label is None or "" then it will be excluded :type label: str :param value: n floats corresponding with axis param :type value: tuple(float) :param axis: every axis which will have a doubleSpinBox eg. ("x", "y", "z") or ("x", "y", "z", "w") :type axis: tuple(str) :param parent: the widget parent :type parent: QtWidget :param inputMode: restrict the user to this data entry, "string" text, "float" decimal or "int" no decimal :type inputMode: str :param labelRatio: the width ratio of the label/edit boxes, the "label" ratio when compared to the "edit boxes" :type labelRatio: int :param editRatio: the width ratio of the label/edit boxes, the "edit boxes" ratio when compared to the label :type editRatio: int :param spacing: the spacing of each widget :type spacing: int """ super(VectorLineEdit, self).__init__(parent=parent) self.mainLayout = HBoxLayout(parent, (0, 0, 0, 0), spacing) if label: self.label = QtWidgets.QLabel(label, parent=self) self.mainLayout.addWidget(self.label, labelRatio) self._widgets = OrderedDict() vectorEditLayout = HBoxLayout(parent, (0, 0, 0, 0), spacing) for i, v in enumerate(axis): edit = LineEdit(value[i], False, parent, toolTip, inputMode=inputMode) edit.setObjectName("".join([label, v])) edit.textChanged.connect(self._onTextChanged) self._widgets[v] = edit vectorEditLayout.addWidget(edit) self.mainLayout.addLayout(vectorEditLayout, editRatio) self.setLayout(self.mainLayout)
def create(self, parent=None): uiData = self.command.uiData self.item = QtWidgets.QWidgetAction(parent) text = uiData.get("label", "NOLABEL") actionLabel = QtWidgets.QLabel(text) self.item.setDefaultWidget(actionLabel) color = uiData.get("color", "") backColor = uiData.get("backgroundColor", "") if color or backColor: actionLabel.setStyleSheet( "QLabel {background-color: %s; color: %s;}" % (backColor, color)) icon = uiData.get("icon") if icon: if isinstance(icon, QtGui.QIcon): self.item.setIcon(icon) else: icon = iconlib.icon(icon) if not icon.isNull(): self.item.setIcon(icon) self.item.setStatusTip(uiData.get("tooltip")) self.item.triggered.connect(partial(self.triggered.emit, self.command.id)) logger.debug("Added commandAction, {}".format(text)) return self.item
QtGui.QKeySequence("F3"), e).activated.connect(lambda: e.calltipShow(0, "test(foo, bar)")) QtWidgets.QShortcut(QtGui.QKeySequence("Shift+Tab"), e).activated.connect(e.dedentSelection) # Shift + Tab # TODO: somehow these shortcuts don't work in this test-app, but they do in # pyzo. May have something to do with overriding slots of Qt-native objects? QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+C"), e).activated.connect(e.copy) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+X"), e).activated.connect(e.cut) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+V"), e).activated.connect(e.paste) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Shift+V"), e).activated.connect(e.pasteAndSelect) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Z"), e).activated.connect(e.undo) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Y"), e).activated.connect(e.redo) e.setPlainText("foo(bar)\nfor bar in range(5):\n print bar\n" + "\nclass aap:\n def monkey(self):\n pass\n\n") # Run application e.show() s = QtWidgets.QSplitter() s.addWidget(e) s.addWidget(QtWidgets.QLabel("test")) s.show() app.exec_()
QtGui.QKeySequence("F3"), e).activated.connect(lambda: e.calltipShow(0, 'test(foo, bar)')) QtWidgets.QShortcut(QtGui.QKeySequence("Shift+Tab"), e).activated.connect(e.dedentSelection) # Shift + Tab #TODO: somehow these shortcuts don't work in this test-app, but they do in # pyzo. May have something to do with overriding slots of Qt-native objects? QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+C"), e).activated.connect(e.copy) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+X"), e).activated.connect(e.cut) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+V"), e).activated.connect(e.paste) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Shift+V"), e).activated.connect(e.pasteAndSelect) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Z"), e).activated.connect(e.undo) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Y"), e).activated.connect(e.redo) e.setPlainText("foo(bar)\nfor bar in range(5):\n print bar\n" + "\nclass aap:\n def monkey(self):\n pass\n\n") # Run application e.show() s = QtWidgets.QSplitter() s.addWidget(e) s.addWidget(QtWidgets.QLabel('test')) s.show() app.exec_()