minor tweaks
[sface.git] / sface / screens / mainscreen.py
index 53e263a..547baec 100644 (file)
@@ -46,8 +46,14 @@ class NodeView(QTreeView):
             else: model.setData(status_index, QString(node_status['out']))
 
         model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), hostname_index, hostname_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)
         
+                
 
 class NodeNameDelegate(QStyledItemDelegate):
     def __init__(self, parent):
@@ -99,6 +105,7 @@ class NodeNameDelegate(QStyledItemDelegate):
 
         painter.restore()
 
+
 class TreeItem:
     def __init__(self, data, parent=None):
         self.parentItem = parent
@@ -267,23 +274,23 @@ class NodeModel(QAbstractItemModel):
         return ret
 
 
-
 class SliceWidget(QWidget):
     def __init__(self, parent):
         QWidget.__init__(self, parent)
 
         self.network_names = []
-        self.process = None
+        self.process = SfiProcess(self)
 
-        slicename = QLabel ("Slice : %s"%(config.getSlice() or "None"),self)
-        slicename.setScaledContents(False)
+        self.slicename = QLabel("", self)
+        self.updateSliceName()
+        self.slicename.setScaledContents(False)
         searchlabel = QLabel ("Search: ", self)
         searchlabel.setScaledContents(False)
         searchbox = QLineEdit(self)
         searchbox.setAttribute(Qt.WA_MacShowFocusRect, 0)
 
         toplayout = QHBoxLayout()
-        toplayout.addWidget(slicename, 0, Qt.AlignLeft)
+        toplayout.addWidget(self.slicename, 0, Qt.AlignLeft)
         toplayout.addStretch()
         toplayout.addWidget(searchlabel, 0, Qt.AlignRight)
         toplayout.addWidget(searchbox, 0, Qt.AlignRight)
@@ -314,8 +321,35 @@ class SliceWidget(QWidget):
         self.connect(refresh, SIGNAL('clicked()'), self.refresh)
         self.connect(submit, SIGNAL('clicked()'), self.submit)
         self.connect(searchbox, SIGNAL('textChanged(QString)'), self.filter)
+        self.connect(self.nodeView, SIGNAL('hostnameClicked(QString)'),
+                     self.nodeSelectionChanged)
+
+        self.updateView()
+
+    def submitFinished(self):
+        self.setStatus("<font color='green'>Slice data submitted.</font>")
+        QTimer.singleShot(1000, self.refresh)
 
+    def refreshFinished(self):
+        self.setStatus("<font color='green'>Slice data updated.</font>", timeout=5000)
         self.updateView()
+        self.parent().signalAll("rspecUpdated")
+
+    def readSliceRSpec(self):
+        rspec_file = config.getSliceRSpecFile()
+        if os.path.exists(rspec_file):
+            xml = open(rspec_file).read()
+            return xml
+        return None
+
+    def setStatus(self, msg, timeout=None):
+        self.parent().setStatus(msg, timeout)
+
+    def checkRunningProcess(self):
+        if self.process.isRunning():
+            self.setStatus("<font color='red'>There is already a process running. Please wait.</font>")
+            return True
+        return False
 
     def filter(self, filter_string):
         # for hierarchical models QSortFilterProxyModel applies the
@@ -327,13 +361,10 @@ class SliceWidget(QWidget):
         self.filterModel.setFilterRegExp(QRegExp('|'.join(filters)))
 
     def submit(self):
-        xml = self.readSliceRSpec()
-        rspec = RSpec(xml)
-
-        if self.process:
-            self.parent().setStatus("<font color='red'>There is already a process running. Please wait.</font>", 
-                                    timeout=None)
+        if self.checkRunningProcess():
             return
+
+        rspec = RSpec(self.readSliceRSpec())
         
         no_change = True
         all_child = self.nodeModel.rootItem.allChildItems()
@@ -349,47 +380,31 @@ class SliceWidget(QWidget):
                 rspec.remove_sliver(hostname)
                 no_change = False
 
-            
-        self.process = SfiProcess()
-        outfile = self.process.applyRSpec(rspec)
-        self.parent().setStatus("Sending slice data (RSpec). This may take some time...", timeout=None)
-        
-        self.connect(self.process, SIGNAL('finished()'), self.refreshFinished)
-        self.connect(self.process, SIGNAL('finished()'), self.refresh)
+        if no_change:
+            self.setStatus("<font color=red>No change in slice data. Not submitting!</font>", timeout=3000)
+            return
 
-    def submitFinished(self):
-        del self.process
-        self.process = None
-        self.parent().setStatus("<font color='green'>Slice data submitted.</font>", timeout=None)
+        self.disconnect(self.process, SIGNAL('finished()'), self.refreshFinished)
+        self.connect(self.process, SIGNAL('finished()'), self.submitFinished)
 
-    def readSliceRSpec(self):
-        rspec_file = config.getSliceRSpecFile()
-        if os.path.exists(rspec_file):
-            xml = open(rspec_file).read()
-            return xml
-        return None
+        self.process.applyRSpec(rspec)
+        self.setStatus("Sending slice data (RSpec). This will take some time...")
+        
 
     def refresh(self):
         if not config.getSlice():
-            self.parent().setStatus("<font color='red'>Slice not set yet!</font>", timeout=None)
+            self.setStatus("<font color='red'>Slice not set yet!</font>")
             return
 
-        if self.process:
-            self.parent().setStatus("<font color='red'>There is already a process running. Please wait.</font>", 
-                                    timeout=None)
+        if self.process.isRunning():
+            self.setStatus("<font color='red'>There is already a process running. Please wait.</font>")
             return
 
-        self.process = SfiProcess()
-        outfile = self.process.getRSpecFromSM()
-        self.parent().setStatus("Updating slice data. This may take some time...", timeout=None)
-        
+        self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished)
         self.connect(self.process, SIGNAL('finished()'), self.refreshFinished)
 
-    def refreshFinished(self):
-        del self.process
-        self.process = None
-        self.parent().setStatus("<font color='green'>Slice data updated.</font>", timeout=5000)
-        self.updateView()
+        self.process.getRSpecFromSM()
+        self.setStatus("Updating slice data. This will take some time...")
 
     def updateView(self):
         global already_in_nodes
@@ -431,10 +446,26 @@ class SliceWidget(QWidget):
         self.nodeView.expandAll()
         self.nodeView.resizeColumnToContents(1)
 
+    def updateSliceName(self):
+        self.slicename.setText("Slice : %s" % (config.getSlice() or "None"))
+
+    def nodeSelectionChanged(self, hostname):
+        self.parent().nodeSelectionChanged(hostname)
 
 class MainScreen(SfaScreen):
     def __init__(self, parent):
         SfaScreen.__init__(self, parent)
 
         slice = SliceWidget(self)
-        self.init(slice, "Main Window", "OneLab Federation GUI")
+        self.init(slice, "Main Window", "OneLab SFA crawler")
+
+    def rspecUpdated(self):
+        self.mainwin.rspecWindow.updateView()
+        
+    def configurationChanged(self):
+        self.widget.updateSliceName()
+        self.widget.updateView()
+        self.mainwin.rspecWindow.updateView()
+
+    def nodeSelectionChanged(self, hostname):
+        self.mainwin.nodeSelectionChanged(hostname)