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: Remove the use of custom DialogWindow class #350

Merged
merged 4 commits into from
Oct 8, 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
11 changes: 7 additions & 4 deletions gwhat/HydroCalc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from PyQt5.QtCore import pyqtSignal as QSignal
from PyQt5.QtWidgets import (
QGridLayout, QComboBox, QTextEdit, QSizePolicy, QPushButton, QLabel,
QTabWidget, QApplication, QWidget, QMainWindow, QToolBar, QFrame)
QTabWidget, QApplication, QWidget, QMainWindow, QToolBar, QFrame,
QMessageBox)

import matplotlib as mpl
import matplotlib.dates as mdates
Expand All @@ -38,7 +39,6 @@
# ---- Local imports
from gwhat.config.main import CONF
from gwhat.gwrecharge.gwrecharge_gui import RechgEvalWidget
from gwhat.common.widgets import DialogWindow
from gwhat.config.gui import FRAME_SYLE
from gwhat.utils import icons
from gwhat.utils.icons import QToolButtonNormal, get_iconsize
Expand All @@ -49,7 +49,7 @@
from gwhat.widgets.fileio import SaveFileMixin


class WLCalc(DialogWindow, SaveFileMixin):
class WLCalc(QWidget, SaveFileMixin):
"""
This is the interface where are plotted the water level time series. It is
possible to dynamically zoom and span the data, change the display,
Expand All @@ -59,7 +59,7 @@ class WLCalc(DialogWindow, SaveFileMixin):
sig_new_mrc = QSignal()

def __init__(self, datamanager, parent=None):
DialogWindow.__init__(self, parent, maximize=True)
QWidget.__init__(self, parent)
SaveFileMixin.__init__(self)

self._navig_and_select_tools = []
Expand Down Expand Up @@ -506,6 +506,9 @@ def __initUI__(self):
main_layout.setHorizontalSpacing(15)
main_layout.setColumnStretch(0, 100)

def emit_warning(self, message, title='Warning'):
QMessageBox.warning(self, title, message, QMessageBox.Ok)

@property
def water_lvl(self):
return np.array([]) if self.wldset is None else self.wldset.waterlevels
Expand Down
7 changes: 5 additions & 2 deletions gwhat/HydroPrint2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
from gwhat.widgets.buttons import LangToolButton


class HydroprintGUI(myqt.DialogWindow):
class HydroprintGUI(QWidget):

ConsoleSignal = QSignal(str)

def __init__(self, datamanager, parent=None):
super(HydroprintGUI, self).__init__(parent, maximize=True)
super().__init__(parent)

self.__updateUI = True

Expand Down Expand Up @@ -366,6 +366,9 @@ def __init__(self, items, parent=None):

return tabscales

def emit_warning(self, message, title='Warning'):
QMessageBox.warning(self, title, message, QMessageBox.Ok)

def close(self):
"""Close HydroPrint widget."""
self.color_palette_win.close()
Expand Down
51 changes: 0 additions & 51 deletions gwhat/common/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,57 +89,6 @@ def value(self):
return self.__value


class DialogWindow(QDialog):

def __init__(self, parent=None, resizable=False, maximize=True):
super(DialogWindow, self).__init__(parent)

self.__firstshow = True
if maximize is True:
self.__resizable = True
self.setWindowFlags(Qt.Window)
else:
self.__resizable = resizable
self.setWindowFlags(Qt.Window |
Qt.WindowMinimizeButtonHint |
Qt.WindowCloseButtonHint)

self.setWindowIcon(icons.get_icon('master'))

def emit_warning(self, msg, title='Warning'):
btn = QMessageBox.Ok
QMessageBox.warning(self, title, msg, btn)

def show(self):
if self.__firstshow is True:
self.__firstshow = False

self.setAttribute(Qt.WA_DontShowOnScreen, True)
super(DialogWindow, self).show()
super(DialogWindow, self).close()
self.setAttribute(Qt.WA_DontShowOnScreen, False)

qr = self.frameGeometry()
if self.parentWidget():
parent = self.parentWidget()
wp = parent.frameGeometry().width()
hp = parent.frameGeometry().height()
cp = parent.mapToGlobal(QPoint(wp/2, hp/2))
else:
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())

super(DialogWindow, self).show()

if self.__resizable is False:
self.setFixedSize(self.size())
else:
super(DialogWindow, self).show()

self.raise_()


class QToolPanel(QWidget):
"""
A custom widget that mimicks the behavior of the "Tools" sidepanel in
Expand Down
14 changes: 8 additions & 6 deletions gwhat/meteo/weather_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import (
QMenu, QToolButton, QGridLayout, QFileDialog, QApplication, QTableWidget,
QTableWidgetItem, QLabel, QHBoxLayout, QHeaderView, QToolBar)
QTableWidgetItem, QLabel, QHBoxLayout, QHeaderView, QToolBar, QDialog)

# ---- Local library imports
from gwhat.config.ospath import (
get_select_file_dialog_dir, set_select_file_dialog_dir)
from gwhat.utils import icons
from gwhat.config.gui import FRAME_SYLE
from gwhat.utils.icons import QToolButtonVRectSmall, QToolButtonNormal
from gwhat.common.widgets import DialogWindow
from gwhat.widgets.buttons import RangeSpinBoxes
from gwhat.common.utils import save_content_to_file
from gwhat.meteo.weather_reader import WXDataFrameBase
Expand All @@ -44,14 +43,18 @@
mpl.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Arial']})


class WeatherViewer(DialogWindow):
class WeatherViewer(QDialog):
"""
GUI that allows to plot weather normals, save the graphs to file, see
various stats about the dataset, etc...
"""

def __init__(self, parent=None):
super(WeatherViewer, self).__init__(parent, False, False)
super().__init__(parent)
self.setWindowFlags(
Qt.Window | Qt.WindowMinimizeButtonHint | Qt.WindowCloseButtonHint)
self.setWindowTitle('Weather Normals Viewer')
self.setWindowIcon(icons.get_icon('master'))

self.wxdset = None
self.normals = None
Expand All @@ -60,8 +63,6 @@ def __init__(self, parent=None):
self.__initUI__()

def __initUI__(self):
self.setWindowTitle('Weather Averages')
self.setWindowIcon(icons.get_icon('master'))

# ---- Toolbar

Expand Down Expand Up @@ -141,6 +142,7 @@ def __initUI__(self):
main_layout.addWidget(self.grid_weather_normals, 2, 0)
main_layout.setRowStretch(2, 1)
main_layout.setColumnStretch(0, 1)
main_layout.setSizeConstraint(main_layout.SetFixedSize)

def show_monthly_grid(self):
if self.grid_weather_normals.isHidden():
Expand Down