forked from M-Labs/artiq
1
0
Fork 0

gui/applets: support passing command line arguments to code applets

This commit is contained in:
Sebastien Bourdeauducq 2016-09-07 00:47:26 +08:00
parent bf863053b3
commit b982832ddc
2 changed files with 12 additions and 10 deletions

View File

@ -49,14 +49,14 @@ class AppletsCCBDock(applets.AppletsDock):
break break
return parent, applet 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(): if not self.listen_action.isChecked():
return return
parent, applet = self.locate_applet(name, group, True) parent, applet = self.locate_applet(name, group, True)
if is_code: if code is None:
spec = {"ty": "code", "code": command_or_code} spec = {"ty": "command", "command": command}
else: else:
spec = {"ty": "command", "command": command_or_code} spec = {"ty": "code", "code": code, "command": command}
if applet is None: if applet is None:
applet = self.new(name=name, spec=spec, parent=parent) applet = self.new(name=name, spec=spec, parent=parent)
else: else:

View File

@ -156,7 +156,10 @@ class _AppletDock(QDockWidgetCloseDetect):
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)
elif self.spec["ty"] == "code": 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: else:
raise ValueError raise ValueError
@ -377,7 +380,8 @@ class AppletsDock(QtWidgets.QDockWidget):
if item.applet_spec_ty == "command": if item.applet_spec_ty == "command":
return {"ty": "command", "command": item.text(2)} return {"ty": "command", "command": item.text(2)}
elif item.applet_spec_ty == "code": 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: else:
raise ValueError raise ValueError
@ -385,13 +389,12 @@ class AppletsDock(QtWidgets.QDockWidget):
self.table.itemChanged.disconnect() self.table.itemChanged.disconnect()
try: try:
item.applet_spec_ty = spec["ty"] item.applet_spec_ty = spec["ty"]
item.setText(2, spec["command"])
if spec["ty"] == "command": if spec["ty"] == "command":
item.setText(2, spec["command"])
item.setIcon(2, QtGui.QIcon()) item.setIcon(2, QtGui.QIcon())
if hasattr(item, "applet_code"): if hasattr(item, "applet_code"):
del item.applet_code del item.applet_code
elif spec["ty"] == "code": elif spec["ty"] == "code":
item.setText(2, "(code)")
item.setIcon(2, QtWidgets.QApplication.style().standardIcon( item.setIcon(2, QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_FileIcon)) QtWidgets.QStyle.SP_FileIcon))
item.applet_code = spec["code"] item.applet_code = spec["code"]
@ -436,8 +439,7 @@ class AppletsDock(QtWidgets.QDockWidget):
if column == 1: if column == 1:
dock.rename(new_value) dock.rename(new_value)
else: else:
self.set_spec( dock.spec = self.get_spec(item)
item, {"ty": "command", "command": new_value})
elif item.ty == "group": elif item.ty == "group":
# To Qt's credit, it already does everything for us here. # To Qt's credit, it already does everything for us here.
pass pass