Python qtpy.QtWidgets.QPushButton() Examples

The following are 30 code examples of qtpy.QtWidgets.QPushButton(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qtpy.QtWidgets , or try the search function .
Example #1
Source File: lockbox_widget.py    From pyrpl with GNU General Public License v3.0 6 votes vote down vote up
def init_gui(self):
        #self.main_layout = QtWidgets.QVBoxLayout(self)
        self.init_main_layout(orientation="vertical")
        self.init_attribute_layout()

        self.win = pg.GraphicsWindow(title="Expected signal")
        self.plot_item = self.win.addPlot(title='Expected ' + self.module.name)
        self.plot_item.showGrid(y=True, x=True, alpha=1.)
        self.curve = self.plot_item.plot(pen='y')
        self.curve_slope = self.plot_item.plot(pen=pg.mkPen('b', width=5))
        self.symbol = self.plot_item.plot(pen='b', symbol='o')
        self.main_layout.addWidget(self.win)
        self.button_calibrate = QtWidgets.QPushButton('Calibrate')
        self.main_layout.addWidget(self.button_calibrate)
        self.button_calibrate.clicked.connect(lambda: self.module.calibrate())
        self.input_calibrated() 
Example #2
Source File: test_qt_image_base_layer_.py    From napari with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_range_popup_clim_buttons(mock_show, qtbot, layer):
    """The buttons in the clim_popup should adjust the contrast limits value"""
    qtctrl = QtBaseImageControls(layer)
    qtbot.addWidget(qtctrl)
    original_clims = tuple(layer.contrast_limits)
    layer.contrast_limits = (20, 40)
    qtbot.mousePress(qtctrl.contrastLimitsSlider, Qt.RightButton)

    # pressing the reset button returns the clims to the default values
    reset_button = qtctrl.clim_pop.findChild(QPushButton, "reset_clims_button")
    reset_button.click()
    qtbot.wait(20)
    assert tuple(qtctrl.contrastLimitsSlider.values()) == original_clims

    rangebtn = qtctrl.clim_pop.findChild(QPushButton, "full_clim_range_button")
    # the data we created above was uint16 for Image, and float for Surface
    # Surface will not have a "full range button"
    if np.issubdtype(layer.dtype, np.integer):
        rangebtn.click()
        qtbot.wait(20)
        assert tuple(layer.contrast_limits_range) == (0, 2 ** 16 - 1)
        assert tuple(qtctrl.contrastLimitsSlider.range()) == (0, 2 ** 16 - 1)
    else:
        assert rangebtn is None 
Example #3
Source File: SubmitProgressWindow.py    From P4VFX with MIT License 6 votes vote down vote up
def create_controls(self):
        '''
        Create the widgets for the dialog
        '''

        self.overallProgressBar = QtWidgets.QProgressBar()
        self.overallProgressBar.setMinimum(0)
        self.overallProgressBar.setMaximum(self.totalFiles)
        self.overallProgressBar.setValue(0)

        self.fileProgressBar = QtWidgets.QProgressBar()
        self.fileProgressBar.setMinimum(0)
        self.fileProgressBar.setMaximum(100)
        self.fileProgressBar.setValue(0)

        self.quitBtn = QtWidgets.QPushButton("Cancel") 
Example #4
Source File: test_qt_dock_widget.py    From napari with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_add_dock_widget_from_list(make_test_viewer):
    """Test that we can add a list of widgets and they will be combined"""
    viewer = make_test_viewer()
    widg = QPushButton('button')
    widg2 = QPushButton('button')

    dwidg = viewer.window.add_dock_widget(
        [widg, widg2], name='test', area='right'
    )
    assert viewer.window._qt_window.findChild(QDockWidget, 'test')
    assert isinstance(dwidg.widget.layout, QVBoxLayout)

    dwidg = viewer.window.add_dock_widget(
        [widg, widg2], name='test2', area='bottom'
    )
    assert viewer.window._qt_window.findChild(QDockWidget, 'test2')
    assert isinstance(dwidg.widget.layout, QHBoxLayout) 
Example #5
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
def test_load_ui_custom_auto(tmpdir):
    """
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    """

    app = get_qapp()

    with enabled_qcombobox_subclass(tmpdir):
        from qcombobox_subclass import _QComboBoxSubclass
        ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, _QComboBoxSubclass) 
Example #6
Source File: test_uic.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_load_ui_custom_auto(tmpdir):
    """
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    """

    app = get_qapp()

    with enabled_qcombobox_subclass(tmpdir):
        from qcombobox_subclass import _QComboBoxSubclass
        ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, _QComboBoxSubclass) 
Example #7
Source File: OpenedFilesWindow.py    From P4VFX with MIT License 5 votes vote down vote up
def create_controls(self):
        '''
        Create the widgets for the dialog
        '''
        headers = ["File", "Type", "Action", "User", "Folder"]

        self.tableWidget = QtWidgets.QTableWidget(0, len(headers))
        self.tableWidget.setMaximumHeight(200)
        self.tableWidget.setMinimumWidth(500)
        self.tableWidget.setHorizontalHeaderLabels(headers)
        self.tableWidget.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.tableWidget.setSelectionMode(
            QtWidgets.QAbstractItemView.SingleSelection)


        self.openSelectedBtn = QtWidgets.QPushButton("Open")
        self.openSelectedBtn.setEnabled(False)
        self.openSelectedBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0228.png")))

        self.revertFileBtn = QtWidgets.QPushButton("Remove from changelist")
        self.revertFileBtn.setEnabled(False)
        self.revertFileBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0308.png")))

        self.refreshBtn = QtWidgets.QPushButton("Refresh")
        self.refreshBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0175.png")))

        self.updateTable() 
Example #8
Source File: script_ui.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.setEnabled(True)
        Dialog.resize(533, 564)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/script.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Dialog.setWindowIcon(icon)
        Dialog.setAutoFillBackground(True)
        Dialog.setSizeGripEnabled(True)
        Dialog.setModal(True)
        self.main_layout = QtWidgets.QVBoxLayout(Dialog)
        self.main_layout.setObjectName("main_layout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.show_qrcode = QtWidgets.QPushButton(Dialog)
        self.show_qrcode.setAutoDefault(False)
        self.show_qrcode.setObjectName("show_qrcode")
        self.horizontalLayout.addWidget(self.show_qrcode)
        self.copy_button = QtWidgets.QPushButton(Dialog)
        self.copy_button.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
        self.copy_button.setAutoDefault(False)
        self.copy_button.setObjectName("copy_button")
        self.horizontalLayout.addWidget(self.copy_button)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.button_box = QtWidgets.QDialogButtonBox(Dialog)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.button_box.sizePolicy().hasHeightForWidth())
        self.button_box.setSizePolicy(sizePolicy)
        self.button_box.setOrientation(QtCore.Qt.Horizontal)
        self.button_box.setStandardButtons(QtWidgets.QDialogButtonBox.Close|QtWidgets.QDialogButtonBox.Save)
        self.button_box.setObjectName("button_box")
        self.horizontalLayout.addWidget(self.button_box)
        self.main_layout.addLayout(self.horizontalLayout)

        self.retranslateUi(Dialog)
        self.button_box.rejected.connect(Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog) 
Example #9
Source File: test_uic.py    From qtpy with MIT License 5 votes vote down vote up
def test_load_ui():
    """
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    """
    app = get_qapp()
    ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, QComboBox) 
Example #10
Source File: test_uic.py    From qtpy with MIT License 5 votes vote down vote up
def test_load_ui_custom_auto(tmpdir):
    """
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    """

    app = get_qapp()

    with enabled_qcombobox_subclass(tmpdir):
        from qcombobox_subclass import _QComboBoxSubclass
        ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, _QComboBoxSubclass) 
Example #11
Source File: yml_editor.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, module, state):
        self.module = module
        self.state = state

        super(YmlEditor, self).__init__()
        if state is None:
            state = "current"
        self.setWindowTitle(".:Yml editor:. " + "Module: '" + \
                    str(self.module.name) + "' State: '" + str(state) + "'")

        self.editor = QtWidgets.QTextEdit()
        self.button_cancel = QtWidgets.QPushButton("Cancel without saving")
        self.button_cancel.clicked.connect(self.cancel)
        self.button_refresh = QtWidgets.QPushButton("Load data from config file")
        self.button_refresh.clicked.connect(self.refresh)
        self.button_load_all = QtWidgets.QPushButton("Load all current attributes from memory")
        self.button_load_all.clicked.connect(self.load_all)
        self.button_save = QtWidgets.QPushButton("Save to file + set to memory" if self.state is None else "Save to file")
        self.button_save.clicked.connect(self.save)

        self.lay = QtWidgets.QVBoxLayout()
        self.setLayout(self.lay)
        self.lay.addWidget(self.editor)

        self.lay_h = QtWidgets.QHBoxLayout()
        self.lay.addLayout(self.lay_h)
        self.lay_h.addWidget(self.button_cancel)
        self.lay_h.addWidget(self.button_refresh)
        self.lay_h.addWidget(self.button_load_all)
        self.lay_h.addWidget(self.button_save)

        self.refresh() 
Example #12
Source File: spinbox.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def make_layout(self):
        self.lay = QtWidgets.QHBoxLayout()
        self.lay.setContentsMargins(0,0,0,0)
        self.lay.setSpacing(0)
        self.setLayout(self.lay)
        if self.labeltext is not None:
            self.label = QtWidgets.QLabel(self.labeltext)
            self.lay.addWidget(self.label)
        if self.log_increment:
            self.up = QtWidgets.QPushButton('*')
            self.down = QtWidgets.QPushButton('/')
        else:
            self.up = QtWidgets.QPushButton('+')
            self.down = QtWidgets.QPushButton('-')
        self.line = QtWidgets.QLineEdit()
        self.line.setStyleSheet("QLineEdit { qproperty-cursorPosition: 0; }") # align text on the left
        # http://stackoverflow.com/questions/18662157/qt-qlineedit-widget-to-get-long-text-left-aligned
        self.lay.addWidget(self.down)
        self.lay.addWidget(self.line)
        self.lay.addWidget(self.up)
        self.up.setMaximumWidth(15)
        self.down.setMaximumWidth(15)
        self.up.pressed.connect(self.first_step)
        self.down.pressed.connect(self.first_step)
        self.up.released.connect(self.finish_step)
        self.down.released.connect(self.finish_step)
        self.line.editingFinished.connect(self.validate)
        self._button_up_down = False
        self._button_down_down = False

    # keyboard interface 
Example #13
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent, startindex, *args, **kwargs):
        self.parent = parent
        self.startindex = startindex
        super(ListElementWidget, self).__init__(*args, **kwargs)
        self.set_horizontal()
        self.button_remove = QtWidgets.QPushButton('-')
        self.button_remove.clicked.connect(self.remove_this_element)
        self.button_remove.setFixedWidth(3 * 10)
        self.layout.addWidget(self.button_remove, 0) # stretch=0
        self.layout.addStretch(1)
        # this is very nice for debugging, but should probably be removed later
        setattr(self.module, '_'+self.attribute_name+'_widget', self.parent) 
Example #14
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def _make_widget(self):
        self.widget = QtWidgets.QFrame()
        self.widget_layout = QtWidgets.QVBoxLayout()
        self.widget.setLayout(self.widget_layout)
        self.widgets = []
        self.button_add = QtWidgets.QPushButton("+")
        self.button_add.clicked.connect(self.append_default)
        self.widget_layout.addWidget(self.button_add)
        self.widget_layout.addStretch(1)
        self.widget_layout.setContentsMargins(0, 0, 0, 0)
        self.selected = None
        self.update_widget_names() 
Example #15
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def _make_widget(self):
        desc = pyrpl_utils.recursive_getattr(self.module, '__class__.' + self.attribute_name)
        val = pyrpl_utils.recursive_getattr(self.module, self.attribute_name)
        self.widget = QtWidgets.QPushButton("setting up...")
        self.widget.clicked.connect(self.button_clicked) 
Example #16
Source File: lockbox_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent):
        super(AnalogTfSpec, self).__init__(parent)
        self.parent = parent
        self.module = self.parent.module
        self.layout = QtWidgets.QVBoxLayout(self)
        self.label = QtWidgets.QLabel("Analog transfer function")
        self.layout.addWidget(self.label)
        self.button = QtWidgets.QPushButton('Change...')
        self.layout.addWidget(self.button)
        self.button.clicked.connect(self.change)
        self.dialog = AnalogTfDialog(self)
        self.layout.setContentsMargins(0,0,0,0)
        self.change_analog_tf() 
Example #17
Source File: lockbox_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def init_gui(self):
        #self.main_layout = QtWidgets.QVBoxLayout(self)
        self.init_main_layout(orientation="vertical")
        self.init_attribute_layout()
        for name, attr in self.attribute_widgets.items():
            self.attribute_layout.removeWidget(attr)
        self.lay_h1 = QtWidgets.QHBoxLayout()
        self.main_layout.addLayout(self.lay_h1)
        self.lay_v1 = QtWidgets.QVBoxLayout()
        self.lay_h1.addLayout(self.lay_v1)
        self.lay_v2 = QtWidgets.QVBoxLayout()
        self.lay_h1.addLayout(self.lay_v2)
        aws = self.attribute_widgets
        #self.lay_v1.addWidget(aws['name'])
        self.lay_v1.addWidget(aws['input'])
        self.lay_v2.addWidget(aws['setpoint'])
        self.lay_v1.addWidget(aws['duration'])
        self.lay_v2.addWidget(aws['gain_factor'])
        self.lay_h2 = QtWidgets.QVBoxLayout()
        self.main_layout.addLayout(self.lay_h2)
        self.output_widgets = []
        for output in self.module.lockbox.outputs:
            self.output_widgets.append(self.module.outputs[output.name]._create_widget())
            self.lay_h2.addWidget(self.output_widgets[-1])
        #self.lay_h3 = QtWidgets.QHBoxLayout()
        #self.main_layout.addLayout(self.lay_h3)
        aws['function_call'].set_horizontal()
        #self.lay_h3.addWidget(aws['function_call'])
        self.main_layout.addWidget(aws['function_call'])
        self.button_goto = QtWidgets.QPushButton('Go to this stage')
        self.button_goto.clicked.connect(self.module.enable)
        self.main_layout.addWidget(self.button_goto) 
Example #18
Source File: lockbox_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def init_gui(self):
        self.init_main_layout(orientation="horizontal")
        self.init_attribute_layout()
        self.stage_widgets = []
        self.button_add = QtWidgets.QPushButton('+')
        self.button_add.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
        #self.button_add.setMinimumHeight(60)
        self.button_add.clicked.connect(lambda: self.module.append(self.module[-1].setup_attributes))
        self.main_layout.addWidget(self.button_add)
        for stage in self.module:
            self.stage_created([stage])
        self.main_layout.addStretch(2) 
Example #19
Source File: base_module_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def init_attribute_layout(self):
        """
        Automatically creates the gui properties for the register_widgets in register_names.
        :return:
        """
        if '\n' in self.module._gui_attributes:
            self.attributes_layout = QtWidgets.QVBoxLayout()
            self.main_layout.addLayout(self.attributes_layout)
            self.attribute_layout = QtWidgets.QHBoxLayout()
            self.attributes_layout.addLayout(self.attribute_layout)
        else:
            self.attribute_layout = QtWidgets.QHBoxLayout()
            self.main_layout.addLayout(self.attribute_layout)
        for attr_name in self.module._gui_attributes:
            if attr_name == '\n':
                self.attribute_layout = QtWidgets.QHBoxLayout()
                self.attributes_layout.addLayout(self.attribute_layout)
            else:
                attribute_value = getattr(self.module, attr_name)  # needed for
                # passing the instance to the descriptor
                attribute = getattr(self.module.__class__, attr_name)
                if callable(attribute):
                    # assume that attribute is a function
                    widget = QtWidgets.QPushButton(attr_name)
                    widget.clicked.connect(getattr(self.module, attr_name))
                else:
                    # standard case: make attribute widget
                    widget = attribute._create_widget(self.module)
                    if widget is None:
                        continue
                    widget.value_changed.connect(self.attribute_changed)
            self.attribute_widgets[attr_name] = widget
            self.attribute_layout.addWidget(widget)
        self.attribute_layout.addStretch(1) 
Example #20
Source File: acquisition_module_widget.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def init_gui(self):
        self.button_single = QtWidgets.QPushButton("Run single")
        self.button_single.clicked.connect(self.run_single_clicked)

        self.button_continuous = QtWidgets.QPushButton("Run continuous")
        self.button_continuous.clicked.connect(self.run_continuous_clicked)

        self.button_restart_averaging = QtWidgets.QPushButton(
            'Restart averaging')
        self.button_restart_averaging.clicked.connect(self.restart_clicked)

        self.button_save = QtWidgets.QPushButton("Save curve")
        self.button_save.clicked.connect(self.module.save_curve)

        self.current_avg_label = CurrentAvgLabel()

        aws = self.attribute_widgets
        self.attribute_layout.removeWidget(aws["trace_average"])
        self.attribute_layout.removeWidget(aws["curve_name"])

        self.button_layout.addWidget(self.current_avg_label)
        self.button_layout.addWidget(aws["trace_average"])
        self.button_layout.addWidget(aws["curve_name"])
        self.button_layout.addWidget(self.button_single)
        self.button_layout.addWidget(self.button_continuous)
        self.button_layout.addWidget(self.button_restart_averaging)
        self.button_layout.addWidget(self.button_save)
        self.main_layout.addLayout(self.button_layout)

        self.button_layout.setStretchFactor(self.button_single, 1)
        self.button_layout.setStretchFactor(self.button_continuous, 1)
        self.button_layout.setStretchFactor(self.button_restart_averaging, 1)
        self.button_layout.setStretchFactor(self.button_save, 1)
        self.button_layout.addStretch(1)
        self.attribute_layout.setStretch(0, 0) # since widgets are all removed
        # and re-added, the stretch ends up on the left, so better cancel it
        # and make a new one at the end 
Example #21
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
def test_load_ui():
    """
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    """
    app = get_qapp()
    ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, QComboBox) 
Example #22
Source File: test_uic.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_load_ui():
    """
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    """
    app = get_qapp()
    ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, QComboBox) 
Example #23
Source File: OpenedFilesWindow.py    From P4VFX with MIT License 5 votes vote down vote up
def create_controls(self):
        '''
        Create the widgets for the dialog
        '''
        headers = ["File", "Type", "Action", "User", "Folder"]

        self.tableWidget = QtWidgets.QTableWidget(0, len(headers))
        self.tableWidget.setMaximumHeight(200)
        self.tableWidget.setMinimumWidth(500)
        self.tableWidget.setHorizontalHeaderLabels(headers)
        self.tableWidget.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.tableWidget.setSelectionMode(
            QtWidgets.QAbstractItemView.SingleSelection)


        self.openSelectedBtn = QtWidgets.QPushButton("Open")
        self.openSelectedBtn.setEnabled(False)
        self.openSelectedBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0228.png")))

        self.revertFileBtn = QtWidgets.QPushButton("Remove from changelist")
        self.revertFileBtn.setEnabled(False)
        self.revertFileBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0308.png")))

        self.refreshBtn = QtWidgets.QPushButton("Refresh")
        self.refreshBtn.setIcon(QtGui.QIcon(
            os.path.join(interop.getIconPath(), "File0175.png")))

        self.updateTable() 
Example #24
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
def test_load_ui_custom_auto(tmpdir):
    """
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    """

    app = get_qapp()

    with enabled_qcombobox_subclass(tmpdir):
        from qcombobox_subclass import _QComboBoxSubclass
        ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, _QComboBoxSubclass) 
Example #25
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
def test_load_ui():
    """
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    """
    app = get_qapp()
    ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, QComboBox) 
Example #26
Source File: QComplexWidgets.py    From pylustrator with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, axis: str, signal_target_changed: QtCore.Signal):
        """ A widget to change the tick properties

        Args:
            axis: whether to use the "x" or "y" axis
            signal_target_changed: a signal to emit when the target changed
        """
        QtWidgets.QWidget.__init__(self)
        self.setWindowTitle("Figure - " + axis + "-Axis - Ticks - Pylustrator")
        self.setWindowIcon(QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icons", "ticks.ico")))
        self.layout = QtWidgets.QVBoxLayout(self)
        self.axis = axis

        self.label = QtWidgets.QLabel(
            "Ticks can be specified, one tick pre line.\nOptionally a label can be provided, e.g. 1 \"First\",")
        self.layout.addWidget(self.label)

        self.layout2 = QtWidgets.QHBoxLayout()
        self.layout.addLayout(self.layout2)

        self.input_ticks = TextWidget(self.layout2, axis + "-Ticks:", multiline=True, horizontal=False)
        self.input_ticks.editingFinished.connect(self.ticksChanged)

        self.input_ticks2 = TextWidget(self.layout2, axis + "-Ticks (minor):", multiline=True, horizontal=False)
        self.input_ticks2.editingFinished.connect(self.ticksChanged2)

        self.input_scale = ComboWidget(self.layout, axis + "-Scale", ["linear", "log", "symlog", "logit"])
        self.input_scale.link(axis + "scale", signal_target_changed)

        self.input_font = TextPropertiesWidget(self.layout)

        self.input_labelpad = NumberWidget(self.layout, axis + "-Labelpad", min=-999)
        self.input_labelpad.link(axis + "axis.labelpad", signal_target_changed, direct=True)

        self.button_ok = QtWidgets.QPushButton("Ok")
        self.layout.addWidget(self.button_ok)
        self.button_ok.clicked.connect(self.hide) 
Example #27
Source File: test_uic.py    From winpython with MIT License 5 votes vote down vote up
def test_load_ui_custom_auto(tmpdir):
    """
    Test that we can load a .ui file with custom widgets without having to
    explicitly specify a dictionary of custom widgets, even in the case of
    PySide.
    """

    app = get_qapp()

    with enabled_qcombobox_subclass(tmpdir):
        from qcombobox_subclass import _QComboBoxSubclass
        ui = loadUi(os.path.join(os.path.dirname(__file__), 'test_custom.ui'))

    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, _QComboBoxSubclass) 
Example #28
Source File: test_uic.py    From winpython with MIT License 5 votes vote down vote up
def test_load_ui():
    """
    Make sure that the patched loadUi function behaves as expected with a
    simple .ui file.
    """
    app = get_qapp()
    ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
    assert isinstance(ui.pushButton, QtWidgets.QPushButton)
    assert isinstance(ui.comboBox, QComboBox) 
Example #29
Source File: test_qt_dock_widget.py    From napari with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_add_dock_widget(make_test_viewer):
    """Test basic add_dock_widget functionality"""
    viewer = make_test_viewer()
    widg = QPushButton('button')
    dwidg = viewer.window.add_dock_widget(widg, name='test')
    assert not dwidg.is_vertical
    assert viewer.window._qt_window.findChild(QDockWidget, 'test')
    assert dwidg.widget == widg
    dwidg._on_visibility_changed(True)  # smoke test

    widg2 = QPushButton('button')
    dwidg2 = viewer.window.add_dock_widget(widg2, name='test2', area='right')
    assert dwidg2.is_vertical
    assert viewer.window._qt_window.findChild(QDockWidget, 'test2')
    assert dwidg2.widget == widg2
    dwidg2._on_visibility_changed(True)  # smoke test

    with pytest.raises(ValueError):
        # 'under' is not a valid area
        viewer.window.add_dock_widget(widg2, name='test2', area='under')

    with pytest.raises(ValueError):
        # 'under' is not a valid area
        viewer.window.add_dock_widget(
            widg2, name='test2', allowed_areas=['under']
        )

    with pytest.raises(TypeError):
        # allowed_areas must be a list
        viewer.window.add_dock_widget(
            widg2, name='test2', allowed_areas='under'
        ) 
Example #30
Source File: QComplexWidgets.py    From pylustrator with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, layout: QtWidgets.QLayout, axis: str, signal_target_changed: QtCore.Signal):
        """ a widget to change the properties of an axes (label, limits)

        Args:
            layout: the layout to which to add this widget
            axis: whether to use "x" or the "y" axis
            signal_target_changed: the signal when a target changed
        """
        QtWidgets.QWidget.__init__(self)
        layout.addWidget(self)
        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.targetChanged = signal_target_changed
        self.targetChanged.connect(self.setTarget)

        self.input_label = TextWidget(self.layout, axis + "-Label:")

        def wrapTargetLabel(axis_object):
            try:
                target = getattr(getattr(axis_object, f"get_{axis}axis")(), "get_label")()
            except AttributeError:
                target = None
            self.targetChanged_wrapped.emit(target)

        self.targetChanged.connect(wrapTargetLabel)
        self.input_label.link("text", signal=self.targetChanged_wrapped)

        self.input_lim = DimensionsWidget(self.layout, axis + "-Lim:", "-", "", free=True)
        self.input_lim.link(axis + "lim", signal=self.targetChanged)

        self.button_ticks = QtWidgets.QPushButton(
            QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icons", "ticks.ico")), "")
        self.button_ticks.clicked.connect(self.showTickWidget)
        self.layout.addWidget(self.button_ticks)

        self.tick_edit = QTickEdit(axis, signal_target_changed)