Viewing file: messageWindow.py (3.86 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python
import string
import gtk from rhpl.translate import _, N_
# 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
# this seems to be wordwrapping text passed to # it, which is making for ugly error messages self.dialog = gtk.MessageDialog(parent, 0, style, buttons, text) self.dialog.label.set_line_wrap(gtk.FALSE) 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 WarningDialog(MessageWindow): def __init__ (self, text, parent=None): MessageWindow.__init__(self, _("Warning:"), text, type="warning", parent=parent)
class OkDialog(MessageWindow): def __init__ (self, text, parent=None): MessageWindow.__init__(self, _("OK dialog:"), text, type="ok", parent=parent)
class YesNoDialog(MessageWindow): def __init__ (self, text, parent=None): MessageWindow.__init__(self,_("Yes/No dialog:"), text, type="yesno", parent=parent)
class QuestionDialog(MessageWindow): def __init__ (self, text, parent=None): MessageWindow.__init__(self,_("Question dialog:"), text, type="question", parent=parent)
|