forked from mgear-dev/naming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
83 lines (63 loc) · 1.83 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
# qt bindings
Qt = None
if Qt is None:
try:
import PyQt5 as Qt
from PyQt5 import QtCore, QtGui, QtWidgets
except ImportError:
pass
if Qt is None:
try:
import PySide2 as Qt
from PySide2 import QtCore, QtGui, QtWidgets
except ImportError:
pass
if Qt is None:
try:
import PyQt4 as Qt
from PyQt4 import QtCore, QtGui
QtWidgets = QtGui
except ImportError:
pass
if Qt is None:
try:
import PySide as Qt
from PySide import QtCore, QtGui
QtWidgets = QtGui
except ImportError:
pass
if Qt is None:
raise Exception("Qt binding not found")
# application code
class MultiCompleter(QtWidgets.QCompleter):
def pathFromIndex(self, index):
suggestion = super(MultiCompleter, self).pathFromIndex(index)
currentText = self.widget().text()
splittedText = currentText.rsplit("_", 1)
splittedText[-1] = suggestion
return "_".join(splittedText)
def splitPath(self, path):
return [path.split("_")[-1]]
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QMainWindow()
pane = QtWidgets.QWidget()
layout = QtWidgets.QVBoxLayout()
tokens = ["description", "side", "category", "type"]
model = QtGui.QStringListModel()
model.setStringList(tokens)
tokenCompleter = MultiCompleter()
tokenCompleter.setModel(model)
activeRule = QtWidgets.QLineEdit()
activeRule.setPlaceholderText("Type rule pattern here")
activeRule.setCompleter(tokenCompleter)
layout.addWidget(activeRule)
tokenList = QtWidgets.QListView()
tokenList.setModel(model)
layout.addWidget(tokenList)
layout.addStretch()
pane.setLayout(layout)
w.setCentralWidget(pane)
w.show()
sys.exit(app.exec_())