forked from M-Labs/artiq
applets: separate create/create+enable CCB policies
This commit is contained in:
parent
ff20ed2710
commit
ebb0ba17f5
|
@ -15,10 +15,37 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
sep = QtWidgets.QAction(self.table)
|
sep = QtWidgets.QAction(self.table)
|
||||||
sep.setSeparator(True)
|
sep.setSeparator(True)
|
||||||
self.table.addAction(sep)
|
self.table.addAction(sep)
|
||||||
self.listen_action = QtWidgets.QAction(
|
|
||||||
"Listen to client control broadcasts", self.table)
|
ccbp_global_menu = QtWidgets.QMenu()
|
||||||
self.listen_action.setCheckable(True)
|
actiongroup = QtWidgets.QActionGroup(self.table)
|
||||||
self.table.addAction(self.listen_action)
|
actiongroup.setExclusive(True)
|
||||||
|
self.ccbp_global_ignore = QtWidgets.QAction("Ignore requests", self.table)
|
||||||
|
self.ccbp_global_ignore.setCheckable(True)
|
||||||
|
ccbp_global_menu.addAction(self.ccbp_global_ignore)
|
||||||
|
actiongroup.addAction(self.ccbp_global_ignore)
|
||||||
|
self.ccbp_global_create = QtWidgets.QAction("Create applets", self.table)
|
||||||
|
self.ccbp_global_create.setCheckable(True)
|
||||||
|
self.ccbp_global_create.setChecked(True)
|
||||||
|
ccbp_global_menu.addAction(self.ccbp_global_create)
|
||||||
|
actiongroup.addAction(self.ccbp_global_create)
|
||||||
|
self.ccbp_global_enable = QtWidgets.QAction("Create and enable applets",
|
||||||
|
self.table)
|
||||||
|
self.ccbp_global_enable.setCheckable(True)
|
||||||
|
ccbp_global_menu.addAction(self.ccbp_global_enable)
|
||||||
|
actiongroup.addAction(self.ccbp_global_enable)
|
||||||
|
|
||||||
|
ccbp_global_action = QtWidgets.QAction(
|
||||||
|
"Client control broadcast policy (global)", self.table)
|
||||||
|
ccbp_global_action.setMenu(ccbp_global_menu)
|
||||||
|
self.table.addAction(ccbp_global_action)
|
||||||
|
|
||||||
|
def get_ccpb_global(self):
|
||||||
|
if self.ccbp_global_ignore.isChecked():
|
||||||
|
return "ignore"
|
||||||
|
if self.ccbp_global_create.isChecked():
|
||||||
|
return "create"
|
||||||
|
if self.ccbp_global_enable.isChecked():
|
||||||
|
return "enable"
|
||||||
|
|
||||||
def locate_applet(self, name, group, create_groups):
|
def locate_applet(self, name, group, create_groups):
|
||||||
if group is None:
|
if group is None:
|
||||||
|
@ -50,7 +77,8 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
return parent, applet
|
return parent, applet
|
||||||
|
|
||||||
def ccb_create_applet(self, name, command, group=None, code=None):
|
def ccb_create_applet(self, name, command, group=None, code=None):
|
||||||
if not self.listen_action.isChecked():
|
ccbp = self.get_ccpb_global()
|
||||||
|
if ccbp == "ignore":
|
||||||
return
|
return
|
||||||
parent, applet = self.locate_applet(name, group, True)
|
parent, applet = self.locate_applet(name, group, True)
|
||||||
if code is None:
|
if code is None:
|
||||||
|
@ -61,10 +89,12 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
applet = self.new(name=name, spec=spec, parent=parent)
|
applet = self.new(name=name, spec=spec, parent=parent)
|
||||||
else:
|
else:
|
||||||
self.set_spec(applet, spec)
|
self.set_spec(applet, spec)
|
||||||
|
if ccbp == "enable":
|
||||||
applet.setCheckState(0, QtCore.Qt.Checked)
|
applet.setCheckState(0, QtCore.Qt.Checked)
|
||||||
|
|
||||||
def ccb_disable_applet(self, name, group=None):
|
def ccb_disable_applet(self, name, group=None):
|
||||||
if not self.listen_action.isChecked():
|
ccbp = self.get_ccpb_global()
|
||||||
|
if ccbp != "create":
|
||||||
return
|
return
|
||||||
parent, applet = self.locate_applet(name, group, False)
|
parent, applet = self.locate_applet(name, group, False)
|
||||||
if applet is not None:
|
if applet is not None:
|
||||||
|
@ -85,9 +115,9 @@ class AppletsCCBDock(applets.AppletsDock):
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
return {
|
return {
|
||||||
"applets": applets.AppletsDock.save_state(self),
|
"applets": applets.AppletsDock.save_state(self),
|
||||||
"listen": self.listen_action.isChecked()
|
"ccbp_global": self.get_ccpb_global()
|
||||||
}
|
}
|
||||||
|
|
||||||
def restore_state(self, state):
|
def restore_state(self, state):
|
||||||
applets.AppletsDock.restore_state(self, state["applets"])
|
applets.AppletsDock.restore_state(self, state["applets"])
|
||||||
self.listen_action.setChecked(state["listen"])
|
getattr(self, "ccbp_global_" + state["ccbp_global"]).setChecked(True)
|
||||||
|
|
Loading…
Reference in New Issue