Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7efd9905412c
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 811f123a17c4
Choose a head ref
  • 8 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 9, 2016

  1. Copy the full SHA
    6aaf6c8 View commit details
  2. Copy the full SHA
    ff20ed2 View commit details
  3. Copy the full SHA
    ebb0ba1 View commit details
  4. applets: fix indices

    sbourdeauducq committed Sep 9, 2016
    Copy the full SHA
    615807a View commit details
  5. Copy the full SHA
    6144839 View commit details
  6. applets: use a different workaround to disable editing

    True to itself, Qt did not miss the opportunity to trash widgets inside
    QTreeWidgetItems when they are moved by drag-and-drop. Problem known for
    more than 6 years and still not fixed as of Qt 5.7.
    sbourdeauducq committed Sep 9, 2016
    Copy the full SHA
    4bdbc5b View commit details
  7. Copy the full SHA
    769b1e2 View commit details
  8. Copy the full SHA
    811f123 View commit details
Showing with 195 additions and 54 deletions.
  1. +147 −17 artiq/dashboard/applets_ccb.py
  2. +45 −35 artiq/gui/applets.py
  3. +3 −2 artiq/language/environment.py
164 changes: 147 additions & 17 deletions artiq/dashboard/applets_ccb.py
Original file line number Diff line number Diff line change
@@ -15,42 +15,140 @@ def __init__(self, *args, **kwargs):
sep = QtWidgets.QAction(self.table)
sep.setSeparator(True)
self.table.addAction(sep)
self.listen_action = QtWidgets.QAction(
"Listen to client control broadcasts", self.table)
self.listen_action.setCheckable(True)
self.table.addAction(self.listen_action)

def locate_applet(self, name, group, create_groups):
if group is None:
group = []
elif isinstance(group, str):
group = [group]
ccbp_group_menu = QtWidgets.QMenu()
actiongroup = QtWidgets.QActionGroup(self.table)
actiongroup.setExclusive(True)
self.ccbp_group_none = QtWidgets.QAction("No policy", self.table)
self.ccbp_group_none.setCheckable(True)
self.ccbp_group_none.triggered.connect(lambda: self.set_ccbp(""))
ccbp_group_menu.addAction(self.ccbp_group_none)
actiongroup.addAction(self.ccbp_group_none)
self.ccbp_group_ignore = QtWidgets.QAction("Ignore requests", self.table)
self.ccbp_group_ignore.setCheckable(True)
self.ccbp_group_ignore.triggered.connect(lambda: self.set_ccbp("ignore"))
ccbp_group_menu.addAction(self.ccbp_group_ignore)
actiongroup.addAction(self.ccbp_group_ignore)
self.ccbp_group_create = QtWidgets.QAction("Create applets", self.table)
self.ccbp_group_create.setCheckable(True)
self.ccbp_group_create.triggered.connect(lambda: self.set_ccbp("create"))
ccbp_group_menu.addAction(self.ccbp_group_create)
actiongroup.addAction(self.ccbp_group_create)
self.ccbp_group_enable = QtWidgets.QAction("Create and enable applets",
self.table)
self.ccbp_group_enable.setCheckable(True)
self.ccbp_group_enable.triggered.connect(lambda: self.set_ccbp("enable"))
ccbp_group_menu.addAction(self.ccbp_group_enable)
actiongroup.addAction(self.ccbp_group_enable)
self.ccbp_group_action = QtWidgets.QAction("Group CCB policy", self.table)
self.ccbp_group_action.setMenu(ccbp_group_menu)
self.table.addAction(self.ccbp_group_action)
self.table.itemSelectionChanged.connect(self.update_group_ccbp_menu)

ccbp_global_menu = QtWidgets.QMenu()
actiongroup = QtWidgets.QActionGroup(self.table)
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("Global CCB policy", self.table)
ccbp_global_action.setMenu(ccbp_global_menu)
self.table.addAction(ccbp_global_action)

def update_group_ccbp_menu(self):
selection = self.table.selectedItems()
if selection:
item = selection[0]
if item.ty == "applet":
item = item.parent()
if item is None:
self.ccbp_group_action.setEnabled(False)
else:
self.ccbp_group_action.setEnabled(True)
ccbp = item.text(1)
if ccbp == "":
self.ccbp_group_none.setChecked(True)
else:
getattr(self, "ccbp_group_" + ccbp).setChecked(True)
else:
self.ccbp_group_action.setEnabled(False)

def set_ccbp(self, ccbp):
item = self.table.selectedItems()[0]
if item.ty == "applet":
item = item.parent()
item.setText(1, ccbp)

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 get_ccpb(self, group):
ccbp = self.get_ccpb_global()
parent = self.table.invisibleRootItem()
for g in group:
new_parent = None
for i in range(parent.childCount()):
child = parent.child(i)
if child.ty == "group" and child.text(0) == g:
c_ccbp = child.text(1)
if c_ccbp:
ccbp = c_ccbp
new_parent = child
break
if new_parent is None:
return ccbp
else:
parent = new_parent
return ccbp

def locate_applet(self, name, group, create_groups):
parent = self.table.invisibleRootItem()
for g in group:
new_parent = None
for i in range(parent.childCount()):
child = parent.child(i)
if child.ty == "group" and child.text(1) == g:
if child.ty == "group" and child.text(0) == g:
new_parent = child
break
if new_parent is None:
if create_groups:
new_parent = self.new_group(g, parent)
new_parent = self.new_group(g, parent=parent)
else:
return None, None
parent = new_parent

applet = None
for i in range(parent.childCount()):
child = parent.child(i)
if child.ty == "applet" and child.text(1) == name:
if child.ty == "applet" and child.text(0) == name:
applet = child
break
return parent, applet

def ccb_create_applet(self, name, command, group=None, code=None):
if not self.listen_action.isChecked():
if group is None:
group = []
elif isinstance(group, str):
group = [group]

ccbp = self.get_ccpb(group)
if ccbp == "ignore":
return
parent, applet = self.locate_applet(name, group, True)
if code is None:
@@ -61,15 +159,45 @@ def ccb_create_applet(self, name, command, group=None, code=None):
applet = self.new(name=name, spec=spec, parent=parent)
else:
self.set_spec(applet, spec)
applet.setCheckState(0, QtCore.Qt.Checked)
if ccbp == "enable":
applet.setCheckState(0, QtCore.Qt.Checked)

def ccb_disable_applet(self, name, group=None):
if not self.listen_action.isChecked():
if group is None:
group = []
elif isinstance(group, str):
group = [group]

ccbp = self.get_ccpb(group)
if ccbp != "enable":
return
parent, applet = self.locate_applet(name, group, False)
if applet is not None:
applet.setCheckState(0, QtCore.Qt.Unchecked)

def ccb_disable_applet_group(self, group):
if isinstance(group, str):
group = [group]

ccbp = self.get_ccpb(group)
if ccbp != "enable":
return
if not group:
return
wi = self.table.invisibleRootItem()
for g in group:
nwi = None
for i in range(wi.childCount()):
child = wi.child(i)
if child.ty == "group" and child.text(0) == g:
nwi = child
break
if nwi is None:
return
else:
wi = nwi
wi.setCheckState(0, QtCore.Qt.Unchecked)

def ccb_notify(self, message):
try:
service = message["service"]
@@ -79,15 +207,17 @@ def ccb_notify(self, message):
self.ccb_create_applet(*args, **kwargs)
elif service == "disable_applet":
self.ccb_disable_applet(*args, **kwargs)
elif service == "disable_applet_group":
self.ccb_disable_applet_group(*args, **kwargs)
except:
logger.error("failed to process CCB", exc_info=True)

def save_state(self):
return {
"applets": applets.AppletsDock.save_state(self),
"listen": self.listen_action.isChecked()
"ccbp_global": self.get_ccpb_global()
}

def restore_state(self, state):
applets.AppletsDock.restore_state(self, state["applets"])
self.listen_action.setChecked(state["listen"])
getattr(self, "ccbp_global_" + state["ccbp_global"]).setChecked(True)
Loading