Exemplo n.º 1
0
def report_patherror(message, path):
	"""Display a <Cancel>/<Retry>/<Examine> dialog.
	This will raise an OSError exception if the user selects Cancel, or
	will return successfully if the user chooses to retry."""
	from rox import g, filer, toplevel_ref, toplevel_unref, ButtonMixed
	toplevel_ref()
	box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION,
				g.BUTTONS_CANCEL, message)

	button = ButtonMixed(g.STOCK_REDO, _('Retry'))
	button.set_flags(g.CAN_DEFAULT)
	button.show()
	box.add_action_widget(button, g.RESPONSE_OK)

	button = ButtonMixed(g.STOCK_JUMP_TO, _('Examine'))
	button.set_flags(g.CAN_DEFAULT)
	button.show()
	box.add_action_widget(button, g.RESPONSE_APPLY)

	box.set_position(g.WIN_POS_CENTER)
	box.set_title(_('Error:'))
	box.set_default_response(g.RESPONSE_APPLY)
	while 1:
		resp = box.run()
		if resp != g.RESPONSE_APPLY: break
		filerpath = os.path.normpath(path)
		filer.show_file(filerpath)
	box.destroy()
	toplevel_unref()
	if resp != g.RESPONSE_OK:
		raise OSError, message
Exemplo n.º 2
0
Arquivo: debug.py Projeto: jfmc/logen
def show_exception(type, value, tb, auto_details=False):
    """Display this exception in an error box. The user has the options
	of ignoring the error, quitting the application and examining the
	exception in more detail. See also rox.report_exception()."""

    QUIT = 1
    DETAILS = 2
    SAVE = 3

    brief = "".join(traceback.format_exception_only(type, value))

    toplevel_ref()
    box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief)

    if not auto_details:
        button = ButtonMixed(g.STOCK_ZOOM_IN, _("_Details"))
        button.set_flags(g.CAN_DEFAULT)
        button.show()
        box.add_action_widget(button, DETAILS)

    box.add_button(g.STOCK_OK, g.RESPONSE_OK)
    box.set_default_response(g.RESPONSE_OK)

    box.set_position(g.WIN_POS_CENTER)
    box.set_title(_("Error"))
    reply = []

    def response(box, resp):
        reply.append(resp)
        g.mainquit()

    box.connect("response", response)
    box.show()

    bug_report = "Traceback (most recent call last):\n" + "".join(
        traceback.format_stack(tb.tb_frame.f_back)
        + traceback.format_tb(tb)
        + traceback.format_exception_only(type, value)
    )

    while 1:
        if auto_details:
            resp = DETAILS
            auto_details = False
        else:
            g.mainloop()
            resp = reply.pop()
        if resp == g.RESPONSE_OK or resp == g.RESPONSE_DELETE_EVENT:
            break
        if resp == SAVE:
            global savebox
            if savebox:
                savebox.destroy()

            def destroy(box):
                savebox = None

            from saving import StringSaver

            savebox = StringSaver(bug_report, "BugReport")
            savebox.connect("destroy", destroy)
            savebox.show()
            continue
        if resp == QUIT:
            sys.exit(1)
        assert resp == DETAILS
        box.set_response_sensitive(DETAILS, False)
        box.set_has_separator(False)

        button = ButtonMixed(g.STOCK_SAVE, _("_Bug Report"))
        button.set_flags(g.CAN_DEFAULT)
        button.show()
        box.add_action_widget(button, SAVE)
        box.action_area.set_child_secondary(button, True)

        button = ButtonMixed(g.STOCK_QUIT, _("Forced Quit"))
        button.set_flags(g.CAN_DEFAULT)
        button.show()
        box.add_action_widget(button, QUIT)
        box.action_area.set_child_secondary(button, True)

        ee = ExceptionExplorer(tb)
        box.vbox.pack_start(ee)
        ee.show()
    box.destroy()
    toplevel_unref()
Exemplo n.º 3
0
def report_patherror(message, path):
    """Display a <Cancel>/<Retry>/<Examine> dialog.
	This will raise an OSError exception if the user selects Cancel, or
	will return successfully if the user chooses to retry."""
    from rox import g, filer, toplevel_ref, toplevel_unref, ButtonMixed
    toplevel_ref()
    box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL,
                          message)

    button = ButtonMixed(g.STOCK_REDO, _('Retry'))
    button.set_flags(g.CAN_DEFAULT)
    button.show()
    box.add_action_widget(button, g.RESPONSE_OK)

    button = ButtonMixed(g.STOCK_JUMP_TO, _('Examine'))
    button.set_flags(g.CAN_DEFAULT)
    button.show()
    box.add_action_widget(button, g.RESPONSE_APPLY)

    box.set_position(g.WIN_POS_CENTER)
    box.set_title(_('Error:'))
    box.set_default_response(g.RESPONSE_APPLY)
    while 1:
        resp = box.run()
        if resp != g.RESPONSE_APPLY: break
        filerpath = os.path.normpath(path)
        filer.show_file(filerpath)
    box.destroy()
    toplevel_unref()
    if resp != g.RESPONSE_OK:
        raise OSError, message
Exemplo n.º 4
0
def show_exception(type, value, tb, auto_details = False):
	"""Display this exception in an error box. The user has the options
	of ignoring the error, quitting the application and examining the
	exception in more detail. See also rox.report_exception()."""

	QUIT = 1
	DETAILS = 2
	SAVE = 3
	
	brief = ''.join(traceback.format_exception_only(type, value))

	toplevel_ref()
	box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief)
	
	if not auto_details:
		button = ButtonMixed(g.STOCK_ZOOM_IN, _('_Details'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, DETAILS)

	box.add_button(g.STOCK_HELP, g.RESPONSE_HELP)
	box.add_button(g.STOCK_OK, g.RESPONSE_OK)
	box.set_default_response(g.RESPONSE_OK)

	box.set_position(g.WIN_POS_CENTER)
	box.set_title(_('Error'))
	reply = []
	def response(box, resp):
		reply.append(resp)
		g.main_quit()
	box.connect('response', response)
	box.show()

	if tb:
		bug_report = 'Traceback (most recent call last):\n' + \
			     ''.join(traceback.format_stack(tb.tb_frame.f_back) +
				     traceback.format_tb(tb) +
				     traceback.format_exception_only(type, value))
	else:
		bug_report = 'No stack trace.'

	while 1:
		if auto_details:
			resp = DETAILS
			auto_details = False
		else:
			g.main()
			resp = reply.pop()
		if resp == int(g.RESPONSE_OK) or resp == int(g.RESPONSE_DELETE_EVENT):
			break
		if resp == SAVE:
			global savebox
			if savebox:
				savebox.destroy()
			def destroy(box):
				global savebox	# For pychecker
				savebox = None
			from saving import StringSaver
			savebox = StringSaver(bug_report, 'BugReport')
			savebox.connect('destroy', destroy)
			savebox.show()
			continue
		if resp == QUIT:
			sys.exit(1)
		elif resp == int(g.RESPONSE_HELP):
			_show_debug_help()
			continue
		assert resp == DETAILS
		box.set_response_sensitive(DETAILS, False)

		button = ButtonMixed(g.STOCK_SAVE, _('_Bug Report'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, SAVE)
		box.action_area.set_child_secondary(button, True)

		button = ButtonMixed(g.STOCK_QUIT, _('Forced Quit'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, QUIT)
		box.action_area.set_child_secondary(button, True)

		if tb:
			ee = ExceptionExplorer(tb)
			box.vbox.pack_start(ee)
			ee.show()
		else:
			no_trace = g.Label('No traceback object!')
			box.vbox.pack_start(no_trace)
			no_trace.show()
	box.destroy()
	toplevel_unref()
Exemplo n.º 5
0
def show_exception(type, value, tb, auto_details = False):
	"""Display this exception in an error box. The user has the options
	of ignoring the error, quitting the application and examining the
	exception in more detail. See also rox.report_exception()."""

	QUIT = 1
	DETAILS = 2
	SAVE = 3
	
	brief = ''.join(traceback.format_exception_only(type, value))

	toplevel_ref()
	box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief)
	
	if not auto_details:
		button = ButtonMixed(g.STOCK_ZOOM_IN, _('_Details'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, DETAILS)

	box.add_button(g.STOCK_HELP, g.RESPONSE_HELP)
	box.add_button(g.STOCK_OK, g.RESPONSE_OK)
	box.set_default_response(g.RESPONSE_OK)

	box.set_position(g.WIN_POS_CENTER)
	box.set_title(_('Error'))
	box.show()

	if tb:
		bug_report = 'Traceback (most recent call last):\n' + \
			     ''.join(traceback.format_stack(tb.tb_frame.f_back) +
				     traceback.format_tb(tb) +
				     traceback.format_exception_only(type, value))
	else:
		bug_report = 'No stack trace.'

	while 1:
		if auto_details:
			resp = DETAILS
			auto_details = False
		else:
			resp = box.run()
		if resp == int(g.RESPONSE_OK) or resp == int(g.RESPONSE_DELETE_EVENT):
			break
		if resp == SAVE:
			global savebox
			if savebox:
				savebox.destroy()
			def destroy(box):
				global savebox	# For pychecker
				savebox = None
			from saving import StringSaver
			savebox = StringSaver(bug_report, 'BugReport')
			savebox.connect('destroy', destroy)
			savebox.show()
			continue
		if resp == QUIT:
			sys.exit(1)
		elif resp == int(g.RESPONSE_HELP):
			_show_debug_help()
			continue
		assert resp == DETAILS
		box.set_response_sensitive(DETAILS, False)

		button = ButtonMixed(g.STOCK_SAVE, _('_Bug Report'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, SAVE)
		box.action_area.set_child_secondary(button, True)

		button = ButtonMixed(g.STOCK_QUIT, _('Forced Quit'))
		button.set_flags(g.CAN_DEFAULT)
		button.show()
		box.add_action_widget(button, QUIT)
		box.action_area.set_child_secondary(button, True)

		if tb:
			ee = ExceptionExplorer(tb)
			box.vbox.pack_start(ee)
			ee.show()
		else:
			no_trace = g.Label('No traceback object!')
			box.vbox.pack_start(no_trace)
			no_trace.show()
	box.destroy()
	toplevel_unref()