rename selected column to status and give better description
[sface.git] / sface / screens / mainscreen.py
index 3d9aaff..fa29ec6 100644 (file)
@@ -11,6 +11,11 @@ from sface.screens.sfascreen import SfaScreen
 
 already_in_nodes = []
 
 
 already_in_nodes = []
 
+node_status = { "in": "Already Selected",
+                "out": "Not Selected",
+                "add": "To be Added",
+                "remove": "To be Removed"}
+
 class NodeView(QTreeView):
     def __init__(self, parent):
         QTreeView.__init__(self, parent)
 class NodeView(QTreeView):
     def __init__(self, parent):
         QTreeView.__init__(self, parent)
@@ -26,18 +31,18 @@ class NodeView(QTreeView):
     def mouseDoubleClickEvent(self, event):
         index = self.currentIndex()
         model = index.model()
     def mouseDoubleClickEvent(self, event):
         index = self.currentIndex()
         model = index.model()
-        select_index = model.index(index.row(), 2, index.parent())
-        select_data = select_index.data().toString()
+        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()
 
         hostname_index = model.index(index.row(), 1, index.parent())
         hostname_data = hostname_index.data().toString()
 
-        if select_data == "true":
-            model.setData(select_index, QString("remove"))
-        elif select_data == "false":
-            model.setData(select_index, QString("add"))
-        elif select_data in ("add", "remove"):
-            if hostname_data in already_in_nodes: model.setData(select_index, QString("true"))
-            else: model.setData(select_index, QString("false"))
+        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']))
+            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)"), hostname_index, hostname_index)
                 
@@ -50,12 +55,11 @@ class NodeNameDelegate(QStyledItemDelegate):
     def paint(self, painter, option, index):
         model = index.model()
         data = "%s" % index.data().toString()
     def paint(self, painter, option, index):
         model = index.model()
         data = "%s" % index.data().toString()
-        select_index = model.index(index.row(), 2, index.parent())
-        select_data = select_index.data().toString()
-#        if select_data == "false":
-#            model.setData(select_index, QString("add"))
+        status_index = model.index(index.row(), 2, index.parent())
+        status_data = status_index.data().toString()
 
 
-        if select_data not in ("true", "add", "remove"): # default view
+        if status_data not in (node_status['in'], node_status['remove'], node_status['add']):
+            # default view
             QStyledItemDelegate.paint(self, painter, option, index)
             return
 
             QStyledItemDelegate.paint(self, painter, option, index)
             return
 
@@ -73,19 +77,19 @@ class NodeNameDelegate(QStyledItemDelegate):
         painter.setRenderHint(QPainter.Antialiasing)
         painter.drawRoundedRect(rect, 4, 4)
 
         painter.setRenderHint(QPainter.Antialiasing)
         painter.drawRoundedRect(rect, 4, 4)
 
-        if select_data == "true": # already in the slice
+        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))
 
             painter.fillPath(path, QColor.fromRgb(0, 250, 0))
             painter.setPen(QColor.fromRgb(0, 0, 0))
             painter.drawText(option.rect, 0, QString(data))
 
-        elif select_data == "add": # newly added to the slice
+        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))
 
             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 select_data == "remove": # removed from the slice
+        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.fillPath(path, QColor.fromRgb(250, 0, 0))
             painter.setPen(QColor.fromRgb(0, 0, 0))
             painter.drawText(option.rect, 0, QString(data))
@@ -172,7 +176,7 @@ class NodeModel(QAbstractItemModel):
         self.__initRoot()
 
     def __initRoot(self):
         self.__initRoot()
 
     def __initRoot(self):
-        self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Selected")])
+        self.rootItem = TreeItem([QString("Testbed"), QString("Hostname"), QString("Status")])
 
     def getItem(self, index):
         if index.isValid():
 
     def getItem(self, index):
         if index.isValid():
@@ -359,11 +363,11 @@ class SliceWidget(QWidget):
             already_in_nodes += sliver_nodes
 
             for node in sliver_nodes:
             already_in_nodes += sliver_nodes
 
             for node in sliver_nodes:
-                nodeItem = TreeItem([QString(""), QString("%s" % node), QString("true")], networkItem)
+                nodeItem = TreeItem([QString(""), QString("%s" % node), QString(node_status['in'])], networkItem)
                 networkItem.appendChild(nodeItem)
 
             for node in available_nodes:
                 networkItem.appendChild(nodeItem)
 
             for node in available_nodes:
-                nodeItem = TreeItem([QString(""), QString(node), QString("false")], networkItem)
+                nodeItem = TreeItem([QString(""), QString(node), QString(node_status['out'])], networkItem)
                 networkItem.appendChild(nodeItem)
 
             self.nodeModel.rootItem.appendChild(networkItem)
                 networkItem.appendChild(nodeItem)
 
             self.nodeModel.rootItem.appendChild(networkItem)