/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to ui.py

Merged UI work from progressbar branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""GTK UI
20
20
"""
21
21
 
22
 
from gi.repository import Gtk
 
22
from gi.repository import (
 
23
    Gtk,
 
24
    )
23
25
 
24
26
from bzrlib.ui import UIFactory
25
27
 
33
35
    return with_main_iteration
34
36
 
35
37
 
36
 
class PromptDialog(Gtk.MessageDialog):
 
38
class PromptDialog(Gtk.Dialog):
37
39
    """Prompt the user for a yes/no answer."""
38
40
 
39
 
    def __init__(self, prompt, parent=None):
40
 
        super(PromptDialog, self).__init__(
41
 
            parent, Gtk.DialogFlags.DESTROY_WITH_PARENT,
42
 
            Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, prompt)
43
 
 
44
 
 
45
 
class InfoDialog(Gtk.MessageDialog):
46
 
    """Show the user an informational message."""
47
 
 
48
 
    MESSAGE_TYPE = Gtk.MessageType.INFO
49
 
 
50
 
    def __init__(self, prompt, parent=None):
51
 
        super(InfoDialog, self).__init__(
52
 
            parent, Gtk.DialogFlags.DESTROY_WITH_PARENT,
53
 
            self.MESSAGE_TYPE, Gtk.ButtonsType.CLOSE, prompt)
54
 
 
55
 
 
56
 
class WarningDialog(InfoDialog):
57
 
    """Show the user a warning message."""
58
 
 
59
 
    MESSAGE_TYPE = Gtk.MessageType.WARNING
60
 
 
61
 
 
62
 
class ErrorDialog(InfoDialog):
63
 
    """Show the user a warning message."""
64
 
 
65
 
    MESSAGE_TYPE = Gtk.MessageType.ERROR
 
41
    def __init__(self, prompt):
 
42
        super(PromptDialog, self).__init__()
 
43
 
 
44
        label = Gtk.Label(label=prompt)
 
45
        self.get_content_area().pack_start(label, True, True, 10)
 
46
        self.get_content_area().show_all()
 
47
 
 
48
        self.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO,
 
49
                         Gtk.ResponseType.NO)
66
50
 
67
51
 
68
52
class GtkProgressBar(Gtk.ProgressBar):
193
177
        dialog.destroy()
194
178
        return (response == Gtk.ResponseType.YES)
195
179
 
196
 
    def show_message(self, msg):
197
 
        """See UIFactory.show_message."""
198
 
        dialog = InfoDialog(msg)
199
 
        dialog.run()
200
 
        dialog.destroy()
201
 
 
202
 
    def show_warning(self, msg):
203
 
        """See UIFactory.show_warning."""
204
 
        dialog = WarningDialog(msg)
205
 
        dialog.run()
206
 
        dialog.destroy()
207
 
 
208
 
    def show_error(self, msg):
209
 
        """See UIFactory.show_error."""
210
 
        dialog = ErrorDialog(msg)
211
 
        dialog.run()
212
 
        dialog.destroy()
213
 
 
214
 
    def show_user_warning(self, warning_id, **message_args):
215
 
        """See UIFactory.show_user_warning."""
216
 
        if warning_id not in self.suppressed_warnings:
217
 
            message = self.format_user_warning(warning_id, message_args)
218
 
            self.show_warning(message)
219
 
 
220
180
    def get_password(self, prompt='', **kwargs):
221
181
        """Prompt the user for a password.
222
182
 
237
197
            return None
238
198
 
239
199
    def _progress_all_finished(self):
240
 
        """See UIFactory._progress_all_finished."""
 
200
        """See UIFactory._progress_all_finished"""
241
201
        pbw = self._progress_bar_widget
242
202
        if pbw:
243
203
            pbw.finished()
249
209
            self.set_progress_bar_widget(ProgressBarWindow())
250
210
 
251
211
    def _progress_updated(self, task):
252
 
        """See UIFactory._progress_updated."""
 
212
        """See UIFactory._progress_updated"""
253
213
        self._ensure_progress_widget()
254
214
        self._progress_bar_widget.update(task.msg,
255
215
                                         task.current_cnt, task.total_cnt)
256
216
 
257
217
    def report_transport_activity(self, transport, byte_count, direction):
258
 
        """See UIFactory.report_transport_activity."""
 
218
        """See UIFactory.report_transport_activity"""
259
219
        self._ensure_progress_widget()
260
220
        self._progress_bar_widget.tick()