diff --git a/mslib/msui/autoplot_dockwidget.py b/mslib/msui/autoplot_dockwidget.py index d75bd13f3..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() @@ -298,7 +309,12 @@ def add_to_treewidget(self, parent, parent2, config_settings, treewidget, flight config_settings["automated_plotting_flights"].append([flight, sections, vertical, filename, itime, vtime]) parent.refresh_signal_emit.emit() if treewidget.objectName() == "autoplotSecsTreeWidget": - if url is None: + if url == "": + QMessageBox.information( + self, + "WARNING", + "Please select the URL, layer, styles and level (row information first)" + ) return item = QTreeWidgetItem([url, layer, styles, level, self.stime, self.etime, self.intv]) self.autoplotSecsTreeWidget.addTopLevelItem(item) @@ -346,7 +362,12 @@ def update_treewidget(self, parent, parent2, config_settings, treewidget, flight parent.refresh_signal_emit.emit() if treewidget.objectName() == "autoplotSecsTreeWidget": - if url is None: + if url == "": + QMessageBox.information( + self, + "WARNING", + "Please select the URL, layer, styles and level (row information first)" + ) return selected_item = self.autoplotSecsTreeWidget.currentItem() selected_item.setText(0, url) diff --git a/mslib/utils/mssautoplot.py b/mslib/utils/mssautoplot.py index 52dd4d94d..3ac186411 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, msc_url, msc_auth_password, msc_username, msc_password) + self.pdlg = pdlg self.myfig = qt.SideViewPlotter() self.ax = self.myfig.ax self.fig = self.myfig.fig @@ -396,7 +400,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, @@ -520,7 +524,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() @@ -547,21 +555,18 @@ def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime): msc_auth_password = mslib.utils.auth.get_password_from_keyring(service_name=f"MSCOLAB_AUTH_{msc_url}", username="mscolab") msc_username = config["MSS_auth"][msc_url] - msc_password = mslib.utils.auth.get_password_from_keyring(service_name="MSCOLAB", username=msc_username) + msc_password = mslib.utils.auth.get_password_from_keyring(service_name=msc_url, username=msc_username) # 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":