Example #1
0
def stdinconsoleMain():
	import appinfo
	if appinfo.args.shell:
		print "Setting up Python shell interface"
		# This is hacky for now but actually I don't really know a better way.
		# The problem is that the main thread might be used by the GUI.
		# Thus, we can only cancel this here via the shell itself.
		from better_exchook import debug_shell
		from queue import queue
		import utils
		shellGlobals = {
			"state": state,
			"queue": queue,
			}
		shellGlobals.update(utils.__dict__)
		debug_shell(
			shellGlobals, shellGlobals,
			execWrapper=utils.do_in_mainthread)
		# The shell exited. Quit.
		state.quit()
		return
	
	fd = sys.stdin.fileno()
	if not os.isatty(fd): return # don't do anything

	# the main thread is pushing stdin updates to stdinQueue.
	setTtyNoncanonical(sys.stdin.fileno())
	print "stdin input ready"

	for ch in stdinQueue.read():
		handleInput(ch)

	restoreTty(fd)
Example #2
0
def stdinconsoleMain():
	import appinfo
	if appinfo.args.shell:
		print "Setting up Python shell interface"
		# This is hacky for now but actually I don't really know a better way.
		# The problem is that the main thread might be used by the GUI.
		# Thus, we can only cancel this here via the shell itself.
		from better_exchook import debug_shell
		from queue import queue
		import utils
		shellGlobals = {
			"state": state,
			"queue": queue,
			}
		shellGlobals.update(utils.__dict__)
		debug_shell(
			shellGlobals, shellGlobals,
			execWrapper=utils.do_in_mainthread)
		print "Python shell quit."
		# The shell exited. Quit.
		state.quit()
		return
	
	fd = sys.stdin.fileno()
	if not os.isatty(fd): return # don't do anything

	# the main thread is pushing stdin updates to stdinQueue.
	setTtyNoncanonical(sys.stdin.fileno())
	print "stdin input ready"

	for ch in stdinQueue.read():
		handleInput(ch)

	restoreTty(fd)
Example #3
0
def stdinconsoleMain():
	import appinfo
	if appinfo.args.shell:
		print "Setting up Python shell interface"
		# This is hacky for now but actually I don't really know a better way.
		# The problem is that the main thread might be used by the GUI.
		# Thus, we can only cancel this here via the shell itself.
		from better_exchook import debug_shell
		from queue import queue
		import utils
		shellGlobals = {
			"state": state,
			"queue": queue,
			}
		shellGlobals.update(utils.__dict__)
		debug_shell(
			shellGlobals, shellGlobals,
			execWrapper=utils.do_in_mainthread)
		# The shell exited. Quit.
		state.quit()
		return
	
	fd = sys.stdin.fileno()
	if not os.isatty(fd): return # don't do anything

	try:
		# This import will fail if there is no GUI.
		import gui

	except: # no GUI

		# the main thread is pushing stdin updates to stdinQueue.
		setTtyNoncanonical(sys.stdin.fileno())
		print "stdin input ready"

		for ch in stdinQueue.read():
			handleInput(ch)

	else:
		# No stdin handling when we have a GUI
		return
	
		# the GUI is handling the main thread.
		# it means we dont get stdinQueue updates here.
		# as we need a way to be able to cancel this,
		# we only can frequently check with a timeout here.
		setTtyNoncanonical(fd, timeout=1)

		from threading import currentThread
		thread = currentThread()
		print "stdin input ready"
		while not thread.cancel:
			ch = os.read(fd,7)
			if ch:
				handleInput(ch)

	restoreTty(fd)
Example #4
0
def handleInput(ch):
	if ch == "q" or ch == "\0" or ch == "":
		print "stdin: quit"
		state.quit()
	try:
		if ch == "\x1b[D": # left
			state.player.seekRel(-10)
			printState()
		elif ch == "\x1b[C": #right
			state.player.seekRel(10)
			printState()
		elif ch == "\n": # return
			state.nextSong()
		elif ch == " ":
			state.playPause()
		elif ch == "r":
			reloadModules()
	except:
		sys.excepthook(*sys.exc_info())
Example #5
0
def handleInput(ch):
	if ch == "q" or ch == "\0" or ch == "":
		print "stdin: quit"
		state.quit()
	try:
		if ch == "\x1b[D": # left
			state.player.seekRel(-10)
			printState()
		elif ch == "\x1b[C": #right
			state.player.seekRel(10)
			printState()
		elif ch == "\n": # return
			state.nextSong()
		elif ch == " ":
			state.playPause()
		elif ch == "r":
			reloadModules()
		elif ch == "i":
			printState()
		elif ch == "h":
			printHelp()
	except:
		sys.excepthook(*sys.exc_info())