Skip to content

Commit

Permalink
kml tutorial refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer committed Nov 15, 2023
1 parent f0f0304 commit 15bf085
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 122 deletions.
2 changes: 1 addition & 1 deletion mslib/msui/msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def notify(QObject, QEvent):
application.setWindowIcon(QtGui.QIcon(icons('128x128')))
application.setApplicationDisplayName("MSUI")
application.setAttribute(QtCore.Qt.AA_DisableWindowContextHelpButton)
mainwindow = MSUIMainWindow(tutorial_mode=args.tutorials)
mainwindow = MSUIMainWindow(tutorial_mode=args.tutorials or tutorial_mode)
if version.parse(__version__) >= version.parse('9.0.0') and version.parse(__version__) < version.parse('10.0.0'):
from mslib.utils.migration.config_before_nine import read_config_file as read_config_file_before_nine
from mslib.utils.migration.config_before_nine import config_loader as config_loader_before_nine
Expand Down
9 changes: 9 additions & 0 deletions mslib/msui/msui_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,38 @@ def get_shortcuts(self):
shortcuts = {}
for qobject in QtWidgets.QApplication.topLevelWidgets():
actions = []
# QAction
actions.extend([
(action.parent().window() if hasattr(action.parent(), "window") else action.parent(),
action.toolTip(), action.text().replace("&&", "%%").replace("&", "").replace("%%", "&"),
action.objectName(),
",".join([shortcut.toString() for shortcut in action.shortcuts()]), action)
for action in qobject.findChildren(
QtWidgets.QAction) if len(action.shortcuts()) > 0 or self.cbNoShortcut.checkState()])

# QShortcut
actions.extend([(shortcut.parentWidget().window(), shortcut.whatsThis(), "",
shortcut.objectName(), shortcut.key().toString(), shortcut)
for shortcut in qobject.findChildren(QtWidgets.QShortcut)])

# QAbstractButton
actions.extend([(button.window(), button.toolTip(), button.text().replace("&&", "%%").replace("&", "")
.replace("%%", "&"), button.objectName(),
button.shortcut().toString() if button.shortcut() else "", button)
for button in qobject.findChildren(QtWidgets.QAbstractButton) if button.shortcut() or
self.cbNoShortcut.checkState()])

# Additional objects which have no shortcuts, if requested
# QComboBox
actions.extend([(obj.window(), obj.toolTip(), obj.currentText(), obj.objectName(), "", obj)
for obj in qobject.findChildren(QtWidgets.QComboBox) if self.cbNoShortcut.checkState()])

# QAbstractSpinBox, QLineEdit
actions.extend([(obj.window(), obj.toolTip(), obj.text(), obj.objectName(), "", obj)
for obj in qobject.findChildren(QtWidgets.QAbstractSpinBox) +
qobject.findChildren(QtWidgets.QLineEdit)
if self.cbNoShortcut.checkState()])
# QPlainTextEdit, QTextEdit
actions.extend([(obj.window(), obj.toolTip(), obj.toPlainText(), obj.objectName(), "", obj)
for obj in qobject.findChildren(QtWidgets.QPlainTextEdit) +
qobject.findChildren(QtWidgets.QTextEdit)
Expand Down
28 changes: 7 additions & 21 deletions tutorials/pictures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
This file is part of MSS.
:copyright: Copyright 2016-2022 by the MSS team, see AUTHORS.
:copyright: Copyright 2016-2023 by the MSS team, see AUTHORS.
:license: APACHE-2.0, see LICENSE for details.
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,23 +24,9 @@
limitations under the License.
"""
import os
import sys

use_platform = sys.platform
if sys.platform in ('linux', 'linux2', 'darwin'):
use_platform = 'linux'

TUTORIALS = ["hexagoncontrol",
"kml",
"mscolab",
"performancesettings",
"remotesensing",
"satellitetrack",
"views",
"waypoints",
"wms"]


def picture(tutorial="wms", name="layers.png"):
if tutorial in TUTORIALS:
return os.path.join(os.path.abspath(os.path.normpath(os.path.dirname(__file__))), tutorial, use_platform, name)


MSUI_CONFIG_PATH = os.environ.get('MSUI_CONFIG_PATH')

def picture(name="layers.png"):
return os.path.join(MSUI_CONFIG_PATH, 'tutorial_images', name)
150 changes: 51 additions & 99 deletions tutorials/tutorial_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,28 @@ def automate_kml():
pag.hotkey('ctrl', 'command', 'f') if platform == 'darwin' else 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(3)
pag.sleep(1)
# lets create our helper images
create_tutorial_images()

# Changing map to Global
try:
pic = picture('topviewwindow-01-europe-cyl.png')
x, y = pag.locateCenterOnScreen(pic)

pag.click(x, y, interval=2)
pag.press('down', presses=2, interval=0.5)
pag.press(enter, interval=1)
pag.sleep(5)
except (ImageNotFoundException, OSError, Exception):
print("\n Exception : Map change dropdown could not be located on the screen")
raise

# Opening KML overlay dockwidget
try:
x, y = pag.locateCenterOnScreen(picture('wms', 'selecttoopencontrol.png'))
x, y = pag.locateCenterOnScreen(picture('topviewwindow-select-to-open-control.png'))
pag.click(x, y, interval=2)
pag.sleep(1)
pag.press('down', presses=4, interval=1)
Expand All @@ -68,9 +83,13 @@ def automate_kml():
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'select to open control\' button/option not found on the screen.")

create_tutorial_images()



# Adding the KML files and loading them
try:
x, y = pag.locateCenterOnScreen(picture('kml', 'add_kml_files.png'))
x, y = pag.locateCenterOnScreen(picture('topviewwindow-add-kml-files.png'))
pag.click(x, y, duration=2)
pag.sleep(1)
pag.typewrite(kml_file_path1, interval=0.1)
Expand All @@ -90,130 +109,63 @@ def automate_kml():

# Unselecting and Selecting Files to demonstrate visibility on the map.
try:
x1, y1 = pag.locateCenterOnScreen(picture('kml', 'unselect_all_files.png'))
x1, y1 = pag.locateCenterOnScreen(picture('topviewwindow-unselect-all-files.png'))
pag.click(x1, y1, duration=2)
pag.sleep(2)
try:
x1, y1 = pag.locateCenterOnScreen(picture('kml', 'select_all_files.png'))
x1, y1 = pag.locateCenterOnScreen(picture('topviewwindow-select-all-files.png'))
pag.click(x1, y1, duration=2)
pag.sleep(2)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'Select All Files(Unselecting & Selecting)\' button not found on the screen.")
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'Select All Files(Unselecting & Selecting)\' button not found on the screen.")
raise

create_tutorial_images()
# Selecting and Customizing the Folder.kml file
try:
x, y = pag.locateCenterOnScreen(picture('kml', 'colored_line.png'))
pag.click(x + 100, y, duration=2)
pag.sleep(4)
try:
# Changing color of folder.kml file
x1, y1 = pag.locateCenterOnScreen(picture('kml', 'changecolor.png'))
pag.click(x1, y1, duration=2)
pag.sleep(4)
x2, y2 = pag.locateCenterOnScreen(picture('kml', 'pick_screen_color.png'))
pag.click(x2, y2 - 30, duration=1)
pag.sleep(3)
pag.press(enter)
pag.sleep(4)

pag.click(x1, y1, duration=2)
pag.sleep(4)
x2, y2 = pag.locateCenterOnScreen(picture('kml', 'pick_screen_color.png'))
pag.click(x2 + 20, y2 - 50, duration=1)
pag.sleep(3)
pag.press(enter)
pag.sleep(4)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'Change Color (folder.kml)\' button not found on the screen.")
raise
try:
# Changing Linewidth of folder.kml file
x1, y1 = pag.locateCenterOnScreen(picture('kml', 'changecolor.png'))
pag.click(x1 + 12, y1 + 50, duration=2)
pag.sleep(2)
pag.hotkey(ctrl, 'a')
for _ in range(8):
pag.press('down')
pag.sleep(3)
pag.hotkey(ctrl, 'a')
pag.typewrite('6.50', interval=1)
pag.press(enter)
pag.sleep(3)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'Change Color(folder.kml again)\' button not found on the screen.")
raise
# Selecting and Customizing the color.kml file
pag.click(x + 100, y + 38, duration=2)
pag.sleep(2)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'KML Overlay\' fixed text not found on the screen.")
raise

# Changing map to Global
try:
x, y = pag.locateCenterOnScreen(picture('wms', 'europe_cyl.png'))
pag.click(x, y, interval=2)
pag.press('down', presses=2, interval=0.5)
pag.press(enter, interval=1)
pag.sleep(5)
except (ImageNotFoundException, OSError, Exception):
print("\n Exception : Map change dropdown could not be located on the screen")
raise
pag.move(-200, 0, duration=1)
pag.click(interval=2)

# select the black line
try:
x, y = pag.locateCenterOnScreen(picture('kml', 'colored_line.png'))
pag.click(x + 100, y, duration=2)
# Changing color of folder.kml file
x1, y1 = pag.locateCenterOnScreen(picture('topviewwindow-change-color.png'))
pag.click(x1, y1, duration=2)
pag.sleep(4)
pag.move(-220, -300, duration=1)
pag.click(interval=2)
pag.press(enter)
pag.sleep(1)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'KML Overlay\' fixed text not found on the screen.")
print("\nException :\'Change Color \' button not found on the screen.")
raise

try:
# Changing color of color.kml file
x1, y1 = pag.locateCenterOnScreen(picture('kml', 'changecolor.png'))
pag.click(x1, y1, duration=2)
pag.sleep(4)
x2, y2 = pag.locateCenterOnScreen(picture('kml', 'pick_screen_color.png'))
pag.click(x2 - 20, y2 - 50, duration=1)
pag.sleep(3)
pag.press(enter)
pag.sleep(3)

pag.click(x1, y1, duration=2)
pag.sleep(4)
x2, y2 = pag.locateCenterOnScreen(picture('kml', 'pick_screen_color.png'))
pag.click(x2 - 5, y2 - 120, duration=1)
pag.sleep(3)
pag.press(enter)
pag.sleep(4)

# Changing Linewidth of color.kml file
# Changing Linewidth of folder.kml file
x1, y1 = pag.locateCenterOnScreen(picture('topviewwindow-change-color.png'))
pag.click(x1 + 12, y1 + 50, duration=2)
pag.sleep(4)
pag.sleep(2)
pag.hotkey(ctrl, 'a')
pag.sleep(1)
pag.typewrite('6.53', interval=1)
pag.sleep(1)
pag.press(enter)
pag.sleep(3)

for _ in range(8):
pag.press('down')
pag.sleep(3)
pag.hotkey(ctrl, 'a')
pag.sleep(1)
pag.typewrite('3.45', interval=1)
pag.sleep(1)
pag.typewrite('6.50', interval=1)
pag.press(enter)
pag.sleep(3)
except (ImageNotFoundException, OSError, Exception):
print("\nException :\'Change Color(Color.kml file)\' button not found on the screen.")
print("\nException :\'Change Color(folder.kml again)\' button not found on the screen.")
raise


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


def create_tutorial_images():
pag.hotkey('ctrl', 'f')
pag.sleep(1)
pag.hotkey('enter')


if __name__ == '__main__':
start(target=automate_kml, duration=220)
2 changes: 1 addition & 1 deletion tutorials/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def call_msui():
"""
Calls the main MSS GUI window since operations are to be performed on it only.
"""
msui.main()
msui.main(tutorial_mode=True)


def platform_keys():
Expand Down

0 comments on commit 15bf085

Please sign in to comment.