Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mslib/msui/autoplot_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def configure_from_path(self, parent, config_settings):
self.resize_treewidgets()

def add_to_treewidget(self, parent, parent2, config_settings, treewidget, flight, sections, vertical, filename,
itime, vtime, url, layer, styles, level):
itime, vtime, url, layer, styles, level):
if treewidget.objectName() == "autoplotTreeWidget":
if self.autoplotSecsTreeWidget.topLevelItemCount() == 0:
QMessageBox.information(
Expand All @@ -302,7 +302,9 @@ def add_to_treewidget(self, parent, parent2, config_settings, treewidget, flight
flight = ""
else:
if filename != parent2.mscolab.active_operation_name:
filename += ".ftml"
filename = os.path.join(const.MSUI_CONFIG_PATH, filename + ".ftml")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you do "save as" the used directory is stored at
https://github.com/Open-MSS/MSS/blob/develop/mslib/msui/msui_mainwindow.py#L946

self.last_save_directory

You need to enable access to the var and use it then. We need the dir where the file is stored by File - Save_As

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can pass it into the topview and from there to the dockingwidget, see https://github.com/Open-MSS/MSS/blob/develop/mslib/msui/msui_mainwindow.py#L1029

else:
filename = os.path.join(const.MSUI_CONFIG_PATH, filename + ".ftml")
item = QTreeWidgetItem([flight, sections, vertical, filename, itime, vtime])
self.autoplotTreeWidget.addTopLevelItem(item)
self.autoplotTreeWidget.setCurrentItem(item)
Expand Down Expand Up @@ -330,13 +332,15 @@ def add_to_treewidget(self, parent, parent2, config_settings, treewidget, flight
self.resize_treewidgets()

def update_treewidget(self, parent, parent2, config_settings, treewidget, flight, sections, vertical, filename,
itime, vtime, url, layer, styles, level):
itime, vtime, url, layer, styles, level):
if flight.startswith("new flight track"):
filename = ""
flight = ""
else:
if filename != parent2.mscolab.active_operation_name:
filename += ".ftml"
filename = os.path.join(const.MSUI_CONFIG_PATH, filename + ".ftml")
else:
filename = os.path.join(const.MSUI_CONFIG_PATH, filename + ".ftml")
if treewidget.objectName() == "autoplotTreeWidget":
selected_item = self.autoplotTreeWidget.currentItem()
selected_item.setText(0, flight)
Expand Down
69 changes: 41 additions & 28 deletions mslib/utils/mssautoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def load_from_operation(op_name, msc_url, msc_auth_password, username, password)
msc_auth = ("mscolab", msc_auth_password)
session.auth = msc_auth
session.headers.update({'x-test': 'true'})
# ToDp fix config_loader it gets a list of two times the entry
response = session.get(urljoin(msc_url, 'status'), timeout=tuple(config_loader(dataset="MSCOLAB_timeout")[0]))
response = session.get(urljoin(msc_url, 'status'), timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
session.close()
if response.status_code == 401:
logging.error("Error", 'Server authentication data were incorrect.')
Expand All @@ -119,8 +118,7 @@ def load_from_operation(op_name, msc_url, msc_auth_password, username, password)
session.headers.update({'x-test': 'true'})
url = urljoin(msc_url, "token")
try:
# ToDp fix config_loader it gets a list of two times the entry
response = session.post(url, data=data, timeout=tuple(config_loader(dataset="MSCOLAB_timeout")[0]))
response = session.post(url, data=data, timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
response.raise_for_status()
except requests.exceptions.RequestException as ex:
logging.error("unexpected error: %s %s %s", type(ex), url, ex)
Expand Down Expand Up @@ -158,7 +156,7 @@ def get_xml_data(msc_url, token, op_id):
"op_id": op_id
}
url = urljoin(msc_url, "get_operation_by_id")
r = requests.get(url, data=data)
r = requests.get(url, data=data, timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
if r.text != "False":
xml_content = json.loads(r.text)["content"]
return xml_content
Expand Down Expand Up @@ -187,7 +185,7 @@ def get_op_id(msc_url, token, op_name):
"skip_archived": skip_archived
}
url = urljoin(msc_url, "operations")
r = requests.get(url, data=data)
r = requests.get(url, data=data, timeout=tuple(config_loader(dataset="MSCOLAB_timeout")))
if r.text != "False":
_json = json.loads(r.text)
operations = _json["operations"]
Expand Down Expand Up @@ -218,6 +216,10 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p
flight = self.config["automated_plotting_flights"][0][0]
section = self.config["automated_plotting_flights"][0][1]
filename = self.config["automated_plotting_flights"][0][3]
config_dir = os.path.dirname(os.path.expanduser(cpath))
if filename and not os.path.isabs(filename):
filename = os.path.join(config_dir, filename)
logging.debug("Resolved filename: %s", filename)
if self.__class__.__name__ == "TopViewPlotting":
try:
self.params = get_projection_params(self.config["predefined_map_sections"][section]["CRS"].lower())
Expand All @@ -234,15 +236,13 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p
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))
if not os.path.exists(filename):
print(f"FTML file {filename} does not exist")
if self.pdlg:
self.pdlg.close()
raise SystemExit(f"FTML file {filename} does not exist")
self.read_ftml(filename)
print(filename)

def setup(self):
pass
Expand Down Expand Up @@ -589,42 +589,55 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer,
@click.option('--stime', default="", help='Starting time for downloading multiple plots with a fixed interval.')
@click.option('--etime', default="", help='Ending time for downloading multiple plots with a fixed interval.')
@click.option('--raw', default=False, help='Saves the raw image with its projection in topview')
@click.option('--ftml-path', default="", help='Override the FTML file path from the configuration.')
@click.pass_context
def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime, raw):
def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime, raw, ftml_path):
pdlg = None

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()
pdlg.canceled.connect(lambda: close_process_dialog(pdlg))
pdlg.setWindowModality(Qt.WindowModal)
pdlg.setAutoReset(True) # Close dialog automatically when reaching max value
pdlg.setAutoClose(True) # Automatically close when value reaches maximum
pdlg.setValue(0) # Initial progress value

# Set window flags to ensure visibility and modality
pdlg.setAutoReset(True)
pdlg.setAutoClose(True)
pdlg.setValue(0)
pdlg.setWindowFlags(pdlg.windowFlags() | Qt.CustomizeWindowHint | Qt.WindowTitleHint)

pdlg.setValue(0)

conf.read_config_file(path=cpath)
config = conf.config_loader()

# flight_name = config["automated_plotting_flights"][0][0]
# file = config["automated_plotting_flights"][0][3]
if ftml_path:
# Override the FTML file path in the configuration
if not os.path.exists(ftml_path):
print(f"Provided FTML file path {ftml_path} does not exist")
if ctx.obj is not None:
pdlg.close()
raise SystemExit(f"Provided FTML file path {ftml_path} does not exist")
config["automated_plotting_flights"][0][3] = ftml_path

if ctx.obj is not None:
pdlg.setValue(1)

msc_url = config["mscolab_server_url"]
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=msc_url, username=msc_username)
try:
msc_auth_password = mslib.utils.auth.get_password_from_keyring(service_name=f"MSCOLAB_AUTH_{msc_url}",
username="mscolab")
except KeyError:
msc_auth_password = None

try:
msc_username = config["MSS_auth"][msc_url]
except KeyError:
msc_username = None
msc_password = None
if msc_username is not None:
msc_password = mslib.utils.auth.get_password_from_keyring(service_name=msc_url, username=msc_username)

# Choose view (top or side)
if view == "top":
Expand Down