/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: Curtis Hovey
  • Date: 2011-09-08 03:11:06 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110908031106-c0s7grzmctdyghcm
Fixed packing args.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""GTK UI
20
20
"""
21
21
 
22
 
import gtk
23
 
import sys
 
22
from gi.repository import Gtk
24
23
 
25
 
from bzrlib import progress
26
24
from bzrlib.ui import UIFactory
27
25
 
28
26
 
29
 
class PromptDialog(gtk.Dialog):
30
 
    """ Prompt the user for a yes/no answer. """
 
27
class PromptDialog(Gtk.Dialog):
 
28
    """Prompt the user for a yes/no answer."""
 
29
 
31
30
    def __init__(self, prompt):
32
 
        gtk.Dialog.__init__(self)
33
 
 
34
 
        label = gtk.Label(prompt)
35
 
        self.vbox.pack_start(label, padding=10)
36
 
        self.vbox.show_all()
37
 
 
38
 
        self.add_buttons(gtk.STOCK_YES, gtk.RESPONSE_YES, gtk.STOCK_NO,
39
 
                         gtk.RESPONSE_NO)
40
 
 
41
 
 
42
 
class GtkProgressBar(gtk.ProgressBar):
 
31
        super(PromptDialog, self).__init__()
 
32
 
 
33
        label = Gtk.Label(label=prompt)
 
34
        self.get_content_area().pack_start(label, True, True, 10)
 
35
        self.get_content_area().show_all()
 
36
 
 
37
        self.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES, Gtk.STOCK_NO,
 
38
                         Gtk.ResponseType.NO)
 
39
 
 
40
 
 
41
class GtkProgressBar(Gtk.ProgressBar):
43
42
 
44
43
    def __init__(self):
45
 
        gtk.ProgressBar.__init__(self)
 
44
        super(GtkProgressBar, self).__init__()
46
45
        self.set_fraction(0.0)
47
46
        self.current = None
48
47
        self.total = None
64
63
            if self.fraction < 0.0 or self.fraction > 1.0:
65
64
                raise AssertionError
66
65
            self.set_fraction(self.fraction)
67
 
        while gtk.events_pending():
68
 
            gtk.main_iteration()
 
66
        while Gtk.events_pending():
 
67
            Gtk.main_iteration()
69
68
 
70
69
    def finished(self):
71
70
        self.hide()
74
73
        self.hide()
75
74
 
76
75
 
77
 
class ProgressBarWindow(gtk.Window):
 
76
class ProgressBarWindow(Gtk.Window):
78
77
 
79
78
    def __init__(self):
80
 
        super(ProgressBarWindow, self).__init__(type=gtk.WINDOW_TOPLEVEL)
 
79
        super(ProgressBarWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
81
80
        self.set_border_width(0)
82
81
        self.set_title("Progress")
83
 
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
 
82
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
84
83
        self.pb = GtkProgressBar()
85
84
        self.add(self.pb)
86
85
        self.resize(250, 15)
96
95
 
97
96
    def finished(self):
98
97
        self.pb.finished()
99
 
        self.hide_all()
 
98
        self.hide()
100
99
        self.destroy()
101
100
 
102
101
    def clear(self):
103
102
        self.pb.clear()
104
 
        self.hide_all()
105
 
 
106
 
 
107
 
class ProgressPanel(gtk.HBox):
 
103
        self.hide()
 
104
 
 
105
 
 
106
class ProgressPanel(Gtk.HBox):
108
107
 
109
108
    def __init__(self):
110
109
        super(ProgressPanel, self).__init__()
111
 
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
112
 
                                                 gtk.ICON_SIZE_BUTTON)
 
110
        image_loading = Gtk.Image.new_from_stock(Gtk.STOCK_REFRESH,
 
111
                                                 Gtk.IconSize.BUTTON)
113
112
        image_loading.show()
114
113
 
115
114
        self.pb = GtkProgressBar()
116
115
        self.set_spacing(5)
117
116
        self.set_border_width(5)
118
 
        self.pack_start(image_loading, False, False)
119
 
        self.pack_start(self.pb, True, True)
 
117
        self.pack_start(image_loading, False, False, 0)
 
118
        self.pack_start(self.pb, True, True, 0)
120
119
 
121
120
    def tick(self, *args, **kwargs):
122
121
        self.show_all()
128
127
 
129
128
    def finished(self):
130
129
        self.pb.finished()
131
 
        self.hide_all()
 
130
        self.hide()
132
131
 
133
132
    def clear(self):
134
133
        self.pb.clear()
135
 
        self.hide_all()
136
 
 
137
 
 
138
 
class PasswordDialog(gtk.Dialog):
 
134
        self.hide()
 
135
 
 
136
 
 
137
class PasswordDialog(Gtk.Dialog):
139
138
    """ Prompt the user for a password. """
140
139
 
141
140
    def __init__(self, prompt):
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()
 
141
        super(PasswordDialog, self).__init__()
 
142
 
 
143
        label = Gtk.Label(label=prompt)
 
144
        self.get_content_area().pack_start(label, True, True, 10)
 
145
 
 
146
        self.entry = Gtk.Entry()
148
147
        self.entry.set_visibility(False)
149
 
        self.vbox.pack_end(self.entry, padding=10)
150
 
 
151
 
        self.vbox.show_all()
152
 
 
153
 
        self.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK,
154
 
                         gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
 
148
        self.get_content_area().pack_end(self.entry, False, False, 10)
 
149
 
 
150
        self.get_content_area().show_all()
 
151
 
 
152
        self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK,
 
153
                         Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
155
154
 
156
155
    def _get_passwd(self):
157
156
        return self.entry.get_text()
175
174
        dialog = PromptDialog(prompt)
176
175
        response = dialog.run()
177
176
        dialog.destroy()
178
 
        return (response == gtk.RESPONSE_YES)
 
177
        return (response == Gtk.ResponseType.YES)
179
178
 
180
179
    def get_password(self, prompt='', **kwargs):
181
180
        """Prompt the user for a password.
191
190
        response = dialog.run()
192
191
        passwd = dialog.passwd
193
192
        dialog.destroy()
194
 
        if response == gtk.RESPONSE_OK:
 
193
        if response == Gtk.ResponseType.OK:
195
194
            return passwd
196
195
        else:
197
196
            return None