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

PR: Save BRF graphs language in user configs #316

Merged
merged 7 commits into from
Sep 15, 2020
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
5 changes: 5 additions & 0 deletions gwhat/HydroCalc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ def set_wxdset(self, wxdset):
self.rechg_eval_widget.set_wxdset(wxdset)
self.draw_weather()

def close(self):
"""Close this groundwater level calc window."""
self.brf_eval_widget.close()
super().close()

# ---- MRC handlers

def btn_show_mrc_isclicked(self):
Expand Down
72 changes: 40 additions & 32 deletions gwhat/brf_mod/kgs_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg


# ---- Imports: Local

# ---- Local imports
import gwhat.common.widgets as myqt
from gwhat.widgets.layout import VSep, HSep
from gwhat.widgets.buttons import (LangToolButton, OnOffToolButton,
ExportDataButton)
from gwhat.widgets.buttons import LangToolButton, OnOffToolButton
from gwhat.common import StyleDB
from gwhat.config.main import CONF
from gwhat.utils import icons
from gwhat.utils.icons import QToolButtonNormal, QToolButtonSmall
from gwhat.utils.dates import qdatetime_from_xldate
Expand Down Expand Up @@ -131,14 +130,18 @@ class BRFManager(myqt.QFrameLayout):
def __init__(self, wldset=None, parent=None):
super(BRFManager, self).__init__(parent)

# Setup the BRF results viewer.
self.viewer = BRFViewer(wldset, parent)
self.viewer.btn_language.set_language(
CONF.get('brf', 'graphs_labels_language'))

self.kgs_brf_installer = None
self.__initGUI__()

def __initGUI__(self):
self.setContentsMargins(10, 10, 10, 10)

# ---- Detrend and Correct Options
# Detrend and Correct Options
self.baro_spinbox = myqt.QDoubleSpinBox(100, 0, show_buttons=True)
self.baro_spinbox.setRange(0, 9999)
self.baro_spinbox.setKeyboardTracking(True)
Expand Down Expand Up @@ -167,7 +170,7 @@ def __initGUI__(self):
options_layout.setColumnStretch(1, 100)
options_layout.setContentsMargins(0, 0, 0, 0)

# ---- BRF date range
# Setup BRF date range widgets.
self.date_start_edit = QDateTimeEdit()
self.date_start_edit.setCalendarPopup(True)
self.date_start_edit.setDisplayFormat('dd/MM/yyyy hh:mm')
Expand Down Expand Up @@ -202,15 +205,15 @@ def __initGUI__(self):
seldata_layout.setRowStretch(1, 100)
seldata_layout.setContentsMargins(0, 0, 0, 0)

# ---- Toolbar
# Setup the toolbar.
btn_comp = QPushButton('Compute BRF')
btn_comp.clicked.connect(self.calc_brf)
btn_comp.setFocusPolicy(Qt.NoFocus)

self.btn_show = QToolButtonSmall(icons.get_icon('search'))
self.btn_show.clicked.connect(self.viewer.show)

# ---- Main Layout
# Setup the main Layout.
self.addLayout(daterange_layout, 0, 0)
self.addLayout(seldata_layout, 0, 1)
self.setRowMinimumHeight(1, 15)
Expand All @@ -225,7 +228,12 @@ def __initGUI__(self):
if not KGSBRFInstaller().kgsbrf_is_installed():
self.__install_kgs_brf_installer()

# ---- Properties
# ---- Public API
def close(self):
""""Clos this brf manager"""
CONF.set('brf', 'graphs_labels_language',
self.viewer.btn_language.language)
super().close()

@property
def nlag_baro(self):
Expand Down Expand Up @@ -280,26 +288,6 @@ def set_brfperiod(self, period):
widget.blockSignals(False)
self.wldset.save_brfperiod(period)

# ---- KGS BRF installer
def __install_kgs_brf_installer(self):
"""
Installs a KGSBRFInstaller that overlays the whole brf tool
layout until the KGS_BRF program is installed correctly.
"""
self.kgs_brf_installer = KGSBRFInstaller()
self.kgs_brf_installer.sig_kgs_brf_installed.connect(
self.__uninstall_kgs_brf_installer)
self.addWidget(self.kgs_brf_installer, 0, 0,
self.rowCount(), self.columnCount())

def __uninstall_kgs_brf_installer(self):
"""
Uninstall the KGSBRFInstaller after the KGS_BRF program has been
installed properly.
"""
self.kgs_brf_installer.sig_kgs_brf_installed.disconnect()
self.kgs_brf_installer = None

def set_wldset(self, wldset):
"""Set the namespace for the wldset in the widget."""
self.wldset = wldset
Expand All @@ -326,6 +314,27 @@ def set_daterange(self, daterange):
widget.setMaximumDateTime(qdatetime_from_xldate(daterange[1]))
widget.blockSignals(False)

# ---- KGS BRF installer
def __install_kgs_brf_installer(self):
"""
Installs a KGSBRFInstaller that overlays the whole brf tool
layout until the KGS_BRF program is installed correctly.
"""
self.kgs_brf_installer = KGSBRFInstaller()
self.kgs_brf_installer.sig_kgs_brf_installed.connect(
self.__uninstall_kgs_brf_installer)
self.addWidget(self.kgs_brf_installer, 0, 0,
self.rowCount(), self.columnCount())

def __uninstall_kgs_brf_installer(self):
"""
Uninstall the KGSBRFInstaller after the KGS_BRF program has been
installed properly.
"""
self.kgs_brf_installer.sig_kgs_brf_installed.disconnect()
self.kgs_brf_installer = None

# ---- Calculations
def calc_brf(self):
"""Prepare the data, calcul the brf, and save and plot the results."""

Expand Down Expand Up @@ -439,8 +448,7 @@ def __initGUI__(self):

self.total_brf = QLabel('/ 0')

# ---- Language button

# Setup the language button.
self.btn_language = LangToolButton()
self.btn_language.setToolTip(
"Set the language of the text shown in the graph.")
Expand Down Expand Up @@ -670,7 +678,7 @@ def set_wldset(self, wldset):

def plot_brf(self):
self.brf_canvas.figure.set_language(self.btn_language.language)
if self.wldset.brf_count() == 0:
if self.wldset is None or self.wldset.brf_count() == 0:
self.brf_canvas.figure.empty_BRF()
else:
name = self.wldset.get_brfname_at(self.current_brf.value()-1)
Expand Down
3 changes: 3 additions & 0 deletions gwhat/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
'last_project_filepath': '../Projects/Example/Example.gwt'
}
),
('brf',
{'graphs_labels_language': 'english'}
),
]


Expand Down
1 change: 1 addition & 0 deletions gwhat/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def closeEvent(self, event):
"""Qt method override to close the project before close the app."""
print('Closing projet')
self.pmanager.close()
self.tab_hydrocalc.close()
print('Closing GWHAT')
event.accept()

Expand Down