~gary-lasker/software-center/tech-items-to-launcher-fix-lp1006483

« back to all changes in this revision

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

  • Committer: Michael Vogt
  • Date: 2012-05-22 12:38:02 UTC
  • mfrom: (2989.21.11 fix-965093)
  • Revision ID: michael.vogt@ubuntu.com-20120522123802-2bqdr6ujhp95k010
merged lp:~nataliabidart/software-center/fix-965093, many thanks!

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import gi
20
20
gi.require_version("Gtk", "3.0")
21
 
import os
22
21
 
23
22
from gi.repository import Gtk, GObject
24
23
 
 
24
from softwarecenter.enums import SOFTWARE_CENTER_DEBUG_TABS
 
25
 
25
26
 
26
27
class SpinnerView(Gtk.Viewport):
27
 
    """
28
 
    a panel that contains a spinner preset to a standard size and centered
29
 
    an optional label_text value can be specified for display with the spinner
30
 
    """
 
28
    """A panel that contains a spinner with an optional legend.
 
29
 
 
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.
 
32
 
 
33
    """
 
34
 
31
35
    def __init__(self, label_text=""):
32
36
        Gtk.Viewport.__init__(self)
33
37
        self.spinner = Gtk.Spinner()
48
52
        self.set_shadow_type(Gtk.ShadowType.NONE)
49
53
 
50
54
    def start_and_show(self):
51
 
        """
52
 
        start the spinner and show it
53
 
        """
 
55
        """Start the spinner and show it."""
54
56
        self.spinner.start()
55
57
        self.spinner.show()
56
58
 
57
59
    def stop_and_hide(self):
58
 
        """
59
 
        stop the spinner and hide it
60
 
        """
 
60
        """Stop the spinner and hide it."""
61
61
        self.spinner.stop()
62
62
        self.spinner.hide()
63
63
 
64
64
    def set_text(self, spinner_text=""):
65
 
        """
66
 
        useful for adding/removing/changing the label text after the spinner
67
 
        instance has been created
68
 
        """
 
65
        """Add/remove/change this spinner's label text."""
69
66
        self.spinner_label.set_markup('<big>%s</big>' % spinner_text)
70
67
 
 
68
    def get_text(self):
 
69
        """Return the spinner's currently set label text."""
 
70
        return self.spinner_label.get_text()
 
71
 
71
72
 
72
73
class SpinnerNotebook(Gtk.Notebook):
73
74
    """ this provides a Gtk.Notebook that contains a content page
78
79
 
79
80
    def __init__(self, content, msg=""):
80
81
        Gtk.Notebook.__init__(self)
 
82
        self._last_timeout_id = None
81
83
        self.spinner_view = SpinnerView(msg)
82
84
        # its critical to show() the spinner early as otherwise
83
85
        # gtk_notebook_set_active_page() will not switch to it
84
86
        self.spinner_view.show()
85
 
        if not "SOFTWARE_CENTER_DEBUG_TABS" in os.environ:
 
87
        if not SOFTWARE_CENTER_DEBUG_TABS:
86
88
            self.set_show_tabs(False)
87
89
        self.set_show_border(False)
88
90
        self.append_page(content, Gtk.Label("content"))
91
93
    def _unmask_view_spinner(self):
92
94
        # start is actually start_and_show()
93
95
        self.spinner_view.start_and_show()
 
96
        self.set_current_page(self.SPINNER_PAGE)
 
97
        self._last_timeout_id = None
94
98
        return False
95
99
 
96
100
    def show_spinner(self, msg=""):
100
104
        # "mask" the spinner view momentarily to prevent it from flashing into
101
105
        # view in the case of short delays where it isn't actually needed
102
106
        self.spinner_view.stop_and_hide()
103
 
        GObject.timeout_add(100, self._unmask_view_spinner)
104
 
        self.set_current_page(self.SPINNER_PAGE)
 
107
        self._last_timeout_id = GObject.timeout_add(250,
 
108
                                                    self._unmask_view_spinner)
105
109
 
106
110
    def hide_spinner(self):
107
111
        """ hide the spinner page again and show the content page """
 
112
        if self._last_timeout_id is not None:
 
113
            GObject.source_remove(self._last_timeout_id)
 
114
            self._last_timeout_id = None
108
115
        self.spinner_view.stop_and_hide()
109
116
        self.set_current_page(self.CONTENT_PAGE)
110
117