import os
import glob
import pygame
import subprocess
import sys
def DefLaunchSomething(EmuChoose,GameChoose,AllMedia,font,Resolution,BlackImg,WHERE_TEXTE,SIZE_TEXTE,Background,Orientation):
	PyrScreen =   pygame.display.set_mode(Resolution)
	WHERE_TEXTE_W,WHERE_TEXTE_Y=WHERE_TEXTE
	fond = pygame.transform.scale(pygame.image.load(Background).convert(),Resolution)
	PyrScreen.blit(fond, (0,0))
	PyrScreen.blit(pygame.transform.scale(pygame.image.load(BlackImg).convert(),(SIZE_TEXTE)),(WHERE_TEXTE))

	PathOfGame=AllMedia+EmuChoose+"/ROMS/"
	GameChooseJoker=GameChoose + ".*"
	FullPathJoker=glob.glob(os.path.join(PathOfGame, GameChooseJoker))
	PathOfBin=AllMedia + "../BIN/"
	BinCooseJoker=PathOfBin + EmuChoose +".*"
	FullPathJokerBin=glob.glob(os.path.join(PathOfBin, BinCooseJoker))
	if FullPathJokerBin:
		BinFullPathJoker=FullPathJokerBin[0]
		if EmuChoose == "SYS":
			##print "EmuChoose: " + EmuChoose + " | GameChoose : " + GameChoose
			APP=BinFullPathJoker + " " + GameChoose + " " + Orientation 
			p = subprocess.Popen(APP, shell=True)
			sys.exit("GO play bitch ;)")		
		else:
			if FullPathJoker:
				GameFullPathJoker=FullPathJoker[0]
			else:
				GameFullPathJoker="xxxxxxxxxxxxxxxxxxxxx"
			if (os.path.isfile(GameFullPathJoker)):
				##print "EmuChoose: " + EmuChoose + " | GameChoose : " + GameChoose
				APP="BIN/" + EmuChoose +".sh" + " " + GameChoose + " " + Orientation 
				p = subprocess.Popen(APP, shell=True)
				sys.exit("GO play bitch ;)")		
				
			else:
				##print "Roms " + GameChoose + " NOT FOUND " + AllMedia+EmuChoose + "/ROMS/"
				text1 = "Roms " + GameChoose + " NOT FOUND" 
				text2 = font.render(text1, True, pygame.Color("white"))
				PyrScreen.blit(pygame.transform.scale(pygame.image.load(BlackImg).convert(),(SIZE_TEXTE)),((WHERE_TEXTE)))
				PyrScreen.blit(text2,(WHERE_TEXTE_W,WHERE_TEXTE_Y)).bottomleft
		

