X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fscreens%2Fmainscreen.py;h=4792179ef249021b6b0f5875a6813ce827bdcc21;hp=58116175b5f5d3678338bf9728f140d5a7ef385c;hb=c3786a55ebf09c0bc22fc23da529d0cca14dd210;hpb=65c93a598a2f80c9040b21d675b9ee219def815e diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py index 5811617..4792179 100644 --- a/sface/screens/mainscreen.py +++ b/sface/screens/mainscreen.py @@ -15,6 +15,18 @@ node_status = { "in": "Already Selected", "add": "To be Added", "remove": "To be Removed"} +tag_status = { "in": "Already Set", + "out": "Not Set", + "add": "To be Added", + "remove": "To be Removed"} + +def itemType(index): + if index.parent().parent().isValid(): + return "tag" + else: + return "node" + + class NodeView(QTreeView): def __init__(self, parent): QTreeView.__init__(self, parent) @@ -33,24 +45,34 @@ class NodeView(QTreeView): model = index.model() status_index = model.index(index.row(), 2, index.parent()) status_data = status_index.data().toString() - hostname_index = model.index(index.row(), 1, index.parent()) - hostname_data = hostname_index.data().toString() - - if status_data == node_status['in']: - model.setData(status_index, QString(node_status['remove'])) - elif status_data == node_status['out']: - model.setData(status_index, QString(node_status['add'])) - elif status_data in (node_status['add'], node_status['remove']): - if hostname_data in already_in_nodes: model.setData(status_index, QString(node_status['in'])) + node_index = model.index(index.row(), 1, index.parent()) + node_data = node_index.data().toString() + + if itemType(node_index) == "tag": + if status_data == tag_status['in']: + model.setData(status_index, QString(tag_status['remove'])) + elif status_data == tag_status['add']: + model.setData(status_index, QString(tag_status['out'])) + elif status_data == tag_status['remove']: + model.setData(status_index, QString(tag_status['in'])) else: model.setData(status_index, QString(node_status['out'])) + else: + # This is a hostname + if status_data == node_status['in']: + model.setData(status_index, QString(node_status['remove'])) + elif status_data == node_status['out']: + model.setData(status_index, QString(node_status['add'])) + elif status_data in (node_status['add'], node_status['remove']): + if node_data in already_in_nodes: model.setData(status_index, QString(node_status['in'])) + else: model.setData(status_index, QString(node_status['out'])) - model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), hostname_index, hostname_index) + model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), node_index, node_index) def currentChanged(self, current, previous): model = current.model() - hostname_index = model.index(current.row(), 1, current.parent()) - hostname_data = hostname_index.data().toString() - self.emit(SIGNAL('hostnameClicked(QString)'), hostname_data) + node_index = model.index(current.row(), 1, current.parent()) + node_data = node_index.data().toString() + self.emit(SIGNAL('hostnameClicked(QString)'), node_data) @@ -60,47 +82,85 @@ class NodeNameDelegate(QStyledItemDelegate): def paint(self, painter, option, index): model = index.model() - data = "%s" % index.data().toString() status_index = model.index(index.row(), 2, index.parent()) status_data = status_index.data().toString() - if status_data not in (node_status['in'], node_status['remove'], node_status['add']): - # default view - QStyledItemDelegate.paint(self, painter, option, index) - return - fm = QFontMetrics(option.font) rect = option.rect - rect.setWidth(fm.width(QString(data)) + 8) - rect.setHeight(rect.height() - 2) - rect.setX(rect.x() + 4) - x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width() - - path = QPainterPath() - path.addRoundedRect(x, y, w, h, 4, 4) - - painter.save() - painter.setRenderHint(QPainter.Antialiasing) - painter.drawRoundedRect(rect, 4, 4) - - if status_data == node_status['in']: # already in the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(option.rect, 0, QString(data)) - - elif status_data == node_status['add']: # newly added to the slice - painter.fillPath(path, QColor.fromRgb(0, 250, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(option.rect, 0, QString(data)) - painter.drawRect(x + w + 10, y + 3, 10, 10) - painter.fillRect(x + w + 10, y + 3, 10, 10, QColor.fromRgb(0, 250, 0)) - - elif status_data == node_status['remove']: # removed from the slice - painter.fillPath(path, QColor.fromRgb(250, 0, 0)) - painter.setPen(QColor.fromRgb(0, 0, 0)) - painter.drawText(option.rect, 0, QString(data)) - painter.drawRect(x + w + 10, y + 3, 10, 10) - painter.fillRect(x + w + 10, y + 3, 10, 10, QColor.fromRgb(250, 0, 0)) + + if itemType(index) == "node": + data = "%s" % index.data().toString() + #if status_data not in (node_status['in'], node_status['remove'], node_status['add']): + # default view + # QStyledItemDelegate.paint(self, painter, option, index) + # return + + rect.setHeight(rect.height() - 2) + rect.setWidth(fm.width(QString(data)) + 6) + rect.setX(rect.x() + 5) + rect.setY(rect.y() - 1) + x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width() + + path = QPainterPath() + path.addRoundedRect(x - 1, y + 1, w, h, 4, 4) + + painter.save() + painter.setRenderHint(QPainter.Antialiasing) + + if status_data == node_status['in']: # already in the slice + painter.fillPath(path, QColor("cyan")) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + elif status_data == node_status['add']: # newly added to the slice + painter.fillPath(path, QColor.fromRgb(0, 250, 0)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + elif status_data == node_status['remove']: # removed from the slice + painter.fillPath(path, QColor.fromRgb(250, 0, 0)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + else: + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + else: + indent = 16 + tag = index.data().toStringList() + data = "%s: %s" % (tag[0], tag[1]) + rect.setHeight(rect.height() - 2) + rect.setWidth(fm.width(QString(data)) + 6 + indent) + rect.setX(rect.x() + 4 + indent) + rect.setY(rect.y() - 1) + + x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width() + + path = QPainterPath() + path.addRoundedRect(x - 1, y + 1, w, h, 4, 4) + + painter.save() + painter.setRenderHint(QPainter.Antialiasing) + + if status_data == tag_status['in']: # already in the slice + painter.fillPath(path, QColor("cyan")) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + elif status_data == tag_status['add']: # newly added to the slice + painter.fillPath(path, QColor.fromRgb(0, 250, 0)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + elif status_data == tag_status['remove']: # removed from the slice + painter.fillPath(path, QColor.fromRgb(250, 0, 0)) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) + + else: + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(option.rect, 0, QString(data)) painter.restore() @@ -191,7 +251,7 @@ class NodeModel(QAbstractItemModel): self.__initRoot() def __initRoot(self): - self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Status"), QString("Tags")]) + self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Status")]) def getItem(self, index): if index.isValid(): @@ -257,6 +317,13 @@ class NodeModel(QAbstractItemModel): item = self.getItem(index) return item.data(index.column()) + def nodestatus(self, index): + if not index.isValid(): + return QVariant() + + item = self.getItem(index) + return item.nodestatus(index.column()) + def flags(self, index): if not index.isValid(): return 0 @@ -418,11 +485,14 @@ class SliceWidget(QWidget): networks = rspec.get_network_list() for network in networks: self.network_names.append(network) - attrs = "" - for (name, value) in rspec.get_default_sliver_attributes(network): - attrs += "%s/%s " % (name, value) - networkItem = TreeItem([QString(network), QString(""), QString(""), QString(attrs)], self.nodeModel.rootItem) - + data = [QString(network), QString(""), QString("")] + #taglist = QStringList() + #attrs = rspec.get_default_sliver_attributes(network) + #for (name, value) in attrs: + # taglist.append(QString("%s/%s" % (name, value))) + # taglist.append(QString("in")) + #data.append(taglist) + networkItem = TreeItem(data, self.nodeModel.rootItem) all_nodes = rspec.get_node_list(network) sliver_nodes = rspec.get_sliver_list(network) available_nodes = filter(lambda x:x not in sliver_nodes, all_nodes) @@ -430,12 +500,17 @@ class SliceWidget(QWidget): already_in_nodes += sliver_nodes for node in sliver_nodes: - attrs = "" - for (name, value) in rspec.get_sliver_attributes(node, network): - attrs += "%s/%s " % (name, value) - nodeItem = TreeItem([QString(""), QString("%s" % node), QString(node_status['in']), QString(attrs)], networkItem) + data = [QString(""), QString(node), QString(node_status['in'])] + nodeItem = TreeItem(data, networkItem) networkItem.appendChild(nodeItem) + attrs = rspec.get_sliver_attributes(node, network) + for (name, value) in attrs: + tagstring = QStringList([name, value]) + data = [QString(""), tagstring, QString(tag_status['in'])] + tagItem = TreeItem(data, nodeItem) + nodeItem.appendChild(tagItem) + for node in available_nodes: nodeItem = TreeItem([QString(""), QString(node), QString(node_status['out']), QString("")], networkItem) networkItem.appendChild(nodeItem)