class FeatScanUi(ScanUi): """A Frontend displaying scan parameters with appropriate units. """ def connect_backend(self): target = self.backend.instrument feat_name = self.backend.feat_name feat = target.feats[feat_name] def _pimp(widget): WidgetMixin.wrap(widget) widget.bind_feat(feat) for name in 'start stop step_size'.split(): _pimp(getattr(self.widget, name)) if feat.limits and len(feat.limits) == 3: self.widget.step_size.setMinimum(feat.limits[2]) else: self.widget.step_size.setMinimum(0) super().connect_backend() if __name__ == '__main__': from lantz.drivers.examples import LantzSignalGenerator with LantzSignalGenerator('TCPIP::localhost::5678::SOCKET') as inst: app = FeatScan('frequency', fungen=inst) start_gui_app(app, FeatScanUi)
# the drivers you need (In this case just simulated dummy drivers). from lantz.drivers.examples.dummydrivers import DummyOsci # Drivers are instantiated in the usual way. osci = DummyOsci('COM2') # You create a function that will be called by the loop # It requires three parameters # counter - the iteration number # iterations - total number of iterations # overrun - a boolean indicating if the time required for the operation # is longer than the interval. def measure(counter, iterations, overrun): print(counter, iterations, overrun) data = osci.measure() print(data) # You instantiate the loop app = Loop() # and assign the function to the body of the loop app.body = measure # Finally you start the program start_gui_app(app, LoopUi) # This contains a very complete GUI for a loop you can easily create a customized version!
def on_mode_changed(self, new_index): if new_index == StepsMode.step_size: self.widget.step_count.setEnabled(False) self.widget.step_size.setEnabled(True) elif new_index == StepsMode.step_count: self.widget.step_count.setEnabled(True) self.widget.step_size.setEnabled(False) self.recalculate() def on_loop_done(self, cancelled): self.widget.start_stop.setText('Start') self.widget.start_stop.setEnabled(True) self.widget.start_stop.setChecked(False) if self.widget.progress_bar.maximum(): self.widget.progress_bar.setValue( self.widget.progress_bar.maximum()) else: self.widget.progress_bar.setMaximum(1) if __name__ == '__main__': def func(current, total, overrun): print('func', current, total, overrun) app = Scan() app.body = func start_gui_app(app, ScanUi)
self.widget.duration.setReadOnly(False) self.widget.iterations.setReadOnly(True) elif new_index == StopMode.Iterations: self.widget.duration.setEnabled(True) self.widget.iterations.setEnabled(True) self.widget.duration.setReadOnly(True) self.widget.iterations.setReadOnly(False) elif new_index == StopMode.IterationsTimeOut: self.widget.duration.setEnabled(True) self.widget.iterations.setEnabled(True) self.widget.duration.setReadOnly(False) self.widget.iterations.setReadOnly(False) self.recalculate() def on_loop_done(self, cancelled): self.widget.start_stop.setText('Start') self.widget.start_stop.setEnabled(True) self.widget.start_stop.setChecked(False) if self.widget.progress_bar.maximum(): self.widget.progress_bar.setValue(self.widget.progress_bar.maximum()) else: self.widget.progress_bar.setMaximum(1) if __name__ == '__main__': def func(current, total, overrun): print('func', current, total, overrun) app = Loop() app.body = func start_gui_app(app, LoopUi)
~~~~~~~~~~~~ This example shows how to use a more complex app, loading the configuration from an external file and :copyright: 2014 by Lantz Authors, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ # From lantz, you import a helper function. from lantz.ui.app import start_gui_app from myapps import AmplitudeScannerShutter, AmplitudeScannerShutterUi # To instantiated BigApp in this example, the configuration is loaded from a yaml file # For each instrument in the yaml file, the corresponding one in BigApp is found (matched by name). # an assigned to a new instance of the driver created using the corresponding class, args and kwargs. # Then variables are checked to see if they are an instance of Backend (in this case scanner). # In that case, "sub qapp" is instantiated. When BigApp notice that `osci` and `fungen` are # also present in the small qapp, it will assign the corresponding drivers # (a way should be provided to use subapps with different naming) app = AmplitudeScannerShutter.config_from_file('lab_config.yaml') # calling show, displays the user interface and blocks the execution # under the hood it creates a QtApp and start it. start_gui_app(app, AmplitudeScannerShutterUi)
pbar.setPalette(self._overrun_palette) else: pbar.setPalette(self._ok_palette) def on_mode_changed(self, new_index): if new_index == StepsMode.step_size: self.widget.step_count.setEnabled(False) self.widget.step_size.setEnabled(True) elif new_index == StepsMode.step_count: self.widget.step_count.setEnabled(True) self.widget.step_size.setEnabled(False) self.recalculate() def on_loop_done(self, cancelled): self.widget.start_stop.setText('Start') self.widget.start_stop.setEnabled(True) self.widget.start_stop.setChecked(False) if self.widget.progress_bar.maximum(): self.widget.progress_bar.setValue(self.widget.progress_bar.maximum()) else: self.widget.progress_bar.setMaximum(1) if __name__ == '__main__': def func(current, total, overrun): print('func', current, total, overrun) app = Scan() app.body = func start_gui_app(app, ScanUi)
This example shows how to use a more complex app, loading the configuration from an external file and :copyright: 2014 by Lantz Authors, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ # From lantz, you import a helper function. from lantz.ui.app import start_gui_app from myapps import AmplitudeScannerShutter, AmplitudeScannerShutterUi # To instantiated BigApp in this example, the configuration is loaded from a yaml file # For each instrument in the yaml file, the corresponding one in BigApp is found (matched by name). # an assigned to a new instance of the driver created using the corresponding class, args and kwargs. # Then variables are checked to see if they are an instance of Backend (in this case scanner). # In that case, "sub qapp" is instantiated. When BigApp notice that `osci` and `fungen` are # also present in the small qapp, it will assign the corresponding drivers # (a way should be provided to use subapps with different naming) app = AmplitudeScannerShutter.config_from_file("lab_config.yaml") # calling show, displays the user interface and blocks the execution # under the hood it creates a QtApp and start it. start_gui_app(app, AmplitudeScannerShutterUi)
This example shows how to use the loop block (backend and frontend) inside another gui. The gui incorporates a plot. :copyright: 2015 by Lantz Authors, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ # From lantz, you import a helper function. from lantz.ui.app import start_gui_app # the drivers you need (In this case just simulated dummy drivers). from lantz.drivers.examples.dummydrivers import DummyOsci from myapps import LoopOsciMeasure, LoopPlot # Drivers are instantiated in the usual way. osci = DummyOsci('COM2') # You instantiate the backend app = LoopOsciMeasure(osci=osci) # Finally you start the program start_gui_app(app, LoopPlot) # Notice that the LoopPlot GUI is not tied to the LoopOsciMeasure backend. # It just requires a backend that has a measure method and that emits a new_data signal!