1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2009 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 from gpodder
.gtkui
.widgets
import SpinningProgressIndicator
30 class ProgressIndicator(object):
31 # Delayed time until window is shown (for short operations)
34 # Time between GUI updates after window creation
37 def __init__(self
, title
, subtitle
=None, cancellable
=False, parent
=None):
39 self
.subtitle
= subtitle
40 self
.cancellable
= cancellable
43 self
.progressbar
= None
45 self
._initial
_message
= None
46 self
._initial
_progress
= None
47 self
.source_id
= gobject
.timeout_add(self
.DELAY
, self
._create
_progress
)
49 def _on_delete_event(self
, window
, event
):
51 self
.dialog
.response(gtk
.RESPONSE_CANCEL
)
54 def _create_progress(self
):
55 self
.dialog
= gtk
.MessageDialog(self
.parent
, \
56 0, 0, gtk
.BUTTONS_CANCEL
, self
.subtitle
or self
.title
)
57 self
.dialog
.connect('delete-event', self
._on
_delete
_event
)
58 if gpodder
.ui
.fremantle
:
60 hildon
.hildon_gtk_window_set_progress_indicator(self
.dialog
, True)
61 self
.dialog
.set_title(self
.title
)
62 self
.dialog
.set_deletable(self
.cancellable
)
63 self
.dialog
.label
.set_selectable(False)
65 self
.dialog
.set_response_sensitive(gtk
.RESPONSE_CANCEL
, \
68 self
.progressbar
= gtk
.ProgressBar()
69 self
.progressbar
.set_ellipsize(pango
.ELLIPSIZE_END
)
71 # If the window is shown after the first update, set the progress
72 # info so that when the window appears, data is there already
73 if self
._initial
_progress
is not None:
74 self
.progressbar
.set_fraction(self
._initial
_progress
)
75 if self
._initial
_message
is not None:
76 self
.progressbar
.set_text(self
._initial
_message
)
78 self
.dialog
.vbox
.add(self
.progressbar
)
79 if gpodder
.ui
.fremantle
:
80 self
.dialog
.set_image(gtk
.Image())
82 self
.indicator
= SpinningProgressIndicator()
83 self
.dialog
.set_image(self
.indicator
)
84 self
.dialog
.show_all()
86 gobject
.source_remove(self
.source_id
)
87 self
.source_id
= gobject
.timeout_add(self
.INTERVAL
, self
._update
_gui
)
90 def _update_gui(self
):
92 self
.indicator
.step_animation()
95 def on_message(self
, message
):
97 self
.progressbar
.set_text(message
)
99 self
._initial
_message
= message
101 def on_progress(self
, progress
):
103 self
.progressbar
.set_fraction(progress
)
105 self
._initial
_progress
= progress
107 def on_finished(self
):
108 if self
.dialog
is not None:
109 self
.dialog
.destroy()
110 gobject
.source_remove(self
.source_id
)