Exemple #1
0
    def make_main_frame(self):
        self.main_frame = QWidget()
        win = pg.GraphicsWindow()
        self.crosshair_lb = pg.LabelItem(justify='right')
        win.addItem(self.crosshair_lb) 
        self.plot = win.addPlot(row=1, col=0) 
        self.plot.showGrid(x=True, y=True)
        self.right_panel = QGroupBox("Spectrometer Settings")
        
        hbox = QHBoxLayout()
        for w in [win, self.right_panel]:
            hbox.addWidget(w)

        form = QFormLayout()
        
        self.integration_sb = pg.SpinBox(value=0.001, bounds=(10*1e-6, 6553500*1e-6), suffix='s', siPrefix=True, \
                dec=True, step=1)
        self.integration_sb.valueChanged.connect(self.change_integration_time)

        self.persistence_sb = QtGui.QSpinBox()
        self.persistence_sb.setValue(7)
        self.persistence_sb.setRange(1,10)
        self.persistence_sb.valueChanged.connect(self.change_persistence)

        self.take_background_btn = QtGui.QPushButton('Take background')
        self.take_background_btn.clicked.connect(self.on_take_background)
        self.conc_lb = pg.ValueLabel()

        self.spec_temp_lb = pg.ValueLabel()

        self.use_background_cb = QtGui.QCheckBox("enabled")
        self.use_background_cb.stateChanged.connect(self.on_use_background)

        form.addRow("Integration time", self.integration_sb)
        form.addRow("Persistence",  self.persistence_sb)
        
        form.addRow("Background", self.take_background_btn)
        form.addRow("Use background", self.use_background_cb)
        self.right_panel.setLayout(form)
        self.main_frame.setLayout(hbox)
        self.setCentralWidget(self.main_frame)
Exemple #2
0
    def _init_ui(self, mainwindow):

        self.central_wid = QWidget(mainwindow)
        self._set_central_wid_properties()
        self.mainwindow = mainwindow
        self.mainwindow.setCentralWidget(self.central_wid)  
        
        

        # grid layout to put all widgets
        self.wid_layout = QGridLayout()
           
        
        # =====================================================================
        # control panel
        # =====================================================================
        self.graphics_layout = QGridLayout()
        self.vl = pg.ValueLabel(formatStr='{avgValue:0.2f} {suffix}')
        self.vl.setValue(-1)
        self.graphics_layout.addWidget(self.vl, 0, 0, 4, 4)
        
        
        # =====================================================================
        # control panel
        # =====================================================================
        self.controls_layout = QGridLayout()


        # =====================================================================
        # control buttons - layout
        # =====================================================================
        self.startBtn = QPushButton('START')
        self.controls_layout.addWidget(self.startBtn, 0, 0, 1, 1)
        self.stopBtn = QPushButton('STOP')
        self.controls_layout.addWidget(self.stopBtn, 1, 0, 1, 1)
        
        
        # =====================================================================
        # control buttons - connections
        # =====================================================================
        self.startBtn.clicked.connect(self.start_thread)
        self.stopBtn.clicked.connect(self.stop_thread)

       # ============================================================
        # put everything together
        # ============================================================
        self.wid_layout.addItem(self.graphics_layout, 0, 0, 2, 2)
        self.wid_layout.addItem(self.controls_layout, 0, 2, 2, 2)     
        # self.wid_layout.setColumnStretch(0, 10)
        # self.wid_layout.setColumnStretch(8, 2)
        
        self.central_wid.setLayout(self.wid_layout)
    def __init__(self):
        """Create the coarseScan GUI as used in the scanner app. Uses the coarse_scan_design.py from the \drivers folder.
        The actual scanning functionality is set in the scanning classes. These should be callable without the GUI"""
        QtGui.QWidget.__init__(self, None)

        # Set up the user interface from Designer.
        self.ui = Ui_Form()
        self.cs = CoarseScan()
        self.ui.setupUi(self)
        pg.ValueLabel(siPrefix=False, formatStr=None)
        self.plot_wdg = pg.PlotWidget()
        self.plot_wdg.enableAutoRange()

        self.plot_wdg.showAxis('top', show=True)
        self.plot_wdg.showAxis('right', show=True)
        pg.ValueLabel(siPrefix=False, formatStr=None)
        pg.setConfigOption('background', 0.3)
        pg.setConfigOption('foreground', 'w')

        self.ui.gridLayout.addWidget(self.plot_wdg, 0, 2, 8, 1)
        self.region = pg.LinearRegionItem()

        # Connect all the buttons etc
        # scanning
        self.ui.btn_scan.clicked.connect(self.scan)

        self.ui.comboBox_detection.activated[str].connect(
            (lambda: self.switch_channel()))
        self.ui.comboBox_wavelength.activated[str].connect(
            (lambda: self.switch_channel_2()))
        self.ui.comboBox_test_detection.activated[str].connect(
            (lambda: self.switch_channel_3()))
        self.ui.comboBox_pd_no_disk.activated[str].connect(
            (lambda: self.switch_channel_4()))
        self.ui.comboBox_plotting_coarse_scan.activated[str].connect(
            (lambda: self.plot_results()))
        self.ui.btn_save.clicked.connect(self.save_file)
 def visualise_pyqtgraph(self,
                         xdata,
                         ydata,
                         xlabel=None,
                         x_units=None,
                         ylabel=None,
                         y_units=None):
     self.plot_wdg.clear()
     pg.setConfigOption('background', 0.3)
     pg.setConfigOption('foreground', 'w')
     self.plot_wdg.enableAutoRange()
     pg.ValueLabel(siPrefix=False)
     pg.ValueLabel(parent=self.plot_wdg, siPrefix=False)
     self.plot_wdg.plot(xdata, ydata, pen='w')
     self.plot_wdg.setLabel("bottom",
                            text=str(xlabel),
                            units=str(x_units),
                            unitPrefix=" ")
     self.plot_wdg.setLabel("left",
                            text=str(ylabel),
                            units=str(y_units),
                            unitPrefix=" ")
     pg.ValueLabel(parent=self.plot_wdg, siPrefix=False)
     pg.ValueLabel(siPrefix=False)
    def home(self):
        """Build the main interface here"""
        pg.setConfigOption('background', 0.3)
        pg.setConfigOption('foreground', 'w')
        pg.ValueLabel(siPrefix=True, formatStr=None)
        # main layout
        self.mainLayout = QtGui.QVBoxLayout()

        # add all main to the main vLayout
        self.mainLayout.addWidget(coarse_scan_GUI())
        self.mainLayout.addWidget(fine_scan_GUI())
        #self.mainLayout.addWidget(self.scrollArea)

        # central widget
        self.centralWidget = QtGui.QWidget()
        self.centralWidget.setLayout(self.mainLayout)

        # set central widget
        self.setCentralWidget(self.centralWidget)
Exemple #6
0
    def __init__(self, text='', parent=None, suffix='', siPrefix=False, averageTime=0, formatStr=None, siPrecision=3, textUpdateTime=None, **kwargs):
        """
        Convenience class that combines pyqtgraph.ValueLabel into a pyqtgraph.LabelItem.
        It inherits from LabelItem so see that documentation for usage and arguments.
        It adds the setValue method of ValueLabel. All other unknown methods are passed on to the internal ValueLabel
        object.
        The ValueLabel arguments are passed on to the internal ValueLabel object.
        It has two additional arguments. siPrecision allows to modify the number of significant digits while the
        ValueLabel has siPrefix=True. textUpdateTime allows to reduce the frequency of updating the gui by not updating
        the text every call to setValue (default value of None, does update every time)
        Note that the arguments of LabelItem are not included in this docstring (except for text), please refer to
        LabelItem documentation.

        :param text: initial text to display (see pyqtgraph.LabelItem)
        :type text: str
        :param suffix: the (SI) unit
        :type suffix: str
        :param siPrefix: when True it converts things like 0.024 V to 24 mV
        :type siPrefix: bool
        :param averageTime: optional, see pyqtgraph.ValueLabel
        :type averageTime: float
        :param formatStr: optional, see pyqtgraph.ValueLabel
        :type formatStr: str
        :param siPrecision: optional, allows to deviate from the default of 3 significant digits
        :type siPrecision: int
        :param textUpdateTime: optional, time between updates of text (default is None which updates every time)
        :type textUpdateTime: float
        """
        value_kwargs = {'parent':parent}
        if suffix is not None:
            value_kwargs['suffix'] = suffix
        if siPrefix is not None:
            value_kwargs['siPrefix'] = siPrefix
        if averageTime is not None:
            value_kwargs['averageTime'] = averageTime
        if formatStr is not None:
            value_kwargs['formatStr'] = formatStr
        super().__init__(text=text, parent=parent, **kwargs)
        self._ValueLabel = pg.ValueLabel(**value_kwargs)
        self.__siPrecision = siPrecision
        self.__textUpdateTime = textUpdateTime
        self.__last_update_text = time()
    def __init__(
        self,
        names: tuple = ("Process Variable", "Controller Output"),
        numPoints: int = 200,
        interval: int = 17,
        ranges: tuple = ((-2.0, 2.0), (-2.0, 2.0)),
        units: tuple = ('Monkeys', 'Parrots'),
        controlPipe: multiprocessing.connection.Connection = None,
        streamPipeRX: multiprocessing.connection.Connection = None,
        theme: str = 'dark',
    ):
        """
        Graphs' constructor. Lengths of tuple arguments should be equal and each item in them should respectively match
        others

        :param names: tuple of strings with graphs' names
        :param numPoints: number of points in each graph
        :param interval: time in ms to force the plot refresh
        :param ranges: tuple of tuples with (min,max) values of each plot respectively
        :param units: tuple of strings representing measurement unit of each plot
        :param controlPipe: multiprocessing.Connection instance to communicate with a stream source
        :param streamPipeRX: multiprocessing.Connection instance from where new points should arrive
        :param theme: string representing visual appearance of the widget ('light' or 'dark')
        """

        # lengths of tuple arguments should be equal
        assert len(names) == len(ranges) == len(units)

        # need to set a theme before any other pyqtgraph operations
        if theme != 'dark':
            pyqtgraph.setConfigOption('background', 'w')
            pyqtgraph.setConfigOption('foreground', 'k')

        super(CustomGraphicsLayoutWidget, self).__init__()

        self.nPoints = numPoints
        self.pointsCnt = 0
        self.lastPoint = np.zeros(len(names))
        self.interval = interval

        self.names = list(names)  # for usage outside the class
        self.ranges = list(ranges)

        # X (time) axis is "starting" at the right border (current time) and goes to the past to the left (negative
        # time). It remains the same for an entire Graphs lifetime
        self.timeAxes = np.linspace(-numPoints * interval, 0, numPoints)

        if controlPipe is not None and streamPipeRX is not None:
            self._isOfflineMode = False

            self.controlPipe = controlPipe

            self.overflowCheckTimer = QTimer()
            self.overflowCheckTimer.timeout.connect(self._overflowCheck)

            self.streamPipeRX = streamPipeRX
        else:
            self._isOfflineMode = True

        self._isRun = False

        self.graphs = []
        for name, range in zip(names, ranges):
            if name == names[-1]:
                graph = self.addPlot(y=np.zeros(numPoints),
                                     labels={
                                         'right': name,
                                         'bottom': "Time, ms"
                                     },
                                     pen='r')
            else:
                graph = self.addPlot(y=np.zeros(numPoints),
                                     labels={'right': name},
                                     pen='r')
            graph.setRange(yRange=range)
            graph.hideButtons()
            graph.hideAxis('left')
            graph.showGrid(x=True, y=True, alpha=0.2)
            self.graphs.append(graph)
            self.nextRow()

        # label widget accumulating incoming values and calculating an average from last 'averageTime' seconds
        self.averageLabels = []
        for name, unit in zip(names, units):
            averageLabel = pyqtgraph.ValueLabel(siPrefix=True,
                                                suffix=unit,
                                                averageTime=numPoints *
                                                interval * 0.001)
            averageLabel.setToolTip(
                f"Average {name} value of last {averageLabel.averageTime:.2f}s"
            )
            self.averageLabels.append(averageLabel)

        # data receiving and plots redrawing timer
        self.updateTimer = QTimer()
        self.updateTimer.timeout.connect(self._update)

        # notify a user about an overflow by a red circle appearing in an upper-left corner of the plot canvas
        self._warningSign = None
        self.warningSignRemoveTimer = QTimer()
        self.warningSignRemoveTimer.setSingleShot(True)
        self.warningSignRemoveTimer.setInterval(
            STREAM_PIPE_OVERFLOW_WARNING_SIGN_DURATION)
        self.warningSignRemoveTimer.timeout.connect(self._removeWarningSign)
Exemple #8
0
"""

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtWidgets

app = pg.mkQApp("Joystick Button Example")
mw = QtWidgets.QMainWindow()
mw.resize(300, 50)
mw.setWindowTitle('pyqtgraph example: JoystickButton')
cw = QtWidgets.QWidget()
mw.setCentralWidget(cw)
layout = QtWidgets.QGridLayout()
cw.setLayout(layout)
mw.show()

l1 = pg.ValueLabel(siPrefix=True, suffix='m')
l2 = pg.ValueLabel(siPrefix=True, suffix='m')
jb = pg.JoystickButton()
jb.setFixedWidth(30)
jb.setFixedHeight(30)

layout.addWidget(l1, 0, 0)
layout.addWidget(l2, 0, 1)
layout.addWidget(jb, 0, 2)

x = 0
y = 0


def update():
    global x, y, l1, l2, jb
Exemple #9
0
w2 = pg.console.ConsoleWidget()
d2.addWidget(w2)

## Hide title bar on dock 3
d3.hideTitleBar()
w3 = pg.PlotWidget(title="Plot inside dock with no title bar")
w3.plot(np.random.normal(size=100))
d3.addWidget(w3)

w4 = pg.PlotWidget(title="temp")
w4.plot(np.random.normal(size=100))
d4.addWidget(w4)

w5 = pg.ImageView()
w5.setImage(np.random.normal(size=(100, 100)))
d5.addWidget(w5)

w6 = pg.ValueLabel(suffix="bpm")
formatStr = None
d6.addWidget(w6)

#lcd = QtGui.QLCDNumber(self)

win.show()

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()