Skip to content

Commit 477b453

Browse files
committed
About dialog box: code refactoring with guidata
1 parent 3f04af4 commit 477b453

File tree

6 files changed

+53
-58
lines changed

6 files changed

+53
-58
lines changed

doc/requirements.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ The :mod:`plotpy` package requires the following Python modules:
99
- Summary
1010
* - Python
1111
- >=3.8, <4
12-
-
12+
-
1313
* - guidata
14-
- >=3.0.1
14+
- >=3.1
1515
- Automatic GUI generation for easy dataset editing and display
1616
* - PythonQwt
1717
- >=0.10
@@ -23,10 +23,10 @@ The :mod:`plotpy` package requires the following Python modules:
2323
- >=1.3
2424
- Fundamental algorithms for scientific computing in Python
2525
* - Pillow
26-
-
26+
-
2727
- Python Imaging Library (Fork)
2828
* - tifffile
29-
-
29+
-
3030
- Read and write TIFF files
3131
* - PyQt5
3232
- >=5.11
@@ -42,19 +42,19 @@ Optional modules for development:
4242
- Version
4343
- Summary
4444
* - black
45-
-
45+
-
4646
- The uncompromising code formatter.
4747
* - isort
48-
-
48+
-
4949
- A Python utility / library to sort Python imports.
5050
* - pylint
51-
-
51+
-
5252
- python code static checker
5353
* - Coverage
54-
-
54+
-
5555
- Code coverage measurement for Python
5656
* - Cython
57-
-
57+
-
5858
- The Cython compiler for writing C extensions in the Python language.
5959

6060
Optional modules for building the documentation:
@@ -67,19 +67,19 @@ Optional modules for building the documentation:
6767
- Version
6868
- Summary
6969
* - PyQt5
70-
-
70+
-
7171
- Python bindings for the Qt cross platform application toolkit
7272
* - sphinx
73-
-
73+
-
7474
- Python documentation generator
7575
* - sphinx-copybutton
76-
-
76+
-
7777
- Add a copy button to each of your code cells.
7878
* - sphinx_qt_documentation
79-
-
79+
-
8080
- Plugin for proper resolve intersphinx references for Qt elements
8181
* - python-docs-theme
82-
-
82+
-
8383
- The Sphinx theme for the CPython docs and related projects
8484

8585
Optional modules for running test suite:
@@ -92,14 +92,14 @@ Optional modules for running test suite:
9292
- Version
9393
- Summary
9494
* - pytest
95-
-
95+
-
9696
- pytest: simple powerful testing with Python
9797
* - pytest-cov
98-
-
98+
-
9999
- Pytest plugin for measuring coverage.
100100
* - pytest-qt
101-
-
101+
-
102102
- pytest support for PyQt and PySide applications
103103
* - pytest-xvfb
104-
-
104+
-
105105
- A pytest plugin to run Xvfb (or Xephyr/Xvnc) for tests.

plotpy/tests/gui/test_simple_window.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
from plotpy.builder import make
2929
from plotpy.config import _
3030
from plotpy.plot import PlotOptions, PlotWidget
31-
from plotpy.widgets.about import about
32-
33-
APP_NAME = _("Application example")
34-
VERSION = "1.0.0"
31+
from plotpy.widgets import about
3532

3633

3734
class ImageParam(DataSet):
@@ -168,8 +165,8 @@ def __init__(self):
168165

169166
def setup(self):
170167
"""Setup window parameters"""
171-
self.setWindowIcon(get_icon("python.png"))
172-
self.setWindowTitle(APP_NAME)
168+
self.setWindowIcon(get_icon("plotpy.svg"))
169+
self.setWindowTitle(_("Application example"))
173170
self.resize(QC.QSize(600, 800))
174171

175172
# Welcome message in statusbar:
@@ -210,7 +207,7 @@ def setup(self):
210207
self,
211208
_("About..."),
212209
icon=get_std_icon("MessageBoxInformation"),
213-
triggered=self.about,
210+
triggered=lambda parent=self: about.show_about_dialog(parent),
214211
)
215212
add_actions(help_menu, (about_action,))
216213

@@ -222,21 +219,6 @@ def setup(self):
222219
self.mainwidget = CentralWidget(self, toolbar)
223220
self.setCentralWidget(self.mainwidget)
224221

225-
# ------?
226-
def about(self):
227-
"""About box"""
228-
QW.QMessageBox.about(
229-
self,
230-
_("About ") + APP_NAME,
231-
"<b>{}</b> v{}"
232-
"<p>{} Pierre Raybaut<br><br>{}".format(
233-
APP_NAME,
234-
VERSION,
235-
_("Developped by"),
236-
about(html=True, copyright_only=True),
237-
),
238-
)
239-
240222
# ------I/O
241223
def new_image(self):
242224
"""Create a new image"""

plotpy/tools/misc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
get_plot_qrect,
2323
)
2424
from plotpy.tools.base import CommandTool, DefaultToolbarID, RectangularActionTool
25-
from plotpy.widgets.about import about
25+
from plotpy.widgets import about
2626
from plotpy.widgets.resizedialog import ResizeDialog
2727

2828

@@ -260,8 +260,7 @@ def __init__(self, manager, toolbar_id=DefaultToolbarID):
260260

261261
def activate_command(self, plot, checked):
262262
"""Activate tool"""
263-
264-
QW.QMessageBox.about(plot, _("About") + " plotpy", about(html=True))
263+
about.show_about_dialog(plot)
265264

266265

267266
class PrintTool(CommandTool):

plotpy/widgets/about.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,45 @@
55
66
"""
77

8-
import platform
9-
import sys
8+
from __future__ import annotations
109

11-
from qtpy import QtCore as QC
12-
from qwt import QWT_VERSION_STR
10+
import guidata
11+
import qwt
12+
from guidata.widgets.about import get_general_infos
13+
from qtpy.QtWidgets import QMessageBox, QWidget
1314

1415
import plotpy
16+
from plotpy.config import _
1517

1618

17-
def about(html=True, copyright_only=False):
18-
"""Return text about this package"""
19-
python_version = "{} {}".format(
20-
platform.python_version(), "64 bits" if sys.maxsize > 2**32 else "32 bits"
21-
)
19+
def about(html: bool = True, copyright_only: bool = False) -> str:
20+
"""Return text about this package
21+
22+
Args:
23+
html: return html text. Defaults to True.
24+
copyright_only: if True, return only copyright
25+
26+
Returns:
27+
str: text about this package
28+
"""
2229
shortdesc = (
2330
f"Plotpy {plotpy.__version__}\n\n"
2431
f"Plotpy is a set of tools for curve and image plotting.\n"
2532
f"Created by Pierre Raybaut."
2633
)
27-
desc = (
28-
f"Copyright © 2023 CEA\n\nPython {python_version}, "
29-
f"Qt {QC.__version__}, PythonQwt {QWT_VERSION_STR} on {platform.system()}"
30-
)
34+
addinfos = f"guidata {guidata.__version__}, PythonQwt {qwt.__version__}"
35+
desc = get_general_infos(addinfos)
3136
if not copyright_only:
3237
desc = f"{shortdesc}\n\n{desc}"
3338
if html:
3439
desc = desc.replace("\n", "<br />")
3540
return desc
41+
42+
43+
def show_about_dialog(parent: QWidget) -> None:
44+
"""Show ``plotpy`` about dialog
45+
46+
Args:
47+
parent (QWidget): parent widget
48+
"""
49+
QMessageBox.about(parent, _("About") + " plotpy", about(html=True))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
]
3030
requires-python = ">=3.8, <4"
3131
dependencies = [
32-
"guidata>=3.0.1",
32+
"guidata>=3.1",
3333
"PythonQwt>=0.10",
3434
"NumPy>=1.17",
3535
"SciPy>=1.3",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PyQt5
66
PythonQwt>=0.10
77
SciPy>=1.3
88
black
9-
guidata>=3.0.1
9+
guidata>=3.1
1010
isort
1111
pylint
1212
pytest

0 commit comments

Comments
 (0)