2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
5
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
6
__docformat__ = 'restructuredtext en'
9
from PyQt4.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \
12
from calibre.gui2 import config
14
class ThrobbingButton(QToolButton):
16
def __init__(self, *args):
17
QToolButton.__init__(self, *args)
18
self.animation = QPropertyAnimation(self, 'iconSize', self)
19
self.animation.setDuration(60/72.*1000)
20
self.animation.setLoopCount(4)
21
self.normal_icon_size = QSize(64, 64)
22
self.animation.valueChanged.connect(self.value_changed)
23
self.setCursor(Qt.PointingHandCursor)
24
self.animation.finished.connect(self.animation_finished)
26
def set_normal_icon_size(self, w, h):
27
self.normal_icon_size = QSize(w, h)
28
self.setIconSize(self.normal_icon_size)
30
self.setMinimumSize(self.sizeHint())
32
self.setMinimumSize(QSize(w+5, h+5))
34
def animation_finished(self):
35
self.setIconSize(self.normal_icon_size)
37
def enterEvent(self, ev):
38
self.start_animation()
40
def leaveEvent(self, ev):
43
def value_changed(self, val):
46
def start_animation(self):
47
if config['disable_animations']: return
48
if self.animation.state() != self.animation.Stopped or not self.isVisible():
50
size = self.normal_icon_size.width()
51
smaller = int(0.7 * size)
52
self.animation.setStartValue(QSize(smaller, smaller))
53
self.animation.setEndValue(self.normal_icon_size)
54
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
56
def stop_animation(self):
58
self.animation_finished()
61
if __name__ == '__main__':
62
from PyQt4.Qt import QApplication, QWidget, QHBoxLayout, QIcon
63
app = QApplication([])
65
w.setLayout(QHBoxLayout())
67
b.setIcon(QIcon(I('donate.svg')))
68
w.layout().addWidget(b)
70
b.set_normal_icon_size(64, 64)