示例#1
0
文件: OptionsBox.py 项目: jfmc/logen
		def destroyed(widget):
			rox.toplevel_unref()
			if self.changed():
				try:
					self.options.save()
				except:
					rox.report_exception()
示例#2
0
文件: fileutils.py 项目: jfmc/logen
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
示例#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
示例#4
0
 def destroyed(widget):
     rox.toplevel_unref()
     if self.changed():
         try:
             self.options.save()
         except:
             rox.report_exception()
示例#5
0
 def Quit(self):
     """Stop acting as a server.  The window count is reduced by one (if
     this is the first call to Quit) to remove the ref added by __init__.
     The application will remain running while it still has windows open
     unless you override this to change the behavior."""
     if self.active:
         rox.toplevel_unref()
         self.active=False
     rox.g.main_quit()
示例#6
0
文件: tasks.py 项目: jfmc/logen
def _handle_run_queue():
	global _idle_blocker
	assert _run_queue

	next = _run_queue[0]
	assert next.happened

	if next is _idle_blocker:
		# Since this blocker will never run again, create a
		# new one for future idling.
		_idle_blocker = IdleBlocker()
	
	tasks = next._rox_lib_tasks.keys()
	#print "Resume", tasks
	for task in tasks:
		# Run 'task'.
		task._resume()
	
	del _run_queue[0]

	if _run_queue:
		return True
	rox.toplevel_unref()
	return False
示例#7
0
def _handle_run_queue():
    global _idle_blocker
    assert _run_queue

    next = _run_queue[0]
    assert next.happened

    if next is _idle_blocker:
        # Since this blocker will never run again, create a
        # new one for future idling.
        _idle_blocker = IdleBlocker()

    tasks = frozenset(next._rox_lib_tasks)
    #print "Resume", tasks
    for task in tasks:
        # Run 'task'.
        task._resume()

    del _run_queue[0]

    if _run_queue:
        return True
    rox.toplevel_unref()
    return False
示例#8
0
文件: debug.py 项目: 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()
示例#9
0
文件: tasks.py 项目: jfmc/logen
	def _timeout(self):
		rox.toplevel_unref()
		self.trigger()
示例#10
0
    def __init__(self,
                 document,
                 uri,
                 type='text/plain',
                 discard=False,
                 parent=None):
        """See SaveArea.__init__.
		parent was added in version 2.0.5. To support older versions, use set_transient_for.
		If discard is True then an extra discard button is added to the dialog."""
        g.Dialog.__init__(self, parent=parent)
        self.set_has_separator(False)

        self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL)
        self.add_button(g.STOCK_SAVE, g.RESPONSE_OK)
        self.set_default_response(g.RESPONSE_OK)

        if discard:
            discard_area = g.HButtonBox()

            def discard_clicked(event):
                document.discard()
                self.destroy()

            button = rox.ButtonMixed(g.STOCK_DELETE, _('_Discard'))
            discard_area.pack_start(button, False, True, 2)
            button.connect('clicked', discard_clicked)
            button.unset_flags(g.CAN_FOCUS)
            button.set_flags(g.CAN_DEFAULT)
            self.vbox.pack_end(discard_area, False, True, 0)
            self.vbox.reorder_child(discard_area, 0)

            discard_area.show_all()

        self.set_title(_('Save As:'))
        self.set_position(g.WIN_POS_MOUSE)
        self.set_wmclass('savebox', 'Savebox')
        self.set_border_width(1)

        # Might as well make use of the new nested scopes ;-)
        self.set_save_in_progress(0)

        class BoxedArea(SaveArea):
            def set_uri(area, uri):
                SaveArea.set_uri(area, uri)
                if discard:
                    document.discard()

            def save_done(area):
                document.save_done()
                self.destroy()

            def set_sensitive(area, sensitive):
                if self.window:
                    # Might have been destroyed by now...
                    self.set_save_in_progress(not sensitive)
                    SaveArea.set_sensitive(area, sensitive)

        save_area = BoxedArea(document, uri, type)
        self.save_area = save_area

        save_area.show_all()
        self.build_main_area()

        i = uri.rfind('/')
        i = i + 1
        # Have to do this here, or the selection gets messed up
        save_area.entry.grab_focus()
        g.Editable.select_region(save_area.entry, i, -1)  # PyGtk bug

        #save_area.entry.select_region(i, -1)

        def got_response(widget, response):
            if self.save_in_progress:
                try:
                    document.save_cancelled()
                except:
                    rox.report_exception()
                return
            if response == int(g.RESPONSE_CANCEL):
                self.destroy()
            elif response == int(g.RESPONSE_OK):
                self.save_area.save_to_file_in_entry()
            elif response == int(g.RESPONSE_DELETE_EVENT):
                pass
            else:
                raise Exception('Unknown response!')

        self.connect('response', got_response)

        rox.toplevel_ref()
        self.connect('destroy', lambda w: rox.toplevel_unref())
示例#11
0
def setup_login():
	try:
		session_dirs = ['/etc/X11/sessions', '/etc/dm/Sessions',
				'/etc/X11/dm/Sessions', '/usr/share/xsessions',
				'/opt/kde3/share/apps/kdm/sessions']
		# TODO: more guesses about where KDE is installed, /opt/kde3
		# works for SuSE 9.2
		for d in session_dirs:
			if os.path.isdir(d):
				session_dir = d
				break
		else:
			rox.croak(_('I wanted to install a rox.desktop file in your '
				"session directory, but I couldn't find one! I tried "
				"these places (defaults for gdm2, at least):\n\n") +
				'\n'.join(session_dirs))
		iskde=(session_dir.find('kde')>=0)
		
		if not os.path.isdir('/usr/local/sbin'):
			rox.croak(_('/usr/local/sbin directory is missing! I want to '
				'install the rox-session script there... Please create it '
				'and try again.'))

		desktop_path = os.path.join(session_dir, 'rox.desktop')
		session_path = '/usr/local/sbin/rox-session'

		maker = su.SuProxyMaker('I need permission to create these files:\n' +
					   desktop_path + '\n' +
					   session_path)
		yield maker.blocker
		root = maker.get_root()
		
		q = root.open(desktop_path, 'w')
		yield q
		stream = q.result

		if iskde:
			dtype='XSession'
		else:
			dtype='Application'
		
		q = root.write(stream, """[Desktop Entry]\n
Encoding=UTF-8
Name=ROX
Comment=This session logs you into the ROX desktop
Exec=/usr/local/sbin/rox-session
Type=%s
""" % dtype)
		yield q

		q = root.close(stream)
		yield q

		q = root.open(session_path, 'w')
		yield q
		stream = q.result

		q = root.write(stream, get_session_script())
		yield q

		q = root.close(stream)
		yield q

		q = root.chmod(session_path, 0755)
		yield q
		
		rox.info(_("OK, now logout by your usual method, and choose ROX from "
			"the session menu on your login screen just after entering your "
			"user name (but before entering your password)."))
		rox.toplevel_unref()
	except:
		rox.toplevel_unref()
		raise
示例#12
0
文件: debug.py 项目: boube/minino
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()
示例#13
0
文件: saving.py 项目: boube/minino
	def __init__(self, document, uri, type = 'text/plain', discard = False, parent = None):
		"""See SaveArea.__init__.
		parent was added in version 2.0.5. To support older versions, use set_transient_for.
		If discard is True then an extra discard button is added to the dialog."""
		g.Dialog.__init__(self, parent = parent)
		self.set_has_separator(False)

		self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL)
		self.add_button(g.STOCK_SAVE, g.RESPONSE_OK)
		self.set_default_response(g.RESPONSE_OK)

		if discard:
			discard_area = g.HButtonBox()

			def discard_clicked(event):
				document.discard()
				self.destroy()
			button = rox.ButtonMixed(g.STOCK_DELETE, _('_Discard'))
			discard_area.pack_start(button, False, True, 2)
			button.connect('clicked', discard_clicked)
			button.unset_flags(g.CAN_FOCUS)
			button.set_flags(g.CAN_DEFAULT)
			self.vbox.pack_end(discard_area, False, True, 0)
			self.vbox.reorder_child(discard_area, 0)
			
			discard_area.show_all()

		self.set_title(_('Save As:'))
		self.set_position(g.WIN_POS_MOUSE)
		self.set_wmclass('savebox', 'Savebox')
		self.set_border_width(1)

		# Might as well make use of the new nested scopes ;-)
		self.set_save_in_progress(0)
		class BoxedArea(SaveArea):
			def set_uri(area, uri):
				SaveArea.set_uri(area, uri)
				if discard:
					document.discard()
			def save_done(area):
				document.save_done()
				self.destroy()

			def set_sensitive(area, sensitive):
				if self.window:
					# Might have been destroyed by now...
					self.set_save_in_progress(not sensitive)
					SaveArea.set_sensitive(area, sensitive)
		save_area = BoxedArea(document, uri, type)
		self.save_area = save_area

		save_area.show_all()
		self.build_main_area()

		i = uri.rfind('/')
		i = i + 1
		# Have to do this here, or the selection gets messed up
		save_area.entry.grab_focus()
		g.Editable.select_region(save_area.entry, i, -1) # PyGtk bug
		#save_area.entry.select_region(i, -1)

		def got_response(widget, response):
			if self.save_in_progress:
				try:
					document.save_cancelled()
				except:
					rox.report_exception()
				return
			if response == int(g.RESPONSE_CANCEL):
				self.destroy()
			elif response == int(g.RESPONSE_OK):
				self.save_area.save_to_file_in_entry()
			elif response == int(g.RESPONSE_DELETE_EVENT):
				pass
			else:
				raise Exception('Unknown response!')
		self.connect('response', got_response)

		rox.toplevel_ref()
		self.connect('destroy', lambda w: rox.toplevel_unref())
示例#14
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()
示例#15
0
 def _timeout(self):
     rox.toplevel_unref()
     self.trigger()