X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fscreens%2Fuserscreen.py;h=db0d3e78219d0911966aa0976d1167e3b2c59d4d;hp=6b800b78369a424345812ec64596543990176ef2;hb=57955fb30bcffb386779c0b75cc6f8d7db1795d3;hpb=62dde09f684bc81e571f8c0d8439b39ec9b5cf2f diff --git a/sface/screens/userscreen.py b/sface/screens/userscreen.py index 6b800b7..db0d3e7 100644 --- a/sface/screens/userscreen.py +++ b/sface/screens/userscreen.py @@ -15,11 +15,70 @@ NAME_COLUMN = 0 MEMBERSHIP_STATUS_COLUMN = 1 SERVER_MEMBERSHIP_STATUS_COLUMN = 2 +# maximum length of a name to display before clipping +NAME_MAX_LEN = 48 + user_status = { "in": "Already Selected", "out": "Not Selected", "add": "To be Added", "remove": "To be Removed"} +color_status = { "in": QColor.fromRgb(0, 250, 250), + "add": QColor.fromRgb(0, 250, 0), + "remove": QColor.fromRgb(250, 0, 0) } + + +class UserNameDelegate(QStyledItemDelegate): + def __init__(self, parent): + QStyledItemDelegate.__init__(self, parent) + + def displayText(self, value, locale): + data = str(QStyledItemDelegate.displayText(self, value, locale)) + if (len(data)>NAME_MAX_LEN): + data = data[:(NAME_MAX_LEN-3)] + "..." + return QString(data) + + def paint(self, painter, option, index): + model = index.model() + data = str(self.displayText(index.data(), QLocale())) + status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent()) + status_data = status_index.data().toString() + + fm = QFontMetrics(option.font) + rect = QRect(option.rect) + + rect.setHeight(rect.height() - 2) + rect.setWidth(fm.width(QString(data)) + 6) + rect.setX(rect.x() + 5) + rect.setY(rect.y() - 1) + + textRect = QRect(option.rect) + textRect.setWidth(fm.width(QString(data)) + 6) + textRect.setX(rect.x()) + + 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)) + + color = None + for x in user_status.keys(): + if (user_status[x] == status_data) and (x in color_status): + color = color_status[x] + + if color != None: + painter.fillPath(path, color) + painter.setPen(QColor.fromRgb(0, 0, 0)) + painter.drawText(textRect, Qt.AlignVCenter, QString(data)) + + painter.restore() + class UserView(QTableView): def __init__(self, parent=None): QTableView.__init__(self, parent) @@ -31,7 +90,18 @@ class UserView(QTableView): self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setToolTip("Double click on a row to change its status.") + self.setItemDelegateForColumn(0, UserNameDelegate(self)) + + def keyPressEvent(self, event): + if (event.key() == Qt.Key_Space): + self.toggleSelection() + else: + QTableView.keyPressEvent(self, event) + def mouseDoubleClickEvent(self, event): + self.toggleSelection() + + def toggleSelection(self): index = self.currentIndex() model = index.model() status_index = model.index(index.row(), MEMBERSHIP_STATUS_COLUMN, index.parent()) @@ -57,7 +127,6 @@ class UserView(QTableView): model = current.model() node_index = model.index(current.row(), 0, current.parent()) node_data = node_index.data().toString() - self.emit(SIGNAL('hostnameClicked(QString)'), node_data) def hideUnusableColumns(self): self.hideColumn(SERVER_MEMBERSHIP_STATUS_COLUMN) @@ -85,27 +154,33 @@ class UserModel(QStandardItemModel): slice_persons.append({"name": name, "role": "researcher", "member": user_status["in"]}) added_persons.append(name) - i=1 + i=0 while (os.path.exists(config.getAuthorityListFile(i))): rec = self.readUserRecord(i) if rec: - name = str(rec.get_name()) - if not name in added_persons: - slice_persons.append({"name": name, "role": "", "member": user_status["out"]}) - added_persons.append(name) + type = str(rec.get_type()) + if (type == "user"): + name = str(rec.get_name()) + if not name in added_persons: + slice_persons.append({"name": name, "role": "", "member": user_status["out"]}) + added_persons.append(name) i=i+1 rootItem = self.invisibleRootItem() for person in slice_persons: - rootItem.appendRow([QStandardItem(QString(person["name"])), - #QStandardItem(QString(person["role"])), - QStandardItem(QString(person["member"])), - QStandardItem(QString(person["member"]))]) + rootItem.appendRow([self.readOnlyItem(person["name"]), + self.readOnlyItem(person["member"]), + self.readOnlyItem(person["member"])]) headers = QStringList() << "User Name" << "Status" << "ServerStatus" self.setHorizontalHeaderLabels(headers) + def readOnlyItem(self, x): + item = QStandardItem(QString(x)) + item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) + return item + def updateRecord(self, slicerec): change = False @@ -198,17 +273,35 @@ class UsersWidget(QWidget): self.updateView() def submitFinished(self): - self.setStatus("Slice data submitted.") - QTimer.singleShot(1000, self.refresh) + self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished) + + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("Slice user data submitted.") + QTimer.singleShot(1000, self.refresh) + else: + self.setStatus("Slice user submit failed: %s" % (faultString)) def getSliceRecordFinished(self): - self.setStatus("Authority data refreshed.", timeout=5000) - self.refreshAuthority() + self.disconnect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished) + + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("Slice record refreshed.") + self.refreshAuthority() + else: + self.setStatus("Slice rec refresh error: %s" % (faultString)) def getAuthorityRecordFinished(self): - self.setStatus("Slice data refreshed.", timeout=5000) - self.updateView() - #self.parent().signalAll("usersUpdated") + self.disconnect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished) + + faultString = self.process.getFaultString() + if not faultString: + self.setStatus("User data refreshed.") + self.updateView() + #self.parent().signalAll("usersUpdated") + else: + self.setStatus("Authority rec refresh error: %s" % (faultString)) def readSliceRecord(self): rec_file = config.getSliceRecordFile() @@ -251,7 +344,6 @@ class UsersWidget(QWidget): rec_file = config.getSliceRecordFile() file(rec_file, "w").write(rec.save_to_string()) - self.disconnect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished) self.connect(self.process, SIGNAL('finished()'), self.submitFinished) self.process.updateRecord(rec_file) @@ -266,17 +358,15 @@ class UsersWidget(QWidget): self.setStatus("There is already a process running. Please wait.") return - self.disconnect(self.process, SIGNAL('finished()'), self.submitFinished) self.connect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished) self.process.getSliceRecord() self.setStatus("Refreshing slice record. This will take some time...") def refreshAuthority(self): - self.disconnect(self.process, SIGNAL('finished()'), self.getSliceRecordFinished) self.connect(self.process, SIGNAL('finished()'), self.getAuthorityRecordFinished) - self.process.listRecords(config.getAuthority(), "user", config.getAuthorityListFile()) + self.process.listRecords(config.getAuthority(), None, config.getAuthorityListFile()) self.setStatus("Refreshing user records. This will take some time...") def updateView(self):