got the SlicePickerWindow working, added ability to pick user slices in addition...
authorsmbaker <smbaker@fc8clean.lan>
Mon, 31 Oct 2011 02:53:43 +0000 (19:53 -0700)
committersmbaker <smbaker@fc8clean.lan>
Mon, 31 Oct 2011 02:53:43 +0000 (19:53 -0700)
sface/sfidata.py
sface/sliceview.py

index 0ba93cb..a70cb47 100644 (file)
@@ -79,7 +79,7 @@ class SfaceRSpec(RSpec):
 
     def get_node_sliver_type(self, node, network):
         node = self.get_node_element(node, network)
-        if not node:
+        if node is None:
             return ""
 
         sliver_types = node.xpath("sliver_type")
@@ -128,7 +128,16 @@ class SfiData:
     def getUserSliceHrns(self):
         rec = self.getUserRecord()
         if rec:
-            return rec.get_field("slices")
+            slices = rec.get_field("slices")
+            if (type(slices)!=list) or (len(slices)<1):
+                return []
+
+            # get_field("slices") is returning [{"text": name}, {"text": name}, ...]
+            if (type(slices[0])==dict):
+                if "text" in slices[0]:
+                    slices = [x["text"] for x in slices]
+
+            return slices
 
         return []
 
index 7490128..0629e3b 100644 (file)
@@ -7,6 +7,7 @@ from PyQt4.QtGui import *
 from sfa.util.record import SfaRecord, SliceRecord, AuthorityRecord
 from sface.config import config
 from sface.sfidata import SfiData
+from sface.sfiprocess import SfiProcess
 
 NAME_COLUMN = 0
 MEMBERSHIP_STATUS_COLUMN = 1
@@ -14,6 +15,10 @@ MEMBERSHIP_STATUS_COLUMN = 1
 # maximum length of a name to display before clipping
 NAME_MAX_LEN = 48
 
+MODE_AUTHORITY_SLICES = 0x01
+MODE_USER_SLICES =      0x02
+MODE_SELECT_SINGLE =    0x10
+
 slice_status = { "in": "Selected",
                 "out": "Not Selected"}
 
@@ -71,8 +76,9 @@ class SliceNameDelegate(QStyledItemDelegate):
         painter.restore()
 
 class SliceView(QTableView):
-    def __init__(self, parent=None):
+    def __init__(self, mode=0, parent=None):
         QTableView.__init__(self, parent)
+        self.mode = mode
 
         self.setSelectionBehavior(QAbstractItemView.SelectRows)
         self.setSelectionMode(QAbstractItemView.SingleSelection)
@@ -89,9 +95,26 @@ class SliceView(QTableView):
         else:
             QTableView.keyPressEvent(self, event)
 
+    def selectionChanged(self, selected, deselected):
+        QTableView.selectionChanged(self, selected, deselected)
+        if (self.mode & MODE_SELECT_SINGLE) != 0:
+            self.unselectAll()
+            self.toggleSelection()
+
     def mouseDoubleClickEvent(self, event):
         self.toggleSelection()
 
+    def unselectAll(self):
+        index = self.currentIndex()
+        model = index.model()
+        for row in range(0, model.rowCount()):
+            status_index = model.index(row, MEMBERSHIP_STATUS_COLUMN, index.parent())
+            model.setData(status_index, QString(slice_status['out']))
+
+        #model.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"),
+        #            model.index(0, MEMBERSHIP_STATUS_COLUMN, index.parent()),
+        #            model.index(model.rowCount(), MEMBERSHIP_STATUS_COLUMN, index.parent()))
+
     def toggleSelection(self):
         index = self.currentIndex()
         model = index.model()
@@ -112,9 +135,6 @@ class SliceView(QTableView):
         node_index = model.index(current.row(), 0, current.parent())
         node_data = node_index.data().toString()
 
-MODE_AUTHORITY_SLICES = 1
-MODE_USER_SLICES = 2
-
 class SliceModel(QStandardItemModel):
     def __init__(self, rows=0, columns=4, parent=None, mode=MODE_AUTHORITY_SLICES):
          QStandardItemModel.__init__(self, rows, columns, parent)
@@ -123,7 +143,7 @@ class SliceModel(QStandardItemModel):
     def updateModel(self):
         self.clear()
 
-        if (self.mode == MODE_AUTHORITY_SLICES):
+        if (self.mode & MODE_AUTHORITY_SLICES) != 0:
             slice_names = SfiData().getAuthorityHrns(type="slice")
         else: # MODE_USER_SLICES
             slice_names = SfiData().getUserSliceHrns()
@@ -156,12 +176,15 @@ class SliceModel(QStandardItemModel):
         return slices
 
 class SlicePickerWindow(QDialog):
-    def __init__(self, parent=None):
+    def __init__(self, mode=MODE_AUTHORITY_SLICES, parent=None):
         super(SlicePickerWindow, self).__init__(parent)
+        self.mode = mode
+        self.slices = None
+
         self.setWindowTitle("Slice Picker")
 
         sliceLabel = QLabel("Slices:")
-        self.sliceView = SliceView()
+        self.sliceView = SliceView(mode=self.mode)
 
         self.status = QLabel("")
         self.status.setMaximumWidth(640)
@@ -179,16 +202,41 @@ class SlicePickerWindow(QDialog):
         self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
         self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
 
-        self.sliceModel = SliceModel()
-        self.refreshAuthority()
+        self.sliceModel = SliceModel(mode=mode)
+
+        self.refresh()
 
     def accept(self):
         self.slices = self.sliceModel.getSelectedSlices()
+        print self.slices
         QDialog.accept(self)
 
     def setStatus(self, x):
         self.status.setText(x)
 
+    def refresh(self):
+        if (self.mode & MODE_AUTHORITY_SLICES) != 0:
+            self.refreshAuthority()
+        else:
+            self.refreshUser()
+
+    def refreshUser(self):
+        self.process = SfiProcess(self)
+        self.connect(self.process, SIGNAL('finished()'), self.getUserRecordFinished)
+
+        self.process.getRecord(hrn=config.getUser(), filename=config.getUserRecordFile())
+        self.setStatus("Refreshing user record. This will take a moment...")
+
+    def getUserRecordFinished(self):
+        self.disconnect(self.process, SIGNAL('finished()'), self.getUserRecordFinished)
+
+        faultString = self.process.getFaultString()
+        if not faultString:
+            self.setStatus("<font color='green'>Slice list refreshed.</font>")
+            self.updateSliceView()
+        else:
+            self.setStatus("<font color='red'>User rec refresh error: %s</font>" % (faultString))
+
     def refreshAuthority(self):
         self.process = SfiProcess(self)
         self.connect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished)