def plotDataset(self, dataset, irow, kind='osc'): #datatype = dataset.attrs['datatype'] sr = float(dataset.attrs['sampling_rate']) t = np.arange(0, len(dataset)) / sr if kind == 'osc': pl = self.data_layout.addPlot(title=dataset.name, name=str(irow), row=irow, col=0) pl.plot(t, dataset) pl.showGrid(x=True, y=True) #pl.Dow if kind == 'spec': Pxx, freqs, ts = specgram(dataset, Fs=sr, NFFT=512, noverlap=400) img = pg.ImageItem(np.log(Pxx.T)) #img.setLevels((-5, 10)) img.setScale(ts[-1] / Pxx.shape[1]) vb = self.data_layout.addViewBox(name=str(irow), row=irow, col=0) g = pg.GridItem() vb.addItem(g) vb.addItem(img) vb.setMouseEnabled(x=True, y=False) return vb, img return pl
def configNewAxis(self): assert isinstance(self.ax, pg.AxisItem) assert isinstance(self.vb, pg.ViewBox) self.ax.setZValue(self.z_value) axis_width = self.plot_area.main_window.axis_width self.setAxisLabel() self.ax.linkToView(self.vb) if self.ax.preferredWidth() <= axis_width: self.ax.setWidth(w=axis_width) old_axis = self.plot_area.layout.getItem(0, 0) if isinstance(old_axis, pg.AxisItem): if old_axis.width() > self.ax.width(): axis_width = old_axis.width() self.ax.setWidth(w=axis_width) self.plot_area.layout.removeItem(old_axis) self.ax.update() self.plot_area.layout.addItem(self.ax, row=0, col=0) """ By default the major bottom (x) axis of the plot area has its tick labels hidden, in case multiple plotted signals are not synced. Each time a new view is added a separate GridItem is created. pg.GridItem() does not accept any inputs, thus changing grid line style has to be done inside, or GridItem class needs an update. """ gr = pg.GridItem() self.vb.addItem(gr) self.ax.geometryChanged.connect(self.plot_area.maxWidthChanged)
def init_img_view_box(self): """""" vb = pg.ViewBox() vb.setAspectLocked() # Add axis # self.add_axis(vb, 'left', 200, '') # self.add_axis(vb, 'bottom', 0, 'T') # self.add_axis_name(vb) self.add_axis_name(vb, name='Time (n of freq calculated)', pos=(100, 0), angle=0) self.add_axis_name(vb, name='Frequency (Hz - need to correct)', pos=(-10, 50), angle=90) # img of the spectrogram img = pg.ImageItem( ) # TODO: ALEXM: rotate so that it is in the right direction (longest with longest) vb.addItem(img) # grid g = pg.GridItem() vb.addItem(g) # wave name txt self.add_wave_name_txt_label(vb) pg_layout = pg.GraphicsLayoutWidget() pg_layout.addItem(vb) return pg_layout, img
def _populate_gui(self): ''' Create plots and other things in the GUI ''' self.view_box = pyqtgraph.ViewBox() self.win.setCentralItem(self.view_box) # TODO Since the graphics object does code parsing it needs to interact with the view window. Seems ugly self.stream_graphics_object = StreamGraphicsObject(self) self.view_box.addItem(self.stream_graphics_object) self.grid_item = pyqtgraph.GridItem() self.view_box.addItem(self.grid_item)
def initUI(self): self.setWindowTitle('Profile') layout = self.addLayout(row=1, col=1) ### view box to draw profile and semi mask self.viewBox = layout.addViewBox(row=1, col=0, lockAspect=True) ### grid gridItem = pg.GridItem() self.viewBox.addItem(gridItem)
def buildGraph(self): """ Add data to the graph """ dataColor = (102,178,255) dataBorderColor = (180,220,255) barGraph = self.graph.plotWidget barGraph.clear() barGraph.addItem(pyqtgraph.BarGraphItem(x=range(len(self.x)), height=self.y, width=0.5, brush=dataColor, pen=dataBorderColor)) barGraph.addItem(pyqtgraph.GridItem()) barGraph.getAxis('bottom').setTicks([self.x]) barGraph.setTitle(title=self.graphTitle)
def __init__(self): super(ImageGraph, self).__init__() # Add image window object data = np.random.normal(size=(100, 100)) self.image_item = pg.ImageItem() self.set_image(data) # Create graph object self.view_box = self.w.addViewBox(lockAspect=True, row=1, col=0) # Add to viewbox g = pg.GridItem() self.view_box.addItem(g) self.view_box.addItem(self.image_item)
def __init__(self): super(SplineEditorTestWidget, self).__init__() self.spl_roi = SplineROI(pos=[(0, 0), (1, 1), (10, 10), (10, 20)]) self.setGeometry(300, 300, 450, 450) self.setWindowTitle("Bezier Curves") ############################### # Set up UI ############################### self.ui = Ui_Form() self.ui.setupUi(self) self.vb = self.ui.canvas.addViewBox() self.vb.addItem(self.spl_roi) self.vb.addItem(pg.GridItem())
def clicked(): # print("button click") btn = QtGui.QPushButton("BTN") btn.clicked.connect(clicked) prox = QtGui.QGraphicsProxyWidget() prox.setWidget(btn) prox.setPos(100,0) vb.addItem(prox) g = pg.GridItem() vb.addItem(g) ## Start Qt event loop unless running in interactive mode. if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()
def __init__(self, layout, image_arrays=[], configs=None): QtGui.QWidget.__init__(self) self.w = layout self.image_arrays = image_arrays self.imroi = [] ## only used by send_back, considering remove this self.images = {} self.raw_array = {} self.triangulation_array = None self.warped_top_array = None self.backActivated = False self.state = { 'lastAlign': None, ## 'rigid'/'affine' 'heatmapLoaded': False, 'heatmapShown': False, 'lastHeatmap': None, 'showTri': True, } self.prev_region = [{ 'size': None, 'pos': None, 'angle': None }, { 'size': None, 'pos': None, 'angle': None }] self.affine_matrix = None self.piecewise_param = None self.projective_tform = None self.v = self.w.addViewBox(row=0, col=0, lockAspect=True) self.button_area = ButtonArea(parent=self, mode='panel') self.w.addItem(self.button_area, row=1, col=0) self.w.layout.setRowFixedHeight(1, 12.) g = pg.GridItem() self.v.addItem(g) for i, arr in enumerate(self.image_arrays): self.add_image(arr) ## signals self.button_area.buttons['restore'].clicked.connect( self.restore_alignment) self.button_area.buttons['tri'].clicked.connect( self.triangulation_requested)
def init_viewbox(): """Helper function to init the ViewBox """ global win, vb win = pg.GraphicsWindow() win.ci.layout.setContentsMargins(0,0,0,0) win.resize(200, 200) win.show() vb = win.addViewBox() # set range before viewbox is shown vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0) # required to make mapFromView work properly. qtest.qWaitForWindowShown(win) g = pg.GridItem() vb.addItem(g) app.processEvents()
def create_dashboard(data, peaks): global i, cnt, j, pk, xk, yk, posx, posy, text, hr class KeyPressWindow(pg.GraphicsLayoutWidget): sigKeyPress = QtCore.pyqtSignal(object) def keyPressEvent(self, ev): self.scene().keyPressEvent(ev) self.sigKeyPress.emit(ev) def keyPressed(evt): if evt.key() == QtCore.Qt.Key_P: timer.stop() if evt.key() == QtCore.Qt.Key_S: timer.start() timer = QtCore.QTimer() app = QtGui.QApplication(sys.argv) w1 = KeyPressWindow() w1.setBackground((155, 155, 155)) w1.sigKeyPress.connect(keyPressed) w1.show() w1.resize(tk.Tk().winfo_screenwidth(), tk.Tk().winfo_screenheight()) cnt = 0 s4 = pg.ScatterPlotItem(size=10, pen=pg.mkPen(0.5), brush=pg.mkBrush(0, 0, 255, 120)) st = 1 j = 0 ax = [] hr = 50 ############ECG PLOT############# p = w1.addPlot(row=0, col=0, colspan=3) p.hideAxis('left') p.hideAxis('bottom') plt_grid = pg.GridItem() # plt_grid.setPen() # plt_grid.hideAxis('left') vb = p.getViewBox() vb.setBackgroundColor((255, 255, 255)) curveax = p.plot(pen=pg.mkPen((0, 0, 0), width=1)) p.addItem(curveax) p.addItem(s4) p.addItem(plt_grid) # p.showGrid(x = True, y = True) #####################################3 #####HEART RATE############# x = np.linspace(-5, 5, 10) y = np.sin(x) / x p1 = w1.addPlot(row=1, col=0) p1.plot(x=x, y=y, pen=(255, 255, 255)) vb1 = p1.getViewBox() vb1.setBackgroundColor((255, 255, 255)) fileName1 = '/home/hticpose/Pictures/Picture3.jpg' img1 = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap(fileName1)) img1.scale(1, -1) p1.hideAxis('left') p1.hideAxis('bottom') p1.addItem(img1) text = pg.TextItem("test", color=(0, 0, 0), anchor=(-0.3, 0.5)) changingLabel = QtGui.QLabel() font = changingLabel.font() font.setPointSize(86) text.setFont(font) texthr = pg.TextItem("test", color=(0, 0, 0), anchor=(-0.3, 0.5)) changingLabel = QtGui.QLabel() fonthr = changingLabel.font() fonthr.setPointSize(40) texthr.setFont(fonthr) texthr.setText("HR") texthr.setPos(130, y.max() / 2 - 220) p1.addItem(text) p1.addItem(texthr) ################################# #####BREATHING RATE############# x1 = np.linspace(-5, 5, 10) y1 = np.sin(x1) / x1 p2 = w1.addPlot(row=1, col=1) p2.plot(x=x1, y=y1, pen=(255, 255, 255)) vb2 = p2.getViewBox() vb2.setBackgroundColor((255, 255, 255)) fileName2 = '/home/hticpose/Pictures/edit br.jpg' img2 = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap(fileName2)) img2.scale(1, -1) p2.addItem(img2) p2.hideAxis('left') p2.hideAxis('bottom') text1 = pg.TextItem("test", color=(0, 0, 0), anchor=(-0.3, 0.5)) changingLabel = QtGui.QLabel() font1 = changingLabel.font() font1.setPointSize(86) text1.setFont(font1) textbr = pg.TextItem("test", color=(0, 0, 0), anchor=(-0.3, 0.5)) changingLabel = QtGui.QLabel() fontbr = changingLabel.font() fontbr.setPointSize(40) textbr.setFont(fontbr) textbr.setText("BR") textbr.setPos(130, y.max() / 2 - 220) p2.addItem(text1) p2.addItem(textbr) ################################# ###### MESSAGE ############# p3 = w1.addPlot(row=1, col=2) p3.plot(x=x1, y=y1, pen=(255, 255, 255)) vb3 = p3.getViewBox() vb3.setBackgroundColor((255, 255, 255)) p3.hideAxis('left') p3.hideAxis('bottom') ########################## xk = [x for x in peaks[0] if x <= 1000] yk = [float(data[0][y]) for y in xk] for i in range(st, st + 1000): ax.append(float(data[0][i])) cnt = len(xk) def update(): global i, j, cnt, xk, yk, text, k, hr s4.clear() ax.pop(0) if (len(xk) != 0 and xk[0] < 1): xk.pop(0) yk.pop(0) xk = [x - 1 for x in xk] if (i + 1 < len(data[j])): i += 1 if (cnt < len(peaks[j]) and i == peaks[j][cnt]): cnt += 1 xk.append(1000) yk.append(data[j][i]) else: hr += 100 cnt = 0 j += 1 i = 0 if (hr > 150): hr = 50 ax.append(float(data[j][i])) posx = [x - 1 for x in xk] posy = yk print(i) # if i%50 == 0: # p1.removeItem(img1) # p1.removeItem(text) # p1.removeItem(texthr) # # text.setText('') # else: # p1.addItem(img1) # p1.addItem(text) # p1.addItem(texthr) text.setText('{}'.format(hr)) text1.setText('{}'.format(hr)) if hr < 100: text.setPos(95, y.max() / 2 - 160) text1.setPos(95, y.max() / 2 - 160) else: text.setPos(60, y.max() / 2 - 160) text1.setPos(60, y.max() / 2 - 160) s4.addPoints(x=posx, y=posy) curveax.setData(ax) timer.timeout.connect(update) timer.start(5) if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()
def _createVB(self): """ create a vb to show xy-view :return: """ self.bd = pg.GraphicsLayoutWidget() # set left-axis left_axis = pg.AxisItem(orientation='left', pen=(255, 255, 255)) left_axis.setLabel(text='X', units='m') left_axis.setTickSpacing(5, 1) left_axis.enableAutoSIPrefix(False) self.bd.ci.addItem(left_axis, 0, 0) # set vb self.vb = pg.ViewBox(name='Birdview') self.bd.ci.addItem(self.vb, 0, 1) # set bottom-axis bottom_axis = pg.AxisItem(orientation='bottom', pen=(255, 255, 255)) bottom_axis.setLabel(text='Y', units='m') bottom_axis.setTickSpacing(5, 1) bottom_axis.enableAutoSIPrefix(False) self.bd.ci.addItem(bottom_axis, 1, 1) # set stretch layout = self.bd.ci.layout layout.setContentsMargins(1, 1, 1, 1) layout.setHorizontalSpacing(0) layout.setVerticalSpacing(0) for i in range(2): layout.setRowPreferredHeight(i, 0) layout.setRowMinimumHeight(i, 0) layout.setRowSpacing(i, 10) layout.setRowStretchFactor(i, 1000) layout.setRowStretchFactor(1, 1) for i in range(2): layout.setColumnPreferredWidth(i, 0) layout.setColumnMinimumWidth(i, 0) layout.setColumnSpacing(i, 0) layout.setColumnStretchFactor(i, 1) layout.setColumnStretchFactor(1, 1000) # linx axis left_axis.linkToView(self.vb) bottom_axis.linkToView(self.vb) # invert left-axis self.vb.invertX() # set the default range self.vb.setXRange(-200, 200) self.vb.setYRange(0, 200) # add grid grid = pg.GridItem() self.vb.addItem(grid) # add inf-line h_line = pg.InfiniteLine(pos=(0, 0), angle=0, pen=self.background_Pen) v_line = pg.InfiniteLine(pos=(0, 0), angle=90, pen=self.background_Pen) self.vb.addItem(h_line) self.vb.addItem(v_line)
import pyqtgraph as pg import microdaq # Params DATA_COUNT = 10000 SAMPLE_RATE_HZ = 100000 DURATION_SEC = 60 CHANNEL = 1 # Create plot with pyqtgraph win = pg.GraphicsWindow(title="Scope FFT - demo") win.resize(800, 600) p_data = win.addPlot(row=1, col=1, title="ANALOG INPUT (CHANNEL 1)") p_data.addItem(pg.GridItem()) p_data.setLabel(axis="left", units="V") p_fft = win.addPlot(row=2, col=1, title="FFT (CHANNEL 1)") p_fft.addItem(pg.GridItem()) p_fft.setLabel(axis="bottom", units="Hz") xf = np.arange(DATA_COUNT / 2) * (SAMPLE_RATE_HZ / DATA_COUNT) xd = np.arange(DATA_COUNT) p_fft_handle = p_fft.plot(xf, np.zeros(int(DATA_COUNT / 2)), pen="r") p_data_handle = p_data.plot(xd, np.zeros(DATA_COUNT), pen="g") # Create MLink object, connect to MicroDAQ device mdaq = microdaq.Device("10.10.1.1") # Init analog input scan
def initUI(self): self.ui.actionExit.toggled.connect(self.closeEvent) self.ui.scan1D_filePath_find.clicked.connect(self.scan1D_filePath_find) self.ui.scan3D_path_dialog.clicked.connect(self.scan3D_path_dialog) self.ui.usbSpectr_set_integr_time.clicked.connect( self.usbSpectr_set_integr_time) self.ui.connect_DAQmx.toggled[bool].connect(self.connect_DAQmx) self.ui.DAQmx_find_shift.clicked.connect(self.optimizeDAQmx) self.ui.HWP_go.clicked.connect(self.HWP_go) self.ui.HWP_go_home.clicked.connect(self.HWP_go_home) self.ui.HWP_negative_step.clicked.connect(self.HWP_negative_step) self.ui.HWP_positive_step.clicked.connect(self.HWP_positive_step) self.ui.Pi_X_go.clicked.connect(self.Pi_X_go) self.ui.Pi_Y_go.clicked.connect(self.Pi_Y_go) self.ui.Pi_Z_go.clicked.connect(self.Pi_Z_go) self.ui.Pi_XYZ_50mkm.clicked.connect(self.Pi_XYZ_50mkm) self.ui.Pi_autoZero.clicked.connect(self.Pi_autoZero) self.ui.connect_rotPiezoStage.toggled[bool].connect( self.connect_rotPiezoStage) self.ui.rotPiezoStage_Go.clicked.connect(self.rotPiezoStage_Go) self.ui.scanPolar.toggled[bool].connect(self.scanPolar) self.ui.scan1D_Scan.toggled[bool].connect(self.scan1D_Scan) self.ui.start3DScan.toggled[bool].connect(self.start3DScan) self.ui.fast3DScan.toggled[bool].connect(self.start_fast3DScan) self.ui.startCalibr.toggled[bool].connect(self.startCalibr) self.calibrTimer.timeout.connect(self.onCalibrTimer) self.ui.connect_pico.toggled[bool].connect(self.connect_pico) self.ui.pico_set.clicked.connect(self.pico_set) self.ui.Pi_Set.clicked.connect(self.Pi_Set) ######################################################################## ######################################################################## ######################################################################## self.tabColors = { 0: 'green', 1: 'red', 2: 'wine', 3: 'orange', 4: 'blue', } self.ui.configTabWidget.tabBar().currentChanged.connect(self.styleTabs) self.pw = pg.PlotWidget( name='PlotMain' ) ## giving the plots names allows us to link their axes together #self.ui.plotArea.addWidget(self.pw) self.line0 = self.pw.plot() self.line1 = self.pw.plot(pen=(255, 0, 0)) self.line3 = self.pw.plot(pen=(255, 0, 255)) self.pw_preview = pg.PlotWidget( name='preview' ) ## giving the plots names allows us to link their axes together self.ui.previewArea.addWidget(self.pw_preview) self.line_DAQmx_sig = self.pw_preview.plot(pen=(255, 0, 0)) self.line_DAQmx_sig1 = self.pw_preview.plot(pen=(255, 255, 0)) self.line_DAQmx_ref = self.pw_preview.plot(pen=(255, 0, 255)) self.line_pico_ChA = self.pw_preview.plot(pen=(255, 215, 0)) self.line_pico_ChB = self.pw_preview.plot(pen=(0, 255, 255)) self.pw1 = pg.PlotWidget( name='Graph1' ) ## giving the plots names allows us to link their axes together self.ui.plotArea.addWidget(self.pw1) self.line_pmt = self.pw1.plot(pen=(255, 215, 0)) self.line_pmt1 = self.pw1.plot(pen=(0, 255, 255)) self.line_spectra = self.pw1.plot(pen=(0, 255, 0)) self.img = pg.ImageView( ) ## giving the plots names allows us to link their axes together data = np.zeros((100, 100)) self.ui.imageArea.addWidget(self.img) self.img.setImage(data) colors = [(0, 0, 0), (255, 214, 112)] cmap = pg.ColorMap(pos=[0., 1.], color=colors) self.img.setColorMap(cmap) g = pg.GridItem() self.img.addItem(g) self.img1 = pg.ImageView( ) ## giving the plots names allows us to link their axes together data = np.zeros((100, 100)) self.ui.imageArea.addWidget(self.img1) self.img1.setImage(data) colors = [(0, 0, 0), (204, 255, 255)] cmap = pg.ColorMap(pos=[0., 1.], color=colors) self.img1.setColorMap(cmap) g1 = pg.GridItem() self.img1.addItem(g1)
def UiComponents(self): # creating a widget object self.widget = QWidget() # IP Address of Connected Device self.ConnectedIpAddressLabel = QLabel(f'STM32 Status: -') self.ConnectedIpAddressLabel.setAlignment(QtCore.Qt.AlignCenter) # --------- Signal 1 -------- # Frequency Widgets self.signal1Label = QLabel("Signal 1") self.signal1Label.setAlignment(QtCore.Qt.AlignCenter) self.signal1FrequencyLabel = QLabel("Frequency:") self.signal1FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[0]}') self.signal1FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal1FrequencyTextBox.setFixedWidth(50) self.signal1FrequencyLabelUnits = QLabel("Hz") self.signal1FrequencyLabelUnits.setFixedWidth(20) self.signal1CheckBox = QCheckBox("Activated") self.signal1CheckBox.stateChanged.connect(self.updateCheckBox1) self.signal1CurveMenu = QComboBox() self.signal1CurveMenu.addItem("Sine") self.signal1CurveMenu.addItem("Cosine") self.signal1CurveMenu.currentIndexChanged.connect(self.updateComboBox1) # User Frequency Signal 1 change Button self.signal1FrequencyButton = QPushButton('OK') # setting geometry of button self.signal1FrequencyButton.setFixedWidth(30) self.signal1FrequencyButton.clicked.connect(self.signal1FrequencyButton_clicked) # Amplitude Widgets self.signal1AmplitudeLabel = QLabel("Amplitude:") self.signal1AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[0]}') self.signal1AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal1AmplitudeTextBox.setFixedWidth(50) self.signal1AmplitudeLabelUnits = QLabel("V") self.signal1AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 1 change Button self.signal1AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal1AmplitudeButton.setFixedWidth(30) self.signal1AmplitudeButton.clicked.connect(self.signal1AmplitudeButton_clicked) # --------- Signal 2 -------- # Frequency Widgets self.signal2Label = QLabel("Signal 2") self.signal2Label.setAlignment(QtCore.Qt.AlignCenter) self.signal2FrequencyLabel = QLabel("Frequency:") self.signal2FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[1]}') self.signal2FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal2FrequencyTextBox.setFixedWidth(50) self.signal2FrequencyLabelUnits = QLabel("Hz") self.signal2FrequencyLabelUnits.setFixedWidth(20) self.signal2CheckBox = QCheckBox("Activated") self.signal2CheckBox.stateChanged.connect(self.updateCheckBox2) self.signal2CurveMenu = QComboBox() self.signal2CurveMenu.addItem("Sine") self.signal2CurveMenu.addItem("Cosine") self.signal2CurveMenu.currentIndexChanged.connect(self.updateComboBox2) # User Frequency Signal 2 change Button self.signal2FrequencyButton = QPushButton('OK') # setting geometry of button self.signal2FrequencyButton.setFixedWidth(30) self.signal2FrequencyButton.clicked.connect(self.signal2FrequencyButton_clicked) # Amplitude Widgets self.signal2AmplitudeLabel = QLabel("Amplitude:") self.signal2AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[1]}') self.signal2AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal2AmplitudeTextBox.setFixedWidth(50) self.signal2AmplitudeLabelUnits = QLabel("V") self.signal2AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 2 change Button self.signal2AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal2AmplitudeButton.setFixedWidth(30) self.signal2AmplitudeButton.clicked.connect(self.signal2AmplitudeButton_clicked) # --------- Signal 3 -------- # Frequency Widgets self.signal3Label = QLabel("Signal 3") self.signal3Label.setAlignment(QtCore.Qt.AlignCenter) self.signal3FrequencyLabel = QLabel("Frequency:") self.signal3FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[2]}') self.signal3FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal3FrequencyTextBox.setFixedWidth(50) self.signal3FrequencyLabelUnits = QLabel("Hz") self.signal3FrequencyLabelUnits.setFixedWidth(20) self.signal3CheckBox = QCheckBox("Activated") self.signal3CheckBox.stateChanged.connect(self.updateCheckBox3) self.signal3CurveMenu = QComboBox() self.signal3CurveMenu.addItem("Sine") self.signal3CurveMenu.addItem("Cosine") self.signal3CurveMenu.currentIndexChanged.connect(self.updateComboBox3) # User Frequency Signal 3 change Button self.signal3FrequencyButton = QPushButton('OK') # setting geometry of button self.signal3FrequencyButton.setFixedWidth(30) self.signal3FrequencyButton.clicked.connect(self.signal3FrequencyButton_clicked) # Amplitude Widgets self.signal3AmplitudeLabel = QLabel("Amplitude:") self.signal3AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[2]}') self.signal3AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal3AmplitudeTextBox.setFixedWidth(50) self.signal3AmplitudeLabelUnits = QLabel("V") self.signal3AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 3 change Button self.signal3AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal3AmplitudeButton.setFixedWidth(30) self.signal3AmplitudeButton.clicked.connect(self.signal3AmplitudeButton_clicked) # --------- Signal 4 -------- # Frequency Widgets self.signal4Label = QLabel("Signal 4") self.signal4Label.setAlignment(QtCore.Qt.AlignCenter) self.signal4FrequencyLabel = QLabel("Frequency:") self.signal4FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[3]}') self.signal4FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal4FrequencyTextBox.setFixedWidth(50) self.signal4FrequencyLabelUnits = QLabel("Hz") self.signal4FrequencyLabelUnits.setFixedWidth(20) self.signal4CheckBox = QCheckBox("Activated") self.signal4CheckBox.stateChanged.connect(self.updateCheckBox4) self.signal4CurveMenu = QComboBox() self.signal4CurveMenu.addItem("Sine") self.signal4CurveMenu.addItem("Cosine") self.signal4CurveMenu.currentIndexChanged.connect(self.updateComboBox4) # User Frequency Signal 4 change Button self.signal4FrequencyButton = QPushButton('OK') # setting geometry of button self.signal4FrequencyButton.setFixedWidth(40) self.signal4FrequencyButton.clicked.connect(self.signal4FrequencyButton_clicked) # Amplitude Widgets self.signal4AmplitudeLabel = QLabel("Amplitude:") self.signal4AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[3]}') self.signal4AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal4AmplitudeTextBox.setFixedWidth(50) self.signal4AmplitudeLabelUnits = QLabel("V") self.signal4AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 4 change Button self.signal4AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal4AmplitudeButton.setFixedWidth(40) self.signal4AmplitudeButton.clicked.connect(self.signal4AmplitudeButton_clicked) # --------- Signal 5 -------- # Frequency Widgets self.signal5Label = QLabel("Signal 5") self.signal5Label.setAlignment(QtCore.Qt.AlignCenter) self.signal5FrequencyLabel = QLabel("Frequency:") self.signal5FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[4]}') self.signal5FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal5FrequencyTextBox.setFixedWidth(50) self.signal5FrequencyLabelUnits = QLabel("Hz") self.signal5FrequencyLabelUnits.setFixedWidth(20) self.signal5CheckBox = QCheckBox("Activated") self.signal5CheckBox.stateChanged.connect(self.updateCheckBox5) self.signal5CurveMenu = QComboBox() self.signal5CurveMenu.addItem("Sine") self.signal5CurveMenu.addItem("Cosine") self.signal5CurveMenu.currentIndexChanged.connect(self.updateComboBox5) # User Frequency Signal 5 change Button self.signal5FrequencyButton = QPushButton('OK') # setting geometry of button self.signal5FrequencyButton.setFixedWidth(40) self.signal5FrequencyButton.clicked.connect(self.signal5FrequencyButton_clicked) # Amplitude Widgets self.signal5AmplitudeLabel = QLabel("Amplitude:") self.signal5AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[4]}') self.signal5AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal5AmplitudeTextBox.setFixedWidth(50) self.signal5AmplitudeLabelUnits = QLabel("V") self.signal5AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 5 change Button self.signal5AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal5AmplitudeButton.setFixedWidth(40) self.signal5AmplitudeButton.clicked.connect(self.signal5AmplitudeButton_clicked) # --------- Signal 6 -------- # Frequency Widgets self.signal6Label = QLabel("Signal 6") self.signal6Label.setAlignment(QtCore.Qt.AlignCenter) self.signal6FrequencyLabel = QLabel("Frequency:") self.signal6FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[5]}') self.signal6FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal6FrequencyTextBox.setFixedWidth(50) self.signal6FrequencyLabelUnits = QLabel("Hz") self.signal6FrequencyLabelUnits.setFixedWidth(20) self.signal6CheckBox = QCheckBox("Activated") self.signal6CheckBox.stateChanged.connect(self.updateCheckBox6) self.signal6CurveMenu = QComboBox() self.signal6CurveMenu.addItem("Sine") self.signal6CurveMenu.addItem("Cosine") self.signal6CurveMenu.currentIndexChanged.connect(self.updateComboBox6) # User Frequency Signal 6 change Button self.signal6FrequencyButton = QPushButton('OK') # setting geometry of button self.signal6FrequencyButton.setFixedWidth(40) self.signal6FrequencyButton.clicked.connect(self.signal6FrequencyButton_clicked) # Amplitude Widgets self.signal6AmplitudeLabel = QLabel("Amplitude:") self.signal6AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[5]}') self.signal6AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal6AmplitudeTextBox.setFixedWidth(50) self.signal6AmplitudeLabelUnits = QLabel("V") self.signal6AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 6 change Button self.signal6AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal6AmplitudeButton.setFixedWidth(40) self.signal6AmplitudeButton.clicked.connect(self.signal6AmplitudeButton_clicked) # --------- Signal 7 -------- # Frequency Widgets self.signal7Label = QLabel("Signal 7") self.signal7Label.setAlignment(QtCore.Qt.AlignCenter) self.signal7FrequencyLabel = QLabel("Frequency:") self.signal7FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[6]}') self.signal7FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal7FrequencyTextBox.setFixedWidth(50) self.signal7FrequencyLabelUnits = QLabel("Hz") self.signal7FrequencyLabelUnits.setFixedWidth(20) self.signal7CheckBox = QCheckBox("Activated") self.signal7CheckBox.stateChanged.connect(self.updateCheckBox7) self.signal7CurveMenu = QComboBox() self.signal7CurveMenu.addItem("Sine") self.signal7CurveMenu.addItem("Cosine") self.signal7CurveMenu.currentIndexChanged.connect(self.updateComboBox7) # User Frequency Signal 7 change Button self.signal7FrequencyButton = QPushButton('OK') # setting geometry of button self.signal7FrequencyButton.setFixedWidth(40) self.signal7FrequencyButton.clicked.connect(self.signal7FrequencyButton_clicked) # Amplitude Widgets self.signal7AmplitudeLabel = QLabel("Amplitude:") self.signal7AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[6]}') self.signal7AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal7AmplitudeTextBox.setFixedWidth(50) self.signal7AmplitudeLabelUnits = QLabel("V") self.signal7AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 7 change Button self.signal7AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal7AmplitudeButton.setFixedWidth(40) self.signal7AmplitudeButton.clicked.connect(self.signal7AmplitudeButton_clicked) # --------- Signal 8 -------- # Frequency Widgets self.signal8Label = QLabel("Signal 8") self.signal8Label.setAlignment(QtCore.Qt.AlignCenter) self.signal8FrequencyLabel = QLabel("Frequency:") self.signal8FrequencyTextBox = QLineEdit(f'{self.signalFrequencies[7]}') self.signal8FrequencyTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal8FrequencyTextBox.setFixedWidth(50) self.signal8FrequencyLabelUnits = QLabel("Hz") self.signal8FrequencyLabelUnits.setFixedWidth(20) self.signal8CheckBox = QCheckBox("Activated") self.signal8CheckBox.stateChanged.connect(self.updateCheckBox8) self.signal8CurveMenu = QComboBox() self.signal8CurveMenu.addItem("Sine") self.signal8CurveMenu.addItem("Cosine") self.signal8CurveMenu.currentIndexChanged.connect(self.updateComboBox8) # User Frequency Signal 8 change Button self.signal8FrequencyButton = QPushButton('OK') # setting geometry of button self.signal8FrequencyButton.setFixedWidth(40) self.signal8FrequencyButton.clicked.connect(self.signal8FrequencyButton_clicked) # Amplitude Widgets self.signal8AmplitudeLabel = QLabel("Amplitude:") self.signal8AmplitudeTextBox = QLineEdit(f'{self.signalAmplitudes[7]}') self.signal8AmplitudeTextBox.setAlignment(QtCore.Qt.AlignRight) self.signal8AmplitudeTextBox.setFixedWidth(50) self.signal8AmplitudeLabelUnits = QLabel("V") self.signal8AmplitudeLabelUnits.setFixedWidth(20) # User Frequency Signal 8 change Button self.signal8AmplitudeButton = QPushButton('OK') # setting geometry of button self.signal8AmplitudeButton.setFixedWidth(40) self.signal8AmplitudeButton.clicked.connect(self.signal8AmplitudeButton_clicked) # -------------- Output Signal Plot ------------------ # Creating Plot Label for Input Signal self.inputSignalLabel = QLabel("Input Signal to STM32") self.inputSignalLabel.setMaximumHeight(15) # creating a plot window for input Signals self.inputSignalPlot = pg.PlotWidget() # plot color pen = pg.mkPen(color=(105, 105, 105)) # create input Signal for FreeRTOS self.inputSignal = pg.PlotCurveItem(x = self.time, y = self.combinedSignal, pen = pen) # add item to plot window self.inputSignalPlot.addItem(self.inputSignal) # set plot properties # self.inputSignalPlot.setXRange(0, 1024, padding=0) self.inputSignalPlot.setBackground('w') # add grid self.inputSignalGrid = pg.GridItem() self.inputSignalPlot.addItem(self.inputSignalGrid) # hide x and y axis self.inputSignalPlot.getPlotItem().hideAxis('bottom') self.inputSignalPlot.getPlotItem().hideAxis('left') self.inputSignalPlot.setXRange(0, NUMBER_OF_SAMPLES, padding=0) # --------------- FFT Result Plot -------------------- # Creating Plot Label for fft results self.fftResultsLabel = QLabel("FFT Result") self.fftResultsLabel.setMaximumHeight(15) # creating a plot window for fft self.fftResultsPlot = pg.PlotWidget() # plot color pen = pg.mkPen(color=(0, 0, 0)) # create fft Output signals self.fftOutput = pg.BarGraphItem(x = np.zeros(self.numberOfSamples), height = np.zeros(self.numberOfSamples), width=0.8, fillLevel=1, brush=(105, 105, 105)) # add item to plot window self.fftResultsPlot.addItem(self.fftOutput) # set plot properties self.fftResultsPlot.setXRange(0, FFT_SIZE, padding=0) self.fftResultsPlot.setBackground('w') # Creating a grid layout self.layout = QGridLayout() # setting this layout to the widget self.widget.setLayout(self.layout) # create highest frequencies found self.fftFrequenciesResults = QLabel("") # -------------------- widget positions ------------------- # vertical and horizontal lines for limitations self.layout.addWidget(QVLine(), 1, 1, 45, 1) self.layout.addWidget(QHLine(), 1, 1, 1, 48) self.layout.addWidget(QHLine(), 3, 1, 1, 5) self.layout.addWidget(QHLine(), 8, 2, 1, 4) self.layout.addWidget(QHLine(), 13, 2, 1, 4) self.layout.addWidget(QHLine(), 18, 2, 1, 4) self.layout.addWidget(QHLine(), 23, 2, 1, 4) self.layout.addWidget(QHLine(), 28, 2, 1, 4) self.layout.addWidget(QHLine(), 33, 2, 1, 4) self.layout.addWidget(QHLine(), 38, 2, 1, 4) self.layout.addWidget(QVLine(), 1, 6, 44, 1) self.layout.addWidget(QHLine(), 23, 6, 1, 43) self.layout.addWidget(QHLine(), 45, 1, 1, 48) self.layout.addWidget(QVLine(), 1, 50, 44, 1) # connection status widget self.layout.addWidget(self.ConnectedIpAddressLabel, 2, 2, 1, 4) # signal 1 preferences self.layout.addWidget(self.signal1Label, 4, 1, 1, 5) self.layout.addWidget(self.signal1CheckBox, 5, 2, 1, 1) self.layout.addWidget(self.signal1CurveMenu, 5, 4, 1, 2) self.layout.addWidget(self.signal1FrequencyLabel, 6, 2, 1, 1) self.layout.addWidget(self.signal1FrequencyTextBox, 6, 3, 1, 1) self.layout.addWidget(self.signal1FrequencyLabelUnits, 6, 4, 1, 1) self.layout.addWidget(self.signal1FrequencyButton, 6, 5, 1, 1 ) self.layout.addWidget(self.signal1AmplitudeLabel, 7, 2, 1, 1) self.layout.addWidget(self.signal1AmplitudeTextBox, 7, 3, 1, 1) self.layout.addWidget(self.signal1AmplitudeLabelUnits, 7, 4, 1, 1) self.layout.addWidget(self.signal1AmplitudeButton, 7, 5, 1, 1) # signal 2 preferences self.layout.addWidget(self.signal2Label, 9, 1, 1, 5) self.layout.addWidget(self.signal2CheckBox, 10, 2, 1, 1) self.layout.addWidget(self.signal2CurveMenu, 10, 4, 1, 2) self.layout.addWidget(self.signal2FrequencyLabel, 11, 2, 1, 1) self.layout.addWidget(self.signal2FrequencyTextBox, 11, 3, 1, 1) self.layout.addWidget(self.signal2FrequencyLabelUnits, 11, 4, 1, 1) self.layout.addWidget(self.signal2FrequencyButton, 11, 5, 1, 1 ) self.layout.addWidget(self.signal2AmplitudeLabel, 12, 2, 1, 1) self.layout.addWidget(self.signal2AmplitudeTextBox, 12, 3, 1, 1) self.layout.addWidget(self.signal2AmplitudeLabelUnits, 12, 4, 1, 1) self.layout.addWidget(self.signal2AmplitudeButton, 12, 5, 1, 1) # signal 3 preferences self.layout.addWidget(self.signal3Label, 14, 1, 1, 5) self.layout.addWidget(self.signal3CheckBox, 15, 2, 1, 1) self.layout.addWidget(self.signal3CurveMenu, 15, 4, 1, 2) self.layout.addWidget(self.signal3FrequencyLabel, 16, 2, 1, 1) self.layout.addWidget(self.signal3FrequencyTextBox, 16, 3, 1, 1) self.layout.addWidget(self.signal3FrequencyLabelUnits, 16, 4, 1, 1) self.layout.addWidget(self.signal3FrequencyButton, 16, 5, 1, 1 ) self.layout.addWidget(self.signal3AmplitudeLabel, 17, 2, 1, 1) self.layout.addWidget(self.signal3AmplitudeTextBox, 17, 3, 1, 1) self.layout.addWidget(self.signal3AmplitudeLabelUnits, 17, 4, 1, 1) self.layout.addWidget(self.signal3AmplitudeButton, 17, 5, 1, 1) # signal 4 preferences self.layout.addWidget(self.signal4Label, 19, 1, 1, 5) self.layout.addWidget(self.signal4CheckBox, 20, 2, 1, 1) self.layout.addWidget(self.signal4CurveMenu, 20, 4, 1, 2) self.layout.addWidget(self.signal4FrequencyLabel, 21, 2, 1, 1) self.layout.addWidget(self.signal4FrequencyTextBox, 21, 3, 1, 1) self.layout.addWidget(self.signal4FrequencyLabelUnits, 21, 4, 1, 1) self.layout.addWidget(self.signal4FrequencyButton, 21, 5, 1, 1 ) self.layout.addWidget(self.signal4AmplitudeLabel, 22, 2, 1, 1) self.layout.addWidget(self.signal4AmplitudeTextBox, 22, 3, 1, 1) self.layout.addWidget(self.signal4AmplitudeLabelUnits, 22, 4, 1, 1) self.layout.addWidget(self.signal4AmplitudeButton, 22, 5, 1, 1) # signal 5 preferences self.layout.addWidget(self.signal5Label, 24, 1, 1, 5) self.layout.addWidget(self.signal5CheckBox, 25, 2, 1, 1) self.layout.addWidget(self.signal5CurveMenu, 25, 4, 1, 2) self.layout.addWidget(self.signal5FrequencyLabel, 26, 2, 1, 1) self.layout.addWidget(self.signal5FrequencyTextBox, 26, 3, 1, 1) self.layout.addWidget(self.signal5FrequencyLabelUnits, 26, 4, 1, 1) self.layout.addWidget(self.signal5FrequencyButton, 26, 5, 1, 1 ) self.layout.addWidget(self.signal5AmplitudeLabel, 27, 2, 1, 1) self.layout.addWidget(self.signal5AmplitudeTextBox, 27, 3, 1, 1) self.layout.addWidget(self.signal5AmplitudeLabelUnits, 27, 4, 1, 1) self.layout.addWidget(self.signal5AmplitudeButton, 27, 5, 1, 1) # signal 6 preferences self.layout.addWidget(self.signal6Label, 29, 1, 1, 5) self.layout.addWidget(self.signal6CheckBox, 30, 2, 1, 1) self.layout.addWidget(self.signal6CurveMenu, 30, 4, 1, 2) self.layout.addWidget(self.signal6FrequencyLabel, 31, 2, 1, 1) self.layout.addWidget(self.signal6FrequencyTextBox, 31, 3, 1, 1) self.layout.addWidget(self.signal6FrequencyLabelUnits, 31, 4, 1, 1) self.layout.addWidget(self.signal6FrequencyButton, 31, 5, 1, 1 ) self.layout.addWidget(self.signal6AmplitudeLabel, 32, 2, 1, 1) self.layout.addWidget(self.signal6AmplitudeTextBox, 32, 3, 1, 1) self.layout.addWidget(self.signal6AmplitudeLabelUnits, 32, 4, 1, 1) self.layout.addWidget(self.signal6AmplitudeButton, 32, 5, 1, 1) # signal 7 preferences self.layout.addWidget(self.signal7Label, 34, 1, 1, 5) self.layout.addWidget(self.signal7CheckBox, 35, 2, 1, 1) self.layout.addWidget(self.signal7CurveMenu, 35, 4, 1, 2) self.layout.addWidget(self.signal7FrequencyLabel, 36, 2, 1, 1) self.layout.addWidget(self.signal7FrequencyTextBox, 36, 3, 1, 1) self.layout.addWidget(self.signal7FrequencyLabelUnits, 36, 4, 1, 1) self.layout.addWidget(self.signal7FrequencyButton, 36, 5, 1, 1 ) self.layout.addWidget(self.signal7AmplitudeLabel, 37, 2, 1, 1) self.layout.addWidget(self.signal7AmplitudeTextBox, 37, 3, 1, 1) self.layout.addWidget(self.signal7AmplitudeLabelUnits, 37, 4, 1, 1) self.layout.addWidget(self.signal7AmplitudeButton, 37, 5, 1, 1) # signal 8 preferences self.layout.addWidget(self.signal8Label, 39, 1, 1, 5) self.layout.addWidget(self.signal8CheckBox, 40, 2, 1, 1) self.layout.addWidget(self.signal8CurveMenu, 40, 4, 1, 2) self.layout.addWidget(self.signal8FrequencyLabel, 41, 2, 1, 1) self.layout.addWidget(self.signal8FrequencyTextBox, 41, 3, 1, 1) self.layout.addWidget(self.signal8FrequencyLabelUnits, 41, 4, 1, 1) self.layout.addWidget(self.signal8FrequencyButton, 41, 5, 1, 1 ) self.layout.addWidget(self.signal8AmplitudeLabel, 42, 2, 1, 1) self.layout.addWidget(self.signal8AmplitudeTextBox, 42, 3, 1, 1) self.layout.addWidget(self.signal8AmplitudeLabelUnits, 42, 4, 1, 1) self.layout.addWidget(self.signal8AmplitudeButton, 42, 5, 1, 1) # signal plot self.layout.addWidget(self.inputSignalLabel, 2, 7, 1, 42) self.layout.addWidget(self.inputSignalPlot, 3, 7, 20, 42) # fft result plot self.layout.addWidget(self.fftResultsLabel, 24, 7, 1, 42) self.layout.addWidget(self.fftResultsPlot, 25, 7, 20, 42) # detected frequency results self.layout.addWidget(self.fftFrequenciesResults, 46, 24, 1, 25) # setting this widget as central widget of the main window self.setCentralWidget(self.widget)
def create_dashboard(data, peaks, all_hr, all_br): """[summary] Arguments: data {numpy.ndarray} -- ECG plot peaks {list} -- R peaks all_hr {list} -- Heart rate per minute all_br {list} -- Breathing rate per minute """ global i, rpindex, win, rpeakx, rpeaky, hr, br, hrslid, brslid, slidflaghr, slidflagbr, slidPoshr, slidPosbr, hrindex, chk, chkbr, popflag, trigflag, popwind class KeyPressWindow(pg.GraphicsLayoutWidget): sigKeyPress = QtCore.pyqtSignal(object) def keyPressEvent(self, ev): self.scene().keyPressEvent(ev) self.sigKeyPress.emit(ev) def keyPressed(evt): if evt.key() == QtCore.Qt.Key_P: timer.stop() if evt.key() == QtCore.Qt.Key_S: timer.start() timer = QtCore.QTimer() app = QtGui.QApplication(sys.argv) mscreen = KeyPressWindow() mscreen.sigKeyPress.connect(keyPressed) mscreen.show() mscreen.resize(tk.Tk().winfo_screenwidth(), tk.Tk().winfo_screenheight()) popwind = QtWidgets.QMessageBox() popwind.setIcon(QtWidgets.QMessageBox.Critical) popwind.setWindowTitle("WARNING/COURSE OF ACTION") popwind.setFont(QtGui.QFont("sans-serif", 16)) changingLabel = QtGui.QLabel() #########IDENTIFIERS################### rpindex = 0 win = 37 hrindex = 37 slidPoshr = 0.5 slidPosbr = 0.5 popflag = 0 trigflag = 1 ecg = [] slidflaghr = 0 slidflagbr = 0 hr = all_hr[hrindex] br = all_br[hrindex] ############ECG PLOT############# rpeaks = pg.ScatterPlotItem(size=10, pen=pg.mkPen(0.5), brush=pg.mkBrush(0, 0, 255, 120)) ecgwind = mscreen.addPlot(row=0, col=0, colspan=3) ecgwind.hideAxis('left') ecgwind.hideAxis('bottom') plt_grid = pg.GridItem() ecgbg = ecgwind.getViewBox() ecgbg.setBackgroundColor((255, 255, 255)) curve_ecg = ecgwind.plot(pen=pg.mkPen((0, 0, 0), width=1)) ecgwind.addItem(curve_ecg) ecgwind.addItem(rpeaks) ecgwind.addItem(plt_grid) #####################################3 #####HEART RATE############# curvex1 = np.linspace(-5, 5, 10) curvey1 = np.sin(curvex1) / curvex1 hrwind = mscreen.addPlot(row=1, col=0) hrwind.plot(x=curvex1, y=curvey1, pen=(255, 255, 255)) hrbg = hrwind.getViewBox() hrbg.setBackgroundColor((255, 255, 255)) fileNamehr = '../images/HR.jpg' imghr = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap(fileNamehr)) imghr.scale(1, -1) hrwind.hideAxis('left') hrwind.hideAxis('bottom') hrwind.addItem(imghr) hrval = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) fonthrval = changingLabel.font() fonthrval.setPointSize(86) hrval.setFont(fonthrval) fonthrval.setPointSize(40) texthr = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) fonthr = changingLabel.font() fonthr.setPointSize(40) texthr.setFont(fonthr) texthr.setText("HR") texthr.setPos(130, curvey1.max() / 2 - 220) hrwind.addItem(hrval) hrwind.addItem(texthr) ################################# #####BREATHING RATE############# curvex2 = np.linspace(-5, 5, 10) curvey2 = np.sin(curvex2) / curvex2 brwind = mscreen.addPlot(row=1, col=1) brwind.plot(x=curvex2, y=curvey2, pen=(255, 255, 255)) brbg = brwind.getViewBox() brbg.setBackgroundColor((255, 255, 255)) filebr = '../images/BR.jpg' imgbr = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap(filebr)) imgbr.scale(1, -1) brwind.addItem(imgbr) brwind.hideAxis('left') brwind.hideAxis('bottom') brval = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) font1 = changingLabel.font() font1.setPointSize(86) brval.setFont(font1) textbr = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) fontbr = changingLabel.font() fontbr.setPointSize(40) textbr.setFont(fontbr) textbr.setText("BR") textbr.setPos(130, curvey2.max() / 2 - 220) brwind.addItem(brval) brwind.addItem(textbr) ################################# ###### SLIDER ############# slidwind = mscreen.addPlot(row=1, col=2) slidbg = slidwind.getViewBox() slidbg.setBackgroundColor((255, 255, 255)) curvex3 = np.linspace(0, 860, 2) curvey3 = [-158 for x in curvex3] fileslider = '../images/Slider.jpg' imgslid = pg.QtGui.QGraphicsPixmapItem(pg.QtGui.QPixmap(fileslider)) imgslid.scale(1, -1) slidwind.addItem(imgslid) linehr = slidwind.plot(x=curvex3, y=curvey3, pen=(255, 255, 255)) hrslid = pg.CurvePoint(linehr) slidwind.addItem(hrslid) texthr1 = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) fonthr1 = changingLabel.font() fonthr1.setPointSize(40) texthr1.setFont(fonthr1) texthr1.setText("HR") texthr1.setPos(320, curvey1.max() - 270) slidwind.addItem(texthr1) arrowhr = pg.ArrowItem(angle=90) arrowhr.setStyle(headLen=30) arrowhr.setParentItem(hrslid) hrslid.setPos(slidPoshr) curvey4 = [-465 for x in curvex3] linebr = slidwind.plot(x=curvex3, y=curvey4, pen=(255, 255, 255)) brslid = pg.CurvePoint(linebr) slidwind.addItem(brslid) textbr1 = pg.TextItem(color=(0, 0, 0), anchor=(-0.3, 0.5)) fontbr1 = changingLabel.font() fontbr1.setPointSize(40) textbr1.setFont(fontbr1) textbr1.setText("BR") textbr1.setPos(320, curvey1.max() - 570) slidwind.addItem(textbr1) arrowbr = pg.ArrowItem(angle=90) arrowbr.setStyle(headLen=30) arrowbr.setParentItem(brslid) brslid.setPos(slidPosbr) slidwind.hideAxis('left') slidwind.hideAxis('bottom') ########################## rpeakx = [x for x in peaks[win] if x <= 1000] rpeaky = [float(data[win][y]) for y in rpeakx] chk = 1 chkbr = 1 for i in range(1, 1001): ecg.append(float(data[win][i])) rpindex = len(rpeakx) def update(): global i, win, rpindex, rpeakx, rpeaky, hr, br, hrslid, brslid, slidflaghr, slidflagbr, slidPoshr, slidPosbr, hrindex, chk, chkbr, popflag, trigflag, popwind rpeaks.clear() ecg.pop(0) if (len(rpeakx) != 0 and rpeakx[0] < 1): rpeakx.pop(0) rpeaky.pop(0) rpeakx = [x - 1 for x in rpeakx] if (i + 1 < len(data[win])): i += 1 if (rpindex < len(peaks[win]) and i == peaks[win][rpindex]): rpindex += 1 rpeakx.append(1000) rpeaky.append(data[win][i]) else: rpindex = 0 win += 1 i = 0 if 100 <= hr < 110: meterhr = -1 slidflaghr = 1 elif hr < 100: popflag = 1 meterhr = -2 slidflaghr = 1 elif 150 < hr < 160: meterhr = 1 slidflaghr = 1 elif hr >= 160: popflag = 1 meterhr = 2 slidflaghr = 1 else: if (slidPoshr != 0.5): slidflaghr = 1 meterhr = 0 if br > 45: popflag = 1 slidflagbr = 1 meterbr = 2 if popflag == 1 and trigflag == 1: trigflag = 0 if hr >= 160: popwind.setText( "Heart Rate High\nSeek medical attention if high heart rate persists" ) elif hr <= 110: popwind.setText( "Heart Rate Low\nSeek medical attention if low heart rate persists" ) else: popwind.setText( "Breathing Rate Abnormal\nSeek medical attention if following symptoms are displayed:\n1) Blueness\n2) Severe chest indrawing" ) popwind.show() if slidflaghr == 1 and chk == 1: slidDest, direct = slider(meterhr, slidPoshr) slidPoshr += direct * 0.002 if (direct == -1): if slidPoshr <= slidDest: slidflaghr = 0 chk = 0 elif (direct == 1): if slidPoshr >= slidDest: slidflaghr = 0 chk = 0 hrslid.setPos(slidPoshr) if slidflagbr == 1 and chkbr == 1: slidDestbr, directbr = slider(meterbr, slidPosbr) slidPosbr += directbr * 0.002 if (directbr == -1): if slidPosbr <= slidDestbr: slidflagbr = 0 chkbr = 0 elif (directbr == 1): if slidPosbr >= slidDestbr: slidflagbr = 0 chkbr = 0 brslid.setPos(slidPosbr) ecg.append(float(data[win][i])) rpkx = [x - 1 for x in rpeakx] rpky = rpeaky if i % 2500 == 0: hrindex += 1 hr = all_hr[hrindex] - 15 br = all_br[hrindex] + 31 chk = 1 chkbr = 1 trigflag = 1 hrval.setText('{} '.format(hr)) brval.setText('{} '.format(br)) popflag = 0 if hr < 100: hrval.setPos(95, -159.5253) else: hrval.setPos(60, -159.5253) brval.setPos(95, -159.5253) rpeaks.addPoints(x=rpkx, y=rpky) curve_ecg.setData(ecg) def slider(meter, slidPoshr): if meter == -2: slidDest = 0 direct = -1 elif meter == -1: slidDest = 0.25 if slidPoshr > 0.5: direct = -1 elif slidPoshr < 0.5: direct = 1 direct = -1 elif meter == 1: slidDest = 0.75 if slidPoshr > 0.5: direct = -1 elif slidPoshr < 0.5: direct = 1 elif meter == 2: slidDest = 1 direct = 1 elif meter == 0: slidDest = 0.5 if slidPoshr > 0.5: direct = -1 elif slidPoshr < 0.5: direct = 1 return slidDest, direct timer.timeout.connect(update) timer.start(5) if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()
QtCore.Signal = QtCore.pyqtSignal import pyqtgraph as pg import numpy as np from pyqtgraph import Point app = QtGui.QApplication([]) w = pg.GraphicsWindow() view = w.addViewBox() optics = [] view.setAspectLocked() grid = pg.GridItem() view.addItem(grid) #view.setRange(QtCore.QRectF(-150, 200, 500, 400)) optics = [] rays = [] for y in [0, -20, -40, -60]: l1 = Lens(r1=51.5, r2=0, d=3.6, glass='N-BK7') l2 = Lens(r1=0, r2=51.5, d=3.6, glass='N-BK7') l1.translate(0, y) l2.translate(200, y) optics.append([l1, l2]) view.addItem(l1) view.addItem(l2)
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) #QtGui.QApplication.setGraphicsSystem('raster') #app = QtGui.QApplication([]) self.setWindowTitle('pyqtgraph example: PlotWidget') self.resize(800, 800) cw = QtGui.QWidget() self.setCentralWidget(cw) l = QtGui.QVBoxLayout() cw.setLayout(l) self.img = pg.ImageView( ) ## giving the plots names allows us to link their axes together data = np.zeros((100, 100)) l.addWidget(self.img) self.img.setMinimumHeight(500) self.img.setImage(data) colors = [(0, 0, 0), (255, 214, 112)] cmap = pg.ColorMap(pos=[0., 1.], color=colors) self.img.setColorMap(cmap) g = pg.GridItem() self.img.addItem(g) self.show() pw = pg.PlotWidget( name='Plot1' ) ## giving the plots names allows us to link their axes together l.addWidget(pw) pw1 = pg.PlotWidget( name='Plot2' ) ## giving the plots names allows us to link their axes together l.addWidget(pw1) ## Create an empty plot curve to be filled later, set its pen self.curveA = pw.plot() self.curveA.setPen((255, 0, 0)) self.curveB = pw.plot() self.curveB.setPen((0, 255, 0)) ## Create an empty plot curve to be filled later, set its pen self.curveA1 = pw1.plot() self.curveA1.setPen((255, 0, 0)) self.curveB1 = pw1.plot() self.curveB1.setPen((0, 255, 0)) self.curveX1 = pw1.plot() self.curveX1.setPen((100, 105, 0)) self.piStage = E727() print(self.piStage.ConnectUSBWithBaudRate()) print(self.piStage.qSAI()) self.piStage.qSVO(b'1 2 3') print(self.piStage.VEL([1000, 1000, 1000], b'1 2 3')) print(self.piStage.qVEL()) self.pico.start() time.sleep(3) self.timer.start(0.5) #while self.q.empty(): # time.sleep(0.5) # self.timer.timeout.connect(self.update)
## handles rotating around opposite corner r3b.addRotateHandle([1, 0], [0, 1]) r3b.addRotateHandle([0, 1], [1, 0]) ## handles rotating/scaling around center r3b.addScaleRotateHandle([0, 0.5], [0.5, 0.5]) r3b.addScaleRotateHandle([1, 0.5], [0.5, 0.5]) v3.disableAutoRange('xy') v3.autoRange() text = """Transforming objects with ROI""" w4 = w.addLayout(row=1, col=1) label4 = w4.addLabel(text, row=0, col=0) v4 = w4.addViewBox(row=1, col=0, lockAspect=True) g = pg.GridItem() v4.addItem(g) r4 = pg.ROI([0, 0], [100, 100], removable=True) r4.addRotateHandle([1, 0], [0.5, 0.5]) r4.addRotateHandle([0, 1], [0.5, 0.5]) img4 = pg.ImageItem(arr) v4.addItem(r4) img4.setParentItem(r4) v4.disableAutoRange('xy') v4.autoRange() # Provide a callback to remove the ROI (and its children) when # "remove" is selected from the context menu. def remove():
def test_ViewBox(): global app, win, vb QRectF = pg.QtCore.QRectF win = pg.GraphicsWindow() win.ci.layout.setContentsMargins(0,0,0,0) win.resize(200, 200) win.show() vb = win.addViewBox() # set range before viewbox is shown vb.setRange(xRange=[0, 10], yRange=[0, 10], padding=0) # required to make mapFromView work properly. qtest.qWaitForWindowShown(win) g = pg.GridItem() vb.addItem(g) app.processEvents() w = vb.geometry().width() h = vb.geometry().height() view1 = QRectF(0, 0, 10, 10) size1 = QRectF(0, h, w, -h) assertMapping(vb, view1, size1) # test resize win.resize(400, 400) app.processEvents() w = vb.geometry().width() h = vb.geometry().height() size1 = QRectF(0, h, w, -h) assertMapping(vb, view1, size1) # now lock aspect vb.setAspectLocked() # test wide resize win.resize(800, 400) app.processEvents() w = vb.geometry().width() h = vb.geometry().height() view1 = QRectF(-5, 0, 20, 10) size1 = QRectF(0, h, w, -h) assertMapping(vb, view1, size1) # test tall resize win.resize(400, 800) app.processEvents() w = vb.geometry().width() h = vb.geometry().height() view1 = QRectF(0, -5, 10, 20) size1 = QRectF(0, h, w, -h) assertMapping(vb, view1, size1) # test limits + resize (aspect ratio constraint has priority over limits win.resize(400, 400) app.processEvents() vb.setLimits(xMin=0, xMax=10, yMin=0, yMax=10) win.resize(800, 400) app.processEvents() w = vb.geometry().width() h = vb.geometry().height() view1 = QRectF(-5, 0, 20, 10) size1 = QRectF(0, h, w, -h) assertMapping(vb, view1, size1)