home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1317 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.3 KB  |  80 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. from PyQt4.Qt import QToolButton, QSize, QPropertyAnimation, Qt, QMetaObject
  8. from calibre.gui2 import config
  9.  
  10. class ThrobbingButton(QToolButton):
  11.     
  12.     def __init__(self, *args):
  13.         QToolButton.__init__(self, *args)
  14.         self.animation = QPropertyAnimation(self, 'iconSize', self)
  15.         self.animation.setDuration((60 / 72) * 1000)
  16.         self.animation.setLoopCount(4)
  17.         self.normal_icon_size = QSize(64, 64)
  18.         self.animation.valueChanged.connect(self.value_changed)
  19.         self.setCursor(Qt.PointingHandCursor)
  20.         self.animation.finished.connect(self.animation_finished)
  21.  
  22.     
  23.     def set_normal_icon_size(self, w, h):
  24.         self.normal_icon_size = QSize(w, h)
  25.         self.setIconSize(self.normal_icon_size)
  26.         
  27.         try:
  28.             self.setMinimumSize(self.sizeHint())
  29.         except:
  30.             self.setMinimumSize(QSize(w + 5, h + 5))
  31.  
  32.  
  33.     
  34.     def animation_finished(self):
  35.         self.setIconSize(self.normal_icon_size)
  36.  
  37.     
  38.     def enterEvent(self, ev):
  39.         self.start_animation()
  40.  
  41.     
  42.     def leaveEvent(self, ev):
  43.         self.stop_animation()
  44.  
  45.     
  46.     def value_changed(self, val):
  47.         self.update()
  48.  
  49.     
  50.     def start_animation(self):
  51.         if config['disable_animations']:
  52.             return None
  53.         if self.animation.state() != self.animation.Stopped or not self.isVisible():
  54.             return None
  55.         size = self.normal_icon_size.width()
  56.         smaller = int(0.7 * size)
  57.         self.animation.setStartValue(QSize(smaller, smaller))
  58.         self.animation.setEndValue(self.normal_icon_size)
  59.         QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
  60.  
  61.     
  62.     def stop_animation(self):
  63.         self.animation.stop()
  64.         self.animation_finished()
  65.  
  66.  
  67. if __name__ == '__main__':
  68.     from PyQt4.Qt import QApplication, QWidget, QHBoxLayout, QIcon
  69.     app = QApplication([])
  70.     w = QWidget()
  71.     w.setLayout(QHBoxLayout())
  72.     b = ThrobbingButton()
  73.     b.setIcon(QIcon(I('donate.svg')))
  74.     w.layout().addWidget(b)
  75.     w.show()
  76.     b.set_normal_icon_size(64, 64)
  77.     b.start_animation()
  78.     app.exec_()
  79.  
  80.