6.4. Shared UI
6.4.1. Introduction
All user interfaces within PyMoDAQ are sharing some features that would be complex to maintain if declared everywhere. This is why most of the UI derive from the Custom App base class. However the latter provides only the framework to quickly build interfaces that may be very different. It doesn’t provide a unified way to add direct actions and access to comonly used features such as the PyMoDAQ preferences, the log file or even a direct link to the documentation. This is the role of the SharedUi object that will wraps CustomApps with common features (mostly actions and menus) we will describe below.
6.4.2. Instantiating a SharedUI
The code below shows how to create and instantiate a SharedUI. One should first create a MainWindow either directly or using the make_window method. The SharedUI object take this window as an argument and will build on it the menus and actions, see Fig. 6.7
Fig. 6.7 SharedUI interface.
6.4.3. Menu Bar Description
Figure Fig. 6.7 displays the menu of the SharedUI window with access to all the tools useful within PyMoDAQ and described below:
The File menu will allow you to Restart or Quit the DashBoard
The View menu is allowing to display or not the various toolbars
The Tools menu will allow you to:
Look at the current log file in the default editor. The older logs can be found in the .pymodaq folder, see Configuration.
Open and modify the Preferences related to all pymodaq modules and plugins (see Fig. Fig. 2.8)
Run the leco Coordinator (see LECO communication) if the pymodaq SharedUI is used:
pymodaq.utils.shared_ui import SharedUIis used (adding some more functionalities compared to the pymodaq_gui one).
Fig. 6.8 Preferences popup window.
Finally, the Help menu will allow you to:
Browse the documentation
Check for PyMoDAQ updates
Print the current versions of PyMoDAQ.
6.4.4. Wrapping a SharedUI around a CustomApp
As displayed on Fig. 6.7 several menus are already created in the SharedUI. Therefore when it will wrap a CustomApp, the application menu will be merged (if named identically) together to offer some more advanced options while providing the basic one without having to recode them. The code to allow this is shown below for the DashBoard case:
from pymodaq_gui.utils.widgets.window import make_window
from pymodaq_gui.utils.shared_ui import SharedUI
from pymodaq_gui.qt_utils import mkQApp
from pymodaq.dashboard import DashBoard
app = mkQApp('CommonWindow')
win, area = make_window(title='PyMoDAQ Dashboard')
shared_ui = SharedUI(win)
dashboard = DashBoard(area)
shared_ui.affect_application(dashboard)
sys.exit(app.exec())
where all the magic is done using the line: shared_ui.affect_application(dashboard)
to add the menus and actions described above on top of those of the DashBoard.