def __init__(self, parent=None, image_channel=None, xaxis_channel=None, yaxis_channel=None, roioffsetx_channel=None, roioffsety_channel=None, roiwidth_channel=None, roiheight_channel=None, title='', background='w', image_width=0, image_height=0): """Initialize widget.""" GraphicsLayoutWidget.__init__(self, parent) PyDMWidget.__init__(self) self.thread = None self._imagechannel = None self._xaxischannel = None self._yaxischannel = None self._roioffsetxchannel = None self._roioffsetychannel = None self._roiwidthchannel = None self._roiheightchannel = None self._channels = 7 * [ None, ] self.image_waveform = np.zeros(0) self._image_width = image_width if not xaxis_channel else 0 self._image_height = image_height if not yaxis_channel else 0 self._roi_offsetx = 0 self._roi_offsety = 0 self._roi_width = 0 self._roi_height = 0 self._normalize_data = False self._auto_downsample = True self._last_yaxis_data = None self._last_xaxis_data = None self._auto_colorbar_lims = True self.format_tooltip = '{0:.4g}, {1:.4g}' # ViewBox and imageItem. self._view = ViewBox() self._image_item = ImageItem() self._view.addItem(self._image_item) # ROI self.ROICurve = PlotCurveItem([0, 0, 0, 0, 0], [0, 0, 0, 0, 0]) self.ROIColor = QColor('red') pen = mkPen() pen.setColor(QColor('transparent')) pen.setWidth(1) self.ROICurve.setPen(pen) self._view.addItem(self.ROICurve) # Axis. self.xaxis = AxisItem('bottom') self.xaxis.setPen(QColor(0, 0, 0)) if not xaxis_channel: self.xaxis.setVisible(False) self.yaxis = AxisItem('left') self.yaxis.setPen(QColor(0, 0, 0)) if not yaxis_channel: self.yaxis.setVisible(False) # Colorbar legend. self.colorbar = _GradientLegend() # Title. start_row = 0 if title: self.title = LabelItem(text=title, color='#000000') self.addItem(self.title, 0, 0, 1, 3) start_row = 1 # Set layout. self.addItem(self._view, start_row, 1) self.addItem(self.yaxis, start_row, 0) self.addItem(self.colorbar, start_row, 2) self.addItem(self.xaxis, start_row + 1, 1) self.setBackground(background) self.ci.layout.setColumnSpacing(0, 0) self.ci.layout.setRowSpacing(start_row, 0) # Set color map limits. self.cm_min = 0.0 self.cm_max = 255.0 # Set default reading order of numpy array data to Clike. self._reading_order = ReadingOrder.Clike # Make a right-click menu for changing the color map. self.cm_group = QActionGroup(self) self.cmap_for_action = {} for cm in self.color_maps: action = self.cm_group.addAction(cmap_names[cm]) action.setCheckable(True) self.cmap_for_action[action] = cm # Set the default colormap. self._cm_colors = None self.colorMap = PyDMColorMap.Inferno # Setup the redraw timer. self.needs_redraw = False self.redraw_timer = QTimer(self) self.redraw_timer.timeout.connect(self.redrawImage) self._redraw_rate = 30 self.maxRedrawRate = self._redraw_rate self.newImageSignal = self._image_item.sigImageChanged # Set Channels. self.imageChannel = image_channel self.xAxisChannel = xaxis_channel self.yAxisChannel = yaxis_channel self.ROIOffsetXChannel = roioffsetx_channel self.ROIOffsetYChannel = roioffsety_channel self.ROIWidthChannel = roiwidth_channel self.ROIHeightChannel = roiheight_channel
def __init__(self, parent_widget): GraphicsLayoutWidget.__init__(self, parent_widget) self.parent_widget = parent_widget self.resize(1920, 1080) button_width = 19 ####################################################################### # Plot Channel Plotting Booleans ####################################################################### self.plot_channel_one = True self.plot_channel_two = True self.plot_channel_three = True self.plot_channel_four = True self.plot_channel_five = True self.plot_channel_six = True self.plot_channel_seven = True self.plot_channel_eight = True # The position of this list corispond to the position of the sorted directory_of_frequency_channels keys self.plot_channel_key_booleans = [ True for count in range(len(DICTIONARY_OF_CHANNEL_KEYS.keys())) ] ####################################################################### # Init of linear region that can control all graphs at once ####################################################################### self.linear_region = pg.LinearRegionItem([0, 3000]) self.linear_region.setZValue(-10) ####################################################################### # Init of all plot widgets ####################################################################### self.frequency_plot_graph = self.addPlot(title='Frequency') if ADD_FREQUENCY_LEGEND: self.frequency_resistance_legend = self.frequency_plot_graph.addLegend( ) self.nextRow() self.resistance_graph = self.addPlot(title='Resistance') self.nextRow() self.temperature_plot_graph = self.addPlot(title='Temperature') self.nextRow() self.pressure_plot_graph = self.addPlot(title='Pressure') self.nextRow() self.humidity_plot_graph = self.addPlot(title='Humidity') self.nextRow() self.overview_graph = self.addPlot(title='Overview') self.overview_graph.addItem(self.linear_region) self.frequency_plot_graph.showGrid(x=True, y=True) self.resistance_graph.showGrid(x=True, y=True) self.temperature_plot_graph.showGrid(x=True, y=True) self.pressure_plot_graph.showGrid(x=True, y=True) self.humidity_plot_graph.showGrid(x=True, y=True) self.overview_graph.showGrid(x=True, y=True) self.frequency_plot_graph.sigXRangeChanged.connect( self.update_frequency_region) self.resistance_graph.sigXRangeChanged.connect( self.update_resistance_region) self.temperature_plot_graph.sigXRangeChanged.connect( self.update_temperature_region) self.pressure_plot_graph.sigXRangeChanged.connect( self.update_pressure_region) self.humidity_plot_graph.sigXRangeChanged.connect( self.update_humidity_region) self.frequency_lines = [] for position in range(0, len(DICTIONARY_OF_CHANNEL_KEYS.keys())): self.frequency_lines.append( self.frequency_plot_graph.plot( x=[], y=[], pen=pg.mkPen(cosmetic=True, width=LINE_THICKNESS, color=LINE_COLORS[position]), symbol='o', symbolBrush=pg.mkBrush(LINE_COLORS[position]), name='Channel %d' % position)) self.resistance_line = self.resistance_graph.plot( x=[], y=[], pen=pg.mkPen(cosmetic=True, width=LINE_THICKNESS, color=LINE_COLORS[0]), symbol='o', symbolBrush=pg.mkBrush(LINE_COLORS[0]), name='Resistance') self.temperature_line = self.temperature_plot_graph.plot( x=[], y=[], pen=pg.mkPen(cosmetic=True, width=LINE_THICKNESS, color=LINE_COLORS[1]), symbol='o', symbolBrush=pg.mkBrush(LINE_COLORS[1]), name='Temperature') self.pressure_line = self.pressure_plot_graph.plot( x=[], y=[], pen=pg.mkPen(cosmetic=True, width=LINE_THICKNESS, color=LINE_COLORS[2]), symbol='o', symbolBrush=pg.mkBrush(LINE_COLORS[2]), name='Pressure') self.humidity_line = self.humidity_plot_graph.plot( x=[], y=[], pen=pg.mkPen(cosmetic=True, width=LINE_THICKNESS, color=LINE_COLORS[3]), symbol='o', symbolBrush=pg.mkBrush(LINE_COLORS[3]), name='Humidity') self.linear_region.sigRegionChanged.connect( self.update_plots_using_region) self.resistance_json_path = None self.file_path_json = SELECT_LATEST_FILE_JSON() ####################################################################### # Data Processing Thread ####################################################################### self.server_handler = Server_Handler( self, self.parent_widget.attempt_connection_button) self.server_handler.start() self.process_data_thread = Data_Processing_Stream_Thread(self) self.process_data_thread.start() ####################################################################### # Timers ####################################################################### self.plot_timer_frequency = QtCore.QTimer() self.plot_timer_frequency.timeout.connect(self.plot_frequency_data) self.plot_timer_frequency.start(1000) self.plot_timer_resistance = QtCore.QTimer() self.plot_timer_resistance.timeout.connect(self.plot_resistance_data) self.plot_timer_resistance.start(1000) self.plot_timer_temperature = QtCore.QTimer() self.plot_timer_temperature.timeout.connect(self.plot_temperature_data) self.plot_timer_temperature.start(1000) self.plot_timer_pressure = QtCore.QTimer() self.plot_timer_pressure.timeout.connect(self.plot_pressure_data) self.plot_timer_pressure.start(1000) self.plot_timer_humidity = QtCore.QTimer() self.plot_timer_humidity.timeout.connect(self.plot_humidity_data) self.plot_timer_humidity.start(1000)