-
Notifications
You must be signed in to change notification settings - Fork 8
/
MultiListAnim.py
96 lines (73 loc) · 2.85 KB
/
MultiListAnim.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
# -*- coding: utf-8 -*-
"""Animate your code of PySide"""
import sys
from PySide import QtCore
from PySide import QtGui
from PySide import QtDeclarative
from PySide import QtOpenGL
class ZenWrapper(QtCore.QObject):
def __init__(self, zenItem):
QtCore.QObject.__init__(self)
self._zenItem = zenItem
self._checked = False
def _name(self):
return self._zenItem
def is_checked(self):
return self._checked
def toggle_checked(self):
self._checked = not self._checked
self.changed.emit()
return self._checked
changed = QtCore.Signal()
name = QtCore.Property(unicode, _name, notify=changed)
checked = QtCore.Property(bool, is_checked, notify=changed)
class ZenListModel(QtCore.QAbstractListModel):
def __init__(self, zenItems):
QtCore.QAbstractListModel.__init__(self)
self._zenItems = zenItems
self.setRoleNames({0: 'zenItem'})
def rowCount(self, parent=QtCore.QModelIndex()):
return len(self._zenItems)
def checked(self):
return [x for x in self._zenItems if x.checked]
def data(self, index, role):
if index.isValid() and role == 0:
return self._zenItems[index.row()]
class Controller(QtCore.QObject):
@QtCore.Slot(QtCore.QObject, QtCore.QObject, QtCore.QObject, QtCore.QObject)
def toggled(self, model, wrapper, checkbox, parent):
global view, __doc__
new_value = wrapper.toggle_checked()
new_list = model.checked()
print '='*20, 'New List', '='*20
print '\n'.join(x.name for x in new_list)
view.setWindowTitle('%s (%d)' % (__doc__, len(new_list)))
if new_value:
pa = QtCore.QSequentialAnimationGroup(parent)
anim = QtCore.QPropertyAnimation(checkbox, 'scale')
anim.setDuration(700)
anim.setStartValue(10)
anim.setEndValue(1)
anim.setEasingCurve(QtCore.QEasingCurve.OutSine)
pa.addAnimation(anim)
anim = QtCore.QPropertyAnimation(parent, 'rotation', parent)
anim.setDuration(100)
anim.setStartValue(-180)
anim.setEndValue(0)
pa.addAnimation(anim)
pa.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
zenItems = [ZenWrapper(zenItem.rstrip()) for zenItem in open(__file__) if zenItem.strip() and not zenItem.startswith(' ')]
controller = Controller()
zenItemList = ZenListModel(zenItems)
app = QtGui.QApplication(sys.argv)
view = QtDeclarative.QDeclarativeView()
glw = QtOpenGL.QGLWidget()
view.setViewport(glw)
view.setWindowTitle(__doc__)
view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
rc = view.rootContext()
rc.setContextProperty('controller', controller)
rc.setContextProperty('pythonListModel', zenItemList)
view.setSource(__file__.replace('.py', '.qml'))
view.show()
app.exec_()