X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fscreens%2Fmainscreen.py;h=c51ef7a96f3d18603c57cbf5c1fa65ed1a4ae21f;hp=cc34adb7814a932e19aceaaf27a9387dd5ced2a9;hb=31f39d4d288e990328172ed778292ba801de8001;hpb=0f8d33ec09f1ba0c5a06daec528b141b96a34fc4
diff --git a/sface/screens/mainscreen.py b/sface/screens/mainscreen.py
index cc34adb..c51ef7a 100644
--- a/sface/screens/mainscreen.py
+++ b/sface/screens/mainscreen.py
@@ -26,6 +26,10 @@ tag_status = { "in": "Already Set",
default_tags = "Default tags"
settable_tags = ['delegations', 'initscript']
+NAME_COLUMN = 0
+NODE_STATUS_COLUMN = 1
+MEMBERSHIP_STATUS_COLUMN = 2
+
def itemType(index):
if index.parent().parent().isValid():
return "tag"
@@ -49,9 +53,9 @@ class NodeView(QTreeView):
def mouseDoubleClickEvent(self, event):
index = self.currentIndex()
model = index.model()
- status_index = model.index(index.row(), 1, index.parent())
+ status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
status_data = status_index.data().toString()
- node_index = model.index(index.row(), 0, index.parent())
+ node_index = model.index(index.row(), NAME_COLUMN, index.parent())
node_data = node_index.data().toString()
if itemType(node_index) == "tag":
@@ -141,11 +145,11 @@ class NodeNameDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
model = index.model()
- status_index = model.index(index.row(), 1, index.parent())
+ status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent())
status_data = status_index.data().toString()
fm = QFontMetrics(option.font)
- rect = option.rect
+ rect = QRect(option.rect)
data = index.data().toString()
rect.setHeight(rect.height() - 2)
@@ -161,45 +165,91 @@ class NodeNameDelegate(QStyledItemDelegate):
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
+ if option.state & QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.color(QPalette.Active, QPalette.Highlight))
+
if itemType(index) == "node":
if status_data == node_status['in']: # already in the slice
painter.fillPath(path, QColor.fromRgb(0, 250, 250))
painter.setPen(QColor.fromRgb(0, 0, 0))
- painter.drawText(option.rect, 0, QString(data))
+ painter.drawText(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.drawText(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))
+ painter.drawText(rect, 0, QString(data))
else:
painter.setPen(QColor.fromRgb(0, 0, 0))
- painter.drawText(option.rect, 0, QString(data))
+ painter.drawText(rect, 0, QString(data))
else:
if status_data == tag_status['in']: # already in the slice
painter.fillPath(path, QColor.fromRgb(0, 250, 250))
painter.setPen(QColor.fromRgb(0, 0, 0))
- painter.drawText(option.rect, 0, QString(data))
+ painter.drawText(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))
+ painter.drawText(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))
+ painter.drawText(rect, 0, QString(data))
else:
painter.setPen(QColor.fromRgb(0, 0, 0))
- painter.drawText(option.rect, 0, QString(data))
+ painter.drawText(rect, 0, QString(data))
+
+ painter.restore()
+
+class NodeStatusDelegate(QStyledItemDelegate):
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+
+ def paint(self, painter, option, index):
+ model = index.model()
+ nodestatus_index = model.index(index.row(), NODE_STATUS_COLUMN, index.parent())
+ nodestatus_data = nodestatus_index.data().toString()
+
+ fm = QFontMetrics(option.font)
+ rect = QRect(option.rect)
+
+ data = index.data().toString()
+ 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 option.state & QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.color(QPalette.Active, QPalette.Highlight))
+
+ if (nodestatus_data == ""):
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(rect, 0, QString(data))
+ elif (nodestatus_data == "boot"):
+ painter.fillPath(path, QColor.fromRgb(0, 250, 0))
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(rect, 0, QString(data))
+ else:
+ painter.fillPath(path, QColor.fromRgb(250, 0, 0))
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(rect, 0, QString(data))
painter.restore()
@@ -229,8 +279,9 @@ class SliceWidget(QWidget):
self.filterModel = QSortFilterProxyModel(self) # enable filtering
self.nodeNameDelegate = NodeNameDelegate(self)
+ self.nodeStatusDelegate = NodeStatusDelegate(self)
- refresh = QPushButton("Update Slice Data", self)
+ refresh = QPushButton("Refresh Slice Data", self)
refresh.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
renew = QPushButton("Renew Slice", self)
renew.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
@@ -264,7 +315,7 @@ class SliceWidget(QWidget):
QTimer.singleShot(1000, self.refresh)
def refreshFinished(self):
- self.setStatus("Slice data updated.", timeout=5000)
+ self.setStatus("Slice data refreshed.", timeout=5000)
self.updateView()
self.parent().signalAll("rspecUpdated")
@@ -394,7 +445,7 @@ class SliceWidget(QWidget):
self.connect(self.process, SIGNAL('finished()'), self.refreshFinished)
self.process.getRSpecFromSM()
- self.setStatus("Updating slice data. This will take some time...")
+ self.setStatus("Refreshing slice data. This will take some time...")
def updateView(self):
global already_in_nodes
@@ -420,7 +471,7 @@ class SliceWidget(QWidget):
networkItem = QStandardItem(QString(network))
msg = "%s Nodes\t%s Selected" % (len(all_nodes), len(sliver_nodes))
- rootItem.appendRow([networkItem, QStandardItem(QString(msg))])
+ rootItem.appendRow([networkItem, QStandardItem(QString("")), QStandardItem(QString(msg))])
already_in_nodes += sliver_nodes
@@ -433,33 +484,38 @@ class SliceWidget(QWidget):
tagstring = QString("%s: %s" % (name, value))
tagItem = QStandardItem(tagstring)
status = QStandardItem(QString(tag_status['in']))
- nodeItem.appendRow([tagItem, status])
+ nodeStatus = QStandardItem(QString(""))
+ nodeItem.appendRow([tagItem, nodeStatus, status])
for node in sliver_nodes:
nodeItem = QStandardItem(QString(node))
statusItem = QStandardItem(QString(node_status['in']))
- networkItem.appendRow([nodeItem, statusItem])
+ nodeStatus = QStandardItem(QString(rspec.get_node_element(node, network).attrib.get("boot_state","")))
+ networkItem.appendRow([nodeItem, nodeStatus, statusItem])
attrs = rspec.get_sliver_attributes(node, network)
for (name, value) in attrs:
tagstring = QString("%s: %s" % (name, value))
tagItem = QStandardItem(tagstring)
statusItem = QStandardItem(QString(tag_status['in']))
- nodeItem.appendRow([tagItem, statusItem])
+ nodeStatus = QStandardItem(QString(""))
+ nodeItem.appendRow([tagItem, nodeStatus, statusItem])
for node in available_nodes:
nodeItem = QStandardItem(QString(node))
statusItem = QStandardItem(QString(node_status['out']))
- networkItem.appendRow([nodeItem, statusItem])
+ nodeStatus = QStandardItem(QString(rspec.get_node_element(node, network).attrib.get("boot_state","")))
+ networkItem.appendRow([nodeItem, nodeStatus, statusItem])
self.filterModel.setSourceModel(self.nodeModel)
self.filterModel.setFilterKeyColumn(-1)
self.filterModel.setDynamicSortFilter(True)
- headers = QStringList() << "Hostname or Tag" << "Status"
+ headers = QStringList() << "Hostname or Tag" << "Node Status" << "Membership Status"
self.nodeModel.setHorizontalHeaderLabels(headers)
self.nodeView.setItemDelegateForColumn(0, self.nodeNameDelegate)
+ self.nodeView.setItemDelegateForColumn(1, self.nodeStatusDelegate)
self.nodeView.setModel(self.filterModel)
self.nodeView.expandAll()
self.nodeView.resizeColumnToContents(0)
@@ -514,7 +570,7 @@ class MainScreen(SfaScreen):
SfaScreen.__init__(self, parent)
slice = SliceWidget(self)
- self.init(slice, "Main Window", "OneLab SFA crawler")
+ self.init(slice, "Nodes", "OneLab SFA crawler")
def rspecUpdated(self):
self.mainwin.rspecWindow.updateView()