
import os
import maya.cmds as cmds

class StandardInput:
	"""
	Implements a basic user interface for Python sys.stdin
	
	When a Python call tries to read from sys.stdin in Maya's interactive GUI
	mode, then this object will receive the read call and present the user
	with a basic modal UI that will let them respond to the request for input
	"""
	
	def readline( self ):
		"""
		Read a line of input.  This will prompt the user for a single line of
		input
		"""
		if 'MAYA_IGNORE_DIALOGS' in os.environ:
			return '\n'
		else:
			return self.__promptUser( False )
		
	def read( self ):
		"""
		Read a line of input.  This will prompt the user for multiple 
		lines of input
		"""
		return self.__promptUser( True )
	
	def __promptUser( self, multiLine ):
		result = cmds.promptDialog( title='Python STDIN', 
								  	message='Python is requesting input',
								  	text='', scrollableField=True,
								  	button='OK', defaultButton='OK',
								  	dismissString='Cancel' )
		if 'OK' == result:
			return cmds.promptDialog( query=True, text=True )
		else:
			return '\n'


