Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into add_vi…
Browse files Browse the repository at this point in the history
…sual_cue_when_selecting_brf
  • Loading branch information
jnsebgosselin committed Sep 28, 2020
2 parents 9eac978 + c33da58 commit 82f2490
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 132 deletions.
236 changes: 106 additions & 130 deletions gwhat/brf_mod/kgs_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
QLabel, QDateTimeEdit, QCheckBox, QPushButton, QApplication, QSpinBox,
QAbstractSpinBox, QGridLayout, QDoubleSpinBox, QFrame, QWidget,
QMessageBox, QFileDialog, QComboBox, QDialog, QGroupBox, QToolButton,
QToolBar)
QToolBar, QGroupBox)

from xlrd.xldate import xldate_from_datetime_tuple, xldate_as_datetime
import numpy as np
Expand Down Expand Up @@ -133,8 +133,7 @@ def __init__(self, wldset=None, parent=None):
self._bp_and_et_lags_are_linked = False

self.viewer = BRFViewer(wldset, parent)
self.viewer.btn_language.set_language(
CONF.get('brf', 'graphs_labels_language'))
self.viewer.set_language(CONF.get('brf', 'graphs_labels_language'))
if CONF.get('brf', 'graph_opt_panel_is_visible', False):
self.viewer.toggle_graphpannel()
self.viewer.sig_import_params_in_manager_request.connect(
Expand Down Expand Up @@ -272,8 +271,7 @@ def __initGUI__(self):
# ---- Public API
def close(self):
""""Clos this brf manager"""
CONF.set('brf', 'graphs_labels_language',
self.viewer.btn_language.language)
CONF.set('brf', 'graphs_labels_language', self.viewer.get_language())
CONF.set('brf', 'graph_opt_panel_is_visible',
self.viewer._graph_opt_panel_is_visible)
self.viewer.close()
Expand Down Expand Up @@ -561,10 +559,8 @@ def __init__(self, wldset=None, parent=None):

self.setWindowTitle('BRF Results Viewer')
self.setWindowIcon(icons.get_icon('master'))
self.setWindowFlags(Qt.Window |
Qt.CustomizeWindowHint |
Qt.WindowMinimizeButtonHint |
Qt.WindowCloseButtonHint)
self.setWindowFlags(
Qt.Window | Qt.CustomizeWindowHint | Qt.WindowCloseButtonHint)

self.__initGUI__()
self.set_wldset(wldset)
Expand All @@ -586,14 +582,7 @@ def __initGUI__(self):
self.current_brf.valueChanged.connect(self.navigate_brf)
self.current_brf.setValue(0)

self.total_brf = QLabel('/ 0')

# Setup the language button.
self.btn_language = LangToolButton()
self.btn_language.setToolTip(
"Set the language of the text shown in the graph.")
self.btn_language.sig_lang_changed.connect(self.plot_brf)
self.btn_language.setIconSize(icons.get_iconsize('normal'))
self.total_brf = QLabel(' / 0')

# Generate the toolbar buttons.
self.btn_del = QToolButtonNormal(icons.get_icon('delete_data'))
Expand Down Expand Up @@ -623,6 +612,9 @@ def __initGUI__(self):

self.import_params_in_manager_btn = QToolButtonNormal(
icons.get_icon('content_duplicate'))
self.import_params_in_manager_btn.setToolTip(
'Set the parameters of the BRF tool to the values that were '
'used to calculate the BRF currently displayed in this viewer.')
self.import_params_in_manager_btn.clicked.connect(
lambda _: self.sig_import_params_in_manager_request.emit())

Expand All @@ -632,7 +624,7 @@ def __initGUI__(self):
buttons = [btn_save, self.btn_copy, self.btn_export, self.btn_del,
self.btn_del_all, None, self.btn_prev, self.current_brf,
self.total_brf, self.btn_next, None,
self.import_params_in_manager_btn, self.btn_language]
self.import_params_in_manager_btn]
for button in buttons:
if button is None:
self.toolbar.addSeparator()
Expand Down Expand Up @@ -732,7 +724,7 @@ def new_brf_added(self):

def update_brfnavigate_state(self):
count = self.wldset.brf_count()
self.total_brf.setText('/ %d' % count)
self.total_brf.setText(' / %d' % count)

self.current_brf.setMinimum(min(count, 1))
self.current_brf.setMaximum(count)
Expand Down Expand Up @@ -804,8 +796,14 @@ def set_wldset(self, wldset):
if wldset is not None:
self.update_brfnavigate_state()

def get_language(self):
return self.graph_opt_panel.get_language()

def set_language(self, language):
return self.graph_opt_panel.set_language(language)

def plot_brf(self):
self.brf_canvas.figure.set_language(self.btn_language.language)
self.brf_canvas.figure.set_language(self.get_language())
if self.wldset is None or self.wldset.brf_count() == 0:
self.brf_canvas.figure.empty_BRF()
else:
Expand Down Expand Up @@ -851,8 +849,7 @@ def __init__(self, parent=None):
self.setVisible(False)

def __initGUI__(self):
# ---- Line and Markers Style Widgets

# Setup the line and marker options.
self._errorbar = QCheckBox('Show error bars')
self._errorbar.setChecked(True)
self._errorbar.stateChanged.connect(self._graphconf_changed)
Expand All @@ -869,8 +866,15 @@ def __initGUI__(self):
self._markersize['widget'].valueChanged.connect(
self._graphconf_changed)

# ---- Y-Axis Options Widgets
line_and_marker_groupbox = QGroupBox()
line_and_marker_layout = QGridLayout(line_and_marker_groupbox)
line_and_marker_layout.addWidget(self._errorbar, 0, 0, 1, 2)
line_and_marker_layout.addWidget(self._drawline, 1, 0, 1, 2)
line_and_marker_layout.addWidget(self._markersize['label'], 2, 0)
line_and_marker_layout.addWidget(self._markersize['widget'], 2, 1)
line_and_marker_layout.setColumnStretch(0, 1)

# Setup yaxis options.
self._ylim = {}
self._ylim['min'] = QDoubleSpinBox()
self._ylim['min'].setValue(0)
Expand All @@ -893,18 +897,28 @@ def __initGUI__(self):
self._ylim['scale'].setRange(0.01, 1)
self._ylim['scale'].setEnabled(True)
self._ylim['scale'].valueChanged.connect(self._graphconf_changed)
self._ylim['auto'] = QCheckBox('')
self._ylim['auto'].setCheckState(Qt.Checked)
self._ylim['auto'].stateChanged.connect(self.axis_autocheck_changed)

# ---- X-Axis Options Widgets

self.ylim_groupbox = QGroupBox('Vertical Axis Options')
self.ylim_groupbox.setCheckable(True)
self.ylim_groupbox.setChecked(False)
self.ylim_groupbox.toggled.connect(lambda _: self._graphconf_changed())

ylim_grouplayout = QGridLayout(self.ylim_groupbox)
ylim_grouplayout.addWidget(QLabel('Minimum :'), 0, 0)
ylim_grouplayout.addWidget(self._ylim['min'], 0, 1)
ylim_grouplayout.addWidget(QLabel('Maximum :'), 1, 0)
ylim_grouplayout.addWidget(self._ylim['max'], 1, 1)
ylim_grouplayout.addWidget(QLabel('Scale :'), 2, 0)
ylim_grouplayout.addWidget(self._ylim['scale'], 2, 1)
ylim_grouplayout.setColumnStretch(0, 1)

# Setup xaxis options.
self._xlim = {}
self._xlim['units'] = QComboBox()
self._xlim['units'].addItems(['Hours', 'Days'])
self._xlim['units'].setCurrentIndex(1)
self._xlim['units'].currentIndexChanged.connect(
self.time_units_changed)
self._time_units_changed)
self._xlim['min'] = QSpinBox()
self._xlim['min'].setValue(0)
self._xlim['min'].setSingleStep(1)
Expand All @@ -924,72 +938,47 @@ def __initGUI__(self):
self._xlim['scale'].setRange(0.1, 99)
self._xlim['scale'].setEnabled(True)
self._xlim['scale'].valueChanged.connect(self._graphconf_changed)
self._xlim['auto'] = QCheckBox('')
self._xlim['auto'].setCheckState(Qt.Checked)
self._xlim['auto'].stateChanged.connect(self.axis_autocheck_changed)

self.axis_autocheck_changed()

# ---- Axis Options Layout

axlayout = QGridLayout()

row = 0
axlayout.addWidget(QLabel('y-axis limits:'), 0, 0, 1, 2)
row += 1
axlayout.addWidget(QLabel(' Minimum :'), row, 0)
axlayout.addWidget(self._ylim['min'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Maximum :'), row, 0)
axlayout.addWidget(self._ylim['max'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Scale :'), row, 0)
axlayout.addWidget(self._ylim['scale'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Auto :'), row, 0)
axlayout.addWidget(self._ylim['auto'], row, 1)
row += 1
axlayout.setRowMinimumHeight(row, 15)
row += 1
axlayout.addWidget(QLabel('x-axis limits:'), row, 0, 1, 2)
row += 1
axlayout.addWidget(QLabel(' Time units :'), row, 0)
axlayout.addWidget(self._xlim['units'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Minimum :'), row, 0)
axlayout.addWidget(self._xlim['min'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Maximum :'), row, 0)
axlayout.addWidget(self._xlim['max'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Scale :'), row, 0)
axlayout.addWidget(self._xlim['scale'], row, 1)
row += 1
axlayout.addWidget(QLabel(' Auto :'), row, 0)
axlayout.addWidget(self._xlim['auto'], row, 1)

axlayout.setColumnStretch(3, 100)
axlayout.setContentsMargins(0, 0, 0, 0) # (left, top, right, bottom)

# ---- Graph Panel Layout

self.xlim_groupbox = QGroupBox('Horizontal Axis Options')
self.xlim_groupbox.setCheckable(True)
self.xlim_groupbox.setChecked(False)
self.xlim_groupbox.toggled.connect(lambda _: self._graphconf_changed())

xlim_grouplayout = QGridLayout(self.xlim_groupbox)
xlim_grouplayout.addWidget(QLabel('Time units :'), 0, 0)
xlim_grouplayout.addWidget(self._xlim['units'], 0, 1)
xlim_grouplayout.addWidget(QLabel('Minimum :'), 1, 0)
xlim_grouplayout.addWidget(self._xlim['min'], 1, 1)
xlim_grouplayout.addWidget(QLabel('Maximum :'), 2, 0)
xlim_grouplayout.addWidget(self._xlim['max'], 2, 1)
xlim_grouplayout.addWidget(QLabel('Scale :'), 3, 0)
xlim_grouplayout.addWidget(self._xlim['scale'], 3, 1)
xlim_grouplayout.setColumnStretch(0, 1)

# Setup the language widget.
self.language_combobox = QComboBox()
self.language_combobox.addItems(['English', 'French'])
self.language_combobox.setCurrentIndex(0)
self.language_combobox.setToolTip(
"Set the language of the text shown in the graph.")
self.language_combobox.currentIndexChanged.connect(
self._graphconf_changed)

language_layout = QGridLayout()
language_layout.setContentsMargins(0, 0, 0, 0)
language_layout.addWidget(QLabel('Language :'), 0, 0)
language_layout.addWidget(self.language_combobox, 0, 1)
language_layout.setColumnStretch(1, 1)

# Setup the main layout.
layout = QGridLayout(self)
layout.setContentsMargins(10, 0, 10, 0) # (l, t, r, b)

row = 0
layout.addWidget(self._errorbar, row, 1, 1, 2)
row += 1
layout.addWidget(self._drawline, row, 1, 1, 2)
row += 1
layout.addWidget(self._markersize['label'], row, 1)
layout.addWidget(self._markersize['widget'], row, 2)
row += 1
layout.addWidget(HSep(), row, 1, 1, 2)
row += 1
layout.addLayout(axlayout, row, 1, 1, 2)
row += 1
layout.setRowMinimumHeight(row, 15)
layout.setRowStretch(row, 100)
layout.setSpacing(10)
layout.setContentsMargins(5, 0, 0, 0)
layout.addWidget(line_and_marker_groupbox, 0, 0)
layout.addWidget(self.ylim_groupbox, 1, 0)
layout.addWidget(self.xlim_groupbox, 2, 0)
layout.addLayout(language_layout, 3, 0)
layout.setRowStretch(4, 1)

def _graphconf_changed(self):
"""
Expand All @@ -1000,61 +989,55 @@ def _graphconf_changed(self):
# ---- Graph Panel Properties
@property
def time_units(self):
if self._xlim['auto'].isChecked():
if not self.xlim_groupbox.isChecked():
return 'auto'
else:
return self._xlim['units'].currentText().lower()

@property
def xmin(self):
if self._xlim['auto'].isChecked():
if not self.xlim_groupbox.isChecked():
return None
else:
if self.time_units == 'hours':
return self._xlim['min'].value()/24
return self._xlim['min'].value() / 24
else:
return self._xlim['min'].value()

@property
def xmax(self):
if self._xlim['auto'].isChecked():
if not self.xlim_groupbox.isChecked():
return None
else:
if self.time_units == 'hours':
return self._xlim['max'].value()/24
return self._xlim['max'].value() / 24
else:
return self._xlim['max'].value()

@property
def xscale(self):
if self._xlim['auto'].isChecked():
if not self.xlim_groupbox.isChecked():
return None
else:
if self.time_units == 'hours':
return self._xlim['scale'].value()/24
return self._xlim['scale'].value() / 24
else:
return self._xlim['scale'].value()

@property
def ymin(self):
if self._ylim['auto'].isChecked():
return None
else:
return self._ylim['min'].value()
return (self._ylim['min'].value() if self.ylim_groupbox.isChecked()
else None)

@property
def ymax(self):
if self._ylim['auto'].isChecked():
return None
else:
return self._ylim['max'].value()
return (self._ylim['max'].value() if self.ylim_groupbox.isChecked()
else None)

@property
def yscale(self):
if self._ylim['auto'].isChecked():
return None
else:
return self._ylim['scale'].value()
return (self._ylim['scale'].value() if self.ylim_groupbox.isChecked()
else None)

@property
def show_ebar(self):
Expand All @@ -1068,9 +1051,18 @@ def draw_line(self):
def markersize(self):
return self._markersize['widget'].value()

# ---- Handlers
def get_language(self):
return self.language_combobox.currentText().lower()

def set_language(self, language):
for i in range(self.language_combobox.count()):
if self.language_combobox.itemText(i).lower() == language.lower():
self.language_combobox.setCurrentIndex(i)
self._graphconf_changed()
break

def time_units_changed(self):
# ---- Handlers
def _time_units_changed(self):
""" Handles when the time_units combobox selection changes."""
for xlim in [self._xlim['min'], self._xlim['max'],
self._xlim['scale']]:
Expand All @@ -1083,22 +1075,6 @@ def time_units_changed(self):

self._graphconf_changed()

def axis_autocheck_changed(self):
"""
Handles when the Auto checkbox state change for the
limits of the y-axis or the x-axis.
"""
self._ylim['min'].setEnabled(not self._ylim['auto'].isChecked())
self._ylim['max'].setEnabled(not self._ylim['auto'].isChecked())
self._ylim['scale'].setEnabled(not self._ylim['auto'].isChecked())

self._xlim['units'].setEnabled(not self._xlim['auto'].isChecked())
self._xlim['min'].setEnabled(not self._xlim['auto'].isChecked())
self._xlim['max'].setEnabled(not self._xlim['auto'].isChecked())
self._xlim['scale'].setEnabled(not self._xlim['auto'].isChecked())

self._graphconf_changed()


# %% if __name__ == "__main__"

Expand Down
Loading

0 comments on commit 82f2490

Please sign in to comment.