Skip to content

Commit

Permalink
#478 #479 - fix snap() add focus()
Browse files Browse the repository at this point in the history
  • Loading branch information
kensoh committed Jul 7, 2023
1 parent f8f266c commit 6fc6b32
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RPA for Python :snake:

[**v1.48**](https://github.com/tebelorg/RPA-Python/releases) • [**Use Cases**](#use-cases) • [**API Reference**](#api-reference) • [**About & Credits**](#about--credits) • [**Try on Cloud**](https://colab.research.google.com/drive/1or8DtXZP8ZxJYK52me0dA6O9A1dXKKOE?usp=sharing) • [**PyCon Video**](https://www.youtube.com/watch?v=F2aQKWx_EAE) • [**Telegram Chat**](https://t.me/pythonrpa) • [*中文*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=zh-CN&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*हिन्दी*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=hi&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Español*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Français*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=fr&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*عربى*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=ar&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*বাংলা*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=bn&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Русский*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=ru&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Português*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=pt&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Bahasa*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=id&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Deutsch*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=de&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*More..*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=sr&_x_tr_hl=en-US&_x_tr_pto=wapp)
[**v1.49**](https://github.com/tebelorg/RPA-Python/releases) • [**Use Cases**](#use-cases) • [**API Reference**](#api-reference) • [**About & Credits**](#about--credits) • [**Try on Cloud**](https://colab.research.google.com/drive/1or8DtXZP8ZxJYK52me0dA6O9A1dXKKOE?usp=sharing) • [**PyCon Video**](https://www.youtube.com/watch?v=F2aQKWx_EAE) • [**Telegram Chat**](https://t.me/pythonrpa) • [*中文*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=zh-CN&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*हिन्दी*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=hi&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Español*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Français*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=fr&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*عربى*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=ar&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*বাংলা*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=bn&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Русский*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=ru&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Português*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=pt&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Bahasa*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=id&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*Deutsch*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=de&_x_tr_hl=en-US&_x_tr_pto=wapp) • [*More..*](https://jackfan.us.kg.translate.goog/tebelorg/RPA-Python?_x_tr_sl=en&_x_tr_tl=sr&_x_tr_hl=en-US&_x_tr_pto=wapp)

![RPA for Python demo in Jupyter notebook](https://raw.githubusercontent.com/tebelorg/Tump/master/tagui_python.gif)

Expand Down Expand Up @@ -159,6 +159,7 @@ Function|Parameters|Purpose
`telegram()`|`telegram_id`, `text_to_send` (first look up @rpapybot)|send Telegram message
`keyboard()`|`keys_and_modifiers` (using visual automation)|send keystrokes to screen
`mouse()`|`'down'` or `'up'` (using visual automation)|send mouse event to screen
`focus()`|`app_to_focus`|make application in focus
`wait()`|`delay_in_seconds` (default 5 seconds)|explicitly wait for some time
`table()`|`table number` or `XPath`, `filename_to_save`|save webpage table to CSV
`bin()`|`file_to_bin`, `password` (optional but recommended)|secure temporary storage
Expand Down
2 changes: 1 addition & 1 deletion rpa_package/rpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Apache License 2.0, Copyright 2019 Tebel.Automation Private Limited
# https://github.com/tebelorg/RPA-Python/blob/master/LICENSE.txt
__author__ = 'Ken Soh <[email protected]>'
__version__ = '1.48.1'
__version__ = '1.49.0'

# for backward compatibility, invoke tagui.py functions to use in rpa.py
from tagui import *
4 changes: 2 additions & 2 deletions rpa_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

setup(
name='rpa',
version='1.48.1',
py_modules=['rpa'], install_requires=['tagui>=1.48.1'],
version='1.49.0',
py_modules=['rpa'], install_requires=['tagui>=1.49.0'],
author='Ken Soh',
author_email='[email protected]',
license='Apache License 2.0',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='tagui',
version='1.48.1',
version='1.49.0',
py_modules=['tagui'],
author='Ken Soh',
author_email='[email protected]',
Expand Down
32 changes: 31 additions & 1 deletion tagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Apache License 2.0, Copyright 2019 Tebel.Automation Private Limited
# https://github.com/tebelorg/RPA-Python/blob/master/LICENSE.txt
__author__ = 'Ken Soh <[email protected]>'
__version__ = '1.48.1'
__version__ = '1.49.0'

import subprocess
import os
Expand Down Expand Up @@ -1349,6 +1349,36 @@ def mouse(mouse_action = None):
else:
return True

def focus(app_to_focus = None):
if app_to_focus is None or app_to_focus == '':
show_error('[RPA][ERROR] - app to focus missing for focus()')
return False

else:
if platform.system() == 'Windows':
# download sendKeys.bat if not present
if not os.path.isfile('sendKeys.bat'):
sendKeys_url = 'https://github.com/tebelorg/Tump/releases/download/v1.0.0/sendKeys.bat'
if not download(sendKeys_url, 'sendKeys.bat'):
show_error('[RPA][ERROR] - cannot download sendKeys.bat for focus()')
return False
if os.system('sendKeys.bat "' + app_to_focus + '" "" > nul 2>&1') == 0:
return True
else:
show_error('[RPA][ERROR] - ' + app_to_focus + ' not found for focus()')
return False

elif platform.system() == 'Darwin':
if os.system('osascript -e \'tell application "' + app_to_focus + '" to activate\' > /dev/null 2>&1') == 0:
return True
else:
show_error('[RPA][ERROR] - ' + app_to_focus + ' not found for focus()')
return False

else:
show_error('[RPA][ERROR] - Linux not supported for focus()')
return False

def table(element_identifier = None, filename_to_save = None):
if not _started():
show_error('[RPA][ERROR] - use init() before using table()')
Expand Down

0 comments on commit 6fc6b32

Please sign in to comment.