예제 #1
0
def show():
    log = logging.getLogger()
    log.setLevel(logging.DEBUG)

    app = application()

    logger = Logger(fmt='%(message)s')
    logger.setWindowTitle('Logger Widget')

    for i in range(1, 101):
        level = random.randint(10, 60)
        if level < logging.INFO:
            log.debug('DEBUG {}'.format(i))
        elif level < logging.WARNING:
            log.info('INFO {}'.format(i))
        elif level < logging.ERROR:
            log.warning('WARN {}'.format(i))
        elif level < logging.CRITICAL:
            log.error('ERROR {}'.format(i))
        else:
            log.critical('CRITICAL {}'.format(i))

    logger.resize(800, 400)
    logger.show()
    app.exec()
예제 #2
0
def show():
    app = application()
    w = ConfigurationViewer()
    w.setWindowTitle('MSL-Equipment Configuration Viewer')
    w.resize(app.desktop().width() // 2, app.desktop().height() // 2)
    w.show()
    app.exec_()
예제 #3
0
    def __init__(self):

        app = application()

        self.tab_widget = QtWidgets.QTabWidget()

        self.main_window = QtWidgets.QMainWindow()
        self.main_window.setWindowTitle('Standard Icons')
        self.main_window.setCentralWidget(self.tab_widget)
        self.main_window.closeEvent = self.close_event

        # add a progress bar to the status bar
        self.progress_bar = QtWidgets.QProgressBar(
            self.main_window.statusBar())
        self.progress_bar.setAlignment(QtCore.Qt.AlignCenter)
        self.main_window.statusBar().addPermanentWidget(self.progress_bar)
        self.main_window.showMaximized()

        self.num_icons = 0
        self.file_index = 0
        self.zoom_widget = QtWidgets.QDialog()
        self.zoom_widget.setSizeGripEnabled(True)
        self.zoom_widget.resize(QtCore.QSize(256, 256))
        self.zoom_widget.setWindowFlags(QtCore.Qt.WindowCloseButtonHint)
        vbox = QtWidgets.QVBoxLayout()
        self.zoom_label = QtWidgets.QLabel()
        self.zoom_label.setScaledContents(True)
        vbox.addWidget(self.zoom_label)
        self.zoom_widget.setLayout(vbox)

        qt_icons = [sp for sp in dir(QtWidgets.QStyle) if sp.startswith('SP_')]

        self.windows_files = [
            'accessibilitycpl', 'compstui', 'ddores', 'dmdskres', 'explorer',
            'gameux', 'ieframe', 'imageres', 'mmcndmgr', 'mmres', 'moricons',
            'netcenter', 'netshell', 'networkexplorer', 'pifmgr', 'pnidui',
            'sensorscpl', 'setupapi', 'shell32', 'wmploc', 'wpdshext'
        ]

        self.num_files = 1 + len(self.windows_files)
        self.progress_bar.setRange(0, self.num_files)

        self.add_qt_tab('Qt Icons', qt_icons)

        if has_clr:
            self.windows_index = 0
            self.timer = QtCore.QTimer()
            self.timer.timeout.connect(self.add_windows_tab)
            self.timer.start(0)
        else:
            self.update_message('Loaded {} icons.'.format(self.num_icons))
            self.progress_bar.hide()

        app.exec()
예제 #4
0
def show():
    app = application()
    window = QtWidgets.QWidget()
    window.setWindowTitle('Toggle Switch Example')
    hbox = QtWidgets.QHBoxLayout()
    ts = ToggleSwitch(window)
    ts.toggled.connect(print_state)
    hbox.addWidget(ts)
    window.setLayout(hbox)
    window.show()
    app.exec_()
예제 #5
0
def show():
    app = application()
    b = Button(text='My button', icon=32, icon_size=4., left_click=left, tooltip='Example button')
    b.set_right_click(right)
    b.add_menu_item('My item #1', triggered=item1, shortcut='CTRL+I', icon=43)
    b.add_menu_item('My item #2', triggered=item2, icon=47, tooltip='Second')
    b.add_menu_item('My item #3', shortcut='CTRL+Z', icon=46, tooltip='Visible but disabled (triggered not set)')
    b.add_menu_separator()
    b.add_menu_item('My item #4', triggered=item4, tooltip='Fourth')
    b.show()
    app.exec_()
예제 #6
0
    def read_n_raw_readings(self, n_meas=250, trig_interval=0.02):
        """

        Parameters
        ----------
        n_meas : int
            number of measurements to collect

        Returns
        -------
        tuple of t0_s, data.
        t0_s is the initial time in number of seconds passed since epoch;
        data is a list of n_meas raw values from the RF counter, in Hz
        """
        # set up for fast graphing
        app = application()
        mw = QtWidgets.QMainWindow()
        mw.setWindowTitle("Capacitor raw data")
        cw = QtWidgets.QWidget()
        mw.setCentralWidget(cw)
        layout = QtWidgets.QVBoxLayout()
        cw.setLayout(layout)
        pw1 = pg.PlotWidget(name='Capacitor raw data')
        curve = pw1.plot()
        layout.addWidget(pw1)
        mw.show()

        self.rfcounter.write("INPUT:LEVEL:AUTO ONCE")   # only need to get frequency level once
        self.rfcounter.write("INIT")                    # starts waiting for a trigger
        data = np.empty(n_meas)

        if self.triggerer is not None:
            self.triggerer.start_trigger()

        t0_s = time_ns()/1e9
        rdgs_per_s = 1/trig_interval

        for i in range(n_meas):
            a = self.rfcounter.query("DATA:REM? 1,WAIT")  # a is a string
            # read one data value taken from memory to buffer; remove value from memory after reading
            data[i] = float(a.strip("\n"))

            if i % rdgs_per_s == 0:  # update plot every second
                curve.setData(data[:i])  # show only the collected data
                app.processEvents()

        if self.triggerer is not None:
            self.triggerer.stop_trigger()

        t1_s = time_ns() / 1e9
        print("Elapsed time: {}".format(t1_s - t0_s))

        return t0_s, data
예제 #7
0
def configure(client, **kwargs):
    """Create a Qt application to interact with the image and the OCR algorithm.

    Parameters
    ----------
    client : :class:`~ocr.client.OCRClient`
        The client that is connected to the Raspberry Pi.
    kwargs
        All key-value pairs are passed to the :class:`Gui`.

    Returns
    -------
    :class:`dict`
        The OCR parameters.
    """
    sys.excepthook = excepthook
    app = application()
    gui = Gui(client, **kwargs)
    gui.show()
    app.exec()
    return gui.ocr_params
예제 #8
0
def test_finished():
    class MyWorker(Worker):
        def __init__(self, index):
            super(MyWorker, self).__init__()
            self.index = index
            self.squared = None

        def process(self):
            QtCore.QThread.msleep(500)
            self.squared = self.index**2

    class MyThread(Thread):
        def __init__(self):
            super(MyThread, self).__init__(MyWorker)

    def slot1():
        values.append(t.squared)

    def slot2():
        values.append(t.squared)

    values = []
    app = application()
    t = MyThread()
    t.finished.connect(slot1)
    t.finished.connect(slot2)
    t.start(4)
    assert len(values) == 0
    while t.is_running():
        t.wait(10)
        app.processEvents()

    # allow some time for the event loop to emit the finished() signal to the slots
    for i in range(10):
        QtCore.QThread.msleep(10)
        app.processEvents()

    assert values == [16, 16]
    t.quit()
예제 #9
0
def show():
    log = logging.getLogger()

    app = application()

    logger = Logger()
    logger.setWindowTitle('Logger Widget')

    for i in range(100):
        level = random.randint(10, 60)
        if level < logging.INFO:
            log.debug('debug message {}'.format(i + 1))
        elif level < logging.WARNING:
            log.info('info message {}'.format(i + 1))
        elif level < logging.ERROR:
            log.warning('warning message {}'.format(i + 1))
        elif level < logging.CRITICAL:
            log.error('error message {}'.format(i + 1))
        else:
            log.critical('critical message {}'.format(i + 1))

    logger.resize(800, 400)
    logger.show()
    app.exec_()
예제 #10
0
def show():
    app = application()
    b = BlinkingLEDs()
    b.show()
    app.exec()
예제 #11
0
파일: conftest.py 프로젝트: MSLNZ/msl-qt
import os
import sys

if 'QT_API' not in os.environ and not os.getenv('GITHUB_ACTIONS'):
    os.environ['QT_API'] = 'PySide6' if sys.version_info.minor > 5 else 'PySide2'

sys.excepthook = print

from msl.qt import application
app = application()
예제 #12
0
def test_worker_raises_exception():
    class MyWorker(Worker):
        def __init__(self, seconds, raise_exception):
            super(MyWorker, self).__init__()
            self.seconds = seconds
            self.raise_exception = raise_exception
            self.result = -1

        def process(self):
            QtCore.QThread.sleep(self.seconds)
            if self.raise_exception:
                raise OSError('Cannot open file')
            self.result = self.seconds

    class MyThread(Thread):
        def __init__(self):
            super(MyThread, self).__init__(MyWorker)

        def error_handler(self, exception, traceback):
            assert 'Cannot open file' == str(exception)

    app = application()
    threads = [MyThread() for i in range(10)]

    # check that calling the methods that require
    # self._thread to be created do not raise an exception
    assert all([not thread.is_running() for thread in threads])
    assert all([not thread.is_finished() for thread in threads])
    for t in threads:
        assert t.quit() is None
        assert t.wait() is None
        assert t.stop() is None

    # start certain threads
    for index, thread in enumerate(threads):
        if index % 2:
            thread.start(index,
                         index > 5)  # only raise the exception if index > 5

    assert all(
        [thread.is_running() for i, thread in enumerate(threads) if i % 2])
    assert all([
        not thread.is_running() for i, thread in enumerate(threads)
        if not i % 2
    ])
    assert all([not thread.is_finished() for thread in threads])

    # The following tests that a RuntimeError exception is not raised
    #   RuntimeError: Internal C++ object (*.QtCore.QThread) already deleted.
    #
    # The fact that this test finishes also shows that the QThread did properly quit
    # after an exception is raised by the Worker
    while any([thread.is_running() for thread in threads]):
        for thread in threads:
            thread.wait(100)
        app.processEvents()

    # another check that calling wait() won't block forever
    for thread in threads:
        thread.wait()

    assert all([not thread.is_running() for thread in threads])

    # the threads that started and did not raise an error are finished
    # the threads that never started or that raised an exception are not finished
    assert all([
        thread.is_finished() for i, thread in enumerate(threads)
        if i in [1, 3, 5]
    ])
    assert all([
        not thread.is_finished() for i, thread in enumerate(threads)
        if not i % 2
    ])

    # get the result from each worker
    for index, thread in enumerate(threads):
        if index == 1 or index == 3 or index == 5:
            assert thread.result == index
        elif not index % 2:
            with pytest.raises(AttributeError,
                               match=r'You must start the Thread'):
                r = thread.result
        else:
            assert thread.result == -1
예제 #13
0
def show():
    app = application()
    mb = MessageBased(record.connect(True))
    mb.resize(app.desktop().width() // 2, app.desktop().height() // 2)
    mb.show()
    app.exec_()