~ubuntu-branches/ubuntu/raring/software-center/raring-proposed

« back to all changes in this revision

Viewing changes to softwarecenter/ui/gtk3/widgets/spinner.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2012-10-11 15:33:05 UTC
  • mfrom: (195.1.18 quantal)
  • Revision ID: package-import@ubuntu.com-20121011153305-fm5ln7if3rpzts4n
Tags: 5.4.1.1
* lp:~mvo/software-center/reinstall-previous-purchase-token-fix:
  - fix reinstall previous purchases that have a system-wide
    license key LP: #1065481
* lp:~mvo/software-center/lp1060106:
  - Add missing gettext init for utils/update-software-center-agent
    (LP: #1060106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# Authors:
4
4
#  Gary Lasker
 
5
#  Natalia Bidart
5
6
#
6
7
# This program is free software; you can redistribute it and/or modify it under
7
8
# the terms of the GNU General Public License as published by the Free Software
27
28
class SpinnerView(Gtk.Viewport):
28
29
    """A panel that contains a spinner with an optional legend.
29
30
 
30
 
    The spinner is preset to a standard size and centered. An optional
31
 
    label_text value can be specified for display with the spinner.
 
31
    The spinner can be specified in one of two sizes, and defaults to
 
32
    the larger size. An optional label_text value can be specified for
 
33
    display with the spinner.
32
34
 
33
35
    """
 
36
    # define spinner size options
 
37
    (LARGE,
 
38
     SMALL) = range(2)
34
39
 
35
 
    def __init__(self, label_text=""):
 
40
    def __init__(self, label_text="", spinner_size=LARGE):
36
41
        Gtk.Viewport.__init__(self)
37
42
        self.spinner = Gtk.Spinner()
38
 
        self.spinner.set_size_request(48, 48)
 
43
        if spinner_size not in (self.SMALL, self.LARGE):
 
44
            raise ValueError('The value of spinner_size must be '
 
45
                             'one of SpinnerView.SMALL or SpinnerView.LARGE')
 
46
        if spinner_size == self.LARGE:
 
47
            self.spinner.set_size_request(48, 48)
 
48
        else:
 
49
            self.spinner.set_size_request(24, 24)
39
50
 
40
51
        # use a table for the spinner (otherwise the spinner is massive!)
41
52
        spinner_table = Gtk.Table(3, 3, False)
77
88
    (CONTENT_PAGE,
78
89
     SPINNER_PAGE) = range(2)
79
90
 
80
 
    def __init__(self, content, msg=""):
 
91
    def __init__(self, content, msg="", spinner_size=SpinnerView.LARGE):
81
92
        Gtk.Notebook.__init__(self)
82
93
        self._last_timeout_id = None
83
 
        self.spinner_view = SpinnerView(msg)
 
94
        self.spinner_view = SpinnerView(msg, spinner_size)
84
95
        # its critical to show() the spinner early as otherwise
85
96
        # gtk_notebook_set_active_page() will not switch to it
86
97
        self.spinner_view.show()
101
112
        """ show the spinner page with a alternative message """
102
113
        if msg:
103
114
            self.spinner_view.set_text(msg)
104
 
        # "mask" the spinner view momentarily to prevent it from flashing into
 
115
        # delay showing the spinner view prevent it from flashing into
105
116
        # view in the case of short delays where it isn't actually needed
106
 
        self.spinner_view.stop_and_hide()
107
 
        self._last_timeout_id = GObject.timeout_add(250,
108
 
                                                    self._unmask_view_spinner)
 
117
        # (but only if its not already visible anyway)
 
118
        if self.get_current_page() == self.CONTENT_PAGE:
 
119
            self.spinner_view.stop_and_hide()
 
120
            self._last_timeout_id = GObject.timeout_add(
 
121
                250, self._unmask_view_spinner)
109
122
 
110
123
    def hide_spinner(self):
111
124
        """ hide the spinner page again and show the content page """