<s> from __future__ import with_statement <EOL> from org . sikuli . basics import Debug <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> import time <EOL> import __builtin__ <EOL> import __main__ <EOL> import types <EOL> import sys <EOL> import os <EOL> import inspect <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> import org . sikuli . script . FindFailed as FindFailed <EOL> from org . sikuli . script . FindFailedResponse import * <EOL> from org . sikuli . script . Constants import * <EOL> import org . sikuli . script . Button as Button <EOL> from org . sikuli . script . Button import WHEEL_UP , WHEEL_DOWN <EOL> from org . sikuli . basics import OS <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Region as JRegion <EOL> from Region import * <EOL> from org . sikuli . script import Observing <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Screen as JScreen <EOL> from Screen import * <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from Env import * <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Match <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Pattern <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Location <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import ScreenUnion <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Finder <EOL> from org . sikuli . script import ImageFinder <EOL> from org . sikuli . script import ImageFind <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Image <EOL> from org . sikuli . script import ImageGroup <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import ImagePath <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import App <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script import Key <EOL> from org . sikuli . script import KeyModifier <EOL> from org . sikuli . script . KeyModifier import KEY_CTRL , KEY_SHIFT , KEY_META , KEY_CMD , KEY_WIN , KEY_ALT <EOL> from org . sikuli . script import Mouse <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . basics import Settings <EOL> from org . sikuli . basics import ExtensionManager <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . script . compare import DistanceComparator <EOL> from org . sikuli . script . compare import VerticalComparator <EOL> from org . sikuli . script . compare import HorizontalComparator <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> import SikuliImporter <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" ) <EOL> from org . sikuli . basics import SikuliScript <EOL> from org . sikuli . basics import SikuliX <EOL> def uprint ( * args ) : <EOL> for e in args [ : - <NUM_LIT:1> ] : <EOL> if isinstance ( e , str ) : print e , <EOL> else : print e . encode ( "<STR_LIT:utf8>" ) , <EOL> if isinstance ( args [ - <NUM_LIT:1> ] , str ) : print args [ - <NUM_LIT:1> ] <EOL> else : print args [ - <NUM_LIT:1> ] . encode ( "<STR_LIT:utf8>" ) <EOL> def unicd ( s ) : <EOL> return ucode ( s ) <EOL> def ucode ( s ) : <EOL> return ( unicode ( s , "<STR_LIT:utf8>" ) ) <EOL> def load ( jar ) : <EOL> def _load ( abspath ) : <EOL> if os . path . exists ( abspath ) : <EOL> if not abspath in sys . path : <EOL> sys . path . append ( abspath ) <EOL> return True <EOL> return False <EOL> if _load ( jar ) : <EOL> return True <EOL> path = getBundlePath ( ) <EOL> if path : <EOL> jarInBundle = os . path . join ( path , jar ) <EOL> if _load ( jarInBundle ) : <EOL> return True <EOL> path = ExtensionManager . getInstance ( ) . getLoadPath ( jar ) <EOL> if path and _load ( path ) : <EOL> return True <EOL> return False <EOL> def addImportPath ( path ) : <EOL> addModPath ( path ) <EOL> def addImagePath ( path ) : <EOL> ImagePath . add ( path ) <EOL> def getImagePath ( ) : <EOL> return [ e . pathGiven for e in ImagePath . getPaths ( ) if e ] <EOL> def removeImagePath ( path ) : <EOL> ImagePath . remove ( path ) <EOL> def resetImagePath ( path = None ) : <EOL> if not path : <EOL> path = getBundlePath ( ) ; <EOL> ImagePath . reset ( path ) <EOL> def setBundlePath ( path ) : <EOL> ImagePath . setBundlePath ( path ) <EOL> def getBundlePath ( ) : <EOL> return ImagePath . getBundlePath ( ) <EOL> def getParentPath ( ) : <EOL> return ImagePath . getBundleParentPath ( ) ; <EOL> def makePath ( path1 , path2 ) : <EOL> if ( not isinstance ( path2 , List ) ) : <EOL> path = os . path . join ( path1 , path2 ) <EOL> else : <EOL> path = path1 <EOL> for p in path2 : <EOL> path = os . path . join ( path , p ) <EOL> return path <EOL> def setShowActions ( flag ) : <EOL> Settings . setShowActions ( flag ) <EOL> def popup ( msg , title = "<STR_LIT>" ) : <EOL> SikuliX . popup ( msg , title ) <EOL> def input ( msg = "<STR_LIT>" , default = "<STR_LIT>" , title = "<STR_LIT>" , hidden = False ) : <EOL> if ( hidden ) : <EOL> default = "<STR_LIT>" <EOL> return SikuliX . input ( msg , default , title , hidden ) <EOL> def inputText ( msg = "<STR_LIT>" , title = "<STR_LIT>" , lines = <NUM_LIT:0> , width = <NUM_LIT:0> ) : <EOL> return SikuliX . input ( msg , title , width , lines ) <EOL> def capture ( * args ) : <EOL> scr = ScreenUnion ( ) <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> simg = scr . userCapture ( ) <EOL> if simg : <EOL> return simg . getFilename ( ) <EOL> else : <EOL> return None <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> if __builtin__ . type ( args [ <NUM_LIT:0> ] ) is types . StringType or __builtin__ . type ( args [ <NUM_LIT:0> ] ) is types . UnicodeType : <EOL> simg = scr . userCapture ( args [ <NUM_LIT:0> ] ) <EOL> if simg : <EOL> return simg . getFilename ( ) <EOL> else : <EOL> return None <EOL> else : <EOL> return scr . capture ( args [ <NUM_LIT:0> ] ) . getFilename ( ) <EOL> elif len ( args ) == <NUM_LIT:4> : <EOL> return scr . capture ( args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] , args [ <NUM_LIT:2> ] , args [ <NUM_LIT:3> ] ) . getFilename ( ) <EOL> else : <EOL> return None <EOL> def selectRegion ( msg = None ) : <EOL> if msg : <EOL> r = ScreenUnion ( ) . selectRegion ( msg ) <EOL> else : <EOL> r = ScreenUnion ( ) . selectRegion ( ) <EOL> if r : <EOL> return Region ( r ) <EOL> else : <EOL> return None <EOL> remoteScreen = None <EOL> def use ( scr = None , remote = False ) : <EOL> if remote : <EOL> theGlobals = inspect . currentframe ( ) . f_back . f_back . f_globals <EOL> else : <EOL> theGlobals = inspect . currentframe ( ) . f_back . f_globals <EOL> global remoteScreen <EOL> if remoteScreen : <EOL> remoteScreen . close ( ) <EOL> remoteScreen = None <EOL> if not scr : <EOL> SCREEN = Screen ( ) <EOL> else : <EOL> SCREEN = scr <EOL> Debug . log ( <NUM_LIT:3> , "<STR_LIT>" + SCREEN . toStringShort ( ) ) <EOL> globals ( ) [ '<STR_LIT>' ] = _exposeAllMethods ( SCREEN , globals ( ) . get ( '<STR_LIT>' ) , theGlobals , None ) <EOL> theGlobals [ '<STR_LIT>' ] = SCREEN <EOL> if remote : <EOL> remoteScreen = SCREEN <EOL> return SCREEN <EOL> def useRemote ( adr , port = <NUM_LIT:0> ) : <EOL> global remoteScreen <EOL> import org . sikuli . script . ScreenRemote as SR <EOL> SCREEN = SR ( adr , str ( port ) ) <EOL> if SCREEN . isValid ( ) : <EOL> return use ( SCREEN , True ) <EOL> else : <EOL> return None <EOL> def switchApp ( app ) : <EOL> return App . focus ( app ) <EOL> def openApp ( app ) : <EOL> return App . open ( app ) <EOL> def closeApp ( app ) : <EOL> return App . close ( app ) <EOL> def sleep ( sec ) : <EOL> time . sleep ( sec ) <EOL> def exit ( code = <NUM_LIT:0> ) : <EOL> global remoteScreen <EOL> if remoteScreen : <EOL> remoteScreen . close ( ) <EOL> remoteScreen = None <EOL> SikuliX . cleanUp ( code ) <EOL> sys . exit ( code ) <EOL> def run ( cmd ) : <EOL> return SikuliX . run ( cmd ) <EOL> def shelp ( ) : <EOL> SikuliScript . shelp ( ) <EOL> def byDistanceTo ( x , y = None ) : <EOL> """<STR_LIT>""" <EOL> return DistanceComparator ( x , y ) <EOL> def byX ( m ) : <EOL> """<STR_LIT>""" <EOL> return HorizontalComparator ( ) . compare <EOL> def byY ( m ) : <EOL> """<STR_LIT>""" <EOL> return VerticalComparator ( ) . compare <EOL> def verticalComparator ( ) : <EOL> """<STR_LIT>""" <EOL> return VerticalComparator ( ) . compare <EOL> def horizontalComparator ( ) : <EOL> """<STR_LIT>""" <EOL> return HorizontalComparator ( ) . compare <EOL> def distanceComparator ( x , y = None ) : <EOL> """<STR_LIT>""" <EOL> if y is None : <EOL> return DistanceComparator ( x ) . compare <EOL> return DistanceComparator ( x , y ) . compare <EOL> def addModPath ( path ) : <EOL> if path [ - <NUM_LIT:1> ] == Settings . getFilePathSeperator ( ) : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> if not path in sys . path : <EOL> sys . path . append ( path ) <EOL> def _exposeAllMethods ( anyObject , saved , theGlobals , exclude_list ) : <EOL> if not exclude_list : <EOL> exclude_list = [ '<STR_LIT:class>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> tosave = [ ] <EOL> if not saved : <EOL> saved = [ ] <EOL> for name in dir ( anyObject ) : <EOL> if name in exclude_list : continue <EOL> try : <EOL> if not inspect . ismethod ( getattr ( anyObject , name ) ) : continue <EOL> except : <EOL> continue <EOL> if name [ <NUM_LIT:0> ] != '<STR_LIT:_>' and name [ : <NUM_LIT:7> ] != '<STR_LIT>' : <EOL> try : <EOL> saved . remove ( name ) <EOL> except : <EOL> pass <EOL> tosave . append ( name ) <EOL> theGlobals [ name ] = eval ( "<STR_LIT>" + name ) <EOL> if name == '<STR_LIT>' : Debug . log ( <NUM_LIT:3> , "<STR_LIT>" , name , str ( dict [ name ] ) [ <NUM_LIT:1> : ] ) <EOL> for name in saved : <EOL> if name in theGlobals : <EOL> theGlobals . pop ( name ) <EOL> return tosave <EOL> use ( ) </s>
