22
from gi.repository import Gtk
22
from gi.repository import (
24
26
from bzrlib.ui import UIFactory
29
def main_iteration(function):
30
def with_main_iteration(self, *args, **kwargs):
31
result = function(self, *args, **kwargs)
32
while Gtk.events_pending():
33
Gtk.main_iteration_do(False)
35
return with_main_iteration
27
38
class PromptDialog(Gtk.Dialog):
28
39
"""Prompt the user for a yes/no answer."""
59
72
if msg is not None:
61
74
if None not in (self.current, self.total):
62
self.fraction = float(self.current) / self.total
63
if self.fraction < 0.0 or self.fraction > 1.0:
65
self.set_fraction(self.fraction)
66
while Gtk.events_pending():
76
class ProgressBarWindow(Gtk.Window):
75
fraction = float(self.current) / self.total
76
if fraction < 0.0 or fraction > 1.0:
78
self.set_fraction(fraction)
82
self.set_fraction(0.0)
91
class ProgressContainerMixin:
92
"""Expose GtkProgressBar methods to a container class."""
94
def tick(self, *args, **kwargs):
96
self.pb.tick(*args, **kwargs)
98
def update(self, *args, **kwargs):
100
self.pb.update(*args, **kwargs)
111
class ProgressBarWindow(ProgressContainerMixin, Gtk.Window):
78
113
def __init__(self):
79
114
super(ProgressBarWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
85
120
self.resize(250, 15)
86
121
self.set_resizable(False)
88
def tick(self, *args, **kwargs):
90
self.pb.tick(*args, **kwargs)
92
def update(self, *args, **kwargs):
94
self.pb.update(*args, **kwargs)
106
class ProgressPanel(Gtk.HBox):
124
class ProgressPanel(ProgressContainerMixin, Gtk.Box):
108
126
def __init__(self):
109
super(ProgressPanel, self).__init__()
127
super(ProgressPanel, self).__init__(Gtk.Orientation.HORIZONTAL, 5)
110
128
image_loading = Gtk.Image.new_from_stock(Gtk.STOCK_REFRESH,
111
129
Gtk.IconSize.BUTTON)
112
130
image_loading.show()
114
132
self.pb = GtkProgressBar()
116
133
self.set_border_width(5)
117
134
self.pack_start(image_loading, False, False, 0)
118
135
self.pack_start(self.pb, True, True, 0)
120
def tick(self, *args, **kwargs):
122
self.pb.tick(*args, **kwargs)
124
def update(self, *args, **kwargs):
126
self.pb.update(*args, **kwargs)
137
138
class PasswordDialog(Gtk.Dialog):
138
139
""" Prompt the user for a password. """
183
184
:param kwargs: Arguments which will be expanded into the prompt.
184
185
This lets front ends display different things if
186
:return: The password string, return None if the user
187
:return: The password string, return None if the user
187
188
canceled the request.
189
190
dialog = PasswordDialog(prompt % kwargs)
204
def _progress_updated(self, task):
205
"""See UIFactory._progress_updated"""
205
def _ensure_progress_widget(self):
206
206
if self._progress_bar_widget is None:
207
# Default to a window since nobody gave us a better mean to report
207
# Default to a window since nobody gave us a better means to report
209
209
self.set_progress_bar_widget(ProgressBarWindow())
211
def _progress_updated(self, task):
212
"""See UIFactory._progress_updated"""
213
self._ensure_progress_widget()
210
214
self._progress_bar_widget.update(task.msg,
211
215
task.current_cnt, task.total_cnt)
217
def report_transport_activity(self, transport, byte_count, direction):
218
"""See UIFactory.report_transport_activity"""
219
self._ensure_progress_widget()
220
self._progress_bar_widget.tick()