/usr/share/rhn/up2date_client/messageWindow.py is in rhn-client-tools 1.8.9-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | import string
import gtk
import gettext
t = gettext.translation('rhn-client-tools', fallback=True)
_ = t.ugettext
# wrap a long line...
def wrap_line(line, max_line_size = 100):
if len(line) < max_line_size:
return line
ret = []
l = ""
for w in string.split(line):
if not len(l):
l = w
continue
if len(l) > max_line_size:
ret.append(l)
l = w
else:
l = "%s %s" % (l, w)
if len(l):
ret.append(l)
return string.join(ret, '\n')
# wrap an entire piece of text
def wrap_text(txt):
return string.join(map(wrap_line, string.split(txt, '\n')), '\n')
def addFrame(dialog):
contents = dialog.get_children()[0]
dialog.remove(contents)
frame = gtk.Frame()
frame.set_shadow_type(gtk.SHADOW_OUT)
frame.add(contents)
dialog.add(frame)
class MessageWindow:
def getrc (self):
return self.rc
def hide(self):
self.dialog.hide()
self.dialog.destroy()
gtk.main_iteration()
def __init__ (self, title, text, type="ok", default=None, parent=None):
self.rc = None
if type == 'ok':
buttons = gtk.BUTTONS_OK
style = gtk.MESSAGE_INFO
elif type == 'warning':
buttons = gtk.BUTTONS_OK
style = gtk.MESSAGE_WARNING
elif type == 'okcancel':
buttons = gtk.BUTTONS_OK_CANCEL
style = gtk.MESSAGE_WARNING
elif type == 'yesno':
buttons = gtk.BUTTONS_YES_NO
style = gtk.MESSAGE_QUESTION
elif type == "error":
buttons = gtk.BUTTONS_OK
style = gtk.MESSAGE_ERROR
elif type == "question":
buttons = gtk.BUTTONS_YES_NO
style = gtk.MESSAGE_QUESTION
self.dialog = gtk.MessageDialog(parent, 0, style, buttons)
# Work around for bug #602609
try:
self.dialog.vbox.get_children()[0].get_children()[1].\
get_children()[0].set_line_wrap(False)
except:
self.dialog.label.set_line_wrap(False)
self.dialog.set_markup(text)
if default == "no":
self.dialog.set_default_response(0)
elif default == "yes" or default == "ok":
self.dialog.set_default_response(1)
else:
self.dialog.set_default_response(0)
addFrame(self.dialog)
self.dialog.set_position (gtk.WIN_POS_CENTER)
self.dialog.show_all ()
rc = self.dialog.run()
if rc == gtk.RESPONSE_OK or rc == gtk.RESPONSE_YES:
self.rc = 1
elif (rc == gtk.RESPONSE_CANCEL or rc == gtk.RESPONSE_NO
or rc == gtk.RESPONSE_CLOSE):
self.rc = 0
self.dialog.destroy()
class ErrorDialog(MessageWindow):
def __init__ (self, text, parent=None):
MessageWindow.__init__(self,_("Error:"),
text,
type="error",
parent=parent)
class YesNoDialog(MessageWindow):
def __init__ (self, text, parent=None):
MessageWindow.__init__(self,_("Yes/No dialog:"),
text,
type="yesno",
parent=parent)
class BulletedOkDialog:
"""A dialog box that can have one more sections of text. Each section can
be standard blob of text or a bulleted item.
"""
def __init__ (self, title=None, parent=None):
self.rc = None
self.dialog = gtk.Dialog(title, parent, 0, ("Close", 1))
self.dialog.set_has_separator(False)
# Vbox to contain just the stuff that will be add to the dialog with
# addtext
self.vbox = gtk.VBox(spacing=15)
self.vbox.set_border_width(15)
# Put our vbox into the top part of the dialog
self.dialog.get_children()[0].pack_start(self.vbox, expand=False)
def add_text(self, text):
label = gtk.Label(text)
label.set_alignment(0, 0)
label.set_line_wrap(True)
self.vbox.pack_start(label, expand=False)
def add_bullet(self, text):
label = gtk.Label(text)
label.set_alignment(0, 0)
label.set_line_wrap(True)
hbox = gtk.HBox(spacing=5)
bullet = gtk.Label(u'\u2022')
bullet.set_alignment(0, 0)
hbox.pack_start(bullet, expand=False)
hbox.pack_start(label, expand=False)
self.vbox.pack_start(hbox, expand=False)
def run(self):
# addFrame(self.dialog) # Need to do this differently if we want it
self.dialog.set_position(gtk.WIN_POS_CENTER)
self.dialog.show_all()
rc = self.dialog.run()
if (rc == gtk.RESPONSE_CANCEL or rc == gtk.RESPONSE_NO
or rc == gtk.RESPONSE_CLOSE):
self.rc = 0
self.dialog.destroy()
gtk.main_iteration()
def getrc (self):
return self.rc
|