Skip to content

Commit

Permalink
Modified waypoints tutorial to make it run smoothly on linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
risehr committed Jul 5, 2021
1 parent 2eda795 commit 89d1417
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 45 deletions.
Binary file modified tutorials/pictures/europe(cyl).PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/pictures/europe(cyl)win.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/pictures/next.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/pictures/previous.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 80 additions & 45 deletions tutorials/tutorial_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import pyautogui as pag
import multiprocessing
import sys
import datetime
from sys import platform

from pyscreeze import ImageNotFoundException

from tutorials import screenrecorder as sr
from mslib.msui import mss_pyui

Expand All @@ -38,7 +42,7 @@ def initial_ops():
"""
pag.sleep(5)
if platform == "linux" or platform == "linux2":
pag.hotkey('win', 'd')
pag.hotkey('winleft', 'd')
print("\n INFO : Automation is running on Linux system..\n")
elif platform == "darwin":
pag.hotkey('option', 'command', 'm')
Expand Down Expand Up @@ -74,55 +78,63 @@ def automate_waypoints(obj=None):

# Maximizing the window
try:
if platform == 'linux' or platform == 'linux2' or platform == 'win32':
pag.hotkey('win', 'up')
if platform == 'linux' or platform == 'linux2':
pag.hotkey('winleft', 'up')
elif platform == 'darwin':
pag.hotkey('ctrl', 'command', 'f')
elif platform == 'win32':
pag.hotkey('win', 'up')
except Exception:
print("\nException : Enable Shortcuts for your system or try again!")
pag.sleep(2)
pag.hotkey('ctrl', 'h')
pag.sleep(5)

# Adding waypoints
try:
x, y = pag.locateCenterOnScreen('pictures/add_waypoint.PNG')
pag.click(x, y, interval=2)
except Exception:
except ImageNotFoundException:
print("\nException : Clickable button/option not found on the screen.")
pag.moveTo(712, 347)
pag.click(712, 347, interval=2)
pag.move(-50, 150, duration=1)
pag.click(interval=2)
pag.sleep(1)
pag.moveTo(812, 412)
pag.click(812, 412, interval=2)
pag.move(65, 65, duration=1)
pag.click(interval=2)
pag.sleep(1)

pag.moveTo(915, 560)
pag.click(915, 560, interval=2)
pag.move(-150, 30, duration=1)
x1, y1 = pag.position()
pag.click(interval=2)
pag.sleep(1)
pag.moveTo(1000, 650)
pag.click(1000, 650, interval=2)
pag.move(200, 150, duration=1)
pag.click(interval=2)
x2, y2 = pag.position()
pag.sleep(3)

# Moving waypoints
try:
x, y = pag.locateCenterOnScreen('pictures/move_waypoint.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Move Waypoint button could not be located on the screen")

pag.moveTo(1000, 650, duration=1)
pag.dragTo(1200, 400, duration=1)
pag.moveTo(915, 560, duration=1)
pag.dragTo(950, 321, duration=1)
pag.moveTo(x2, y2, duration=1)
pag.click(interval=2)
pag.dragRel(100, 150, duration=1)
pag.moveTo(x1, y1, duration=1)
pag.dragRel(35, -50, duration=1)
x1, y1 = pag.position()

# Deleting waypoints
try:
x, y = pag.locateCenterOnScreen('pictures/remove_waypoint.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Remove Waypoint button could not be located on the screen")
pag.moveTo(950, 321, duration=1)
pag.click(950, 321, duration=1)
pag.moveTo(x1, y1, duration=1)
pag.click(duration=1)
pag.press('left')
pag.sleep(3)
if platform == 'linux' or platform == 'linux2' or platform == 'win32':
pag.press('enter', interval=1)
Expand All @@ -132,11 +144,15 @@ def automate_waypoints(obj=None):

# Changing map to Global
try:
x, y = pag.locateCenterOnScreen('pictures/europe(cyl).PNG')
pag.click(x,y, interval=2)
except Exception:
if platform == 'linux' or 'linux2' or 'darwin':
x, y = pag.locateCenterOnScreen('pictures/europe(cyl).PNG')
pag.click(x, y, interval=2)
elif platform == 'win32':
x, y = pag.locateCenterOnScreen('pictures/europe(cyl)win.PNG')
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Map change dropdown could not be located on the screen")
pag.press('down', presses=2, interval=2)
pag.press('down', presses=2, interval=0.5)
if platform == 'linux' or platform == 'linux2' or platform == 'win32':
pag.press('enter', interval=1)
elif platform == 'darwin':
Expand All @@ -146,71 +162,90 @@ def automate_waypoints(obj=None):
# Zooming into the map
try:
x, y = pag.locateCenterOnScreen('pictures/zoom.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Zoom button could not be located on the screen")
pag.moveTo(712, 347)
pag.dragRel(500, 200, duration=2)
pag.move(150, 200, duration=1)
pag.dragRel(400, 250, duration=2)
pag.sleep(5)

# Panning into the map
try:
x, y = pag.locateCenterOnScreen('pictures/pan.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Pan button could not be located on the screen")
pag.moveRel(400, 400, duration=1)
pag.dragRel(-100, -50, duration=2)
pag.sleep(5)

pag.moveTo(600, 400, duration=1)
pag.move(-20, -25, duration=1)
pag.dragRel(90, 50, duration=2)
pag.sleep(5)

# Switching to the previous appearance of the map
try:
x, y = pag.locateCenterOnScreen('pictures/previous.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Previous button could not be located on the screen")
pag.sleep(5)

# Switching to the next appearance of the map
try:
x, y = pag.locateCenterOnScreen('pictures/next.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Next button could not be located on the screen")
pag.sleep(5)

# Resetting the map to the original size
try:
x, y = pag.locateCenterOnScreen('pictures/home.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Home button could not be located on the screen")
pag.sleep(5)

# Saving the figure
try:
x, y = pag.locateCenterOnScreen('pictures/save.PNG')
pag.click(x,y, interval=2)
except Exception:
pag.click(x, y, interval=2)
except ImageNotFoundException:
print("\n Exception : Save button could not be located on the screen")
pag.sleep(3)
current_time = datetime.datetime.now().strftime('%d-%m-%Y %H-%M-%S')
fig_filename = f'Fig_{current_time}.PNG'
pag.write(fig_filename, interval=1)
if platform == 'linux' or platform == 'linux2' or platform == 'win32':
pag.sleep(3)
if platform == 'win32':
pag.write(fig_filename, interval=0.25)
pag.press('enter', interval=1)
if platform == 'linux' or platform == 'linux2':
# pag.hotkey('altleft', 'tab') if the save file system window is not in the forefront, use this statement.
# This can happen sometimes. At that time, you just need to uncomment it.
pag.write(fig_filename, interval=0.25)
pag.press('enter', interval=1)
elif platform == 'darwin':
pag.write(fig_filename, interval=0.25)
pag.press('return', interval=1)

print("\nAutomation is over for this tutorial. Watch next tutorial for other functions.")

# Close Everything!
try:
if platform == 'linux' or platform == 'linux2' or platform == 'win32':
if platform == 'linux' or platform == 'linux2':
for _ in range(2):
pag.hotkey('altleft', 'f4')
pag.sleep(3)
pag.press('left')
pag.sleep(3)
pag.press('enter')
pag.sleep(2)
pag.keyDown('altleft')
pag.press('tab')
pag.press('left')
pag.keyUp('altleft')
pag.press('q')
if platform == 'win32':
for _ in range(2):
pag.hotkey('alt', 'f4')
pag.sleep(3)
Expand Down

0 comments on commit 89d1417

Please sign in to comment.