1
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-12-30 10:41:18 +01:00
Files
bec_widgets/docs/user/getting_started/quick_start.md
2025-04-24 08:49:33 +02:00

9.4 KiB

(user.command_line_introduction)=

Quick start

In order to use BEC Widgets as a plotting tool for BEC, it needs to be installed in the same Python environment as the BEC IPython client (please refer to the BEC documentation for more details). Upon startup, the client will automatically launch a GUI and store it as a gui object in the client. The GUI backend will also be automatically connect to the BEC server, giving access to all information on the server and allowing the user to visualize the data in real-time.

BECGuiClient

The gui object is the entry point for users to interact with the BEC Widgets framework. It is an instance of the BECGuiClient class, which provides a set of methods to create and manage the GUI. Upon startup of BEC, we automatically launch a BECDockArea instance, as the default main area for the user interface. However, the startup procedure can be individually configured by the user to launch their own custom GUI. We provide a launcher instance which is accessible through the top menu bar New -> Open Launcher. A new window will open, allowing the user to launch a new BECDockArea instance, an AutoUpdate instance, an individual widget or a custom ui file prepared throught the QtDesigner.

BECDockArea

The BECDockArea is a versatile container to quickly build customized GUIS. It allows adding new widgets through the CLI, or directly via toolbar actions. New widgets can only be added into BECDock instances, which are the individual containers for the widgets. The docks allow us to arrange the widgets in a customizable structure, detach them from the main window and allow for floating windows.

Widgets

Widgets are the building blocks of the BEC Widgets framework. They are the visual components that allow users to interact with the data and control the behavior of the application. Each dock can contain multiple widgets, albeit we recommend for most use cases a single widget per dock. BEC Widgets provides a set of core widgets (cf. widgets). More widgets can be added by the users, and we invite you to explore the developer documentation to learn how to create custom widgets. For the introduction given here, we will focus on the plotting widgets of BECWidgets.

Waveform Plot

The WaveForm is a widget that can be used to visualize 1D waveform data, i.e. to plot data of a monitor against a motor position. The method plot() returns the plot object.

plt = gui.new().new().new(gui.available_widgets.Waveform)
plt.plot(x_name='samx', y_name='bpm4i')

Here, we create a new plot with a subscription to the devices samx and bpm4i and assign the plot to the object plt. We can now use this object to further customize the plot, e.g. changing the title (plt.title = 'my title' ), axis labels (plt.x_label = 'my x label')

We invite you to explore the API of the WaveForm in the documentation or directly in the command line.

To plot custom data, i.e. data that is not directly available through a scan in BEC, we can use the same method, but provide the data directly to the plot.

plt = gui.new().new().new(gui.available_widgets.Waveform)
# 
plt.plot([1,2,3,4], [1,4,9,16])
# or 
plt.plot(x=np.array([1,2,3,4]), y=np.array([1,4,9,16]))
# or 
plt.plot(np.random.rand(10,2))
# or if you like to receive the custom curve item
curve = plt.plot(x=[1,2,3,4], y=[1,4,9,16])

Scatter Plot

The WaveForm widget can also be used to visualize 2D scatter plots. More details on setting up the scatter plot are available in the widget documentation of the scatter plot.

Motor Map

The MotorMap widget can be used to visualize the position of motors. It's focused on tracking and visualizing the position of motors, crucial for precise alignment and movement tracking during scans. More details on setting up the motor map are available in the widget documentation of the motor map.

Image Plot

The Image widget can be used to visualize 2D image data for example a camera. More details on setting up the image plot are available in the widget documentation of the image plot.

Useful Commands

We recommend users to explore the API of the widgets by themselves since we assume that the user interface is supposed to be intuitive and self-explanatory. We appreciate feedback from user in order to constantly improve the experience and allow easy access to the gui, widgets and their functionality. We recommend checking the API documentation, but also by using BEC Widgets, exploring the available functions and check their dockstrings.

gui.new? # shows the dockstring of the new method

In addition, we list below a few useful commands that can be used to interface with the widgets:

gui.windows # returns a dictionary of all docks in the gui
gui.new() # adds a new dock_area to the gui

dock_area = gui.windows['bec']
dock = dock_area.new('my_dock') # adds a new widget of BECFigure to the dock
plt = dock.new(gui.available_widgets.Waveform) # adds a new widget of Waveformto the dock
#dock_area.my_dock.new(gui.available_widgets.Waveform) # alterntive syntax
dock.element_list # returns a list of all widgets in the dock
dock.elements

plt.curves # returns a list of all curves in the plot

We note that commands can also be chained. For example, gui.new().new().new(gui.available_widgets.Waveform) will add a new dock_area to the gui and add a new dock with a Waveform widget to the dock.

Composing a larger GUI

The example given above introduces BEC Widgets with its different components, and provides an overview of how to interact with the widgets. Nevertheless, another power aspect of BEC Widgets lies in the ability to compose a larger GUI with multiple docks and widgets. This section aims to provide a tutorial like guide on how to compose a more complex GUI that (A) live-plots a 1D waveform, (B) plots data from a camera, and (C) tracks the positions of two motors. Let's assume BEC was just started and the gui object is available in the client. A single dock is already attached together with a BEC Figure. Let's add the 1D waveform to this dock, change the color of the line to white and add the title 1D Waveform to the plot.

dock_area = gui.new()
plt = dock_area.new().new(gui.available_widgets.Waveform)
plt.plot(x_name='samx', y_name='bpm4i')
plt.curves[0].set_color(color="white")
plt.title = '1D Waveform'

Next, we add 2 new docks to the gui, one to plot the data of a camera and one to track the positions of two motors.

cam_widget= dock_area.new().new(gui.available_widgets.Image)
cam_widget.image("eiger")
motor_widget = dock_area.new().new(gui.available_widgets.MotorMap)
motor_widget.map("samx", "samy")

Note, we chain commands here which is possible since the new() and new() methods return the dock and the widget respectively. We can now further customize the widgets by changing the title, axis labels, etc.

cam_widget.title = "Camera Image Eiger"
cam_widget.vrange = [0, 100]

As a final step, we can now add also a RingProgressBar to a new dock, and perform a grid_scan with the motors samx and samy. As you see in the example below, all docks are arranged below each other. This is the default behavior of the new() method. However, the docks can be freely arranged by drag and drop as desired by the user. We invite you to explore this by yourself following the example in the video, and build your custom GUI with BEC Widgets.

prog_bar = dock_area.new().new(gui.available_widgets.RingProgressBar)
prog_bar.set_line_widths(15)
scans.grid_scan(dev.samy, -2, 2, 10, dev.samx, -5, 5, 10, exp_time=0.1, relative=False)

gui_complex_gui