exception.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:wahcade 作者: sairuk 项目源码 文件源码
def _info(type, value, tb):
    """display exception"""
    #ungrab a potentially "grabbed" mouse pointer
    gtk.gdk.pointer_ungrab()
    #create dialog
    dialog = gtk.MessageDialog(
        parent = None,
        flags = 0,
        type = gtk.MESSAGE_WARNING,
        buttons = gtk.BUTTONS_NONE,
        message_format = _("<big><b>Error</b></big>"))
    dialog.set_title(_("Bug Detected"))
    dialog.vbox.get_children()[0].get_children()[1].get_children()[0].set_property("use-markup", True)
    dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
    #details
    textview = gtk.TextView() 
    textview.show()
    textview.set_editable(False)
    textview.modify_font(pango.FontDescription("Monospace"))
    sw = gtk.ScrolledWindow() 
    sw.show()
    sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
    sw.add(textview)
    frame = gtk.Frame()
    frame.set_shadow_type(gtk.SHADOW_IN)
    frame.add(sw)
    frame.set_border_width(6)
    dialog.vbox.add(frame)
    textbuffer = textview.get_buffer()
    trace = StringIO.StringIO()
    traceback.print_exception(type, value, tb, None, trace)
    textbuffer.set_text(trace.getvalue())
    textview.set_size_request(gtk.gdk.screen_width()/2, gtk.gdk.screen_height()/3)
    dialog.details = frame
    dialog.set_position(gtk.WIN_POS_CENTER)
    dialog.set_gravity(gtk.gdk.GRAVITY_CENTER)
    dialog.details.show()
    #display the dialog
    resp = dialog.run()
    if resp == gtk.RESPONSE_CLOSE:
        pass
    dialog.destroy()
    sys.exit(1)

#sys.excepthook = _info
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号