~ubuntu-branches/debian/wheezy/calibre/wheezy

« back to all changes in this revision

Viewing changes to src/calibre/gui2/throbber.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-08-11 11:30:57 UTC
  • mfrom: (1.3.14 upstream)
  • mto: (29.3.2 oneiric)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20100811113057-2jhbcbavxw7wlt0c
Tags: 0.7.13+dfsg-1
* New upstream version.
* debian/control: Add python-routes recommends. (Closes: #590561)
* Convert to 3.0 (quilt) source format.
* Bump debhelper compat level to 7, and drop now obsolete
  DEB_DH_INSTALL_SOURCEDIR in debian/rules.
* debian/control: Add missing ${misc:Depends}.
* debian/control: Bump Standards-Version to 3.9.1.
* debian/copyright: Replace obsolete reference to
  /usr/share/common-licenses/BSD with their verbatim text from the original
  source.
* debian/rules: Remove invalid hashbang lines from *.recipe, these have no
  __main__.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
 
3
 
 
4
__license__   = 'GPL v3'
 
5
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
 
6
__docformat__ = 'restructuredtext en'
 
7
 
 
8
 
 
9
from PyQt4.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \
 
10
        QMetaObject
 
11
 
 
12
from calibre.gui2 import config
 
13
 
 
14
class ThrobbingButton(QToolButton):
 
15
 
 
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)
 
25
 
 
26
    def set_normal_icon_size(self, w, h):
 
27
        self.normal_icon_size = QSize(w, h)
 
28
        self.setIconSize(self.normal_icon_size)
 
29
        try:
 
30
            self.setMinimumSize(self.sizeHint())
 
31
        except:
 
32
            self.setMinimumSize(QSize(w+5, h+5))
 
33
 
 
34
    def animation_finished(self):
 
35
        self.setIconSize(self.normal_icon_size)
 
36
 
 
37
    def enterEvent(self, ev):
 
38
        self.start_animation()
 
39
 
 
40
    def leaveEvent(self, ev):
 
41
        self.stop_animation()
 
42
 
 
43
    def value_changed(self, val):
 
44
        self.update()
 
45
 
 
46
    def start_animation(self):
 
47
        if config['disable_animations']: return
 
48
        if self.animation.state() != self.animation.Stopped or not self.isVisible():
 
49
            return
 
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)
 
55
 
 
56
    def stop_animation(self):
 
57
        self.animation.stop()
 
58
        self.animation_finished()
 
59
 
 
60
 
 
61
if __name__ == '__main__':
 
62
    from PyQt4.Qt import QApplication, QWidget, QHBoxLayout, QIcon
 
63
    app = QApplication([])
 
64
    w = QWidget()
 
65
    w.setLayout(QHBoxLayout())
 
66
    b = ThrobbingButton()
 
67
    b.setIcon(QIcon(I('donate.svg')))
 
68
    w.layout().addWidget(b)
 
69
    w.show()
 
70
    b.set_normal_icon_size(64, 64)
 
71
    b.start_animation()
 
72
 
 
73
    app.exec_()