-
Notifications
You must be signed in to change notification settings - Fork 1
/
completionmodel.py
56 lines (47 loc) · 2.11 KB
/
completionmodel.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
from PyQt5.QtCore import QModelIndex, Qt, QAbstractListModel
from PyQt5.QtGui import QIcon
class CompletionModel(QAbstractListModel):
def __init__(self, completions=None, parent=None):
super().__init__(parent)
if not completions:
self.completions = []
else:
self.completions = completions
def rowCount(self, index=QModelIndex()):
return len(self.completions)
def setCompletions(self, completions):
self.beginResetModel()
self.completions = completions
self.endResetModel()
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return
completion = self.completions[index.row()]
if completion.type == "path" and completion.name.endswith("\\"):
name = f"{completion.name[:-1]}/"
else:
name = completion.name
if role == Qt.DisplayRole:
return name
elif role == Qt.EditRole:
return name
elif role == Qt.DecorationRole:
if completion.type == "class":
return QIcon(":/plugins/bettereditor/icons/symbol-class.svg")
elif completion.type == "keyword":
return QIcon(":/plugins/bettereditor/icons/symbol-keyword.svg")
elif completion.type == "function":
return QIcon(":/plugins/bettereditor/icons/symbol-namespace.svg")
elif completion.type == "path":
if name.endswith("/"):
return QIcon(":/plugins/bettereditor/icons/folder.svg")
else:
return QIcon(":/plugins/bettereditor/icons/file-1.svg")
elif completion.type == "statement":
return QIcon(":/plugins/bettereditor/icons/symbol-enumerator.svg")
elif completion.type == "param":
return QIcon(":/plugins/bettereditor/icons/symbol-variable.svg")
elif completion.type == "name":
return QIcon(":/plugins/bettereditor/icons/symbol-key.svg")
else:
return QIcon(":/plugins/bettereditor/icons/symbol-method.svg")