From 8858ba8095826f1c46d5eeb9e193f56597b58f63 Mon Sep 17 00:00:00 2001 From: Charles Baynham Date: Sun, 24 May 2020 12:31:38 +0100 Subject: [PATCH] dashboard: Restart applets if required Restart applets that are already running if a ccb call updates their spec Signed-off-by: Charles Baynham --- artiq/dashboard/applets_ccb.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/artiq/dashboard/applets_ccb.py b/artiq/dashboard/applets_ccb.py index 1337a5363..30fa23db6 100644 --- a/artiq/dashboard/applets_ccb.py +++ b/artiq/dashboard/applets_ccb.py @@ -1,3 +1,4 @@ +import asyncio import logging from PyQt5 import QtCore, QtWidgets @@ -149,15 +150,16 @@ class AppletsCCBDock(applets.AppletsDock): corresponds to a single group. If ``group`` is ``None`` or an empty list, it corresponds to the root. - ``command`` gives the command line used to run the applet, as if it - was started from a shell. The dashboard substitutes variables such as - ``$python`` that gives the complete file name of the Python - interpreter running the dashboard. + ``command`` gives the command line used to run the applet, as if it was + started from a shell. The dashboard substitutes variables such as + ``$python`` that gives the complete file name of the Python interpreter + running the dashboard. If the name already exists (after following any specified groups), the command or code of the existing applet with that name is replaced, and - the applet is shown at its previous position. If not, a new applet - entry is created and the applet is shown at any position on the screen. + the applet is restarted and shown at its previous position. If not, a + new applet entry is created and the applet is shown at any position on + the screen. If the group(s) do not exist, they are created. @@ -181,9 +183,17 @@ class AppletsCCBDock(applets.AppletsDock): else: spec = {"ty": "code", "code": code, "command": command} if applet is None: + logger.debug('Applet {} does not exist: creating'.format(name)) applet = self.new(name=name, spec=spec, parent=parent) else: - self.set_spec(applet, spec) + if spec != self.get_spec(applet): + logger.debug('Applet {} already exists: updating existing spec'.format(name)) + self.set_spec(applet, spec) + if applet.applet_dock: + asyncio.ensure_future(applet.applet_dock.restart()) + else: + logger.debug('Applet {} already exists and no update required'.format(name)) + if ccbp == "enable": applet.setCheckState(0, QtCore.Qt.Checked)