def configure(self): if not self.dev(): return self.setText(0, self.dev().shortName()) # decide usage status toolTip = tr("[not used]") if self.dev().inUse(): toolTip = tr("[in use]") statusTip = "" + toolTip # generate extended device type dependent info toolTip += " " + self.dev().fullName() if self.dev().isBlock(): if self.dev().inUse(): mp = self.dev().mountPoint() if len(mp): toolTip += tr(" [mountpoint: %1]").arg(mp) else: toolTip += tr(" [not mounted]") sizeStr = tr(" size: %1").arg(formatSize(self.dev().size())) toolTip += sizeStr statusTip += sizeStr elif self.dev().isScsi(): statusTip += " " + self.dev().model() curtime = int(time.time()) ts = self.dev().timeStamp() dist = curtime - ts if dist > 0: toolTip += tr(" (added %1 ago)").arg(formatTimeDistance(dist)) # finally set the extended info self.setToolTip(0, toolTip) self.setStatusTip(0, statusTip) self.setData(0, Qt.UserRole, QVariant(self.dev().inUse())) # for the delegate if self.dev().isScsi(): self.addBlockDevice(self.dev().blk())
def formatBlkDev(blkDev, lvl, prefix): if not blkDev: return [] line = [] # add recursion depth dependent prefix o = "" for dummy in range(0, lvl): o = o + " " # add the description of a single device o = o + prefix + blkDev.ioFile() line.append(o) # first column # add usage status line.append(inUseStr(blkDev.inUse())) line.append(blkDev.mountPoint()) line.append(formatSize(blkDev.size())) # last column res = [] res.append(line) # output is list of lines (which are column lists) # add sub devices recursive lvl = lvl + len(prefix) for part in blkDev.partitions(): res.extend(formatBlkDev(part, lvl, prefix)) for holder in blkDev.holders(): res.extend(formatBlkDev(holder, lvl, prefix)) lvl = lvl - len(prefix) return res