def __init__(self, item: QListWidgetItem, parent: QWidget = None): super().__init__(parent) self.item = item self.opacity = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.opacity) layout = QHBoxLayout() self.setLayout(layout) self.position_label = QLabel() self.update_position_label() self.setToolTip(trans._("Click and drag to change call order")) self.plugin_name_label = QElidingLabel() self.plugin_name_label.setObjectName('small_text') self.plugin_name_label.setText(item.hook_implementation.plugin_name) plugin_name_size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) plugin_name_size_policy.setHorizontalStretch(2) self.plugin_name_label.setSizePolicy(plugin_name_size_policy) self.function_name_label = QLabel( item.hook_implementation.function.__name__) self.enabled_checkbox = QCheckBox(self) self.enabled_checkbox.setToolTip( trans._("Uncheck to disable this plugin")) self.enabled_checkbox.stateChanged.connect(self._set_enabled) self.enabled_checkbox.setChecked( getattr(item.hook_implementation, 'enabled', True)) layout.addWidget(self.position_label) layout.addWidget(self.enabled_checkbox) layout.addWidget(self.function_name_label) layout.addWidget(self.plugin_name_label) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0)
def __init__(self, data=None, axis=0, parent=None, **kwargs): super(VolumeView, self).__init__(parent, **kwargs) self.parent = parent self.data = data if axis == -1: axis = 2 if 0 <= axis <= 2: self.axis = axis else: raise IndexError("Index out of range.") # initialize variables self.numberOfSlices = 1 self.currentSlice = 0 # create single view self.sliceView = SliceView(parent=self) # layout self.layout = QVBoxLayout(self) self.layout.addWidget(self.sliceView) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHeightForWidth(True) self.setSizePolicy(sizePolicy) if self.data is not None: self.setData(self.data)
def __init__(self, data=None, imshow_args=None, parent=None, **kwargs): super(SliceView, self).__init__(parent, **kwargs) self.parent = parent self.data = data self.imshow_args = {} if imshow_args is None else imshow_args # make display available self.figure = Figure(facecolor="black") self.__canvas = FigureCanvas(self.figure) self.__imshowAccessor = None # layout self.layout = QVBoxLayout(self) self.layout.addWidget(self.__canvas) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) self.setDisabled(True) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHeightForWidth(True) self.setSizePolicy(sizePolicy) # prepare figure self.axes = self.figure.add_subplot(111) self.figure.subplots_adjust(left=0, right=1, top=1, bottom=0) self.axes.axis("Off") # plot if we can if self.data is not None: self.setData(self.data)
def setup_ui(self): # create title bar, content self.vboxWindow.setContentsMargins(0, 0, 0, 0) self.windowFrame.setObjectName('windowFrame') self.vboxFrame.setContentsMargins(0, 0, 0, 0) self.titleBar.setObjectName('titleBar') self.titleBar.setSizePolicy( QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)) self.hboxTitle.setContentsMargins(0, 0, 0, 0) self.hboxTitle.setSpacing(0) self.lblTitle.setObjectName('lblTitle') self.lblTitle.setAlignment(Qt.AlignCenter) self.hboxTitle.addWidget(self.lblTitle) sp_buttons = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.btnMinimize.setObjectName('btnMinimize') self.btnMinimize.setSizePolicy(sp_buttons) self.hboxTitle.addWidget(self.btnMinimize) self.btnRestore.setObjectName('btnRestore') self.btnRestore.setSizePolicy(sp_buttons) self.btnRestore.setVisible(False) self.hboxTitle.addWidget(self.btnRestore) self.btnMaximize.setObjectName('btnMaximize') self.btnMaximize.setSizePolicy(sp_buttons) self.hboxTitle.addWidget(self.btnMaximize) self.btnClose.setObjectName('btnClose') self.btnClose.setSizePolicy(sp_buttons) self.hboxTitle.addWidget(self.btnClose) self.vboxFrame.addWidget(self.titleBar) self.vboxFrame.addWidget(self.windowContent) self.vboxWindow.addWidget(self.windowFrame) # set window flags self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint) if self._window.app.qt_version >= (5, ): self.setAttribute(Qt.WA_TranslucentBackground) # set stylesheet stylesheet = self.app.ui.get_stylesheet('frameless.qss') self.setStyleSheet(stylesheet) # automatically connect slots QMetaObject.connectSlotsByName(self)
def __init__(self, parent=None): super(DisableDelegate.DelegateClass, self).__init__(parent=parent) self.setText("i") self.setAutoRaise(True) self.setIcon(mk_enableicon()) self.setCheckable(True) sp = QSizePolicy() sp.setWidthForHeight(True) self.setSizePolicy(sp)
def paint(self, painter, option, index): if not self._parent.indexWidget(index): button = QToolButton(self.parent()) button.setAutoRaise(True) button.setText("Delete Operation") button.setIcon(QIcon(path("icons/trash.png"))) sp = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) sp.setWidthForHeight(True) button.setSizePolicy(sp) button.clicked.connect(index.data()) self._parent.setIndexWidget(index, button)
def add(self, name: str): if self.layout.count() == 0: label = QLabel("Jump to reaction on map:") self.layout.addWidget(label) jb = JumpButton(self, name) policy = QSizePolicy() policy.ShrinkFlag = True jb.setSizePolicy(policy) self.layout.addWidget(jb) self.setLayout(self.layout) jb.jumpToMap.connect(self.parent.emit_jump_to_map)
def __init__(self, *args, **kwargs): # Composes a new type consisting of any ImageItem types in imageItem_bases with this classes's helper ImageItem # class (LogScaleImageItem) self.imageItem_bases += (LogScaleImageItem, ) imageItem = type("DynamicImageItem", tuple(self.imageItem_bases), {})() if "imageItem" in kwargs: del kwargs["imageItem"] super(LogScaleIntensity, self).__init__(imageItem=imageItem, *args, **kwargs) self.logScale = True # Setup log scale button self.logIntensityButton = QPushButton("Log Intensity") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.logIntensityButton.sizePolicy().hasHeightForWidth()) self.logIntensityButton.setSizePolicy(sizePolicy) self.logIntensityButton.setObjectName("logIntensity") self.ui.gridLayout.addWidget(self.logIntensityButton, 3, 2, 1, 1) self.logIntensityButton.setCheckable(True) self.setLogScale(True) self.logIntensityButton.clicked.connect(self._setLogScale)
def __init__(self, *args, **kwargs): if kwargs.get("imageItem") and not isinstance(kwargs.get("imageItem"), LogScaleImageItem): raise RuntimeError( "The imageItem set to a LogScaleIntensity ImageView must be a LogScaleImageItem." ) kwargs["imageItem"] = LogScaleImageItem() super(LogScaleIntensity, self).__init__(*args, **kwargs) self.logScale = True # Setup log scale button self.logIntensityButton = QPushButton("Log Intensity") sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.logIntensityButton.sizePolicy().hasHeightForWidth()) self.logIntensityButton.setSizePolicy(sizePolicy) self.logIntensityButton.setObjectName("logIntensity") self.ui.gridLayout.addWidget(self.logIntensityButton, 3, 2, 1, 1) self.logIntensityButton.setCheckable(True) self.setLogScale(True) self.logIntensityButton.clicked.connect(self._setLogScale)
def paint(self, painter, option, index): if not self._parent.indexWidget(index): button = QToolButton(self.parent()) button.setText("i") button.setAutoRaise(True) button.setIcon(enableicon) button.setCheckable(True) sp = QSizePolicy() sp.setWidthForHeight(True) button.setSizePolicy(sp) button.clicked.connect(index.data()) self._parent.setIndexWidget(index, button)
def __init__(self, parent=None): super(AbstractComboListInputWidget, self).__init__(parent) self.main_widget = self.parent() self.previous_text = '' self.setExistsFlag(True) # setup line edit #self.line_edit = QLineEdit("Select & Focus", self) self.line_edit = QLineEdit(self) self.line_edit.editingFinished.connect(self.userFinishedEditing) self.setLineEdit(self.line_edit) self.setEditable(True) # setup completer self.completer = QCompleter(self) self.completer.setCompletionMode(QCompleter.PopupCompletion) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.setPopup(self.view()) self.setCompleter(self.completer) self.pFilterModel = QSortFilterProxyModel(self) # set size policy ( this will ignore the weird resizing effects) size_policy = QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred) self.setSizePolicy(size_policy) # initialize model... model = QStandardItemModel() self.setModel(model) self.setModelColumn(0)
def _init_toolbar(self): for text, tooltip_text, fa_icon, callback, checked in self.toolitems: if text is None: self.addSeparator() else: if fa_icon: a = self.addAction(get_icon(fa_icon), text, getattr(self, callback)) else: a = self.addAction(text, getattr(self, callback)) self._actions[callback] = a if checked is not None: a.setCheckable(True) a.setChecked(checked) if tooltip_text is not None: a.setToolTip(tooltip_text) # Add the x,y location widget at the right side of the toolbar # The stretch factor is 1 which means any resizing of the toolbar # will resize this label instead of the buttons. if self.coordinates: self.locLabel = QLabel("", self) self.locLabel.setAlignment(Qt.AlignRight | Qt.AlignTop) self.locLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored)) labelAction = self.addWidget(self.locLabel) labelAction.setVisible(True) # Adjust icon size or they are too small in PyQt5 by default self.setIconSize(QSize(24, 24)) # Location of a press event self._pressed_xy = None
def __init__(self, *args): """Type name: "DXF module".""" super(DxfOutputDialog, self).__init__("DXF", "dxf.png", "The part sketchs will including in the file.", "There is only wire frame will be generated.", *args) # DXF version option. version_label = QLabel("DXF version:", self) self.version_option = QComboBox(self) self.version_option.addItems( sorted((f"{name} - {DXF_VERSIONS_MAP[name]}" for name in DXF_VERSIONS), key=lambda v: v.split()[-1])) self.version_option.setCurrentIndex(self.version_option.count() - 1) self.version_option.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)) dxf_version_layout = QHBoxLayout() dxf_version_layout.addWidget(version_label) dxf_version_layout.addWidget(self.version_option) self.main_layout.insertLayout(3, dxf_version_layout) # Parts interval. self.interval_enable = QCheckBox("Parts interval:", self) self.interval_enable.setCheckState(Qt.Checked) self.interval_option = QDoubleSpinBox(self) self.interval_option.setValue(10) self.interval_enable.stateChanged.connect( self.interval_option.setEnabled) dxf_interval_layout = QHBoxLayout() dxf_interval_layout.addWidget(self.interval_enable) dxf_interval_layout.addItem( QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)) dxf_interval_layout.addWidget(self.interval_option) self.assembly_layout.insertLayout(2, dxf_interval_layout)
def __init__(self, canvas, parent, coordinates=True): """coordinates: should we show the coordinates on the right?""" QToolBar.__init__(self, parent) self.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea) self._actions = {} # mapping of toolitem method names to QActions. self.coordinates = coordinates for text, tooltip_text, mdi_icon, callback, checked, initializer in self.toolitems: if text is None: self.addSeparator() else: if callable(initializer): a = initializer(self, text, tooltip_text, mdi_icon, callback, checked, initializer) elif mdi_icon: a = self.addAction(get_icon(mdi_icon), text, getattr(self, callback)) else: a = self.addAction(text, getattr(self, callback)) self._actions[callback] = a if checked is not None: a.setCheckable(True) a.setChecked(checked) if tooltip_text is not None: a.setToolTip(tooltip_text) if self.coordinates: self.locLabel = QLabel("", self) self.locLabel.setAlignment(Qt.AlignRight | Qt.AlignTop) self.locLabel.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored)) labelAction = self.addWidget(self.locLabel) labelAction.setVisible(True) NavigationToolbar2.__init__(self, canvas)
def __init__(self, row: int, parent: QWidget) -> None: super(BaseTableWidget, self).__init__(parent) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.setStatusTip( "This table will show about the entities items in current view mode." ) self.setEditTriggers(QAbstractItemView.NoEditTriggers) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) self.setRowCount(row) self.setColumnCount(len(self.headers)) for i, e in enumerate(self.headers): self.setHorizontalHeaderItem(i, QTableWidgetItem(e)) # Table widget column width. header = self.horizontalHeader() header.setSectionResizeMode(QHeaderView.ResizeToContents) @Slot() def emit_selection_changed() -> None: self.row_selection_changed.emit(self.selected_rows()) self.itemSelectionChanged.connect(emit_selection_changed)
def test_construct(qtbot): """ Test the construction of the widget. Expectations: Default values are correctly assigned. Parameters ---------- qtbot : fixture Window for widget testing """ pydm_slider = PyDMSlider() qtbot.addWidget(pydm_slider) assert pydm_slider.alarmSensitiveContent is True assert pydm_slider.alarmSensitiveBorder is False assert pydm_slider._show_limit_labels is True assert pydm_slider._show_value_label is True assert pydm_slider._user_defined_limits is False assert pydm_slider._needs_limit_info is True assert pydm_slider._minimum is None assert pydm_slider._maximum is None assert pydm_slider._user_minimum == -10.0 assert pydm_slider._user_maximum == 10.0 assert pydm_slider._num_steps == 101 assert pydm_slider.orientation == Qt.Horizontal assert pydm_slider.isEnabled() is False assert type(pydm_slider.low_lim_label) == QLabel assert pydm_slider.low_lim_label.sizePolicy() == QSizePolicy( QSizePolicy.Maximum, QSizePolicy.Fixed) assert pydm_slider.low_lim_label.alignment() == Qt.Alignment( Qt.AlignLeft | Qt.AlignTrailing | Qt.AlignVCenter) assert type(pydm_slider.high_lim_label) == QLabel assert pydm_slider.high_lim_label.sizePolicy() == QSizePolicy( QSizePolicy.Maximum, QSizePolicy.Fixed) assert pydm_slider.high_lim_label.alignment() == Qt.Alignment( Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) assert type(pydm_slider._slider) == QSlider assert pydm_slider._slider.orientation() == Qt.Orientation(Qt.Horizontal) assert pydm_slider._slider_position_to_value_map is None assert pydm_slider._mute_internal_slider_changes is False assert pydm_slider._orientation == Qt.Horizontal
def uicreate_label(self, lab, parent): """.""" label = QLabel(lab, parent) sz_pol = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) label.setSizePolicy(sz_pol) label.setStyleSheet("""min-width:2.5em;""") label.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) return label
def __init__(self, appdata: CnaData): QWidget.__init__(self) self.appdata = appdata self.last_selected = None self.reaction_counter = 1 self.add_button = QPushButton("Add new reaction") self.add_button.setIcon(QIcon.fromTheme("list-add")) policy = QSizePolicy() policy.ShrinkFlag = True self.add_button.setSizePolicy(policy) self.reaction_list = DragableTreeWidget() self.reaction_list.setDragEnabled(True) self.reaction_list.setHeaderLabels(["Id", "Name", "Flux"]) self.reaction_list.setSortingEnabled(True) for r in self.appdata.project.cobra_py_model.reactions: self.add_reaction(r) self.reaction_mask = ReactionMask(self) self.reaction_mask.hide() self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) l = QHBoxLayout() l.setAlignment(Qt.AlignRight) l.addWidget(self.add_button) self.splitter = QSplitter() self.splitter.setOrientation(Qt.Vertical) self.splitter.addWidget(self.reaction_list) self.splitter.addWidget(self.reaction_mask) self.layout.addItem(l) self.layout.addWidget(self.splitter) self.setLayout(self.layout) self.reaction_list.currentItemChanged.connect(self.reaction_selected) self.reaction_mask.reactionChanged.connect( self.handle_changed_reaction) self.reaction_mask.reactionDeleted.connect( self.handle_deleted_reaction) self.reaction_mask.jumpToMap.connect(self.emit_jump_to_map) self.reaction_mask.jumpToMetabolite.connect( self.emit_jump_to_metabolite) self.add_button.clicked.connect(self.add_new_reaction)
def __init__(self, *args, **kwargs): super(ExportButton, self).__init__(*args, **kwargs) # Export button self.exportBtn = QPushButton('Export') sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth(self.exportBtn.sizePolicy().hasHeightForWidth()) self.ui.right_layout.addWidget(self.exportBtn) self.exportBtn.clicked.connect(self.export)
def __init__(self, parent): super(TitlebarDarwinButton, self).__init__(parent) self.setIconSize(QSize(15, 15)) self.setMinimumSize(QSize(15, 15)) self.setAutoFillBackground(True) self.setMouseTracking(True) sizepolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) sizepolicy.setHorizontalStretch(0) sizepolicy.setVerticalStretch(0) sizepolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sizepolicy)
def __init__(self, parent=None, toggle_button=None): super().__init__(parent) self._toggleButton = toggle_button self.setObjectName('Activity') self.setMinimumWidth(self.MIN_WIDTH) self.setMinimumHeight(self.MIN_HEIGHT) self.setMaximumHeight(self.MIN_HEIGHT) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.setWindowFlags(Qt.SubWindow | Qt.WindowStaysOnTopHint) self.setModal(False) opacityEffect = QGraphicsOpacityEffect(self) opacityEffect.setOpacity(0.8) self.setGraphicsEffect(opacityEffect) self._baseWidget = QWidget() self._activityLayout = QVBoxLayout() self._activityLayout.addStretch() self._baseWidget.setLayout(self._activityLayout) self._baseWidget.layout().setContentsMargins(0, 0, 0, 0) self._scrollArea = QScrollArea() self._scrollArea.setWidgetResizable(True) self._scrollArea.setWidget(self._baseWidget) self._titleBar = QLabel() title = QLabel('activity', self) title.setObjectName('QtCustomTitleLabel') title.setSizePolicy( QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Maximum) ) line = QFrame(self) line.setObjectName("QtCustomTitleBarLine") titleLayout = QHBoxLayout() titleLayout.setSpacing(4) titleLayout.setContentsMargins(8, 1, 8, 0) line.setFixedHeight(1) titleLayout.addWidget(line) titleLayout.addWidget(title) self._titleBar.setLayout(titleLayout) self._baseLayout = QVBoxLayout() self._baseLayout.addWidget(self._titleBar) self._baseLayout.addWidget(self._scrollArea) self.setLayout(self._baseLayout) self.resize(520, self.MIN_HEIGHT) self.move_to_bottom_right() # TODO: what do we do with any existing progress objects in action? # connect callback to handle new progress objects being added/removed progress._all_instances.events.changed.connect( self.handle_progress_change )
def __init__(self, process, view, index): super(HintsWidget, self).__init__() self.view = view self.setLayout(QGridLayout()) self.layout().addWidget(QLabel(process.name), 0, 0, 1, 2) self.hints = process.hints enabledhints = [hint for hint in self.hints if hint.enabled] for i, hint in enumerate(enabledhints): enablebutton = QPushButton(icon=enableicon) sp = QSizePolicy() sp.setWidthForHeight(True) enablebutton.setSizePolicy(sp) enablebutton.setVisible(False) label = QLabel(hint.name) label.setVisible(False) self.layout().addWidget(enablebutton, i + 1, 0, 1, 1) self.layout().addWidget(label)
def __init__(self, label=None, **kwargs): super(InteractionVolumeView, self).__init__(**kwargs) self.interactionFrame = QFrame(self) self.interactionFrame.setSizePolicy( QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)) self.interactionFrame.setFixedHeight(30) self.interactionLayout = QHBoxLayout(self.interactionFrame) self.interactionLayout.setContentsMargins(5, 5, 5, 5) self.sliceLabel = QLabel(self.interactionFrame) self.sliceLabel.setSizePolicy( QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)) self.updateSliceLabel() self.textLabel = QLineEdit(self.interactionFrame) self.textLabel.setReadOnly(True) self.textLabel.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)) self.textLabel.setAlignment(Qt.AlignCenter) stylesheet = \ "QLineEdit {\n" \ + "border: none;\n" \ + "background-color: rgba(255, 255, 255, 0);\n" \ + "}" self.textLabel.setStyleSheet(stylesheet) if label is not None: self.updateTextLabel(label) self.interactionLayout.addWidget(self.sliceLabel) self.interactionLayout.addWidget(self.textLabel) self.axisSelector = QComboBox(self.interactionFrame) self.axisSelector.setFixedWidth(40) self.axisSelector.insertItems(0, ["0", "1", "2"]) self.interactionLayout.addWidget(self.axisSelector) self.layout.addWidget(self.interactionFrame) self.signalSliceChanged.connect(self.updateSliceLabel) self.axisSelector.currentIndexChanged.connect(self.setAxisAndEmit)
def setAlignment(self, alignment): """ Change the alignment :param int alignment: New alignment Valid alignment values: see :py:class:`qwt.scale_draw.QwtScaleDraw` .. seealso:: :py:meth:`alignment()` """ if self.__data.scaleDraw: self.__data.scaleDraw.setAlignment(alignment) if not self.testAttribute(Qt.WA_WState_OwnSizePolicy): policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if self.__data.scaleDraw.orientation() == Qt.Vertical: policy.transpose() self.setSizePolicy(policy) self.setAttribute(Qt.WA_WState_OwnSizePolicy, False) self.layoutScale()
def __init__(self): super().__init__() self._item_list = [] # The 'first item' is appended to the beginning of the list. The index returned # by the functions of the class is the index of 'self._item_list' array, that # does not include the 'first item'. self._first_item = "Select Line:" self.cb_element_list = QComboBox() self.cb_element_list.currentIndexChanged.connect( self.cb_element_list_current_index_changed) self.setMaximumWidth(300) self.pb_prev = PushButtonMinimumWidth("<") self.pb_prev.pressed.connect(self.pb_prev_pressed) self.pb_next = PushButtonMinimumWidth(">") self.pb_next.pressed.connect(self.pb_next_pressed) self.cb_element_list.addItems([self._first_item]) self.cb_element_list.setCurrentIndex(0) hbox = QHBoxLayout() hbox.setSpacing(0) hbox.setContentsMargins(0, 0, 0, 0) hbox.addWidget(self.pb_prev) hbox.addWidget(self.cb_element_list) hbox.addWidget(self.pb_next) self.setLayout(hbox) sp = QSizePolicy() sp.setControlType(QSizePolicy.PushButton) sp.setHorizontalPolicy(QSizePolicy.Maximum) self.setSizePolicy(sp)
def initScale(self, align): """ Initialize the scale :param int align: Alignment """ self.__data = QwtScaleWidget_PrivateData() self.__data.layoutFlags = 0 if align == QwtScaleDraw.RightScale: self.__data.layoutFlags |= self.TitleInverted self.__data.borderDist = [0, 0] self.__data.minBorderDist = [0, 0] self.__data.margin = 4 self.__data.titleOffset = 0 self.__data.spacing = 2 self.__data.scaleDraw = QwtScaleDraw() self.__data.scaleDraw.setAlignment(align) self.__data.scaleDraw.setLength(10) self.__data.scaleDraw.setScaleDiv(QwtLinearScaleEngine().divideScale( 0.0, 100.0, 10, 5)) self.__data.colorBar.colorMap = QwtLinearColorMap() self.__data.colorBar.isEnabled = False self.__data.colorBar.width = 10 flags = Qt.AlignmentFlag(Qt.AlignHCenter | Qt.TextExpandTabs | Qt.TextWordWrap) self.__data.title.setRenderFlags(flags) self.__data.title.setFont(self.font()) policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if self.__data.scaleDraw.orientation() == Qt.Vertical: policy.transpose() self.setSizePolicy(policy) self.setAttribute(Qt.WA_WState_OwnSizePolicy, False)
def __init__(self, parent, grid, count, vmin=None, vmax=None, legend=None, codim=1, separate_plots=False, dpi=100): assert isinstance(grid, OnedGrid) assert codim in (0, 1) figure = Figure(dpi=dpi) if not separate_plots: axes = figure.gca() axes.hold(True) self.codim = codim lines = () centers = grid.centers(1) if grid._identify_left_right: centers = np.concatenate((centers, [[grid._domain[1]]]), axis=0) self.periodic = True else: self.periodic = False if codim == 1: xs = centers else: xs = np.repeat(centers, 2)[1:-1] for i in range(count): if separate_plots: figure.add_subplot(int(count / 2) + count % 2, 2, i + 1) axes = figure.gca() pad = (vmax[i] - vmin[i]) * 0.1 axes.set_ylim(vmin[i] - pad, vmax[i] + pad) l, = axes.plot(xs, np.zeros_like(xs)) lines = lines + (l, ) if legend and separate_plots: axes.legend([legend[i]]) if not separate_plots: pad = (max(vmax) - min(vmin)) * 0.1 axes.set_ylim(min(vmin) - pad, max(vmax) + pad) if legend: axes.legend(legend) self.lines = lines super().__init__(figure) self.setParent(parent) self.setMinimumSize(300, 300) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
def setup_ui(self, add_items=None): """.""" sz_pol = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) self.setSizePolicy(sz_pol) add_items = add_items or [] add_items.extend(['Zero', 'ServConf']) for item in add_items: self.addItem(item) for reg in sorted(self.ctrls.keys()): self.addItem(reg) self.addItem('Out of Date') self.setCurrentIndex(self.count() - 1) self.activated.connect(self._item_selected)
def __init__(self, parent, title: str = '', vertical=False): super().__init__(parent) self.setObjectName("QtCustomTitleBar") self.setProperty('vertical', str(vertical)) self.vertical = vertical self.setToolTip(trans._('drag to move. double-click to float')) line = QFrame(self) line.setObjectName("QtCustomTitleBarLine") self.close_button = QPushButton(self) self.close_button.setToolTip(trans._('hide this panel')) self.close_button.setObjectName("QTitleBarCloseButton") self.close_button.setCursor(Qt.ArrowCursor) self.close_button.clicked.connect( lambda: self.parent().toggleViewAction().trigger() ) self.float_button = QPushButton(self) self.float_button.setToolTip(trans._('float this panel')) self.float_button.setObjectName("QTitleBarFloatButton") self.float_button.setCursor(Qt.ArrowCursor) self.float_button.clicked.connect( lambda: self.parent().setFloating(not self.parent().isFloating()) ) self.title = QLabel(title, self) self.title.setSizePolicy( QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Maximum) ) if vertical: layout = QVBoxLayout() layout.setSpacing(4) layout.setContentsMargins(0, 8, 0, 8) line.setFixedWidth(1) layout.addWidget(self.close_button, 0, Qt.AlignHCenter) layout.addWidget(self.float_button, 0, Qt.AlignHCenter) layout.addWidget(line, 0, Qt.AlignHCenter) self.title.hide() else: layout = QHBoxLayout() layout.setSpacing(4) layout.setContentsMargins(8, 1, 8, 0) line.setFixedHeight(1) layout.addWidget(self.close_button) layout.addWidget(self.float_button) layout.addWidget(line) layout.addWidget(self.title) self.setLayout(layout) self.setCursor(Qt.OpenHandCursor)
def __init__(self, parent): super(ButtonsWidget, self).__init__(parent) self.setObjectName("buttonsWidget") self.setContentsMargins(0, 0, 0, 0) sizepolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) sizepolicy.setHorizontalStretch(0) sizepolicy.setVerticalStretch(0) sizepolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sizepolicy) self.setStyleSheet("padding: 0px;") self.buttonsLayout = QHBoxLayout(self) self.buttonsLayout.setContentsMargins(0, 0, 0, 0) self.buttonsLayout.setSpacing(0) self.buttonsLayout.setAlignment(Qt.AlignVCenter) self.setLayout(self.buttonsLayout) if qrainbowstyle.USE_DARWIN_BUTTONS: self.btnMinimize = MinimizeDarwinButton(self) self.btnMaximize = MaximizeDarwinButton(self) self.btnRestore = RestoreDarwinButton(self) self.btnClose = CloseDarwinButton(self) else: self.btnMinimize = MinimizeWindowsButton(self) self.btnMaximize = MaximizeWindowsButton(self) self.btnRestore = RestoreWindowsButton(self) self.btnClose = CloseWindowsButton(self) if qrainbowstyle.ALIGN_BUTTONS_LEFT: self.buttonsLayout.addWidget(self.btnClose) if not qrainbowstyle.USE_DARWIN_BUTTONS: self.buttonsLayout.addWidget(self.btnRestore) self.buttonsLayout.addWidget(self.btnMinimize) self.buttonsLayout.addWidget(self.btnMaximize) else: self.buttonsLayout.addWidget(self.btnMinimize) self.buttonsLayout.addWidget(self.btnMaximize) if not qrainbowstyle.USE_DARWIN_BUTTONS: self.buttonsLayout.addWidget(self.btnRestore) self.buttonsLayout.addWidget(self.btnClose) self.btnMinimize.setObjectName("btnMinimize") self.btnMaximize.setObjectName("btnMaximize") if not qrainbowstyle.USE_DARWIN_BUTTONS: self.btnRestore.setObjectName("btnRestore") self.btnClose.setObjectName("btnClose") if qrainbowstyle.USE_DARWIN_BUTTONS: self.buttonsLayout.setSpacing(8)