def __init__(self, state, states): Gtk.VBox.__init__(self, spacing=4) self.__state = state self.__states = states self.units = LabeledComboBoxText(label='Amplitudes in', options=['dB', 'V', 'W']) self.specs = Specs(states[state], parse=float) self.pack_start(self.units, expand=False, fill=True, padding=0) self.pack_start(self.specs, expand=False, fill=True, padding=0)
def __init__(self, state, states): Gtk.VBox.__init__(self, spacing=4) self.__state = state self.__states = states self.units = LabeledComboBoxText(label='Frequencies in', options=['Hz', 'kHz', 'MHz', 'GHz']) self.sampling = LabeledEntry(label='Fs', parse=float) self.specs = Specs(states[state], parse=float) self.pack_start(self.units, expand=True, fill=True, padding=0) self.pack_start(self.sampling, expand=True, fill=True, padding=0) self.pack_start(self.specs, expand=True, fill=True, padding=0)
def __init__(self): Gtk.VBox.__init__(self, spacing=4) self.response_type = LabeledComboBoxText( label='Response type', options=frequency_states.keys()) self.filter_order = LabeledEntry(label='Number of taps', parse=int) self.frequency_specs = FrequencySpecs(state=self.response_type.value, states=frequency_states) self.amplitude_specs = AmplitudeSpecs(state=self.response_type.value, states=amplitude_states) self.description = Gtk.Frame(label="Description") text = Gtk.Label(label='''Design the finite impulse response (FIR) filter whose transfer function minimizes the maximum error between the desired gain and the realized gain in the specified frequency bands using the Remez exchange algorithm. Notes: The amplitude specifications are meant to be gain specifications (e.g., a 20 dB attenuation is specified as -20 dB).''') scroll = Gtk.ScrolledWindow() scroll.add(text) self.description.add(scroll) @self.response_type.changed.register def set_frequency_specs_state(response_type): self.frequency_specs.state = response_type self.amplitude_specs.state = response_type self.pack_start(self.response_type, expand=False, fill=True, padding=0) self.pack_start(self.filter_order, expand=False, fill=True, padding=0) self.pack_start(self.frequency_specs, expand=False, fill=True, padding=0) self.pack_start(self.amplitude_specs, expand=False, fill=True, padding=0) self.pack_start(self.description, expand=True, fill=True, padding=0)
def __init__(self): Gtk.VBox.__init__(self, spacing=4) self.response_type = LabeledComboBoxText( label='Response type', options=frequency_states.keys()) self.filter_order = LabeledEntry(label='Number of taps', parse=int) self.frequency_specs = FrequencySpecs(state=self.response_type.value, states=frequency_states) self.amplitude_specs = AmplitudeSpecs(state=self.response_type.value, states=amplitude_states) self.description = Gtk.Frame(label="Description") text = Gtk.Label(label='''Design a linear-phase finite impulse response (FIR) which has the best approximation to the desired frequency response, in the least squares sense. Notes: The number of taps must be odd. The amplitude specifications are meant to be gain specifications (e.g., a 20 dB attenuation is specified as -20 dB).''') scroll = Gtk.ScrolledWindow() scroll.add(text) self.description.add(scroll) @self.response_type.changed.register def set_frequency_specs_state(response_type): self.frequency_specs.state = response_type self.amplitude_specs.state = response_type self.pack_start(self.response_type, expand=False, fill=True, padding=0) self.pack_start(self.filter_order, expand=False, fill=True, padding=0) self.pack_start(self.frequency_specs, expand=False, fill=True, padding=0) self.pack_start(self.amplitude_specs, expand=False, fill=True, padding=0) self.pack_start(self.description, expand=True, fill=True, padding=0)
def __init__(self): Gtk.VBox.__init__(self, spacing=4) self.response_type = LabeledComboBoxText( label='Response type', options=frequency_states['minimum'].keys()) self.filter_type = LabeledComboBoxText(label='Filter type', options=filter_types.keys()) self.filter_order = FilterOrder() self.frequency_specs = FrequencySpecs( state=self.response_type.value, states=frequency_states['minimum']) self.amplitude_specs = AmplitudeSpecs( state=filter_types[self.filter_type.value], states=amplitude_states['minimum']) self.description = Gtk.Frame(label="Description") text = Gtk.Label(label='''Design an infinite impulse response (IIR) filter. Notes: The amplitude specifications, when requested, are meant to be given as: Gpass: the maximum loss in the passband, Gstop: the minimum attenuation in the stopband, Rpass: the maximum ripple in the passband, Rstop: the minimum attenuation in the stopband.''') scroll = Gtk.ScrolledWindow() scroll.add(text) self.description.add(scroll) @self.response_type.changed.register def set_frequency_specs_state(response_type): self.frequency_specs.state = response_type @self.filter_type.changed.register def on_change_filter_type(filter_type): order = 'minimum' if self.filter_order.minimum.value else 'manual' self.amplitude_specs.states = amplitude_states[order] filter_type = filter_types[filter_type] self.amplitude_specs.state = filter_type if len(self.amplitude_specs.states[ self.amplitude_specs.state]) == 0: self.amplitude_specs.hide() else: self.amplitude_specs.show() @self.filter_order.minimum.changed.register def on_change_order_type(minimum_order): order = 'minimum' if minimum_order else 'manual' filter_type = filter_types[self.filter_type.value] self.frequency_specs.states = frequency_states[order] self.amplitude_specs.states = amplitude_states[order] self.amplitude_specs.state = filter_type if len(self.amplitude_specs.states[ self.amplitude_specs.state]) == 0: self.amplitude_specs.hide() else: self.amplitude_specs.show() self.pack_start(self.response_type, expand=False, fill=True, padding=0) self.pack_start(self.filter_type, expand=False, fill=True, padding=0) self.pack_start(self.filter_order, expand=False, fill=True, padding=0) self.pack_start(self.frequency_specs, expand=False, fill=True, padding=0) self.pack_start(self.amplitude_specs, expand=False, fill=True, padding=0) self.pack_start(self.description, expand=True, fill=True, padding=0)
frequency_states = { 'Lowpass': ['Fpass', 'Fstop'], 'Highpass': ['Fstop', 'Fpass'], 'Bandpass': ['Fstop1', 'Fpass1', 'Fpass2', 'Fstop2'], 'Bandstop': ['Fpass1', 'Fstop1', 'Fstop2', 'Fpass2'], } amplitude_states = { 'Lowpass': ['Apass', 'Astop'], 'Highpass': ['Astop', 'Apass'], 'Bandpass': ['Astop1', 'Apass1', 'Apass2', 'Astop2'], 'Bandstop': ['Apass1', 'Astop1', 'Astop2', 'Apass2'], } filter_type = LabeledComboBoxText(label='Filter type', options=frequency_states.keys()) frequency_specs = FrequencySpecs(state=filter_type.value, states=frequency_states) amplitude_specs = AmplitudeSpecs(state=filter_type.value, states=amplitude_states) button = Gtk.Button(label='Design') def on_clicked(*args): print(f'Filter type: {filter_type.value}') print('Frequency specifications') print(frequency_specs.values) print('Amplitude specifications') print(amplitude_specs.values)
dialog = Gtk.MessageDialog(flags=0, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text=str(msg)) dialog.run() dialog.destroy() if __name__ == '__main__': window = Gtk.Window() window.connect('destroy', Gtk.main_quit) specs_label = Gtk.Label() specs_label.set_markup('<b>Filter specifications</b>') design_method = LabeledComboBoxText(label='Design method', options=factory.filters.keys()) filter_widget = FilterWidget(design_method.value) @design_method.changed.register def set_filter(name): filter_widget.state = name design_button = Gtk.Button(label='Design') export_button = Gtk.Button(label='Export') export_button.show() def on_clicked_design(*args): designer = filter_widget.designer