22
from gi.repository import Gtk
25
from bzrlib import progress
24
26
from bzrlib.ui import UIFactory
27
class PromptDialog(Gtk.Dialog):
28
"""Prompt the user for a yes/no answer."""
29
class PromptDialog(gtk.Dialog):
30
""" Prompt the user for a yes/no answer. """
30
31
def __init__(self, prompt):
31
super(PromptDialog, self).__init__()
33
label = Gtk.Label(label=prompt)
34
self.get_content_area().pack_start(label, True, True, 10)
35
self.get_content_area().show_all()
37
self.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO,
41
class GtkProgressBar(Gtk.ProgressBar):
32
gtk.Dialog.__init__(self)
34
label = gtk.Label(prompt)
35
self.vbox.pack_start(label, padding=10)
38
self.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO,
42
class GtkProgressBar(gtk.ProgressBar):
43
44
def __init__(self):
44
super(GtkProgressBar, self).__init__()
45
gtk.ProgressBar.__init__(self)
45
46
self.set_fraction(0.0)
46
47
self.current = None
76
class ProgressBarWindow(Gtk.Window):
77
class ProgressBarWindow(gtk.Window):
78
79
def __init__(self):
79
super(ProgressBarWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
80
super(ProgressBarWindow, self).__init__(type=gtk.WINDOW_TOPLEVEL)
80
81
self.set_border_width(0)
81
82
self.set_title("Progress")
82
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
83
self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
83
84
self.pb = GtkProgressBar()
85
86
self.resize(250, 15)
96
97
def finished(self):
106
class ProgressPanel(Gtk.HBox):
107
class ProgressPanel(gtk.HBox):
108
109
def __init__(self):
109
110
super(ProgressPanel, self).__init__()
110
image_loading = Gtk.Image.new_from_stock(Gtk.STOCK_REFRESH,
111
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
112
gtk.ICON_SIZE_BUTTON)
112
113
image_loading.show()
114
115
self.pb = GtkProgressBar()
115
116
self.set_spacing(5)
116
117
self.set_border_width(5)
117
self.pack_start(image_loading, False, False, 0)
118
self.pack_start(self.pb, True, True, 0)
118
self.pack_start(image_loading, False, False)
119
self.pack_start(self.pb, True, True)
120
121
def tick(self, *args, **kwargs):
128
129
def finished(self):
129
130
self.pb.finished()
137
class PasswordDialog(Gtk.Dialog):
138
class PasswordDialog(gtk.Dialog):
138
139
""" Prompt the user for a password. """
140
141
def __init__(self, prompt):
141
super(PasswordDialog, self).__init__()
143
label = Gtk.Label(label=prompt)
144
self.get_content_area().pack_start(label, True, True, 10)
146
self.entry = Gtk.Entry()
142
gtk.Dialog.__init__(self)
144
label = gtk.Label(prompt)
145
self.vbox.pack_start(label, padding=10)
147
self.entry = gtk.Entry()
147
148
self.entry.set_visibility(False)
148
self.get_content_area().pack_end(self.entry, False, False, 10)
150
self.get_content_area().show_all()
152
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK,
153
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
149
self.vbox.pack_end(self.entry, padding=10)
153
self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK,
154
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
155
156
def _get_passwd(self):
156
157
return self.entry.get_text()
174
175
dialog = PromptDialog(prompt)
175
176
response = dialog.run()
177
return (response == Gtk.ResponseType.YES)
178
return (response == gtk.RESPONSE_YES)
179
180
def get_password(self, prompt='', **kwargs):
180
181
"""Prompt the user for a password.