diff --git a/docs/samples/config/mss/performance_simple.json.sample b/docs/samples/config/mss/performance_simple.json similarity index 96% rename from docs/samples/config/mss/performance_simple.json.sample rename to docs/samples/config/mss/performance_simple.json index f80ae3c0c..5c20d1a70 100644 --- a/docs/samples/config/mss/performance_simple.json.sample +++ b/docs/samples/config/mss/performance_simple.json @@ -10,6 +10,6 @@ "_comment2": "takeoff_weight: maximum weight for takeoff (lbs)", "_comment3": "empty_weight: aircraft weight without fuel (lbs)", "_comment4": "climb/descent: weight(lbs), altitude(ft), duration(min), distance(nm), fuel(lbs)", - "_comment5": "cruise: weight(lbs), altitude(ft), total air speed(nm/h), fuel flow(lbs/h)" + "_comment5": "cruise: weight(lbs), altitude(ft), total air speed(nm/h), fuel flow(lbs/h)", "_comment6": "ceiling: polynomial coeficients for relating weight (lbs) with peak flightlevel (hft). Leftmost coefficient is the intercept." } diff --git a/tutorials/cursor.py b/tutorials/cursor.py index 93b563f28..dd2733591 100644 --- a/tutorials/cursor.py +++ b/tutorials/cursor.py @@ -1,6 +1,6 @@ """ mss.tutorials.cursor - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~ This python script generates the png image of the cursor for linux systems and store it in 'tutorials/cursor_image.png.' Then, this image is used inside screenrecorder.py file. This displays diff --git a/tutorials/pictures/hexagon_control/linux/add_hexagon.png b/tutorials/pictures/hexagon_control/linux/add_hexagon.png new file mode 100644 index 000000000..c3926b3a3 Binary files /dev/null and b/tutorials/pictures/hexagon_control/linux/add_hexagon.png differ diff --git a/tutorials/pictures/hexagon_control/linux/center_latitude.png b/tutorials/pictures/hexagon_control/linux/center_latitude.png new file mode 100644 index 000000000..b22d60ca1 Binary files /dev/null and b/tutorials/pictures/hexagon_control/linux/center_latitude.png differ diff --git a/tutorials/pictures/hexagon_control/linux/radius.png b/tutorials/pictures/hexagon_control/linux/radius.png new file mode 100644 index 000000000..c9f5ebf75 Binary files /dev/null and b/tutorials/pictures/hexagon_control/linux/radius.png differ diff --git a/tutorials/pictures/hexagon_control/linux/remove_hexagon.png b/tutorials/pictures/hexagon_control/linux/remove_hexagon.png new file mode 100644 index 000000000..72f0a6fdb Binary files /dev/null and b/tutorials/pictures/hexagon_control/linux/remove_hexagon.png differ diff --git a/tutorials/pictures/kml_overlay/linux/add_kml_files.png b/tutorials/pictures/kml_overlay/linux/add_kml_files.png new file mode 100644 index 000000000..46c205efb Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/add_kml_files.png differ diff --git a/tutorials/pictures/kml_overlay/linux/changecolor.png b/tutorials/pictures/kml_overlay/linux/changecolor.png new file mode 100644 index 000000000..6427c24cc Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/changecolor.png differ diff --git a/tutorials/pictures/kml_overlay/linux/kmloverlay.png b/tutorials/pictures/kml_overlay/linux/kmloverlay.png new file mode 100644 index 000000000..40a81fb92 Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/kmloverlay.png differ diff --git a/tutorials/pictures/kml_overlay/linux/mergeandexport.png b/tutorials/pictures/kml_overlay/linux/mergeandexport.png new file mode 100644 index 000000000..d62fd1292 Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/mergeandexport.png differ diff --git a/tutorials/pictures/kml_overlay/linux/pick_screen_color.png b/tutorials/pictures/kml_overlay/linux/pick_screen_color.png new file mode 100644 index 000000000..d4258754f Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/pick_screen_color.png differ diff --git a/tutorials/pictures/kml_overlay/linux/remove_files.png b/tutorials/pictures/kml_overlay/linux/remove_files.png new file mode 100644 index 000000000..adaaf944d Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/remove_files.png differ diff --git a/tutorials/pictures/kml_overlay/linux/select_all_files.png b/tutorials/pictures/kml_overlay/linux/select_all_files.png new file mode 100644 index 000000000..06f82c00a Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/select_all_files.png differ diff --git a/tutorials/pictures/kml_overlay/linux/unselect_all_files.png b/tutorials/pictures/kml_overlay/linux/unselect_all_files.png new file mode 100644 index 000000000..4bb760403 Binary files /dev/null and b/tutorials/pictures/kml_overlay/linux/unselect_all_files.png differ diff --git a/tutorials/pictures/performance_settings/linux/aircraft_weight.png b/tutorials/pictures/performance_settings/linux/aircraft_weight.png new file mode 100644 index 000000000..7e8b60978 Binary files /dev/null and b/tutorials/pictures/performance_settings/linux/aircraft_weight.png differ diff --git a/tutorials/pictures/performance_settings/linux/maximum_takeoff_weight.png b/tutorials/pictures/performance_settings/linux/maximum_takeoff_weight.png new file mode 100644 index 000000000..04f6aa3dd Binary files /dev/null and b/tutorials/pictures/performance_settings/linux/maximum_takeoff_weight.png differ diff --git a/tutorials/pictures/performance_settings/linux/select.png b/tutorials/pictures/performance_settings/linux/select.png new file mode 100644 index 000000000..34890a519 Binary files /dev/null and b/tutorials/pictures/performance_settings/linux/select.png differ diff --git a/tutorials/pictures/performance_settings/linux/show_performance.png b/tutorials/pictures/performance_settings/linux/show_performance.png new file mode 100644 index 000000000..e8d5ae17c Binary files /dev/null and b/tutorials/pictures/performance_settings/linux/show_performance.png differ diff --git a/tutorials/pictures/performance_settings/linux/take_off_time.png b/tutorials/pictures/performance_settings/linux/take_off_time.png new file mode 100644 index 000000000..cd6a2fef5 Binary files /dev/null and b/tutorials/pictures/performance_settings/linux/take_off_time.png differ diff --git a/tutorials/screenrecorder.py b/tutorials/screenrecorder.py index a94a5f777..ab6be5537 100644 --- a/tutorials/screenrecorder.py +++ b/tutorials/screenrecorder.py @@ -1,6 +1,6 @@ """ mss.tutorials.screenrecorder - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script is meant for recording the screens while automated tutorials are running. @@ -85,8 +85,8 @@ def get_fps(self): screen refresh rate of your monitor (if considerable in the program) and sets the FPS. """ with mss.mss() as sct: - bbox = {"top": self.x_start, "left": self.y_start, "width": self.width - self.x_start, - "height": self.height} + bbox = {"top": self.y_start, "left": self.x_start, "width": self.width - self.x_start, + "height": self.height - self.y_start} fps = 0 last_time = time.time() while time.time() - last_time < 1: @@ -117,8 +117,8 @@ def capture(self): mouse_pointer = None width, height = None, None with mss.mss() as sct: - bbox = {"top": self.x_start, "left": self.y_start, "width": self.width - self.x_start, - "height": self.height} + bbox = {"top": self.y_start, "left": self.x_start, "width": self.width - self.x_start, + "height": self.height - self.y_start} self.start_rec_time = time.time() frame_time_ms = 1000 / self.fps frames = 0 diff --git a/tutorials/tutorial_hexagoncontrol.py b/tutorials/tutorial_hexagoncontrol.py new file mode 100644 index 000000000..5cd059a12 --- /dev/null +++ b/tutorials/tutorial_hexagoncontrol.py @@ -0,0 +1,382 @@ +""" + mss.tutorials.tutorial_hexagoncontrol.py + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + This python script generates an automatic demonstration of how to create a hexagon flightrack with the waypoints. + Placing a centre waypoint, how we can draw a perfect hexagon flight path around it with variable radius of + hexagon and variable angle of first waypoint of the hexagon. + This file is part of mss. + + :copyright: Copyright 2021 Hrithik Kumar Verma + :copyright: Copyright 2021 by the mss team, see AUTHORS. + :license: APACHE-2.0, see LICENSE for details. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +import pyautogui as pag +import multiprocessing +import sys +from sys import platform + +from pyscreeze import ImageNotFoundException + +from tutorials import screenrecorder as sr +from mslib.msui import mss_pyui + + +def initial_ops(): + """ + Executes the initial operations such as closing all opened windows and showing the desktop. + """ + pag.sleep(5) + if platform == "linux" or platform == "linux2": + pag.hotkey('winleft', 'd') + print("\n INFO : Automation is running on Linux system..\n") + elif platform == "darwin": + pag.hotkey('option', 'command', 'm') + print("\n INFO : Automation is running on Mac OS..\n") + elif platform == "win32": + pag.hotkey('win', 'd') + print("\n INFO : Automation is running on Windows OS..\n") + else: + pag.alert(text="Sorry, no support on this platform!", title="Platform Exception", button='OK') + + +def call_recorder(): + """ + Calls the screen recorder class to start the recording of the automation. + """ + rec = sr.ScreenRecorder(0, 0, pag.size()[0], pag.size()[1] - 150) + rec.capture() + rec.stop_capture() + + +def call_mss(): + """ + Calls the main MSS GUI window since operations are to be performed on it only. + """ + mss_pyui.main() + + +def automate_hexagoncontrol(): + """ + This is the main automating script of the MSS hexagon control of table view which will be recorded and saved + to a file having dateframe nomenclature with a .mp4 extension(codec). + """ + # Giving time for loading of the MSS GUI. + pag.sleep(5) + tv_x = None + tv_y = None + + # Platform specific things + if platform == 'linux' or platform == 'linux2': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/linux/' + hc_path = 'pictures/hexagon_control/linux/' + win = 'winleft' + ctrl = 'ctrl' + elif platform == 'win32': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/win32/' + hc_path = 'pictures/hexagon_control/linux/' + win = 'win' + ctrl = 'ctrl' + elif platform == 'darwin': + enter = 'return' + wms_path = 'pictures/tutorial_wms/linux/' + hc_path = 'pictures/hexagon_control/linux/' + ctrl = 'command' + + # Maximizing the window + try: + 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) + + # Changing map to Global + try: + if platform == 'linux' or platform == 'linux2' or platform == '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) + 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") + + # Zooming into the map + try: + x, y = pag.locateCenterOnScreen('pictures/zoom.PNG') + pag.click(x, y, interval=2) + pag.move(379, 205, duration=1) + pag.dragRel(70, 75, duration=2) + pag.sleep(5) + except ImageNotFoundException: + print("\n Exception : Zoom button could not be located on the screen") + + # Opening TableView + pag.move(500, None, duration=1) + pag.click(duration=1) + pag.sleep(1) + pag.hotkey('ctrl', 't') + pag.sleep(3) + + # Relocating Tableview by performing operations on table view + try: + x, y = pag.locateCenterOnScreen(f'{wms_path}selecttoopencontrol.png') + pag.moveTo(x + 250, y - 462, duration=1) + if platform == 'linux' or platform == 'linux2': + pag.dragRel(649, 700, duration=3) + elif platform == 'win32' or platform == 'darwin': + pag.dragRel(200, 487, duration=2) + pag.sleep(2) + if platform == 'linux' or platform == 'linux2': + pag.keyDown('altleft') + pag.press('tab') + pag.press('right') + pag.keyUp('altleft') + elif platform == 'win32': + pag.keyDown('alt') + pag.press('tab') + pag.press('right') + pag.keyUp('alt') + elif platform == 'darwin': + pag.keyDown('command') + pag.press('tab') + pag.press('right') + pag.keyUp('command') + pag.sleep(1) + if platform == 'win32' or platform == 'darwin': + pag.dragRel(None, -700, duration=2) + tv_x, tv_y = pag.position() + elif platform == 'linux' or platform == 'linux2': + pag.dragRel(None, -630, duration=2) + tv_x, tv_y = pag.position() + except (ImageNotFoundException, OSError, TypeError, Exception): + print("\nException : TableView's Select to open Control option not found on the screen.") + + # Opening Hexagon Control dockwidget + if tv_x is not None and tv_y is not None: + pag.moveTo(tv_x - 250, tv_y + 462, duration=2) + pag.click(duration=2) + pag.sleep(1) + pag.press('down') + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + + # Entering Centre Latitude and Centre Longitude of Delhi around which hexagon will be drawn + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}center_latitude.png') + pag.sleep(1) + pag.click(x + 370, y, duration=2) + pag.sleep(1) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('28.57', interval=0.3) + pag.sleep(1) + pag.press(enter) + + pag.sleep(1) + pag.click(x + 943, y, duration=2) + pag.sleep(1) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('77.10', interval=0.3) + pag.sleep(1) + pag.press(enter) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Center Latitude\' button not found on the screen.") + + # Clicking on the add hexagon button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}add_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Add Hexagon\' button not found on the screen.") + + # Changing the Radius of the hexagon + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}radius.png') + pag.click(x + 400, y, duration=2) + pag.sleep(1) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('500.00', interval=0.3) + pag.sleep(1) + pag.press(enter) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Radius\' button not found on the screen.") + + # Clicking on the Remove Hexagon Button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}remove_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(2) + pag.press('left') + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Remove Hexagon\' button not found on the screen.") + + # Clicking on the add hexagon button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}add_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Add Hexagon\' button not found on the screen.") + + # Changing the angle of first point of the hexagon + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}radius.png') + pag.sleep(1) + pag.click(x + 967, y, duration=2) + pag.sleep(1) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('90.00', interval=0.3) + pag.sleep(1) + pag.press(enter) + + # Clicking on the Remove Hexagon Button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}remove_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(2) + pag.press('left') + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Remove Hexagon\' button not found on the screen.") + + # Clicking on the add hexagon button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}add_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Add Hexagon\' button not found on the screen.") + + # Changing to a different angle of first point + x, y = pag.locateCenterOnScreen(f'{hc_path}radius.png') + pag.sleep(1) + pag.click(x + 967, y, duration=2) + pag.sleep(1) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('120.00', interval=0.3) + pag.sleep(1) + pag.press(enter) + + # Clicking on the Remove Hexagon Button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}remove_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(2) + pag.press('left') + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Remove Hexagon\' button not found on the screen.") + + # Clicking on the add hexagon button + try: + x, y = pag.locateCenterOnScreen(f'{hc_path}add_hexagon.png') + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Add Hexagon\' button not found on the screen.") + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Radius (for Angle of first point)\' button not found on the screen.") + + pag.moveTo(tv_x, tv_y, duration=2) + pag.click(duration=2) + + print("\nAutomation is over for this tutorial. Watch next tutorial for other functions.") + + # Close Everything! + try: + if platform == 'linux' or platform == 'linux2': + for _ in range(3): + 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(3): + pag.hotkey('alt', 'f4') + pag.sleep(3) + pag.press('left') + pag.sleep(3) + pag.press('enter') + pag.sleep(2) + pag.hotkey('alt', 'tab') + pag.press('q') + elif platform == 'darwin': + for _ in range(3): + pag.hotkey('command', 'w') + pag.sleep(3) + pag.press('left') + pag.sleep(3) + pag.press('return') + pag.sleep(2) + pag.hotkey('command', 'tab') + pag.press('q') + except Exception: + print("Cannot automate : Enable Shortcuts for your system or try again") + + +def main(): + """ + This function runs the above functions as different processes at the same time and can be + controlled from here. (This is the main process.) + """ + p1 = multiprocessing.Process(target=call_mss) + p2 = multiprocessing.Process(target=automate_hexagoncontrol) + p3 = multiprocessing.Process(target=call_recorder) + + print("\nINFO : Starting Automation.....\n") + p3.start() + pag.sleep(3) + initial_ops() + p1.start() + p2.start() + + p2.join() + p1.join() + p3.join() + print("\n\nINFO : Automation Completes Successfully!") + sys.exit() + + +if __name__ == '__main__': + main() diff --git a/tutorials/tutorial_kml.py b/tutorials/tutorial_kml.py new file mode 100644 index 000000000..1c7b2e736 --- /dev/null +++ b/tutorials/tutorial_kml.py @@ -0,0 +1,340 @@ +""" + mss.tutorials.tutorial_kml + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + This python script generates an automatic demonstration of how to overlay kml flles on top of the map in topview. + kml(key hole markup language) is an XML based file format for demonstrating geographical context. This will + demonstrate how to customize the kml files and other various operations on it. + This file is part of mss. + + :copyright: Copyright 2021 Hrithik Kumar Verma + :copyright: Copyright 2021 by the mss team, see AUTHORS. + :license: APACHE-2.0, see LICENSE for details. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +import pyautogui as pag +import multiprocessing +import sys +import os.path +from sys import platform + +from pyscreeze import ImageNotFoundException + +from tutorials import screenrecorder as sr +from mslib.msui import mss_pyui + + +def initial_ops(): + """ + Executes the initial operations such as closing all opened windows and showing the desktop. + """ + pag.sleep(5) + if platform == "linux" or platform == "linux2": + pag.hotkey('winleft', 'd') + print("\n INFO : Automation is running on Linux system..\n") + elif platform == "darwin": + pag.hotkey('option', 'command', 'm') + print("\n INFO : Automation is running on Mac OS..\n") + elif platform == "win32": + pag.hotkey('win', 'd') + print("\n INFO : Automation is running on Windows OS..\n") + else: + pag.alert(text="Sorry, no support on this platform!", title="Platform Exception", button='OK') + + +def call_recorder(): + """ + Calls the screen recorder class to start the recording of the automation. + """ + rec = sr.ScreenRecorder(80, 20, int(pag.size()[0] / 1.5), int(pag.size()[1] - 100)) + rec.capture() + rec.stop_capture() + + +def call_mss(): + """ + Calls the main MSS GUI window since operations are to be performed on it only. + """ + mss_pyui.main() + + +def automate_kml(): + """ + This is the main automating script of the MSS remote sensing tutorial which will be recorded and saved + to a file having dateframe nomenclature with a .mp4 extension(codec). + """ + # Giving time for loading of the MSS GUI. + pag.sleep(5) + + # Platform specific things + if platform == 'linux' or platform == 'linux2': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/linux/' + kml_path = 'pictures/kml_overlay/linux/' + win = 'winleft' + ctrl = 'ctrl' + elif platform == 'win32': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/win32/' + kml_path = 'pictures/kml_overlay/win32/' + win = 'win' + ctrl = 'ctrl' + elif platform == 'darwin': + enter = 'return' + wms_path = 'pictures/tutorial_wms/linux/' + kml_path = 'pictures/kml_overlay/linux/' + ctrl = 'command' + + # Satellite Predictor file path + path = os.path.normpath(os.getcwd() + os.sep + os.pardir) + kml_file_path1 = os.path.join(path, 'docs/samples/kml/folder.kml') + kml_file_path2 = os.path.join(path, 'docs/samples/kml/color.kml') + + # Maximizing the window + try: + 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) + + # Opening KML overlay dockwidget + try: + x, y = pag.locateCenterOnScreen(f'{wms_path}selecttoopencontrol.png') + pag.click(x, y, interval=2) + pag.sleep(1) + pag.press('down', presses=4, interval=1) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'select to open control\' button/option not found on the screen.") + + # Removing all the files present + try: + x, y = pag.locateCenterOnScreen(f'{kml_path}select_all_files.png') + pag.sleep(1) + pag.click(x, y, duration=2) + pag.sleep(3) + # Clicking on Remove Files + try: + x1, y1 = pag.locateCenterOnScreen(f'{kml_path}remove_files.png') + pag.sleep(1) + pag.click(x1, y1, duration=1) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Remove Files\' button not found on the screen.") + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Select All Files\' button not found on the screen.") + + # Adding the KML files and loading them + try: + x, y = pag.locateCenterOnScreen(f'{kml_path}add_kml_files.png') + pag.click(x, y, duration=2) + pag.sleep(1) + pag.typewrite(kml_file_path1, interval=0.1) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + + pag.click(x, y, duration=2) + pag.sleep(1) + pag.typewrite(kml_file_path2, interval=0.1) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Add KML Files\' button not found on the screen.") + + # Unselecting and Selecting Files to demonstrate visibility on the map. + try: + x, y = pag.locateCenterOnScreen(f'{kml_path}unselect_all_files.png') + pag.click(x, y, duration=2) + pag.sleep(2) + try: + x1, y1 = pag.locateCenterOnScreen(f'{kml_path}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 :\'Unselect All Files(Unselecting & Selecting)\' button not found on the screen.") + + # Selecting and Customizing the Folder.kml file + try: + x, y = pag.locateCenterOnScreen(f'{kml_path}kmloverlay.png') + pag.click(x + 100, y + 20, duration=2) + pag.sleep(4) + try: + # Changing color of folder.kml file + x1, y1 = pag.locateCenterOnScreen(f'{kml_path}changecolor.png') + pag.click(x1, y1, duration=2) + pag.sleep(4) + x2, y2 = pag.locateCenterOnScreen(f'{kml_path}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(f'{kml_path}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.") + try: + # Changing Linewidth of folder.kml file + x1, y1 = pag.locateCenterOnScreen(f'{kml_path}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.") + + # Selecting and Customizing the color.kml file + pag.click(x + 100, y + 38, duration=2) + pag.sleep(2) + + # Changing map to Global + try: + if platform == 'linux' or platform == 'linux2' or platform == '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) + 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") + + try: + # Changing color of color.kml file + x1, y1 = pag.locateCenterOnScreen(f'{kml_path}changecolor.png') + pag.click(x1, y1, duration=2) + pag.sleep(4) + x2, y2 = pag.locateCenterOnScreen(f'{kml_path}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(f'{kml_path}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 + pag.click(x1 + 12, y1 + 50, duration=2) + pag.sleep(4) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('6.53', interval=1) + pag.sleep(1) + pag.press(enter) + pag.sleep(3) + + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('3.45', interval=1) + pag.sleep(1) + pag.press(enter) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Change Color(Color.kml file)\' button not found on the screen.") + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'KML Overlay\' fixed text not found on the screen.") + + print("\nAutomation is over for this tutorial. Watch next tutorial for other functions.") + + # Close Everything! + try: + 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) + pag.press('left') + pag.sleep(3) + pag.press('enter') + pag.sleep(2) + pag.hotkey('alt', 'tab') + pag.press('q') + elif platform == 'darwin': + for _ in range(2): + pag.hotkey('command', 'w') + pag.sleep(3) + pag.press('left') + pag.sleep(3) + pag.press('return') + pag.sleep(2) + pag.hotkey('command', 'tab') + pag.press('q') + except Exception: + print("Cannot automate : Enable Shortcuts for your system or try again") + + +def main(): + """ + This function runs the above functions as different processes at the same time and can be + controlled from here. (This is the main process.) + """ + p1 = multiprocessing.Process(target=call_mss) + p2 = multiprocessing.Process(target=automate_kml) + p3 = multiprocessing.Process(target=call_recorder) + + print("\nINFO : Starting Automation.....\n") + p3.start() + pag.sleep(3) + initial_ops() + p1.start() + p2.start() + + p2.join() + p1.join() + p3.join() + print("\n\nINFO : Automation Completes Successfully!") + sys.exit() + + +if __name__ == '__main__': + main() diff --git a/tutorials/tutorial_performancesettings.py b/tutorials/tutorial_performancesettings.py new file mode 100644 index 000000000..6f5468794 --- /dev/null +++ b/tutorials/tutorial_performancesettings.py @@ -0,0 +1,275 @@ +""" + mss.tutorials.tutorial_performancesettings + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + This python script generates an automatic demonstration of how to change the performance of flight track in table + view such as managing fuel capacity, etc. + This file is part of mss. + + :copyright: Copyright 2021 Hrithik Kumar Verma + :copyright: Copyright 2021 by the mss team, see AUTHORS. + :license: APACHE-2.0, see LICENSE for details. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +import pyautogui as pag +import multiprocessing +import sys +import os.path +from sys import platform + +from pyscreeze import ImageNotFoundException + +from tutorials import screenrecorder as sr +from mslib.msui import mss_pyui + + +def initial_ops(): + """ + Executes the initial operations such as closing all opened windows and showing the desktop. + """ + pag.sleep(5) + if platform == "linux" or platform == "linux2": + pag.hotkey('winleft', 'd') + print("\n INFO : Automation is running on Linux system..\n") + elif platform == "darwin": + pag.hotkey('option', 'command', 'm') + print("\n INFO : Automation is running on Mac OS..\n") + elif platform == "win32": + pag.hotkey('win', 'd') + print("\nINFO : Automation is running on Windows OS..\n") + else: + pag.alert(text="Sorry, no support on this platform!", title="Platform Exception", button='OK') + + +def call_recorder(): + """ + Calls the screen recorder class to start the recording of the automation. + """ + rec = sr.ScreenRecorder(80, 80, int(pag.size()[0]) - 400, int(pag.size()[1]) - 150) + rec.capture() + rec.stop_capture() + + +def call_mss(): + """ + Calls the main MSS GUI window since operations are to be performed on it only. + """ + mss_pyui.main() + + +def automate_performance(): + """ + This is the main automating script of the performance settings of table view tutorial which will be recorded and + saved to a file having dateframe nomenclature with a .mp4 extension(codec). + """ + # Giving time for loading of the MSS GUI. + pag.sleep(5) + + # Platform specific things + if platform == 'linux' or platform == 'linux2': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/linux/' + ps_path = 'pictures/performance_settings/linux/' + win = 'winleft' + ctrl = 'ctrl' + elif platform == 'win32': + enter = 'enter' + wms_path = 'pictures/tutorial_wms/win32/' + ps_path = 'pictures/performance_settings/linux/' + win = 'win' + ctrl = 'ctrl' + elif platform == 'darwin': + enter = 'return' + wms_path = 'pictures/tutorial_wms/linux/' + ps_path = 'pictures/performance_settings/linux/' + ctrl = 'command' + + # Satellite Predictor file path + path = os.path.normpath(os.getcwd() + os.sep + os.pardir) + ps_file_path = os.path.join(path, 'docs/samples/config/mss/performance_simple.json') + + # Maximizing the window + try: + 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', 't') + pag.sleep(3) + + # Opening Performance Settings dockwidget + try: + x, y = pag.locateCenterOnScreen(f'{wms_path}selecttoopencontrol.png') + # Relocating the table view window + pag.moveTo(x, y - 462, duration=1) + if platform == 'linux' or platform == 'linux2': + pag.dragRel(10, 100, duration=3) + elif platform == 'win32' or platform == 'darwin': + pag.dragRel(10, 10, duration=2) + pag.sleep(2) + x, y = pag.locateCenterOnScreen(f'{wms_path}selecttoopencontrol.png') + pag.click(x, y, interval=2) + pag.sleep(1) + pag.press('down', presses=2, interval=1) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'select to open control\' button/option not found on the screen.") + + # Exploring through the file system and loading the performance settings json file for a dummy aircraft. + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}select.png') + pag.click(x, y, duration=2) + pag.sleep(1) + pag.typewrite(ps_file_path, interval=0.1) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Select\' button (for loading performance_settings.json file) not found on the screen.") + + # Checking the Show Performance checkbox to display the settings file in the table view + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}show_performance.png') + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Show Performance\' checkbox not found on the screen.") + + # Changing the maximum take off weight + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}maximum_takeoff_weight.png') + pag.click(x + 318, y, duration=2) + pag.sleep(4) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('87000', interval=0.3) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Maximum Takeoff Weight\' fill box not found on the screen.") + + # Changing the aircraft weight of the dummy aircraft + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}aircraft_weight.png') + pag.click(x + 300, y, duration=2) + pag.sleep(4) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + pag.typewrite('48000', interval=0.3) + pag.sleep(1) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Aircraft weight\' fill box not found on the screen.") + + # Changing the take off time of the dummy aircraft + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}take_off_time.png') + pag.click(x + 410, y, duration=2) + pag.sleep(4) + pag.hotkey(ctrl, 'a') + pag.sleep(1) + for _ in range(5): + pag.press('up') + pag.sleep(2) + pag.typewrite('04', interval=0.5) + pag.press(enter) + pag.sleep(2) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Take off time\' fill box not found on the screen.") + + # Showing and hiding the performance settings + try: + x, y = pag.locateCenterOnScreen(f'{ps_path}show_performance.png') + pag.click(x, y, duration=2) + pag.sleep(3) + + pag.click(x, y, duration=2) + pag.sleep(3) + + pag.click(x, y, duration=2) + pag.sleep(3) + except (ImageNotFoundException, OSError, Exception): + print("\nException :\'Show Performance\' checkbox not found on the screen.") + + print("\nAutomation is over for this tutorial. Watch next tutorial for other functions.") + + # Close Everything! + try: + 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) + pag.press('left') + pag.sleep(3) + pag.press('enter') + pag.sleep(2) + pag.hotkey('alt', 'tab') + pag.press('q') + elif platform == 'darwin': + for _ in range(2): + pag.hotkey('command', 'w') + pag.sleep(3) + pag.press('left') + pag.sleep(3) + pag.press('return') + pag.sleep(2) + pag.hotkey('command', 'tab') + pag.press('q') + except Exception: + print("Cannot automate : Enable Shortcuts for your system or try again") + + +def main(): + """ + This function runs the above functions as different processes at the same time and can be + controlled from here. (This is the main process.) + """ + p1 = multiprocessing.Process(target=call_mss) + p2 = multiprocessing.Process(target=automate_performance) + p3 = multiprocessing.Process(target=call_recorder) + + print("\nINFO : Starting Automation.....\n") + p3.start() + pag.sleep(3) + initial_ops() + p1.start() + p2.start() + + p2.join() + p1.join() + p3.join() + print("\n\nINFO : Automation Completes Successfully!") + sys.exit() + + +if __name__ == '__main__': + main() diff --git a/tutorials/tutorial_remotesensing.py b/tutorials/tutorial_remotesensing.py index 4dbe50525..a661510f7 100644 --- a/tutorials/tutorial_remotesensing.py +++ b/tutorials/tutorial_remotesensing.py @@ -1,6 +1,6 @@ """ mss.tutorials.tutorial_remotesensing - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script generates an automatic demonstration of how to work with remote sensing tool in topview. This file is part of mss. @@ -55,7 +55,7 @@ def call_recorder(): """ Calls the screen recorder class to start the recording of the automation. """ - rec = sr.ScreenRecorder(0, 0, int(pag.size()[0] / 1.5), int(pag.size()[1])) + rec = sr.ScreenRecorder(80, 20, int(pag.size()[0] / 1.5), int(pag.size()[1])) rec.capture() rec.stop_capture() @@ -288,7 +288,6 @@ def automate_rs(): pag.press('q') except Exception: print("Cannot automate : Enable Shortcuts for your system or try again") - pag.press('q') def main(): diff --git a/tutorials/tutorial_satellitetrack.py b/tutorials/tutorial_satellitetrack.py index 2794a6dd7..211a8da55 100644 --- a/tutorials/tutorial_satellitetrack.py +++ b/tutorials/tutorial_satellitetrack.py @@ -1,6 +1,6 @@ """ mss.tutorials.tutorial_satellitetrack - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script generates an automatic demonstration of how to work with remote sensing tool in topview. This file is part of mss. @@ -56,7 +56,7 @@ def call_recorder(): """ Calls the screen recorder class to start the recording of the automation. """ - rec = sr.ScreenRecorder(0, 0, int(pag.size()[0] / 1.5) - 100, int(pag.size()[1] - 100)) + rec = sr.ScreenRecorder(80, 20, int(pag.size()[0] / 1.5) - 100, int(pag.size()[1] - 100)) rec.capture() rec.stop_capture() @@ -229,7 +229,6 @@ def automate_rs(): pag.press('q') except Exception: print("Cannot automate : Enable Shortcuts for your system or try again") - pag.press('q') def main(): diff --git a/tutorials/tutorial_views.py b/tutorials/tutorial_views.py index 7de8d9a71..b996bcf3b 100644 --- a/tutorials/tutorial_views.py +++ b/tutorials/tutorial_views.py @@ -1,6 +1,6 @@ """ mss.tutorials.tutorial_views - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script generates an automatic demonstration of how to use the top view, side view, table view and linear view section of Mission Support System in creating a project and planning the flightrack. diff --git a/tutorials/tutorial_waypoints.py b/tutorials/tutorial_waypoints.py index ab16ae77b..6949ae30a 100644 --- a/tutorials/tutorial_waypoints.py +++ b/tutorials/tutorial_waypoints.py @@ -1,6 +1,6 @@ """ mss.tutorials.tutorial_waypoints - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script generates an automatic demonstration of how to play with and use waypoints for activating/creating a flight track. diff --git a/tutorials/tutorial_wms.py b/tutorials/tutorial_wms.py index 75323d698..8f6061db8 100644 --- a/tutorials/tutorial_wms.py +++ b/tutorials/tutorial_wms.py @@ -1,6 +1,6 @@ """ mss.tutorials.tutorial_wms - ~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~ This python script generates an automatic demonstration of how to use the web map service section of Mission Support System and plan flighttracks accordingly.