/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

  • Committer: Jelmer Vernooij
  • Date: 2010-05-25 17:09:02 UTC
  • mto: This revision was merged to the branch mainline in revision 691.
  • Revision ID: jelmer@samba.org-20100525170902-3to8g5iw7ovw79kh
Split out olive into a separate directory.

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
import gtk
 
23
import sys
23
24
 
 
25
from bzrlib import progress
24
26
from bzrlib.ui import UIFactory
25
27
 
26
28
 
27
 
class PromptDialog(Gtk.Dialog):
28
 
    """Prompt the user for a yes/no answer."""
29
 
 
 
29
class PromptDialog(gtk.Dialog):
 
30
    """ Prompt the user for a yes/no answer. """
30
31
    def __init__(self, prompt):
31
 
        GObject.GObject.__init__(self)
 
32
        gtk.Dialog.__init__(self)
32
33
 
33
 
        label = Gtk.Label(label=prompt)
34
 
        self.vbox.pack_start(label, True, True, 10)
 
34
        label = gtk.Label(prompt)
 
35
        self.vbox.pack_start(label, padding=10)
35
36
        self.vbox.show_all()
36
37
 
37
 
        self.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO,
38
 
                         Gtk.ResponseType.NO)
39
 
 
40
 
 
41
 
class GtkProgressBar(Gtk.ProgressBar):
 
38
        self.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO,
 
39
                         gtk.RESPONSE_NO)
 
40
 
 
41
 
 
42
class GtkProgressBar(gtk.ProgressBar):
42
43
 
43
44
    def __init__(self):
44
 
        GObject.GObject.__init__(self)
 
45
        gtk.ProgressBar.__init__(self)
45
46
        self.set_fraction(0.0)
46
47
        self.current = None
47
48
        self.total = None
63
64
            if self.fraction < 0.0 or self.fraction > 1.0:
64
65
                raise AssertionError
65
66
            self.set_fraction(self.fraction)
66
 
        while Gtk.events_pending():
67
 
            Gtk.main_iteration()
 
67
        while gtk.events_pending():
 
68
            gtk.main_iteration()
68
69
 
69
70
    def finished(self):
70
71
        self.hide()
73
74
        self.hide()
74
75
 
75
76
 
76
 
class ProgressBarWindow(Gtk.Window):
 
77
class ProgressBarWindow(gtk.Window):
77
78
 
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()
84
85
        self.add(self.pb)
85
86
        self.resize(250, 15)
103
104
        self.hide_all()
104
105
 
105
106
 
106
 
class ProgressPanel(Gtk.HBox):
 
107
class ProgressPanel(gtk.HBox):
107
108
 
108
109
    def __init__(self):
109
110
        super(ProgressPanel, self).__init__()
110
 
        image_loading = Gtk.Image.new_from_stock(Gtk.STOCK_REFRESH,
111
 
                                                 Gtk.IconSize.BUTTON)
 
111
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
112
                                                 gtk.ICON_SIZE_BUTTON)
112
113
        image_loading.show()
113
114
 
114
115
        self.pb = GtkProgressBar()
134
135
        self.hide_all()
135
136
 
136
137
 
137
 
class PasswordDialog(Gtk.Dialog):
 
138
class PasswordDialog(gtk.Dialog):
138
139
    """ Prompt the user for a password. """
139
140
 
140
141
    def __init__(self, prompt):
141
 
        GObject.GObject.__init__(self)
142
 
 
143
 
        label = Gtk.Label(label=prompt)
144
 
        self.vbox.pack_start(label, True, True, 10)
145
 
 
146
 
        self.entry = Gtk.Entry()
 
142
        gtk.Dialog.__init__(self)
 
143
 
 
144
        label = gtk.Label(prompt)
 
145
        self.vbox.pack_start(label, padding=10)
 
146
 
 
147
        self.entry = gtk.Entry()
147
148
        self.entry.set_visibility(False)
148
149
        self.vbox.pack_end(self.entry, padding=10)
149
150
 
150
151
        self.vbox.show_all()
151
152
 
152
 
        self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK,
153
 
                         Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
 
153
        self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK,
 
154
                         gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
154
155
 
155
156
    def _get_passwd(self):
156
157
        return self.entry.get_text()
174
175
        dialog = PromptDialog(prompt)
175
176
        response = dialog.run()
176
177
        dialog.destroy()
177
 
        return (response == Gtk.ResponseType.YES)
 
178
        return (response == gtk.RESPONSE_YES)
178
179
 
179
180
    def get_password(self, prompt='', **kwargs):
180
181
        """Prompt the user for a password.
190
191
        response = dialog.run()
191
192
        passwd = dialog.passwd
192
193
        dialog.destroy()
193
 
        if response == Gtk.ResponseType.OK:
 
194
        if response == gtk.RESPONSE_OK:
194
195
            return passwd
195
196
        else:
196
197
            return None