-
Notifications
You must be signed in to change notification settings - Fork 4
/
testapp.py
executable file
·96 lines (67 loc) · 2.62 KB
/
testapp.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
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import signal
import sys
sys.path.append(sys.argv[1])
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyKF5 import KItemModels
from PyKF5 import KWidgetsAddons
class TodoWidget(QtWidgets.QWidget):
def __init__(self):
QtWidgets.QWidget.__init__(self)
self.stringListModel = QtCore.QStringListModel();
self.doneSelectionModel = QtCore.QItemSelectionModel()
self.doneSelectionModel.setModel(self.stringListModel)
self.checkableProxy = KItemModels.KCheckableProxyModel()
self.checkableProxy.setSourceModel(self.stringListModel)
self.checkableProxy.setSelectionModel(self.doneSelectionModel)
mainlayout = QtWidgets.QHBoxLayout(self)
todoLayout = QtWidgets.QVBoxLayout(self)
mainlayout.addLayout(todoLayout)
todoLayout.addWidget(QtWidgets.QLabel("TODO list"))
addLayout = QtWidgets.QHBoxLayout(self)
todoLayout.addLayout(addLayout)
self.addLineEdit = QtWidgets.QLineEdit()
addLayout.addWidget(self.addLineEdit)
self.addButton = QtWidgets.QPushButton("Add")
addLayout.addWidget(self.addButton)
self.addButton.clicked.connect(self.add_todo)
self.addLineEdit.returnPressed.connect(self.add_todo)
self.stringsView = QtWidgets.QTreeView()
self.stringsView.header().hide()
self.stringsView.setModel(self.checkableProxy)
self.stringsView.setSelectionMode(QtWidgets.QTreeView.ExtendedSelection)
todoLayout.addWidget(self.stringsView)
self.selectionProxy = KItemModels.KSelectionProxyModel()
self.selectionProxy.setSourceModel(self.stringListModel)
self.selectionProxy.setSelectionModel(self.doneSelectionModel)
l = QtWidgets.QVBoxLayout(self)
mainlayout.addLayout(l)
l.addWidget(QtWidgets.QLabel("DONE list"))
self.selectionView = QtWidgets.QTreeView()
self.selectionView.header().hide()
self.selectionView.setModel(self.selectionProxy)
l.addWidget(self.selectionView)
statusLayout = QtWidgets.QHBoxLayout(self)
l.addLayout(statusLayout)
self.ratingWidget = KWidgetsAddons.KLed()
statusLayout.addWidget(self.ratingWidget)
self.statusText = QtWidgets.QLabel("Status: Ok")
statusLayout.addWidget(self.statusText)
def add_todo(self):
rc = self.stringListModel.rowCount()
self.stringListModel.insertRow(rc)
self.stringListModel.setData(self.stringListModel.index(rc, 0), self.addLineEdit.text())
self.addLineEdit.clear()
app = QtWidgets.QApplication(sys.argv)
todoWidget = TodoWidget()
todoWidget.resize(600, 400)
todoWidget.show()
def sigint_handler(*args):
QtWidgets.QApplication.quit()
signal.signal(signal.SIGINT, sigint_handler)
timer = QtCore.QTimer()
timer.start(16)
timer.timeout.connect(lambda: None)
app.exec_()