Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master' into add_mo…
Browse files Browse the repository at this point in the history
…dels_distplot
  • Loading branch information
jnsebgosselin committed Mar 31, 2021
2 parents 9ed9e85 + 707bf79 commit 21e20a8
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 51 deletions.
8 changes: 2 additions & 6 deletions gwhat/HydroCalc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,13 +1867,9 @@ def mrc2rechg(t, ho, A, B, z, Sy):
from projet.manager_data import DataManager
from projet.reader_projet import ProjetReader
from gwhat import __rootdir__
from gwhat.utils.qthelpers import create_qapplication

app = QApplication(sys.argv)

ft = app.font()
ft.setFamily('Segoe UI')
ft.setPointSize(11)
app.setFont(ft)
app = create_qapplication()

pf = osp.join(__rootdir__, '../Projects/Example/Example.gwt')
pr = ProjetReader(pf)
Expand Down
19 changes: 18 additions & 1 deletion gwhat/gwrecharge/gwrecharge_plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# -----------------------------------------------------------------------------

# ---- Standard library imports
import io
import os
import os.path as osp
import datetime
Expand All @@ -22,6 +23,7 @@
from PyQt5.QtCore import Qt
from PyQt5.QtCore import pyqtSlot as QSlot
from PyQt5.QtCore import pyqtSignal as QSignal
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import (
QGridLayout, QAbstractSpinBox, QApplication, QDoubleSpinBox,
QFileDialog, QGroupBox, QLabel, QMessageBox, QScrollArea, QScrollBar,
Expand Down Expand Up @@ -610,6 +612,13 @@ def create_toolbar(self):
tip='Save current graph as...',
triggered=self._select_savefig_path)

self.btn_copy_to_clipboard = create_toolbutton(
self, icon='copy_clipboard',
text="Copy",
tip="Put a copy of the figure on the Clipboard.",
triggered=self.figcanvas.copy_to_clipboard,
shortcut='Ctrl+C')

self.btn_language = LangToolButton()
self.btn_language.setToolTip(
"Set the language of the text shown in the graph.")
Expand All @@ -625,7 +634,8 @@ def create_toolbar(self):
toolbar.setMovable(False)
toolbar.setIconSize(get_iconsize('normal'))

widgets = [self.btn_save, None, zoom_widget, None, self.btn_language]
widgets = [self.btn_save, self.btn_copy_to_clipboard, None,
zoom_widget, None, self.btn_language]
for widget in widgets:
if widget is None:
toolbar.addSeparator()
Expand Down Expand Up @@ -763,6 +773,13 @@ def set_figure_setp(self, setp):
self.figure.set_size_inches(self.setp['fwidth'], self.setp['fheight'])
self.refresh_margins()

def copy_to_clipboard(self):
"""Put a copy of the figure on the clipboard."""
buf = io.BytesIO()
self.figure.savefig(buf, dpi=300)
QApplication.clipboard().setImage(QImage.fromData(buf.getvalue()))
buf.close()

def clear_ax(self, silent=True):
"""Clear the main axe."""
self.ax0.clear()
Expand Down
27 changes: 25 additions & 2 deletions gwhat/gwrecharge/tests/test_gwrecharge_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# ---- Third party imports
import pytest
from PyQt5.QtGui import QImage
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication

Expand All @@ -36,7 +37,7 @@ def project():
@pytest.fixture()
def figstackmanager(qtbot):
figstackmanager = FigureStackManager()
# qtbot.addWidget(figstackmanager)
qtbot.addWidget(figstackmanager)
figstackmanager.show()
qtbot.waitForWindowShown(figstackmanager)
return figstackmanager
Expand All @@ -61,5 +62,27 @@ def test_figstackmanager(figstackmanager, project):
figstackmanager.stack.setCurrentIndex(index)


def test_copy_to_clipboard(qtbot, figstackmanager, project):
"""
Test that copying figures to the clipboard works as expected.
"""
wldset = project.get_wldset('3040002_15min')
figstackmanager.set_gluedf(wldset.get_glue_at(-1))

for index in range(figstackmanager.stack.count()):
figstackmanager.stack.setCurrentIndex(index)
qtbot.wait(300)

QApplication.clipboard().clear()
assert QApplication.clipboard().text() == ''
assert QApplication.clipboard().image().isNull()

qtbot.mouseClick(
figstackmanager.figmanagers[index].btn_copy_to_clipboard,
Qt.LeftButton)

assert not QApplication.clipboard().image().isNull()


if __name__ == "__main__":
pytest.main(['-x', __file__, '-v', '-rw', '-s'])
pytest.main(['-x', __file__, '-v', '-rw'])
5 changes: 3 additions & 2 deletions gwhat/hydrograph4.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,9 @@ def setup_legend(self):
lg_labels.append(labelDB[2])

# Missing Data Markers
lg_handles.append(self.lmiss_ax4)
lg_labels.append(labelDB[3])
if len(self.lmiss_ax4.get_xdata()):
lg_handles.append(self.lmiss_ax4)
lg_labels.append(labelDB[3])

# Continuous Line Datalogger
lg_handles.append(self.l1_ax2)
Expand Down
43 changes: 11 additions & 32 deletions gwhat/mainwindow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright © 2014-2018 GWHAT Project Contributors
# Copyright © 2014-2021 GWHAT Project Contributors
# https://github.com/jnsebgosselin/gwhat
#
# This file is part of GWHAT (Ground-Water Hydrograph Analysis Toolbox).
Expand All @@ -13,41 +13,26 @@
# moving forward, and remember to keep your UI out of the way.
# http://blog.teamtreehouse.com/10-user-interface-design-fundamentals

from __future__ import division, unicode_literals, print_function

print('Starting GWHAT...')

import matplotlib as mpl
mpl.use('Qt5Agg')

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QApplication, QMainWindow, QTextEdit, QSplitter,
QWidget, QGridLayout, QTextBrowser)
import sys
app = QApplication(sys.argv)
from gwhat.utils.qthelpers import create_qapplication
app = create_qapplication()

from gwhat import __namever__, __appname__
from gwhat.widgets.splash import SplashScrn
splash = SplashScrn()

import platform

ft = app.font()
ft.setPointSize(11)
if platform.system() == 'Windows':
ft.setFamily('Segoe UI')
app.setFont(ft)

from gwhat import __namever__, __appname__
splash.showMessage("Starting %s..." % __namever__)

# ---- Standard library imports
import sys
import platform
from time import ctime
import os.path as osp

from multiprocessing import freeze_support
import tkinter
import tkinter.filedialog
import tkinter.messagebox

# ---- Third party imports
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QMainWindow, QTextEdit, QSplitter,
QWidget, QGridLayout, QTextBrowser)

# ---- Local imports
from gwhat.config.main import CONF
Expand Down Expand Up @@ -218,12 +203,6 @@ def closeEvent(self, event):
self.tab_hydrograph.close()
event.accept()

def show(self):
"""
Extend Qt method.
"""
super().show()

# ---- Main window settings
def _restore_window_geometry(self):
"""
Expand Down
10 changes: 3 additions & 7 deletions gwhat/projet/manager_projet.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,16 @@ def show(self):

if __name__ == '__main__':
import sys
from gwhat.utils.qthelpers import create_qapplication

f = 'C:/Users/jnsebgosselin/Desktop/Project4Testing/Project4Testing.what'

app = QApplication(sys.argv)

ft = app.font()
ft.setFamily('Segoe UI')
ft.setPointSize(11)
app.setFont(ft)
app = create_qapplication()

pm = ProjetManager(projet=None)
pm.show()

dm = DataManager(pm=pm)
dm.show()

app.exec_()
sys.exit(app.exec_())
26 changes: 25 additions & 1 deletion gwhat/utils/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

"""Qt utilities"""

# ---- Standard imports
import sys
import platform

# ---- Third party imports
from PyQt5.QtCore import QByteArray, Qt, QSize
from PyQt5.QtWidgets import QWidget, QSizePolicy, QToolButton
from PyQt5.QtWidgets import (
QWidget, QSizePolicy, QToolButton, QApplication, QStyleFactory)

# ---- Local imports
from gwhat.utils.icons import get_icon


Expand All @@ -26,6 +32,24 @@ def hexstate_to_qbytearray(hexstate):
return QByteArray().fromHex(str(hexstate).encode('utf-8'))


def create_qapplication():
"""Create a QApplication instance if it doesn't already exist"""
qapp = QApplication.instance()
if qapp is None:
print('Creating a QApplication...')
qapp = QApplication(sys.argv)

if platform.system() == 'Windows':
print('Setting style for Windows OS...')
qapp.setStyle(QStyleFactory.create('WindowsVista'))

ft = qapp.font()
ft.setPointSize(10)
ft.setFamily('Segoe UI')
qapp.setFont(ft)
return qapp


def create_toolbar_stretcher():
"""Create a stretcher to be used in a toolbar """
stretcher = QWidget()
Expand Down

0 comments on commit 21e20a8

Please sign in to comment.