forked from M-Labs/artiq
1
0
Fork 0

applets: Add ${server}, ${port_control}, ${port_notify} command substitutions

This facilitates applets that connect back to the master
(e.g. to update datasets on user request, as used by ndscan).
This commit is contained in:
David Nadlinger 2022-06-18 01:00:11 +01:00 committed by Sébastien Bourdeauducq
parent f4d639242d
commit 4c42f65909
2 changed files with 18 additions and 5 deletions

View File

@ -179,7 +179,13 @@ def main():
rpc_clients["dataset_db"]) rpc_clients["dataset_db"])
smgr.register(d_datasets) smgr.register(d_datasets)
d_applets = applets_ccb.AppletsCCBDock(main_window, sub_clients["datasets"]) d_applets = applets_ccb.AppletsCCBDock(main_window,
sub_clients["datasets"],
extra_substitutes={
"server": args.server,
"port_notify": args.port_notify,
"port_control": args.port_control,
})
atexit_register_coroutine(d_applets.stop) atexit_register_coroutine(d_applets.stop)
smgr.register(d_applets) smgr.register(d_applets)
broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify) broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)

View File

@ -93,7 +93,7 @@ class AppletIPCServer(AsyncioParentComm):
class _AppletDock(QDockWidgetCloseDetect): class _AppletDock(QDockWidgetCloseDetect):
def __init__(self, datasets_sub, uid, name, spec): def __init__(self, datasets_sub, uid, name, spec, extra_substitutes):
QDockWidgetCloseDetect.__init__(self, "Applet: " + name) QDockWidgetCloseDetect.__init__(self, "Applet: " + name)
self.setObjectName("applet" + str(uid)) self.setObjectName("applet" + str(uid))
@ -104,6 +104,7 @@ class _AppletDock(QDockWidgetCloseDetect):
self.datasets_sub = datasets_sub self.datasets_sub = datasets_sub
self.applet_name = name self.applet_name = name
self.spec = spec self.spec = spec
self.extra_substitutes = extra_substitutes
self.starting_stopping = False self.starting_stopping = False
@ -152,7 +153,8 @@ class _AppletDock(QDockWidgetCloseDetect):
python = sys.executable.replace("\\", "\\\\") python = sys.executable.replace("\\", "\\\\")
command = command_tpl.safe_substitute( command = command_tpl.safe_substitute(
python=python, python=python,
artiq_applet=python + " -m artiq.applets." artiq_applet=python + " -m artiq.applets.",
**self.extra_substitutes
) )
logger.debug("starting command %s for %s", command, self.applet_name) logger.debug("starting command %s for %s", command, self.applet_name)
await self.start_process(shlex.split(command), None) await self.start_process(shlex.split(command), None)
@ -315,7 +317,11 @@ class _CompleterDelegate(QtWidgets.QStyledItemDelegate):
class AppletsDock(QtWidgets.QDockWidget): class AppletsDock(QtWidgets.QDockWidget):
def __init__(self, main_window, datasets_sub): def __init__(self, main_window, datasets_sub, extra_substitutes={}):
"""
:param extra_substitutes: Map of extra ``${strings}`` to substitute in applet
commands to their respective values.
"""
QtWidgets.QDockWidget.__init__(self, "Applets") QtWidgets.QDockWidget.__init__(self, "Applets")
self.setObjectName("Applets") self.setObjectName("Applets")
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable | self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
@ -323,6 +329,7 @@ class AppletsDock(QtWidgets.QDockWidget):
self.main_window = main_window self.main_window = main_window
self.datasets_sub = datasets_sub self.datasets_sub = datasets_sub
self.extra_substitutes = extra_substitutes
self.applet_uids = set() self.applet_uids = set()
self.table = QtWidgets.QTreeWidget() self.table = QtWidgets.QTreeWidget()
@ -421,7 +428,7 @@ class AppletsDock(QtWidgets.QDockWidget):
self.table.itemChanged.connect(self.item_changed) self.table.itemChanged.connect(self.item_changed)
def create(self, item, name, spec): def create(self, item, name, spec):
dock = _AppletDock(self.datasets_sub, item.applet_uid, name, spec) dock = _AppletDock(self.datasets_sub, item.applet_uid, name, spec, self.extra_substitutes)
self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
dock.setFloating(True) dock.setFloating(True)
asyncio.ensure_future(dock.start()) asyncio.ensure_future(dock.start())