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

Shared UI

Fig. 6.7 SharedUI interface.

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.