def __init__(self, parent, prefs, signal_model): super(SyncHTP1Dialog, self).__init__(parent) self.__preferences = prefs self.__signal_model = signal_model self.__simple_signal = None self.__filters_by_channel = {} self.__current_device_filters_by_channel = {} self.__spinner = None self.__beq_filter = None self.__signal_filter = None self.__last_requested_msoupdate = None self.__last_received_msoupdate = None self.__supports_shelf = False self.__channel_to_signal = {} self.setupUi(self) self.setWindowFlag(Qt.WindowMinimizeButtonHint) self.setWindowFlag(Qt.WindowMaximizeButtonHint) self.syncStatus = qta.IconWidget('fa5s.unlink') self.syncLayout.addWidget(self.syncStatus) self.ipAddress.setText(self.__preferences.get(HTP1_ADDRESS)) self.filterView.setSelectionBehavior(QAbstractItemView.SelectRows) self.__filters = FilterModel(self.filterView, self.__preferences) self.filterView.setModel(FilterTableModel(self.__filters)) self.filterView.horizontalHeader().setSectionResizeMode( QHeaderView.Stretch) self.filterView.selectionModel().selectionChanged.connect( self.__on_filter_selected) self.__magnitude_model = MagnitudeModel( 'preview', self.previewChart, self.__preferences, self.get_curve_data, 'Filter', db_range_calc=dBRangeCalculator(30, expand=True), fill_curves=True) self.connectButton.setIcon(qta.icon('fa5s.check')) self.disconnectButton.setIcon(qta.icon('fa5s.times')) self.resyncFilters.setIcon(qta.icon('fa5s.sync')) self.deleteFiltersButton.setIcon(qta.icon('fa5s.trash')) self.editFilterButton.setIcon(qta.icon('fa5s.edit')) self.selectBeqButton.setIcon(qta.icon('fa5s.folder-open')) self.limitsButton.setIcon(qta.icon('fa5s.arrows-alt')) self.showDetailsButton.setIcon(qta.icon('fa5s.info')) self.createPulsesButton.setIcon(qta.icon('fa5s.wave-square')) self.fullRangeButton.setIcon(qta.icon('fa5s.expand')) self.subOnlyButton.setIcon(qta.icon('fa5s.compress')) self.autoSyncButton.setIcon(qta.icon('fa5s.magic')) self.autoSyncButton.toggled.connect( lambda b: self.__preferences.set(HTP1_AUTOSYNC, b)) self.autoSyncButton.setChecked(self.__preferences.get(HTP1_AUTOSYNC)) self.__ws_client = QtWebSockets.QWebSocket( '', QtWebSockets.QWebSocketProtocol.Version13, None) self.__ws_client.error.connect(self.__on_ws_error) self.__ws_client.connected.connect(self.__on_ws_connect) self.__ws_client.disconnected.connect(self.__on_ws_disconnect) self.__ws_client.textMessageReceived.connect(self.__on_ws_message) self.__disable_on_disconnect() self.filterMapping.itemDoubleClicked.connect( self.__show_mapping_dialog) self.__restore_geometry()
def __init__(self, preferences, signal, filter_model, redraw_main, selected_filter=None, parent=None, valid_filter_types=None): self.__preferences = preferences super(FilterDialog, self).__init__(parent) if parent is not None else super(FilterDialog, self).__init__() self.__redraw_main = redraw_main # for shelf filter, allow input via Q or S not both self.__q_is_active = True # allow user to control the steps for different fields, default to reasonably quick moving values self.__q_step_idx = self.__get_step(self.q_steps, self.__preferences.get(DISPLAY_Q_STEP), 3) self.__s_step_idx = self.__get_step(self.q_steps, self.__preferences.get(DISPLAY_S_STEP), 3) self.__gain_step_idx = self.__get_step(self.gain_steps, self.__preferences.get(DISPLAY_GAIN_STEP), 0) self.__freq_step_idx = self.__get_step(self.freq_steps, self.__preferences.get(DISPLAY_FREQ_STEP), 1) # init the UI itself self.setupUi(self) self.__snapshot = FilterModel(self.snapshotFilterView, self.__preferences, on_update=self.__on_snapshot_change) self.__working = FilterModel(self.workingFilterView, self.__preferences, on_update=self.__on_working_change) self.__selected_id = None self.__decorate_ui() self.__set_q_step(self.q_steps[self.__q_step_idx]) self.__set_s_step(self.q_steps[self.__s_step_idx]) self.__set_gain_step(self.gain_steps[self.__gain_step_idx]) self.__set_freq_step(self.freq_steps[self.__freq_step_idx]) # underlying filter model self.__signal = signal self.__filter_model = filter_model if self.__filter_model.filter.listener is not None: logger.debug(f"Selected filter has listener {self.__filter_model.filter.listener.name}") # init the chart self.__magnitude_model = MagnitudeModel('preview', self.previewChart, preferences, self.__get_data(), 'Filter', fill_primary=True, secondary_data_provider=self.__get_data('phase'), secondary_name='Phase', secondary_prefix='deg', fill_secondary=False, db_range_calc=dBRangeCalculator(30, expand=True), y2_range_calc=PhaseRangeCalculator(), show_y2_in_legend=False) # remove unsupported filter types if valid_filter_types: to_remove = [] for i in range(self.filterType.count()): if self.filterType.itemText(i) not in valid_filter_types: to_remove.append(i) for i1, i2 in enumerate(to_remove): self.filterType.removeItem(i2 - i1) # copy the filter into the working table self.__working.filter = self.__filter_model.clone() # and initialise the view for idx, f in enumerate(self.__working): selected = selected_filter is not None and f.id == selected_filter.id f.id = uuid4() if selected is True: self.__selected_id = f.id self.workingFilterView.selectRow(idx) if self.__selected_id is None: self.__add_working_filter() self.__restore_geometry()
def __init__(self, name, chart, preferences, primary_data_provider, primary_name, secondary_data_provider=None, secondary_name=None, show_legend=lambda: True, db_range_calc=dBRangeCalculator(60), subplot_spec=SINGLE_SUBPLOT_SPEC, redraw_listener=None, grid_alpha=0.5, x_min_pref_key=GRAPH_X_MIN, x_max_pref_key=GRAPH_X_MAX, x_scale_pref_key=GRAPH_X_AXIS_SCALE, fill_curves=False, fill_alpha=0.5, allow_line_resize=False): self.__name = name self.__chart = chart self.__redraw_listener = redraw_listener self.__show_legend = show_legend if allow_line_resize: self.__chart.canvas.mpl_connect('pick_event', self.__adjust_line_size) primary_axes = self.__chart.canvas.figure.add_subplot(subplot_spec) primary_axes.set_ylabel(f"dBFS ({primary_name})") primary_axes.grid(linestyle='-', which='major', linewidth=1, alpha=grid_alpha) primary_axes.grid(linestyle='--', which='minor', linewidth=1, alpha=grid_alpha * 0.5) self.__primary = AxesManager(primary_data_provider, primary_axes, fill_curves, fill_alpha) if secondary_data_provider is None: secondary_axes = None else: secondary_axes = primary_axes.twinx() secondary_axes.set_ylabel(f"dBFS ({secondary_name})") # bump the z axis so pick events are directed to the primary primary_axes.set_zorder(secondary_axes.get_zorder() + 1) primary_axes.patch.set_visible(False) self.__secondary = AxesManager(secondary_data_provider, secondary_axes, fill_curves, fill_alpha) if isinstance(db_range_calc, dBRangeCalculator) and not db_range_calc.expand_range: db_range_calc.expand_range = preferences.get(GRAPH_EXPAND_Y) self.limits = Limits(self.__repr__(), self.__redraw_func, primary_axes, x_lim=(preferences.get(x_min_pref_key), preferences.get(x_max_pref_key)), y_range_calculator=db_range_calc, axes_2=secondary_axes, x_scale=preferences.get(x_scale_pref_key)) self.limits.propagate_to_axes(draw=True) self.__legend = None self.__legend_cid = None self.redraw()