diff --git a/README.md b/README.md index 6d10550f..5e7c6914 100755 --- a/README.md +++ b/README.md @@ -416,6 +416,9 @@ TagUI Writer is a Windows app created by Arnaud Degardin / [@adegard](https://gi +### TAGUI FOR PYTHON +TagUI for Python is a Python package created by TagUI's creator Ken Soh / [@kensoh](https://github.com/kensoh). It brings the digital process automation capabilities of TagUI directly to the Python environment through a simple, expressive and powerful API. To install, `pip install tagui`. For its Python API and architecture, refer to the [project homepage](https://github.com/tebelorg/TagUI-Python). The package is built on TagUI and its architecture is based on integration with TagUI's live mode. At merely 1000 lines of code, one of the project goals is to inspire developers of other programming languages to port it over to their favourite language. + ### FLOW SAMPLES Following automation flow samples ([tagui/src/samples folder](https://github.com/kelaberetiv/TagUI/tree/master/src/samples)) are included with TagUI @@ -919,4 +922,3 @@ TagUI excels in automating user-interface interactions. It's designed to make pr # License TagUI is open-source software released under Apache 2.0 license - diff --git a/src/tagui.sikuli/tagui.py b/src/tagui.sikuli/tagui.py index 33748abf..94545909 100644 --- a/src/tagui.sikuli/tagui.py +++ b/src/tagui.sikuli/tagui.py @@ -19,7 +19,7 @@ # helper function to detect coordinates locator def is_coordinates ( input_locator ): - if input_locator[:1] == '(' and input_locator[-1:] == ')' and input_locator.count(',') == 1: + if input_locator[:1] == '(' and input_locator[-1:] == ')' and input_locator.count(',') in [1,2]: return True else: return False @@ -32,6 +32,19 @@ def x_coordinate ( input_locator ): def y_coordinate ( input_locator ): return int(input_locator[input_locator.find(',')+1:-1]) +# helper function to return Region from (x1,y1),(x2,y2) +def define_region( input_locator ): + input_tokens = input_locator.split(',') + region_x1_coordinate = int(input_tokens[0].replace('(','')) + region_y1_coordinate = int(input_tokens[1].split('-')[0].replace(')','')) + region_x2_coordinate = int(input_tokens[1].split('-')[1].replace('(','')) + region_y2_coordinate = int(input_tokens[2].replace(')','')) + region_width = abs(region_x2_coordinate - region_x1_coordinate) + region_height = abs(region_y2_coordinate - region_y1_coordinate) + region_origin_x = min(region_x1_coordinate,region_x2_coordinate) + region_origin_y = min(region_y1_coordinate,region_y2_coordinate) + return Region(region_origin_x,region_origin_y,region_width,region_height) + # function to map modifier keys to unicode for use in type() def modifiers_map ( input_keys ): modifier_keys = 0 @@ -222,10 +235,15 @@ def save_intent ( raw_intent ): # function for reading text using Tesseract OCR def text_read ( raw_intent ): params = (raw_intent + ' ')[1+(raw_intent + ' ').find(' '):].strip() - param1 = params[:(params + ' ').find(' ')].strip() + param1 = params.split(' to ')[0].strip() print '[tagui] ACTION - ' + raw_intent - if param1.endswith('page.png') or param1.endswith('page.bmp'): + if is_coordinates(param1): + region_layer = define_region(param1) + temp_text = region_layer.text() + output_sikuli_text(temp_text) + return 1 + elif param1.endswith('page.png') or param1.endswith('page.bmp'): fullscreen_layer = Screen() temp_text = fullscreen_layer.text() output_sikuli_text(temp_text) @@ -244,7 +262,14 @@ def snap_intent ( raw_intent ): param1 = params[:params.find(' to ')].strip() param2 = params[4+params.find(' to '):].strip() print '[tagui] ACTION - snap ' + param1 + ' to ' + param2 - if param1.endswith('page.png') or param1.endswith('page.bmp'): + if is_coordinates(param1): + fullscreen_layer = Screen() + region_layer = define_region(param1) + temp_snap_file = fullscreen_layer.capture(region_layer).getFile() + import shutil + shutil.copy(temp_snap_file,param2) + return 1 + elif param1.endswith('page.png') or param1.endswith('page.bmp'): fullscreen_layer = Screen() temp_snap_file = fullscreen_layer.capture(fullscreen_layer.getBounds()).getFile() import shutil diff --git a/src/tagui_header.js b/src/tagui_header.js index f7b003b7..999e943b 100644 --- a/src/tagui_header.js +++ b/src/tagui_header.js @@ -877,7 +877,8 @@ return input_string.replace(/\\/g,'\\\\');} function is_coordinates(input_params) { // helper function to check if string is (x,y) coordinates if ((input_params.length > 4) && (input_params.substr(0,1) == '(') && (input_params.substr(-1) == ')') -&& (input_params.split(',').length == 2) && (!input_params.match(/[a-z]/i))) return true; else return false;} +&& (input_params.split(',').length == 2 || input_params.split(',').length == 3) +&& (!input_params.match(/[a-z]/i))) return true; else return false;} function is_sikuli(input_params) { // helper function to check if input is meant for sikuli visual automation if (input_params.length > 4 && input_params.substr(-4).toLowerCase() == '.png') return true; // support png and bmp diff --git a/src/tagui_parse.php b/src/tagui_parse.php index cdd9a88b..c8e0ee68 100755 --- a/src/tagui_parse.php +++ b/src/tagui_parse.php @@ -561,7 +561,8 @@ function add_concat($source_string) { // parse string and add missing + concaten function is_coordinates($input_params) { // helper function to check if string is (x,y) coordinates if (strlen($input_params)>4 and substr($input_params,0,1)=='(' and substr($input_params,-1)==')' -and substr_count($input_params,',')==1 and ((strpos($input_params,"'+")!==false and strpos($input_params,"+'")!==false) +and (substr_count($input_params,',')==1 or substr_count($input_params,',')==2) +and ((strpos($input_params,"'+")!==false and strpos($input_params,"+'")!==false) or !preg_match('/[a-zA-Z]/',$input_params))) return true; else return false;} function is_sikuli($input_params) { // helper function to check if input is meant for sikuli visual automation diff --git a/src/test/positive_test.signature b/src/test/positive_test.signature index 5b92bbf9..2b6ae0c8 100644 --- a/src/test/positive_test.signature +++ b/src/test/positive_test.signature @@ -904,7 +904,8 @@ return input_string.replace(/\\/g,'\\\\');} function is_coordinates(input_params) { // helper function to check if string is (x,y) coordinates if ((input_params.length > 4) && (input_params.substr(0,1) == '(') && (input_params.substr(-1) == ')') -&& (input_params.split(',').length == 2) && (!input_params.match(/[a-z]/i))) return true; else return false;} +&& (input_params.split(',').length == 2 || input_params.split(',').length == 3) +&& (!input_params.match(/[a-z]/i))) return true; else return false;} function is_sikuli(input_params) { // helper function to check if input is meant for sikuli visual automation if (input_params.length > 4 && input_params.substr(-4).toLowerCase() == '.png') return true; // support png and bmp