Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in view (q)settings handling #1705

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 12 additions & 37 deletions mslib/msui/linearview.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
limitations under the License.
"""

from mslib.utils.config import config_loader, save_settings_qsettings, load_settings_qsettings
from mslib.utils.config import config_loader
from PyQt5 import QtGui, QtWidgets
from mslib.utils.qt import ui_linearview_window as ui
from mslib.utils.qt import ui_linearview_options as ui_opt
Expand All @@ -42,7 +42,7 @@ class MSUI_LV_Options_Dialog(QtWidgets.QDialog, ui_opt.Ui_LinearViewOptionsDialo
Dialog class to specify Linear View Options.
"""

def __init__(self, parent=None, settings_dict=None):
def __init__(self, parent=None, settings=None):
"""
Arguments:
parent -- Qt widget that is parent to this widget.
Expand All @@ -51,33 +51,26 @@ def __init__(self, parent=None, settings_dict=None):
super(MSUI_LV_Options_Dialog, self).__init__(parent)
self.setupUi(self)

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

if settings_dict is not None:
default_settings_dict.update(settings_dict)
settings_dict = default_settings_dict
assert settings is not None

for i in range(self.lv_cbtitlesize.count()):
if self.lv_cbtitlesize.itemText(i) == settings_dict["plot_title_size"]:
if self.lv_cbtitlesize.itemText(i) == settings["plot_title_size"]:
self.lv_cbtitlesize.setCurrentIndex(i)

for i in range(self.lv_cbaxessize.count()):
if self.lv_cbaxessize.itemText(i) == settings_dict["axes_label_size"]:
if self.lv_cbaxessize.itemText(i) == settings["axes_label_size"]:
self.lv_cbaxessize.setCurrentIndex(i)

def get_settings(self):
"""
Returns the specified settings from the GUI elements.
"""
settings_dict = {
settings = {
"plot_title_size": self.lv_cbtitlesize.currentText(),
"axes_label_size": self.lv_cbaxessize.currentText()
}

return settings_dict
return settings


class MSUILinearViewWindow(MSUIMplViewWindow, ui.Ui_LinearWindow):
Expand All @@ -101,15 +94,12 @@ def __init__(self, parent=None, model=None, _id=None):

self.setFlightTrackModel(model)

self.settings_tag = "linearview"
self.load_settings()

# Connect slots and signals.
# ==========================

# 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,26 +137,11 @@ def setFlightTrackModel(self, model):
if self.docks[WMS] is not None:
self.docks[WMS].widget().setFlightTrackModel(model)

def set_options(self):
settings = self.getView().plotter.get_settings()
dlg = MSUI_LV_Options_Dialog(parent=self, settings_dict=settings)
def open_settings_dialog(self):
settings = self.getView().get_settings()
dlg = MSUI_LV_Options_Dialog(parent=self, settings=settings)
dlg.setModal(True)
if dlg.exec_() == QtWidgets.QDialog.Accepted:
settings = dlg.get_settings()
self.getView().plotter.set_settings(settings)
self.save_settings()
self.getView().plotter.set_settings(settings, save=True)
dlg.destroy()

def save_settings(self):
"""
Save the current settings of plot options to the file self.settingsfile.
"""
settings = self.getView().plotter.get_settings()
save_settings_qsettings(self.settings_tag, settings)

def load_settings(self):
"""
Load settings from the file self.settingsfile.
"""
settings = load_settings_qsettings(self.settings_tag)
self.getView().plotter.set_settings(settings)
Loading