~facundo/encuentro/trunk

« back to all changes in this revision

Viewing changes to encuentro/ui/throbber.py

  • Committer: Facundo Batista
  • Date: 2013-04-02 21:23:58 UTC
  • mto: (151.2.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 154.
  • Revision ID: facundo@taniquetil.com.ar-20130402212358-h1hlb5f65oftqyvb
Have a throbber (or spinner).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
 
 
3
# Copyright 2013 Facundo Batista
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
# For further info, check  https://launchpad.net/encuentro
 
18
 
 
19
"""A throbber."""
 
20
 
 
21
import sys
 
22
 
 
23
from os import path
 
24
 
 
25
from PyQt4.QtGui import (
 
26
    QLabel,
 
27
    QMovie,
 
28
)
 
29
from PyQt4.QtCore import Qt
 
30
 
 
31
 
 
32
BASEDIR = path.abspath(path.dirname(path.dirname(path.realpath(sys.argv[0]))))
 
33
 
 
34
 
 
35
class Throbber(QLabel):
 
36
    """A throbber."""
 
37
    def __init__(self):
 
38
        super(Throbber, self).__init__()
 
39
        self.setAlignment(Qt.AlignCenter)
 
40
        fname = path.join(BASEDIR, "encuentro/ui/media/throbber.gif")
 
41
        self._movie = QMovie(fname)
 
42
        self.setMovie(self._movie)
 
43
 
 
44
    def hide(self):
 
45
        """Overload to control the movie."""
 
46
        self._movie.stop()
 
47
        super(Throbber, self).hide()
 
48
 
 
49
    def show(self):
 
50
        """Overload to control the movie."""
 
51
        self._movie.start()
 
52
        super(Throbber, self).show()