import maya
maya.utils.loadStringResourcesForModule(__name__)


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 ):
		okStr = maya.stringTable['y_baseUI.kOK']
		result = cmds.promptDialog( title=maya.stringTable['y_baseUI.kStdinTitle'], 
								  	message=maya.stringTable['y_baseUI.kStdinMessage'],
								  	text='', scrollableField=True,
								  	button=okStr, defaultButton=okStr,
								  	dismissString=maya.stringTable['y_baseUI.kCancel'] )
		if okStr == result:
			return cmds.promptDialog( query=True, text=True )
		else:
			return '\n'


# Copyright (C) 1997-2014 Autodesk, Inc., and/or its licensors.
# All rights reserved.
#
# The coded instructions, statements, computer programs, and/or related
# material (collectively the "Data") in these files contain unpublished
# information proprietary to Autodesk, Inc. ("Autodesk") and/or its licensors,
# which is protected by U.S. and Canadian federal copyright law and by
# international treaties.
#
# The Data is provided for use exclusively by You. You have the right to use,
# modify, and incorporate this Data into other products for purposes authorized 
# by the Autodesk software license agreement, without fee.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. AUTODESK
# DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES
# INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR ARISING FROM A COURSE 
# OF DEALING, USAGE, OR TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS
# LICENSORS BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
# DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS
# LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES.

