Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

#461 - support defining regions for OCR and snapshot #463

Merged
merged 9 commits into from
Jun 21, 2019
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ TagUI Writer is a Windows app created by Arnaud Degardin / [@adegard](https://gi

</details>

### 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

Expand Down Expand Up @@ -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

33 changes: 29 additions & 4 deletions src/tagui.sikuli/tagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/tagui_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/tagui_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down