Skip to content

Commit

Permalink
Made handling and storing of (q)settings more consistent
Browse files Browse the repository at this point in the history
* consistent naming of dialogs
* consistent naming of settings
* move of load/store to one base class
* move of default settings to global, private variables for simpler
  (testing) access
  • Loading branch information
joernu76 committed Mar 20, 2023
1 parent 6b25391 commit 55ff493
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 186 deletions.
4 changes: 2 additions & 2 deletions mslib/msui/linearview.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(self, parent=None, model=None, _id=None):

# Tool opener.
self.cbTools.currentIndexChanged.connect(self.openTool)
self.lvoptionbtn.clicked.connect(self.set_options)
self.lvoptionbtn.clicked.connect(self.open_settings_dialog)

self.openTool(WMS + 1)

Expand Down Expand Up @@ -147,7 +147,7 @@ def setFlightTrackModel(self, model):
if self.docks[WMS] is not None:
self.docks[WMS].widget().setFlightTrackModel(model)

def set_options(self):
def open_settings_dialog(self):
settings = self.getView().plotter.get_settings()
dlg = MSUI_LV_Options_Dialog(parent=self, settings_dict=settings)
dlg.setModal(True)
Expand Down
129 changes: 73 additions & 56 deletions mslib/msui/mpl_qtwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

from mslib.utils.thermolib import convert_pressure_to_vertical_axis_measure
from mslib.utils import thermolib, FatalUserError
from mslib.utils.config import config_loader
from mslib.utils.config import config_loader, save_settings_qsettings, load_settings_qsettings
from mslib.utils.units import units
from mslib.msui import mpl_pathinteractor as mpl_pi
from mslib.msui import mpl_map
Expand All @@ -56,12 +56,51 @@

matplotlib.rcParams['savefig.directory'] = LAST_SAVE_DIRECTORY

_DEFAULT_SETTINGS_TOPVIEW = {
"draw_graticule": True,
"draw_coastlines": True,
"fill_waterbodies": True,
"fill_continents": True,
"draw_flighttrack": True,
"draw_marker": True,
"label_flighttrack": True,
"tov_plot_title_size": "default",
"tov_axes_label_size": "default",
"colour_water": ((153 / 255.), (255 / 255.), (255 / 255.), (255 / 255.)),
"colour_land": ((204 / 255.), (153 / 255.), (102 / 255.), (255 / 255.)),
"colour_ft_vertices": (0, 0, 1, 1),
"colour_ft_waypoints": (1, 0, 0, 1)}

_DEFAULT_SETTINGS_SIDEVIEW = {
"vertical_extent": (1050, 180),
"vertical_axis": "pressure",
"secondary_axis": "no secondary axis",
"plot_title_size": "default",
"axes_label_size": "default",
"flightlevels": [],
"draw_flightlevels": True,
"draw_flighttrack": True,
"fill_flighttrack": True,
"label_flighttrack": True,
"draw_verticals": True,
"draw_marker": True,
"draw_ceiling": True,
"colour_ft_vertices": (0, 0, 1, 1),
"colour_ft_waypoints": (1, 0, 0, 1),
"colour_ft_fill": (0, 0, 1, 0.15),
"colour_ceiling": (0, 0, 1, 0.15)}

_DEFAULT_SETTINGS_LINEARVIEW = {
"plot_title_size": "default",
"axes_label_size": "default"}


class ViewPlotter:
def __init__(self, fig=None, ax=None):
def __init__(self, fig=None, ax=None, settings_tag=None, settings=None):
# setup Matplotlib Figure and Axis
self.fig, self.ax = fig, ax
self.settings = {}
self.settings = settings
self.settings_tag = settings_tag
if self.fig is None:
assert ax is None
self.fig = figure.Figure(facecolor="w") # 0.75
Expand Down Expand Up @@ -115,19 +154,27 @@ def get_settings(self):
"""
return self.settings

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""Update local settings influencing the plotting
Args:
settings (dict): Dictionary of string/value pairs
"""
if settings is not None:
self.settings.update(settings)
if save:
self.save_settings()

def load_settings(self):
self.settings = load_settings_qsettings(self.settings_tag, self.settings)

def save_settings(self):
save_settings_qsettings(self.settings_tag, self.settings)


class TopViewPlotter(ViewPlotter):
def __init__(self, fig=None, ax=None):
super().__init__(fig, ax)
def __init__(self, fig=None, ax=None, settings=None):
super().__init__(fig, ax, settings_tag="topview", settings=_DEFAULT_SETTINGS_TOPVIEW)
self.map = None
self.legimg = None
self.legax = None
Expand All @@ -136,20 +183,8 @@ def __init__(self, fig=None, ax=None):
self.tov_als = None
# Sets the default fontsize parameters' values for topview from MSSDefaultConfig.
self.topview_size_settings = config_loader(dataset="topview")
# logging.debug("applying map appearance settings %s." % settings)
self.set_settings({"draw_graticule": True,
"draw_coastlines": True,
"fill_waterbodies": True,
"fill_continents": True,
"draw_flighttrack": True,
"draw_marker": True,
"label_flighttrack": True,
"tov_plot_title_size": "default",
"tov_axes_label_size": "default",
"colour_water": ((153 / 255.), (255 / 255.), (255 / 255.), (255 / 255.)),
"colour_land": ((204 / 255.), (153 / 255.), (102 / 255.), (255 / 255.)),
"colour_ft_vertices": (0, 0, 1, 1),
"colour_ft_waypoints": (1, 0, 0, 1)})
self.load_settings()
self.set_settings(settings)
self.ax.figure.canvas.draw()

def init_map(self, **kwargs):
Expand Down Expand Up @@ -196,11 +231,11 @@ def clear_figure(self):
self.ax.set_title("Top view", horizontalalignment="left", x=0)
self.ax.figure.canvas.draw()

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""Apply settings from dictionary 'settings' to the view.
If settings is None, apply default settings.
"""
super().set_settings(settings)
super().set_settings(settings, save)

# Stores the exact value of fontsize for topview plot title size(tov_pts)
self.tov_pts = (self.topview_size_settings["plot_title_size"]
Expand Down Expand Up @@ -327,26 +362,8 @@ def __init__(self, fig=None, ax=None, settings=None, numlabels=None, num_interpo
numlabels = config_loader(dataset='num_labels')
if num_interpolation_points is None:
num_interpolation_points = config_loader(dataset='num_interpolation_points')
super().__init__(fig, ax)

# Default settings.
self.set_settings({"vertical_extent": (1050, 180),
"vertical_axis": "pressure",
"secondary_axis": "no secondary axis",
"plot_title_size": "default",
"axes_label_size": "default",
"flightlevels": [],
"draw_flightlevels": True,
"draw_flighttrack": True,
"fill_flighttrack": True,
"label_flighttrack": True,
"draw_verticals": True,
"draw_marker": True,
"draw_ceiling": True,
"colour_ft_vertices": (0, 0, 1, 1),
"colour_ft_waypoints": (1, 0, 0, 1),
"colour_ft_fill": (0, 0, 1, 0.15),
"colour_ceiling": (0, 0, 1, 0.15)})
super().__init__(fig, ax, settings_tag="sideview", settings=_DEFAULT_SETTINGS_SIDEVIEW)
self.load_settings()
self.set_settings(settings)

self.numlabels = numlabels
Expand Down Expand Up @@ -604,17 +621,19 @@ class LinearViewPlotter(ViewPlotter):
flight track / list of waypoints.
"""

def __init__(self, model=None, numlabels=None):
def __init__(self, model=None, numlabels=None, settings=None):
"""
Arguments:
model -- WaypointsTableModel defining the linear section.
"""
if numlabels is None:
numlabels = config_loader(dataset='num_labels')
super().__init__()
super().__init__(settings_tag="linearview", settings=_DEFAULT_SETTINGS_LINEARVIEW)
self.load_settings()

self.settings = {"plot_title_size": "default",
"axes_label_size": "default"}
# Sets the default values of plot sizes from MissionSupportDefaultConfig.
self.linearview_size_settings = config_loader(dataset="linearview")
self.set_settings(settings)

# Setup the plot.
self.numlabels = numlabels
Expand All @@ -624,8 +643,6 @@ def __init__(self, model=None, numlabels=None):
self.waypoints_model = None
self.vertical_lines = []
self.basename = "linearview"
# Sets the default values of plot sizes from MissionSupportDefaultConfig.
self.linearview_size_settings = config_loader(dataset="linearview")

def setup_linear_view(self):
"""Set up a linear section view.
Expand Down Expand Up @@ -708,12 +725,12 @@ def draw_image(self, xmls, colors=None, scales=None):

par.yaxis.label.set_color(color.replace("0x", "#"))

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""
Apply settings from options ui to the linear view
"""

super().set_settings(settings)
super().set_settings(settings, save)

pts = (self.linearview_size_settings["plot_title_size"] if self.settings["plot_title_size"] == "default"
else int(self.settings["plot_title_size"]))
Expand Down Expand Up @@ -778,11 +795,11 @@ def get_plot_size_in_px(self):
def get_settings(self):
return self.plotter.get_settings()

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""
Apply settings from options ui to the linear view
"""
self.plotter.set_settings(settings)
self.plotter.set_settings(settings, save)


def _getSaveFileName(parent, title="Choose a filename to save to", filename="test.png",
Expand Down Expand Up @@ -1251,12 +1268,12 @@ def update_ceiling(self, visible, color):
line.set_visible(visible)
self.draw()

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""Apply settings to view.
"""
old_vertical_lines = self.plotter.settings["draw_verticals"]
if settings is not None:
self.plotter.set_settings(settings)
self.plotter.set_settings(settings, save)
settings = self.plotter.get_settings()
self.set_flight_levels(settings["flightlevels"])
self.set_flight_levels_visible(settings["draw_flightlevels"])
Expand Down Expand Up @@ -1629,12 +1646,12 @@ def plot_multiple_flightpath(self, multiple_flightpath):
"""
self.multiple_flightpath = multiple_flightpath

def set_settings(self, settings):
def set_settings(self, settings, save=False):
"""Apply settings from dictionary 'settings_dict' to the view.
If settings is None, apply default settings.
"""
self.plotter.set_settings(settings)
self.plotter.set_settings(settings, save)
settings = self.get_settings()
if self.waypoints_interactor is not None:
wpi_plotter = self.waypoints_interactor.plotter
Expand Down
7 changes: 5 additions & 2 deletions mslib/msui/multiple_flightpath_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ def __init__(self, parent=None, view=None, listFlightTracks=None,
self.listFlightTracks = listFlightTracks
self.mscolab_server_url = mscolab_server_url
self.token = token
self.ft_settings_dict = self.ui.get_settings()
self.color = (0, 0, 1, 1)
if self.ui is not None:
ft_settings_dict = self.ui.getView().get_settings()
self.color = ft_settings_dict["colour_ft_vertices"]
else:
self.color = (0, 0, 1, 1)
self.obb = []

self.operation_list = False
Expand Down
Loading

0 comments on commit 55ff493

Please sign in to comment.