X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsliceview.py;h=7490128ac2e7460999658b81fa9eb780dc193777;hp=65b65724f905b8b13c58509076a20cc39c926683;hb=96ec1c38a62466c4d69a57835d470fee98a39edc;hpb=dc5a4a16b0819bc27efd1f77d632a76463db82c0 diff --git a/sface/sliceview.py b/sface/sliceview.py index 65b6572..7490128 100644 --- a/sface/sliceview.py +++ b/sface/sliceview.py @@ -112,14 +112,21 @@ 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): + def __init__(self, rows=0, columns=4, parent=None, mode=MODE_AUTHORITY_SLICES): QStandardItemModel.__init__(self, rows, columns, parent) + self.mode = mode def updateModel(self): self.clear() - slice_names = SfiData().getAuthorityHrns(type="slice") + if (self.mode == MODE_AUTHORITY_SLICES): + slice_names = SfiData().getAuthorityHrns(type="slice") + else: # MODE_USER_SLICES + slice_names = SfiData().getUserSliceHrns() rootItem = self.invisibleRootItem() @@ -148,3 +155,60 @@ class SliceModel(QStandardItemModel): return slices +class SlicePickerWindow(QDialog): + def __init__(self, parent=None): + super(SlicePickerWindow, self).__init__(parent) + self.setWindowTitle("Slice Picker") + + sliceLabel = QLabel("Slices:") + self.sliceView = SliceView() + + self.status = QLabel("") + self.status.setMaximumWidth(640) + + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True) + + layout = QVBoxLayout() + layout.addWidget(sliceLabel) + layout.addWidget(self.sliceView) + layout.addWidget(self.status) + layout.addWidget(self.buttonBox) + self.setLayout(layout) + + self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()")) + self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()")) + + self.sliceModel = SliceModel() + self.refreshAuthority() + + def accept(self): + self.slices = self.sliceModel.getSelectedSlices() + QDialog.accept(self) + + def setStatus(self, x): + self.status.setText(x) + + def refreshAuthority(self): + self.process = SfiProcess(self) + self.connect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished) + + self.process.listRecords(config.getAuthority(), None) + self.setStatus("Refreshing slice list. This will take a moment...") + + def getAuthorityRecordFinished(self): + self.disconnect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished) + + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("Slice list refreshed.") + self.updateSliceView() + else: + self.setStatus("Authority rec refresh error: %s" % (faultString)) + + def updateSliceView(self): + self.sliceModel.updateModel() + + self.sliceView.setModel(self.sliceModel) + self.sliceView.resizeColumnToContents(0) +