1
2
3 import gettext
4 t = gettext.translation('rhn-client-tools', fallback=True)
5
6 if not hasattr(t, 'ugettext'):
7 t.ugettext = t.gettext
8 _ = t.ugettext
9
10 from up2date_client.gtk_compat import gtk, GTK3
11
12 if GTK3:
13 DIALOG_LABEL = 0
14 else:
15 DIALOG_LABEL = 1
16
17
19 if len(line) < max_line_size:
20 return line
21 ret = []
22 l = ""
23 for w in line.split():
24 if not len(l):
25 l = w
26 continue
27 if len(l) > max_line_size:
28 ret.append(l)
29 l = w
30 else:
31 l = "%s %s" % (l, w)
32 if len(l):
33 ret.append(l)
34 return '\n'.join(ret)
35
36
38 return '\n'.join(map(wrap_line, txt.split('\n')))
39
41 contents = dialog.get_children()[0]
42 dialog.remove(contents)
43 frame = gtk.Frame()
44 frame.set_shadow_type(gtk.SHADOW_OUT)
45 frame.add(contents)
46 dialog.add(frame)
47
51
53 self.dialog.hide()
54 self.dialog.destroy()
55 gtk.main_iteration_do(True)
56
57 - def __init__ (self, title, text, type="ok", default=None, parent=None):
58 self.rc = None
59 if type == 'ok':
60 buttons = gtk.BUTTONS_OK
61 style = gtk.MESSAGE_INFO
62 elif type == 'warning':
63 buttons = gtk.BUTTONS_OK
64 style = gtk.MESSAGE_WARNING
65 elif type == 'okcancel':
66 buttons = gtk.BUTTONS_OK_CANCEL
67 style = gtk.MESSAGE_WARNING
68 elif type == 'yesno':
69 buttons = gtk.BUTTONS_YES_NO
70 style = gtk.MESSAGE_QUESTION
71 elif type == "error":
72 buttons = gtk.BUTTONS_OK
73 style = gtk.MESSAGE_ERROR
74 elif type == "question":
75 buttons = gtk.BUTTONS_YES_NO
76 style = gtk.MESSAGE_QUESTION
77
78 self.dialog = gtk.MessageDialog(parent, 0, style, buttons)
79
80 try:
81 self.dialog.vbox.get_children()[0].get_children()[DIALOG_LABEL].\
82 get_children()[0].set_line_wrap(False)
83 except:
84 self.dialog.label.set_line_wrap(False)
85 self.dialog.set_markup(text)
86 if default == "no":
87 self.dialog.set_default_response(0)
88 elif default == "yes" or default == "ok":
89 self.dialog.set_default_response(1)
90 else:
91 self.dialog.set_default_response(0)
92
93 addFrame(self.dialog)
94 self.dialog.set_position (gtk.WIN_POS_CENTER)
95 self.dialog.show_all ()
96 rc = self.dialog.run()
97 if rc == gtk.RESPONSE_OK or rc == gtk.RESPONSE_YES:
98 self.rc = 1
99 elif (rc == gtk.RESPONSE_CANCEL or rc == gtk.RESPONSE_NO
100 or rc == gtk.RESPONSE_CLOSE):
101 self.rc = 0
102 self.dialog.destroy()
103
105 - def __init__ (self, text, parent=None):
110
112 - def __init__ (self, text, parent=None):
117
119 """A dialog box that can have one more sections of text. Each section can
120 be standard blob of text or a bulleted item.
121
122 """
123 - def __init__ (self, title=None, parent=None):
124 self.rc = None
125 self.dialog = gtk.Dialog(title, parent, 0, ("Close", 1))
126 if hasattr(self.dialog, 'set_has_separator'):
127 self.dialog.set_has_separator(False)
128
129
130 self.vbox = gtk.VBox(spacing=15)
131 self.vbox.set_border_width(15)
132
133 self.dialog.get_children()[0].pack_start(self.vbox, expand=False, fill=True, padding=0)
134
135 - def add_text(self, text):
136 label = gtk.Label(text)
137 label.set_alignment(0, 0)
138 label.set_line_wrap(True)
139 self.vbox.pack_start(label, expand=False, fill=True, padding=0)
140
142 label = gtk.Label(text)
143 label.set_alignment(0, 0)
144 label.set_line_wrap(True)
145 hbox = gtk.HBox(spacing=5)
146 bullet = gtk.Label(u'\u2022')
147 bullet.set_alignment(0, 0)
148 hbox.pack_start(bullet, expand=False, fill=True, padding=0)
149 hbox.pack_start(label, expand=False, fill=True, padding=0)
150 self.vbox.pack_start(hbox, expand=False, fill=True, padding=0)
151
153
154 self.dialog.set_position(gtk.WIN_POS_CENTER)
155 self.dialog.show_all()
156 rc = self.dialog.run()
157 if (rc == gtk.RESPONSE_CANCEL or rc == gtk.RESPONSE_NO
158 or rc == gtk.RESPONSE_CLOSE):
159 self.rc = 0
160 self.dialog.destroy()
161 gtk.main_iteration_do(True)
162
165