From b982832ddc2d05e1b2e1ed53a50578729563d0af Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 7 Sep 2016 00:47:26 +0800 Subject: [PATCH] gui/applets: support passing command line arguments to code applets --- artiq/dashboard/applets_ccb.py | 8 ++++---- artiq/gui/applets.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/artiq/dashboard/applets_ccb.py b/artiq/dashboard/applets_ccb.py index 26f364949..6a7bb00bb 100644 --- a/artiq/dashboard/applets_ccb.py +++ b/artiq/dashboard/applets_ccb.py @@ -49,14 +49,14 @@ class AppletsCCBDock(applets.AppletsDock): break return parent, applet - def ccb_create_applet(self, name, command_or_code, group=None, is_code=False): + def ccb_create_applet(self, name, command, group=None, code=None): if not self.listen_action.isChecked(): return parent, applet = self.locate_applet(name, group, True) - if is_code: - spec = {"ty": "code", "code": command_or_code} + if code is None: + spec = {"ty": "command", "command": command} else: - spec = {"ty": "command", "command": command_or_code} + spec = {"ty": "code", "code": code, "command": command} if applet is None: applet = self.new(name=name, spec=spec, parent=parent) else: diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index 27c0a380f..86807a20a 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -156,7 +156,10 @@ class _AppletDock(QDockWidgetCloseDetect): logger.debug("starting command %s for %s", command, self.applet_name) await self.start_process(shlex.split(command), None) elif self.spec["ty"] == "code": - await self.start_process([sys.executable], self.spec["code"]) + args = [sys.executable, "-"] + args += shlex.split(self.spec["command"]) + logger.debug("starting code applet %s", self.applet_name) + await self.start_process(args, self.spec["code"]) else: raise ValueError @@ -377,7 +380,8 @@ class AppletsDock(QtWidgets.QDockWidget): if item.applet_spec_ty == "command": return {"ty": "command", "command": item.text(2)} elif item.applet_spec_ty == "code": - return {"ty": "code", "code": item.applet_code} + return {"ty": "code", "code": item.applet_code, + "command": item.text(2)} else: raise ValueError @@ -385,13 +389,12 @@ class AppletsDock(QtWidgets.QDockWidget): self.table.itemChanged.disconnect() try: item.applet_spec_ty = spec["ty"] + item.setText(2, spec["command"]) if spec["ty"] == "command": - item.setText(2, spec["command"]) item.setIcon(2, QtGui.QIcon()) if hasattr(item, "applet_code"): del item.applet_code elif spec["ty"] == "code": - item.setText(2, "(code)") item.setIcon(2, QtWidgets.QApplication.style().standardIcon( QtWidgets.QStyle.SP_FileIcon)) item.applet_code = spec["code"] @@ -436,8 +439,7 @@ class AppletsDock(QtWidgets.QDockWidget): if column == 1: dock.rename(new_value) else: - self.set_spec( - item, {"ty": "command", "command": new_value}) + dock.spec = self.get_spec(item) elif item.ty == "group": # To Qt's credit, it already does everything for us here. pass