2626"""
2727
2828import os
29- import sys
3029import io
3130import re
3231import json
@@ -196,7 +195,7 @@ def get_op_id(msc_url, token, op_name):
196195
197196
198197class Plotting :
199- def __init__ (self , cpath , msc_url = None , msc_auth_password = None , username = None , password = None ):
198+ def __init__ (self , cpath , msc_url = None , msc_auth_password = None , username = None , password = None , pdlg = None ):
200199 """
201200 Initialize the Plotting object with the provided parameters.
202201
@@ -208,6 +207,7 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p
208207 :password: User's password
209208 """
210209 read_config_file (cpath )
210+ self .pdlg = pdlg
211211 self .config = config_loader ()
212212 self .num_interpolation_points = self .config ["num_interpolation_points" ]
213213 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
222222 self .config ["predefined_map_sections" ][section ]["CRS" ].lower ())
223223 except KeyError as e :
224224 print (e )
225- sys . exit ("Invalid SECTION and/or CRS" )
225+ raise SystemExit ("Invalid SECTION and/or CRS" )
226226 self .params ["basemap" ].update (self .config ["predefined_map_sections" ][section ]["map" ])
227227 self .bbox_units = self .params ["bbox" ]
228228 if filename != "" and filename == flight :
229229 self .read_operation (flight , msc_url , msc_auth_password , username , password )
230230 elif filename != "" :
231+ # Todo add the dir to the file in the mssautoplot.json
232+ dirpath = "./"
233+ file_path = os .path .join (dirpath , filename )
234+ exists = os .path .exists (file_path )
235+ if not exists :
236+ print ("Filename {} doesn't exist" .format (filename ))
237+ self .pdlg .close ()
238+ raise SystemExit ("Filename {} doesn't exist" .format (filename ))
231239 self .read_ftml (filename )
232240
233241 def read_ftml (self , filename ):
234- dirpath = "./"
235- file_path = os .path .join (dirpath , filename )
236- exists = os .path .exists (file_path )
237- if not exists :
238- print ("Filename {} doesn't exist" .format (filename ))
239- sys .exit ()
240242 self .wps , self .wp_model_data = load_from_ftml (filename )
241243 self .wp_lats , self .wp_lons , self .wp_locs = [[x [i ] for x in self .wps ] for i in [0 , 1 , 3 ]]
242244 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
262264
263265
264266class TopViewPlotting (Plotting ):
265- def __init__ (self , cpath , msc_url , msc_auth_password , msc_username , msc_password ):
266- super (TopViewPlotting , self ).__init__ (cpath , msc_url , msc_auth_password , msc_username , msc_password )
267+ def __init__ (self , cpath , msc_url , msc_auth_password , msc_username , msc_password , pdlg ):
268+ super (TopViewPlotting , self ).__init__ (cpath , msc_url , msc_auth_password , msc_username , msc_password , pdlg )
269+ self .pdlg = pdlg
267270 self .myfig = qt .TopViewPlotter ()
268271 self .myfig .fig .canvas .draw ()
269272 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,
342345
343346
344347class SideViewPlotting (Plotting ):
345- def __init__ (self , cpath , msc_url , msc_auth_password , msc_username , msc_password ):
348+ def __init__ (self , cpath , msc_url , msc_auth_password , msc_username , msc_password , pdlg ):
346349 # ToDo Implement access to MSColab
347- super (SideViewPlotting , self ).__init__ (cpath )
350+ super (SideViewPlotting , self ).__init__ (cpath , pdlg )
351+ self .pdlg = pdlg
348352 self .myfig = qt .SideViewPlotter ()
349353 self .ax = self .myfig .ax
350354 self .fig = self .myfig .fig
@@ -384,7 +388,7 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer,
384388 self .update_path (filename )
385389 except AttributeError as e :
386390 logging .debug (e )
387- sys . exit ("No FLIGHT Selected" )
391+ raise SystemExit ("No FLIGHT Selected" )
388392 width , height = self .myfig .get_plot_size_in_px ()
389393 p_bot , p_top = [float (x ) * 100 for x in vertical .split ("," )]
390394 self .bbox = tuple ([x for x in (self .num_interpolation_points ,
@@ -496,7 +500,11 @@ def draw(self):
496500@click .option ('--etime' , default = "" , help = 'Ending time for downloading multiple plots with a fixed interval.' )
497501@click .pass_context
498502def main (ctx , cpath , view , ftrack , itime , vtime , intv , stime , etime ):
503+ def close_process_dialog (pdlg ):
504+ pdlg .close ()
505+
499506 if ctx .obj is not None :
507+ # ToDo find a simpler solution, on a split of the package, QT is expensive for such a progressbar
500508 pdlg = QProgressDialog ("Downloading images" , "Cancel" , 0 , 10 , parent = ctx .obj )
501509 pdlg .setMinimumDuration (0 )
502510 pdlg .repaint ()
@@ -527,17 +535,14 @@ def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime):
527535
528536 # Choose view (top or side)
529537 if view == "top" :
530- top_view = TopViewPlotting (cpath , msc_url , msc_auth_password , msc_username , msc_password )
538+ top_view = TopViewPlotting (cpath , msc_url , msc_auth_password , msc_username , msc_password , pdlg )
531539 sec = "automated_plotting_hsecs"
532540 else :
533- side_view = SideViewPlotting (cpath , msc_url , msc_auth_password , msc_username , msc_password )
541+ side_view = SideViewPlotting (cpath , msc_url , msc_auth_password , msc_username , msc_password , pdlg )
534542 sec = "automated_plotting_vsecs"
535543 if ctx .obj is not None :
536544 pdlg .setValue (2 )
537545
538- def close_process_dialog (pdlg ):
539- pdlg .close ()
540-
541546 def draw (no_of_plots ):
542547 try :
543548 if view == "top" :
0 commit comments