diff --git a/mslib/msui/autoplot_dockwidget.py b/mslib/msui/autoplot_dockwidget.py index 156756cce..642915624 100644 --- a/mslib/msui/autoplot_dockwidget.py +++ b/mslib/msui/autoplot_dockwidget.py @@ -29,6 +29,7 @@ import os import json +import logging from datetime import datetime import click @@ -196,9 +197,19 @@ def download_plots_cli(self, config_settings): } # Invoke the main method using click from the mssautoplot - ctx = click.Context(cli_tool) - ctx.obj = self - ctx.invoke(cli_tool, **args) + try: + ctx = click.Context(cli_tool) + ctx.obj = self + ctx.invoke(cli_tool, **args) + except SystemExit as ex: + logging.error("Can't find given data: %s", ex) + QMessageBox.information( + self, + "Error", + ex.args[0] + ) + ctx.obj = None + return def autoplotSecsTreeWidget_selected_row(self): selected_items = self.autoplotSecsTreeWidget.selectedItems() diff --git a/mslib/utils/mssautoplot.py b/mslib/utils/mssautoplot.py index 6e9077471..e9be77dcf 100644 --- a/mslib/utils/mssautoplot.py +++ b/mslib/utils/mssautoplot.py @@ -26,7 +26,6 @@ """ import os -import sys import io import re import json @@ -196,7 +195,7 @@ def get_op_id(msc_url, token, op_name): class Plotting: - def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, password=None): + def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, password=None, pdlg=None): """ Initialize the Plotting object with the provided parameters. @@ -208,6 +207,7 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p :password: User's password """ read_config_file(cpath) + self.pdlg = pdlg self.config = config_loader() self.num_interpolation_points = self.config["num_interpolation_points"] self.num_labels = self.config["num_labels"] @@ -222,21 +222,23 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p self.config["predefined_map_sections"][section]["CRS"].lower()) except KeyError as e: print(e) - sys.exit("Invalid SECTION and/or CRS") + raise SystemExit("Invalid SECTION and/or CRS") self.params["basemap"].update(self.config["predefined_map_sections"][section]["map"]) self.bbox_units = self.params["bbox"] if filename != "" and filename == flight: self.read_operation(flight, msc_url, msc_auth_password, username, password) elif filename != "": + # Todo add the dir to the file in the mssautoplot.json + dirpath = "./" + file_path = os.path.join(dirpath, filename) + exists = os.path.exists(file_path) + if not exists: + print("Filename {} doesn't exist".format(filename)) + self.pdlg.close() + raise SystemExit("Filename {} doesn't exist".format(filename)) self.read_ftml(filename) def read_ftml(self, filename): - dirpath = "./" - file_path = os.path.join(dirpath, filename) - exists = os.path.exists(file_path) - if not exists: - print("Filename {} doesn't exist".format(filename)) - sys.exit() self.wps, self.wp_model_data = load_from_ftml(filename) self.wp_lats, self.wp_lons, self.wp_locs = [[x[i] for x in self.wps] for i in [0, 1, 3]] self.wp_press = [mslib.utils.thermolib.flightlevel2pressure(wp[2] * units.hft).to("Pa").m for wp in self.wps] @@ -262,8 +264,9 @@ def read_operation(self, op_name, msc_url, msc_auth_password, username, password class TopViewPlotting(Plotting): - def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password): - super(TopViewPlotting, self).__init__(cpath, msc_url, msc_auth_password, msc_username, msc_password) + def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg): + super(TopViewPlotting, self).__init__(cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg) + self.pdlg = pdlg self.myfig = qt.TopViewPlotter() self.myfig.fig.canvas.draw() self.fig, self.ax = self.myfig.fig, self.myfig.ax @@ -342,9 +345,10 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, class SideViewPlotting(Plotting): - def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password): + def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg): # ToDo Implement access to MSColab - super(SideViewPlotting, self).__init__(cpath) + super(SideViewPlotting, self).__init__(cpath, pdlg) + self.pdlg = pdlg self.myfig = qt.SideViewPlotter() self.ax = self.myfig.ax self.fig = self.myfig.fig @@ -384,7 +388,7 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, self.update_path(filename) except AttributeError as e: logging.debug(e) - sys.exit("No FLIGHT Selected") + raise SystemExit("No FLIGHT Selected") width, height = self.myfig.get_plot_size_in_px() p_bot, p_top = [float(x) * 100 for x in vertical.split(",")] self.bbox = tuple([x for x in (self.num_interpolation_points, @@ -496,7 +500,11 @@ def draw(self): @click.option('--etime', default="", help='Ending time for downloading multiple plots with a fixed interval.') @click.pass_context def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime): + def close_process_dialog(pdlg): + pdlg.close() + if ctx.obj is not None: + # ToDo find a simpler solution, on a split of the package, QT is expensive for such a progressbar pdlg = QProgressDialog("Downloading images", "Cancel", 0, 10, parent=ctx.obj) pdlg.setMinimumDuration(0) pdlg.repaint() @@ -527,17 +535,14 @@ def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime): # Choose view (top or side) if view == "top": - top_view = TopViewPlotting(cpath, msc_url, msc_auth_password, msc_username, msc_password) + top_view = TopViewPlotting(cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg) sec = "automated_plotting_hsecs" else: - side_view = SideViewPlotting(cpath, msc_url, msc_auth_password, msc_username, msc_password) + side_view = SideViewPlotting(cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg) sec = "automated_plotting_vsecs" if ctx.obj is not None: pdlg.setValue(2) - def close_process_dialog(pdlg): - pdlg.close() - def draw(no_of_plots): try: if view == "top":