tagui.py
def init(visual_automation = False, chrome_browser = True):
    """start and connect to tagui process by checking tagui live mode readiness"""

    global _process, _tagui_started, _tagui_id, _tagui_visual, _tagui_chrome

    if _tagui_started:
        print('[TAGUI][ERROR] - use close() before using init() again')
        return False

    # reset id to track instruction count from tagui python to tagui
    _tagui_id = 0

    # get user home folder location to locate tagui executable
    if platform.system() == 'Windows':
        tagui_directory = os.environ['APPDATA'] + '/' + 'tagui'
    else:
        tagui_directory = os.path.expanduser('~') + '/' + '.tagui'

    tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui'
    end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes'

    # if tagui executable is not found, initiate setup() to install tagui
    if not os.path.isfile(tagui_executable):
        if not setup():
            # error message is shown by setup(), no need for message here
            return False

    # sync tagui delta files for current release if needed
    if not _tagui_delta(tagui_directory): return False

    # on Windows, check if there is space in folder path name
    if platform.system() == 'Windows' and ' ' in os.getcwd():
        print('[TAGUI][INFO] - to use TagUI for Python on Windows, avoid space in folder path name')
        return False

    # create entry flow to launch SikuliX accordingly
    if visual_automation:
        # check for working java jdk for visual automation mode
        if platform.system() == 'Windows':
            shell_silencer = '> nul 2>&1'
        else:
            shell_silencer = '> /dev/null 2>&1'

        if os.system('java -version ' + shell_silencer) != 0:
            print('[TAGUI][INFO] - for visual automation mode, Java JDK v8 (64-bit) or later is required')
            print('[TAGUI][INFO] - to use visual automation feature, download Java JDK v8 (64-bit) from below')
            print('[TAGUI][INFO] - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html')
            return False
        else:
            # start a dummy first run if never run before, to let sikulix integrate jython 
            sikulix_folder = tagui_directory + '/' + 'src' + '/' + 'sikulix'
            if os.path.isfile(sikulix_folder + '/' + 'jython-standalone-2.7.1.jar'):
                os.system('java -jar ' + sikulix_folder + '/' + 'sikulix.jar -h ' + shell_silencer)
            _visual_flow()
    else:
        _python_flow()

    # create tagui_local.js for custom functions
    _tagui_local()

    # invoke web browser accordingly with tagui option
    browser_option = ''
    if chrome_browser:
        browser_option = 'chrome'
    
    # entry shell command to invoke tagui process
    tagui_cmd = tagui_executable + ' tagui_python ' + browser_option

    # run tagui end processes script to flush dead processes
    # for eg execution ended with ctrl+c or forget to close()
    os.system(end_processes_executable)

    try:
        # launch tagui using subprocess
        _process = subprocess.Popen(
            tagui_cmd, shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )

        # loop until tagui live mode is ready or tagui process has ended
        while True:

            # failsafe exit if tagui process gets killed for whatever reason
            if _process.poll() is not None:
                print('[TAGUI][ERROR] - following happens when starting TagUI...')
                print('')
                os.system(tagui_cmd)
                print('')
                _tagui_visual = False
                _tagui_chrome = False
                _tagui_started = False
                return False

            # read next line of output from tagui process live mode interface
            tagui_out = _tagui_read()

            # check that tagui live mode is ready then start listening for inputs
            if 'LIVE MODE - type done to quit' in tagui_out:
                # dummy + start line to clear live mode backspace char before listening
                _tagui_write('echo "[TAGUI][STARTED]"\n')
                _tagui_write('echo "[TAGUI][' + str(_tagui_id) + '] - listening for inputs"\n')
                _tagui_visual = visual_automation
                _tagui_chrome = chrome_browser
                _tagui_started = True

                # loop until tagui live mode is ready and listening for inputs
                # also check _tagui_started to handle unexpected termination
                while _tagui_started and not _ready(): pass
                if not _tagui_started:
                    print('[TAGUI][ERROR] - TagUI process ended unexpectedly')
                    return False

                # remove generated tagui flow, js code and custom functions files
                if os.path.isfile('tagui_python'): os.remove('tagui_python')
                if os.path.isfile('tagui_python.js'): os.remove('tagui_python.js')
                if os.path.isfile('tagui_python.raw'): os.remove('tagui_python.raw')
                if os.path.isfile('tagui_local.js'): os.remove('tagui_local.js')

                # increment id and prepare for next instruction
                _tagui_id = _tagui_id + 1

                return True

    except Exception as e:
        print('[TAGUI][ERROR] - ' + str(e))
        _tagui_visual = False
        _tagui_chrome = False
        _tagui_started = False
        return False
start and connect to tagui process by checking tagui live mode readiness
start and connect to tagui process by checking tagui live mode readiness
start and connect to tagui process by checking tagui live mode readiness
def init(visual_automation = False, chrome_browser = True):
    global _process, _tagui_started, _tagui_id, _tagui_visual, _tagui_chrome
    if _tagui_started:
        print('[TAGUI][ERROR] - use close() before using init() again')
        return False
    _tagui_id = 0
    if platform.system() == 'Windows':
        tagui_directory = os.environ['APPDATA'] + '/' + 'tagui'
    else:
        tagui_directory = os.path.expanduser('~') + '/' + '.tagui'
    tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui'
    end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes'
    if not os.path.isfile(tagui_executable):
        if not setup():
            return False
    if not _tagui_delta(tagui_directory): return False
    if platform.system() == 'Windows' and ' ' in os.getcwd():
        print('[TAGUI][INFO] - to use TagUI for Python on Windows, avoid space in folder path name')
        return False
    if visual_automation:
        if platform.system() == 'Windows':
            shell_silencer = '> nul 2>&1'
        else:
            shell_silencer = '> /dev/null 2>&1'
        if os.system('java -version ' + shell_silencer) != 0:
            print('[TAGUI][INFO] - for visual automation mode, Java JDK v8 (64-bit) or later is required')
            print('[TAGUI][INFO] - to use visual automation feature, download Java JDK v8 (64-bit) from below')
            print('[TAGUI][INFO] - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html')
            return False
        else:
            sikulix_folder = tagui_directory + '/' + 'src' + '/' + 'sikulix'
            if os.path.isfile(sikulix_folder + '/' + 'jython-standalone-2.7.1.jar'):
                os.system('java -jar ' + sikulix_folder + '/' + 'sikulix.jar -h ' + shell_silencer)
            _visual_flow()
    else:
        _python_flow()
    _tagui_local()
    browser_option = ''
    if chrome_browser:
        browser_option = 'chrome'
    tagui_cmd = tagui_executable + ' tagui_python ' + browser_option
    os.system(end_processes_executable)
    try:
        _process = subprocess.Popen(
            tagui_cmd, shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        )
        while True:
            if _process.poll() is not None:
                print('[TAGUI][ERROR] - following happens when starting TagUI...')
                print('')
                os.system(tagui_cmd)
                print('')
                _tagui_visual = False
                _tagui_chrome = False
                _tagui_started = False
                return False
            tagui_out = _tagui_read()
            if 'LIVE MODE - type done to quit' in tagui_out:
                _tagui_write('echo "[TAGUI][STARTED]"\n')
                _tagui_write('echo "[TAGUI][' + str(_tagui_id) + '] - listening for inputs"\n')
                _tagui_visual = visual_automation
                _tagui_chrome = chrome_browser
                _tagui_started = True
                while _tagui_started and not _ready(): pass
                if not _tagui_started:
                    print('[TAGUI][ERROR] - TagUI process ended unexpectedly')
                    return False
                if os.path.isfile('tagui_python'): os.remove('tagui_python')
                if os.path.isfile('tagui_python.js'): os.remove('tagui_python.js')
                if os.path.isfile('tagui_python.raw'): os.remove('tagui_python.raw')
                if os.path.isfile('tagui_local.js'): os.remove('tagui_local.js')
                _tagui_id = _tagui_id + 1
                return True
    except Exception as e:
        print('[TAGUI][ERROR] - ' + str(e))
        _tagui_visual = False
        _tagui_chrome = False
        _tagui_started = False
        return False
def init ( visual_automation = False , chrome_browser = True ) : global _process , _tagui_started , _tagui_id , _tagui_visual , _tagui_chrome if _tagui_started : print ( '[TAGUI][ERROR] - use close() before using init() again' ) return False _tagui_id = 0 if platform . system ( ) == 'Windows' : tagui_directory = os . environ [ 'APPDATA' ] + '/' + 'tagui' else : tagui_directory = os . path . expanduser ( '~' ) + '/' + '.tagui' tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui' end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes' if not os . path . isfile ( tagui_executable ) : if not setup ( ) : return False if not _tagui_delta ( tagui_directory ) : return False if platform . system ( ) == 'Windows' and ' ' in os . getcwd ( ) : print ( '[TAGUI][INFO] - to use TagUI for Python on Windows, avoid space in folder path name' ) return False if visual_automation : if platform . system ( ) == 'Windows' : shell_silencer = '> nul 2>&1' else : shell_silencer = '> /dev/null 2>&1' if os . system ( 'java -version ' + shell_silencer ) != 0 : print ( '[TAGUI][INFO] - for visual automation mode, Java JDK v8 (64-bit) or later is required' ) print ( '[TAGUI][INFO] - to use visual automation feature, download Java JDK v8 (64-bit) from below' ) print ( '[TAGUI][INFO] - https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html' ) return False else : sikulix_folder = tagui_directory + '/' + 'src' + '/' + 'sikulix' if os . path . isfile ( sikulix_folder + '/' + 'jython-standalone-2.7.1.jar' ) : os . system ( 'java -jar ' + sikulix_folder + '/' + 'sikulix.jar -h ' + shell_silencer ) _visual_flow ( ) else : _python_flow ( ) _tagui_local ( ) browser_option = '' if chrome_browser : browser_option = 'chrome' tagui_cmd = tagui_executable + ' tagui_python ' + browser_option os . system ( end_processes_executable ) try : _process = subprocess . Popen ( tagui_cmd , shell = True , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) while True : if _process . poll ( ) is not None : print ( '[TAGUI][ERROR] - following happens when starting TagUI...' ) print ( '' ) os . system ( tagui_cmd ) print ( '' ) _tagui_visual = False _tagui_chrome = False _tagui_started = False return False tagui_out = _tagui_read ( ) if 'LIVE MODE - type done to quit' in tagui_out : _tagui_write ( 'echo "[TAGUI][STARTED]"\n' ) _tagui_write ( 'echo "[TAGUI][' + str ( _tagui_id ) + '] - listening for inputs"\n' ) _tagui_visual = visual_automation _tagui_chrome = chrome_browser _tagui_started = True while _tagui_started and not _ready ( ) : pass if not _tagui_started : print ( '[TAGUI][ERROR] - TagUI process ended unexpectedly' ) return False if os . path . isfile ( 'tagui_python' ) : os . remove ( 'tagui_python' ) if os . path . isfile ( 'tagui_python.js' ) : os . remove ( 'tagui_python.js' ) if os . path . isfile ( 'tagui_python.raw' ) : os . remove ( 'tagui_python.raw' ) if os . path . isfile ( 'tagui_local.js' ) : os . remove ( 'tagui_local.js' ) _tagui_id = _tagui_id + 1 return True except Exception as e : print ( '[TAGUI][ERROR] - ' + str ( e ) ) _tagui_visual = False _tagui_chrome = False _tagui_started = False return False
start and connect to tagui process by checking tagui live mode readiness
start and connect to tagui process by checking tagui live mode readiness
"""start and connect to tagui process by checking tagui live mode readiness""" # reset id to track instruction count from tagui python to tagui # get user home folder location to locate tagui executable # if tagui executable is not found, initiate setup() to install tagui # error message is shown by setup(), no need for message here # sync tagui delta files for current release if needed # on Windows, check if there is space in folder path name # create entry flow to launch SikuliX accordingly # check for working java jdk for visual automation mode # start a dummy first run if never run before, to let sikulix integrate jython  # create tagui_local.js for custom functions # invoke web browser accordingly with tagui option # entry shell command to invoke tagui process # run tagui end processes script to flush dead processes # for eg execution ended with ctrl+c or forget to close() # launch tagui using subprocess # loop until tagui live mode is ready or tagui process has ended # failsafe exit if tagui process gets killed for whatever reason # read next line of output from tagui process live mode interface # check that tagui live mode is ready then start listening for inputs # dummy + start line to clear live mode backspace char before listening # loop until tagui live mode is ready and listening for inputs # also check _tagui_started to handle unexpected termination # remove generated tagui flow, js code and custom functions files # increment id and prepare for next instruction
visual_automation
chrome_browser