def parent(self, index): if not index.isValid(): return QModelIndex() if index.internalId() == 0: return QModelIndex() else: return self.createIndex(index.internalId() - 1, 0, 0)
def index(self, row, column, parent): if not parent.isValid(): if len(QApplication.topLevelWidgets()) <= row: return QModelIndex() else: return self.createIndex(row, column, QApplication.topLevelWidgets()[row]) else: if len(parent.internalPointer().children()) <= row: return QModelIndex() else: return self.createIndex(row, column, parent.internalPointer().children()[row])
def parent(self, index): if not index.isValid(): return QModelIndex() obj = index.internalPointer() tlw = QApplication.topLevelWidgets() if obj in tlw: return QModelIndex() else: if obj.parent() in tlw: return self.createIndex(tlw.index(obj.parent()), 0, obj.parent()) else: return self.createIndex(obj.parent().children().index(obj), 0, obj.parent())
def callback(self, name, *args): if self._paused: self.pevents.append((name, args)) return if self._maxevents != 0 and len(self.events) >= self._maxevents: self.beginRemoveRows(QModelIndex(), 0, len(self.events) - self._maxevents) self.events = self.events[len(self.events) - self._maxevents + 1:] self.endRemoveRows() idx = len(self.events) self.beginInsertRows(QModelIndex(), idx, idx) self.events.append((name, args)) self.endInsertRows()
def addUpload(self, path, localfile, overwrite, resume): """ Requests an upload to the server. @param path: path to upload the file to @type path: str @param localfile: path to the file to upload @type localfile: str @param overwrite: set to True to overwrite an existing file @type overwrite: bool @param resume: set to True to resume a previous upload @type resume: bool @return: the filetransfer id @rtype: int """ retcode = ts3lib.createReturnCode() err, ftid = ts3lib.sendFile( self.schid, self.cid, self.password, joinpath(path, os.path.split(localfile)[-1]), overwrite, resume, os.path.dirname(localfile), retcode) self.beginInsertRows(QModelIndex(), len(self.transfers), len(self.transfers)) self.transfers[ftid] = Upload(err, retcode, localfile) self.endInsertRows() return ftid
def addDownload(self, thefile, downloaddir, overwrite, resume): """ Requests a download from the server and monitors its progress @param thefile: remote file to download @type thefile: File @param downloaddir: path to the download directory @type downloaddir: str @param overwrite: set to True to overwrite an existing file @type overwrite: bool @param resume: set to True to resume a previous download @type resume: bool @return: the filetransfer id @rtype: int """ retcode = ts3lib.createReturnCode() err, ftid = ts3lib.requestFile(self.schid, self.cid, self.password, thefile.fullpath, overwrite, resume, downloaddir, retcode) self.beginInsertRows(QModelIndex(), len(self.transfers), len(self.transfers)) self.transfers[ftid] = Download(err, retcode, thefile, downloaddir) self.endInsertRows() self.downcounter += 1 if self.downcounter == 1: self.timer = self.startTimer(500) return ftid
def parent(self, index): obj = self._indexObject(index) if obj == self.root: return QModelIndex() else: parent = obj.parentNode return self._createIndex(parent.rowOf(), 0, parent)
def cleanup(self): """ Cleanup finished and broken downloads """ for i, ftid in enumerate(list(self.transfers)): trans = self.transfers[ftid] if trans.progress == 100 or trans.hasError: self.beginRemoveRows(QModelIndex(), i, i) del self.transfers[ftid] self.endRemoveRows()
def maximumEvents(self, val): if val < 0: val = 0 self._maxevents = val if val != 0 and len(self.events) > val: idx = len(self.events) - val self.beginRemoveRows(QModelIndex(), 0, idx) self.events = self.events[idx:] self.endRemoveRows()
def highestIndex(self, indexes, node=None): if len(indexes) == 0: return -1 if not node: node = self.index(0, 0, QModelIndex()) for i in range(len(indexes)): if node == indexes[i]: return i for k in range(self.rowCount(node)): for i in range(len(indexes)): kidx = self.index(k, 0, node) if indexes[i] == kidx: return i recursive = self.highestIndex(indexes, kidx) if recursive != -1: return recursive return -1
def parent(self, index): return QModelIndex()
def columnCount(self, parent=QModelIndex()): return len(self.titles)
def rowCount(self, parent=QModelIndex()): if parent.isValid(): return 0 return len(self.files)
def index(self, row, column, parent=QModelIndex()): if parent.isValid(): return QModelIndex() return self.createIndex(row, column)
def columnCount(self, parent=QModelIndex()): return 2