-
Notifications
You must be signed in to change notification settings - Fork 1
/
uselistmodel.py
73 lines (56 loc) · 2.24 KB
/
uselistmodel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from PySide2.QtNetwork import QNetworkReply
from PySide2.QtCore import QAbstractListModel, QMimeData, Qt, QModelIndex, QFileInfo, Signal, Slot
from PySide2.QtGui import QIcon, QColor
from PySide2.QtWidgets import QApplication, QStyle
class ListModel(QAbstractListModel):
rowAdded = Signal()
rowRemoved = Signal()
def __init__(self,data,tablemodel,fileList ,parent=None):
QAbstractListModel.__init__(self, parent)
self.metadataList = fileList
self.tablemodel = tablemodel
def flags(self, index):
defaultFlags = QAbstractListModel.flags(self,index);
return Qt.ItemIsDropEnabled | defaultFlags;
def canDropMimeData(self, data, action, row, column, parent):
for file in data.urls():
aFile = QFileInfo(file.path())
if not aFile.isFile():
return False
return data.hasUrls()
def dropMimeData(self, data, action, row, column, parent):
for file in data.urls():
#if file.isLocalDirectory():
self.addRow(file.path())
return True
def rowCount(self, parent=QModelIndex()):
return len(self.metadataList)
def columnCount(self, parent=QModelIndex()):
return 1
def data(self, index, role):
if role == Qt.DisplayRole:
if index.column() == 0:
return self.metadataList[index.row()].split("/")[-1]
return None
def setData(self,index, value, role):
if role == Qt.EditRole:
if not index.isValid():
return False
if index.column() == 0:
self.dataChanged.emit(index, index)
return index.row()
def addRow(self, filename):
self.beginInsertRows(self.index(len(self.metadataList),0), len(self.metadataList),len(self.metadataList))
self.metadataList.append(filename)
self.endInsertRows()
self.rowAdded.emit()
def removeRow(self, rowIndex):
self.beginRemoveRows(QModelIndex(),rowIndex, rowIndex)
del self.metadataList[rowIndex]
self.endRemoveRows()
self.rowRemoved.emit()
def removeAllRows(self):
newI = 0
for i in range(len(self.metadataList)):
self.removeRow(i-newI)
newI+=1