-
Notifications
You must be signed in to change notification settings - Fork 0
/
t2.py
78 lines (57 loc) · 2.07 KB
/
t2.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
#!/usr/bin/python2
from PyQt4 import QtCore, QtGui
from balancer import schema, db
from balancer.window_ui import Ui_MainWindow
import random
class MyModel(QtGui.QStandardItemModel):
def __init__(self, parent = None):
super(MyModel, self).__init__(parent)
self.m = 10
for i in xrange(0, self.m):
self.appendRow([
QtGui.QStandardItem(str(i)),
QtGui.QStandardItem(str(random.randint(1,1000)))])
self.modelReset.connect(self.logreset)
def logreset(self):
print "== reset happened"
def canFetchMore(self, idx):
if not idx.isValid(): ## only root level can fetch more
return True
return False
def fetchMore(self, idx):
if not idx.isValid():
print "fetching %s -> + X" % self.m
chunk = 100
#no need to begin/end insert rows -- QStandardItemModel will do it itself
for i in xrange(self.m, self.m + chunk):
self.appendRow([
QtGui.QStandardItem(str(i)),
QtGui.QStandardItem(str(random.randint(1,1000)))])
self.m += chunk
def sort(self, col, order):
print "sorting"
super(MyModel, self).sort(col, order)
def doreset(self):
print "reset, m %s -> 0" % self.m
self.m = 0
self.clear()
class Main(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.mymodel = MyModel()
self.sortModel = QtGui.QSortFilterProxyModel()
self.sortModel.setDynamicSortFilter(True)
self.sortModel.setSourceModel(self.mymodel)
self.ui.transactionsList.setModel(self.sortModel)
self.ui.transactionsList.setSortingEnabled(True)
def on_payeeFilter_editingFinished(self):
self.mymodel.doreset()
if __name__ == '__main__':
import sys
sys.path.append('..')
app = QtGui.QApplication(sys.argv)
win = Main()
win.show()
sys.exit(app.exec_())