46 Commits

Author SHA1 Message Date
2bc85654cd Merge pull request 'gitlab refs removed' (#2) from gitlab_hunt into master
Reviewed-on: #2
2025-08-27 08:58:57 +02:00
woznic_n
1278648fc6 gitlab refs removed 2025-08-26 11:59:12 +02:00
d7236401b6 also allow ModuleNotFoundError 2025-03-26 11:24:05 +01:00
bd3ccfa407 Update .gitlab-ci.yml 2024-08-12 15:55:19 +02:00
f97d9a3824 Merge branch 'fix-tests' into 'master'
added libxdamage1

See merge request augustin_s/grum!9
2023-08-16 18:57:38 +02:00
5606d0781f added libxdamage1 2023-08-16 18:50:50 +02:00
7a1a9479c8 updated docstring 2023-05-25 11:16:52 +02:00
7ea180bfb8 Merge branch 'images' into 'master'
Images

See merge request augustin_s/grum!8
2023-05-23 08:45:33 +00:00
fcca087b51 adjusted tests 2023-05-23 10:41:06 +02:00
d958d89da4 added and use constants for default sub window size 2023-05-23 10:19:52 +02:00
dcc554eab8 allow to set color map 2023-05-12 14:59:18 +02:00
cf24d54b62 allow to set levels 2023-05-12 14:35:04 +02:00
0742b9de0f fixed axis labels 2023-05-12 14:28:40 +02:00
ae70ac86a8 added labels to example image 2023-05-12 14:28:07 +02:00
438d5c1eea added image example 2023-05-12 11:17:18 +02:00
2d11fe4ff9 order 2023-04-17 23:36:47 +02:00
dee9cbb934 naming 2023-04-17 23:11:04 +02:00
3ef9032499 use single signal for creating new subwins 2023-04-17 23:09:50 +02:00
f80a7759fb use Description base class; change callbacks to concrete arguments 2023-04-17 22:46:56 +02:00
023ecd7618 added a comment 2023-04-15 13:54:08 +02:00
593241d66f added and use a mapping DescType to MDISubType 2023-04-15 13:51:18 +02:00
839b1a1e21 use DESC_TYPES and stored type to choose DescType on file load 2023-04-15 13:45:35 +02:00
4bb052d665 added description type to class mapping 2023-04-15 13:44:41 +02:00
3c951910b0 extract description type and add it to dict representation 2023-04-15 13:44:00 +02:00
4e95c1f8fd added a Description base class 2023-04-14 23:17:02 +02:00
00b12d800f import order 2023-04-14 18:33:22 +02:00
a7c86eb3b1 moved *Description classes into descs folder 2023-04-14 18:25:10 +02:00
da8d7b0a2b better add_new_desc_to_list; fixed multi plots with marked image; typo 2023-04-14 17:57:33 +02:00
7470f1388b first try on adding 2D image support 2023-04-14 14:17:46 +02:00
a80b568894 enable PYTHONFAULTHANDLER for segfault tracebacks 2023-03-18 11:48:03 +01:00
2edc68151d Merge branch 'gitlab-ci-update' into 'master'
ci: improved ci pipeline; added 3.6 to 3.11 tests

See merge request augustin_s/grum!6
2023-03-14 20:26:39 +00:00
aa03291e42 Merge branch 'tests' into 'master'
Tests

See merge request augustin_s/grum!7
2023-03-14 20:26:23 +00:00
5d97dd6224 added test report artifact 2023-03-14 11:52:03 +01:00
bed086f95f do not test the default 3.8 twice 2023-03-14 11:06:10 +01:00
aa79f1b0a1 removed the version check again 2023-03-14 10:58:31 +01:00
bbb6d6c00c lower the required version 2023-03-14 10:47:06 +01:00
c6f034f2d3 require PyQtWebEngine only for Python version were it exists 2023-03-14 10:42:34 +01:00
a624cf37a4 added some more versions 2023-03-14 09:40:32 +01:00
efd023ae3a a bit of formatting and naming 2023-03-14 09:35:44 +01:00
d65e97c9a7 neater 2023-02-10 12:31:42 +01:00
4fcc10f3da added possibility to extend data 2023-02-10 11:21:54 +01:00
c781601246 added set_data; refactored sync_item_and_plots 2023-02-10 10:10:12 +01:00
831b03a744 added data setter 2023-02-10 10:09:43 +01:00
b94294b579 fixed __dir__ 2023-02-10 10:09:22 +01:00
b14f6e68b4 allow tab completion for the exposed functions on the client side 2023-02-08 21:03:03 +01:00
7d169fdd53 ci: improved ci pipeline; added 3.9 and 3.10 tests 2023-01-28 17:29:56 +01:00
18 changed files with 323 additions and 107 deletions

View File

@@ -1,29 +1,64 @@
stages: stages:
- Test - Tests
- OptionalTests
.install-grum-test: &install-grum-test
- pip install pytest pytest-random-order pytest-cov
- pip install -e ./
- apt-get update
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6 libxdamage1
tests: tests:
stage: Test stage: Tests
image: python:3.8
variables: variables:
QT_QPA_PLATFORM: "offscreen" QT_QPA_PLATFORM: "offscreen"
XDG_RUNTIME_DIR: "/tmp/runtime-root" XDG_RUNTIME_DIR: "/tmp/runtime-root"
PYTHONFAULTHANDLER: 1
script: script:
- pip install pytest pytest-random-order pytest-cov - *install-grum-test
- pip install -e ./ - coverage run --source=./grum -m pytest ./tests --junitxml=report-junit.xml
- pip install PyQtWebEngine
- apt-get update
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6
# - python -m unittest discover -f ./tests
# - coverage run --source=./grum -m unittest discover -f ./tests
- coverage run --source=./grum -m pytest ./tests
- coverage report - coverage report
- coverage xml - coverage xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/' coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts: artifacts:
when: always
reports: reports:
cobertura: coverage.xml junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
tests-3.6:
stage: OptionalTests
image: python:3.6
needs: ["tests"]
allow_failure: true
variables:
QT_QPA_PLATFORM: "offscreen"
XDG_RUNTIME_DIR: "/tmp/runtime-root"
PYTHONFAULTHANDLER: 1
script:
- *install-grum-test
- pytest ./tests
tests-3.7:
extends: "tests-3.6"
image: python:3.7
#tests-3.8:
# extends: "tests-3.6"
# image: python:3.8
tests-3.9:
extends: "tests-3.6"
image: python:3.9
tests-3.10:
extends: "tests-3.6"
image: python:3.10
tests-3.11:
extends: "tests-3.6"
image: python:3.11

View File

@@ -1,6 +1,6 @@
# grum # grum
<img src="https://gitlab.psi.ch/augustin_s/grum/-/wikis/uploads/1a259a1d74e7b79e0230e7bbad3b1284/screenshot2.png" width="50%" /> <img src="https://gitea.psi.ch/SwissFEL/grum/wiki/raw/uploads%2Fe4cd2be847d26bb7ac7100080edbccce%2Fscreenshot.png" width="50%" />
## Overview ## Overview
@@ -22,11 +22,11 @@ Via the RPC server, new plots can be created and new data appended to existing p
- `new_plot(name, cfg)` - `new_plot(name, cfg)`
Creates a new plot named `name` in the grum list. The configuration dict `cfg` is used as arguments for the constructor of [`PlotDescription`](https://gitlab.psi.ch/augustin_s/grum/-/blob/master/grum/plotdesc.py#L4). Creates a new plot named `name` in the grum list. The configuration dict `cfg` is used as arguments for the constructor of [`PlotDescription`](https://gitea.psi.ch/SwissFEL/grum/src/grum/descs/plotdesc.py#L4).
- `append_data(name, point)` - `append_data(name, point)`
Append data point to the plot named `name`. The new `point` is forwarded to [`PlotDescription.append()`](https://gitlab.psi.ch/augustin_s/grum/-/blob/master/grum/plotdesc.py#L18). Append data point to the plot named `name`. The new `point` is forwarded to [`PlotDescription.append()`](https://gitea.psi.ch/SwissFEL/grum/src/grum/descs/plotdesc.py#L24).
### Utility functions ### Utility functions

13
grum/descs/__init__.py Normal file
View File

@@ -0,0 +1,13 @@
from .desc import Description
from .imgdesc import ImageDescription
from .plotdesc import PlotDescription
DESC_TYPES = {
ImageDescription.get_type(): ImageDescription,
PlotDescription.get_type(): PlotDescription
}

23
grum/descs/desc.py Normal file
View File

@@ -0,0 +1,23 @@
class Description:
def to_dict(self):
res = {k: v for k, v in self.__dict__.items() if not k.startswith("_") and k != "name" and v is not None}
tn = self.get_type()
res.setdefault("type", tn)
return res
@classmethod
def get_type(cls):
tn = cls.__name__
suffix = "Description"
if not tn.endswith(suffix):
raise ValueError(f'"{tn}" does not end with "{suffix}"')
tn = tn[:-len(suffix)]
tn = tn.casefold()
tn = tn or None
return tn

52
grum/descs/imgdesc.py Normal file
View File

@@ -0,0 +1,52 @@
import numpy as np
import pyqtgraph as pg
from .desc import Description
class ImageDescription(Description):
def __init__(self, name, title=None, xlabel=None, ylabel=None, image=None, levels=None, cmap="viridis"):
self.name = name
self.title = title
self.xlabel = xlabel
self.ylabel = ylabel
self.image = image
self.levels = levels #TODO: might be better to use vmin and vmax
self.cmap = cmap
@property
def data(self):
return np.asarray(self.image)
@data.setter
def data(self, value):
self.image = value
def append(self, xy):
print("ignored image append")
def extend(self, data):
print("ignored image extend")
def make_plot(self, plotwidget, style):
res = plotwidget.setImage(self.data, levels=self.levels)
if self.title:
plotwidget.setTitle(self.title)
if self.xlabel:
plotwidget.getView().setLabel("bottom", self.xlabel)
if self.ylabel:
plotwidget.getView().setLabel("left", self.ylabel)
if self.cmap:
cm = pg.colormap.get(self.cmap)
plotwidget.setColorMap(cm)
return res

View File

@@ -1,5 +1,7 @@
from .desc import Description
class PlotDescription:
class PlotDescription(Description):
def __init__(self, name, title=None, xlabel=None, ylabel=None, xs=None, ys=None): def __init__(self, name, title=None, xlabel=None, ylabel=None, xs=None, ys=None):
self.name = name self.name = name
@@ -14,12 +16,21 @@ class PlotDescription:
def data(self): def data(self):
return (self.xs, self.ys) return (self.xs, self.ys)
@data.setter
def data(self, value):
self.xs, self.ys = value
def append(self, xy): def append(self, xy):
x, y = xy x, y = xy
self.xs.append(x) self.xs.append(x)
self.ys.append(y) self.ys.append(y)
def extend(self, data):
xs, ys = data
self.xs.extend(xs)
self.ys.extend(ys)
def make_plot(self, plotwidget, style): def make_plot(self, plotwidget, style):
res = plotwidget.plot(self.xs, self.ys, name=self.name, **style) res = plotwidget.plot(self.xs, self.ys, name=self.name, **style)
@@ -36,8 +47,4 @@ class PlotDescription:
return res return res
def to_dict(self):
return {k: v for k, v in self.__dict__.items() if not k.startswith("_") and k != "name" and v is not None}

View File

@@ -1,6 +1,6 @@
import numpy as np import numpy as np
from .plotdesc import PlotDescription from .descs import PlotDescription, ImageDescription
X = np.arange(100) / 10 X = np.arange(100) / 10
@@ -31,4 +31,20 @@ for name, (xs, ys) in exampledata_raw.items():
) )
name = "image"
xdim = ydim = 100
size = xdim * ydim
shape = (xdim, ydim)
img = np.arange(size).reshape(shape) / size
img += np.random.random(shape) / 10
exampledata[name] = ImageDescription(
name,
image=img,
xlabel="x",
ylabel="y"
)

View File

@@ -2,21 +2,27 @@ from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QMainWindow, QSplitter from PyQt5.QtWidgets import QMainWindow, QSplitter
from . import assets from . import assets
from .descs import DESC_TYPES, Description, ImageDescription, PlotDescription
from .dictlist import DictList from .dictlist import DictList
from .exampledata import exampledata from .exampledata import exampledata
from .h5filedlg import open_h5_files_dialog, save_h5_file_dialog from .h5filedlg import open_h5_files_dialog, save_h5_file_dialog
from .io import write_dict, read_dict from .io import write_dict, read_dict
from .mdi import MDIArea, MDISubMultiPlot, MDISubPlot, MDIWindowMode from .mdi import MDIArea, MDISubMultiPlot, MDISubPlot, MDISubImage, MDIWindowMode
from .menus import BarMenu from .menus import BarMenu
from .plotdesc import PlotDescription
from .rpc import RPCServerThread from .rpc import RPCServerThread
from .shortcut import shortcut from .shortcut import shortcut
from .webview import WebView from .webview import WebView
DESC_TYPE_TO_MDI_SUB_TYPE = {
ImageDescription: MDISubImage,
PlotDescription: MDISubPlot
}
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
sig_make_new_plot = pyqtSignal(str, PlotDescription) sig_make_new_subwin = pyqtSignal(str, Description)
def __init__(self, *args, title="grum", host="localhost", port=8000, offline=False, add_examples=False, window_mode=MDIWindowMode.MULTI, **kwargs): def __init__(self, *args, title="grum", host="localhost", port=8000, offline=False, add_examples=False, window_mode=MDIWindowMode.MULTI, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -84,10 +90,13 @@ class MainWindow(QMainWindow):
if not offline: if not offline:
self.rst = rst = RPCServerThread(host, port, doc_title_suffix=title) self.rst = rst = RPCServerThread(host, port, doc_title_suffix=title)
rst.start() rst.start()
rst.server.register_function(self.new_image)
rst.server.register_function(self.new_plot) rst.server.register_function(self.new_plot)
rst.server.register_function(self.append_data) rst.server.register_function(self.append_data)
rst.server.register_function(self.extend_data)
rst.server.register_function(self.set_data)
self.sig_make_new_plot.connect(self.on_make_new_plot) self.sig_make_new_subwin.connect(self.on_make_new_subwin)
def keyPressEvent(self, event): def keyPressEvent(self, event):
@@ -97,16 +106,30 @@ class MainWindow(QMainWindow):
# Remote API calls # Remote API calls
def new_image(self, name, cfg):
"""
Create a new image <name> using the configuration dict <cfg>.
The configuration is forwarded to the constructor of ImageDescription.
Allowed keys are: title, xlabel, ylabel, image, levels, cmap.
"""
desc = self.add_new_desc_to_list(ImageDescription, name, cfg)
if self.menu_settings.checkboxes["Open new plots"].isChecked():
sub = self.mdi.findSubWindow(name)
if sub:
sub.pw.setImage(desc.data) #TODO lacks the list sync
else:
self.sig_make_new_subwin.emit(name, desc)
def new_plot(self, name, cfg): def new_plot(self, name, cfg):
""" """
Create a new plot <name> using the configuration dict <cfg>. Create a new plot <name> using the configuration dict <cfg>.
The configuration is forwarded to the constructor of PlotDescription. The configuration is forwarded to the constructor of PlotDescription.
Allowed keys are: title, xlabel, ylabel, xs, ys. Allowed keys are: title, xlabel, ylabel, xs, ys.
""" """
desc = self.add_new_desc_to_list(name, cfg) desc = self.add_new_desc_to_list(PlotDescription, name, cfg)
if self.menu_settings.checkboxes["Open new plots"].isChecked(): if self.menu_settings.checkboxes["Open new plots"].isChecked():
if not self.mdi.findSubWindow(name): if not self.mdi.findSubWindow(name):
self.sig_make_new_plot.emit(name, desc) self.sig_make_new_subwin.emit(name, desc)
def append_data(self, name, point): def append_data(self, name, point):
""" """
@@ -116,20 +139,35 @@ class MainWindow(QMainWindow):
item = self.lst.get(name) item = self.lst.get(name)
desc = item.value desc = item.value
desc.append(point) desc.append(point)
alarm = True self.sync_item_and_plots(item)
for sub in self.mdi.subWindowList():
if name in sub.plots: def extend_data(self, name, data):
plot = sub.plots[name] """
plot.setData(*desc.data) Extend the current data of the (existing) plot <name>.by <data>
alarm = False The data is forwarded to the extend method of PlotDescription.
item.timestamps.modification.update() """
item.set_alarm(alarm) item = self.lst.get(name)
desc = item.value
desc.extend(data)
self.sync_item_and_plots(item)
def set_data(self, name, data):
"""
Set <data> as the data of the (existing) plot <name>.
The data is assigned to the data attribute of PlotDescription.
"""
item = self.lst.get(name)
desc = item.value
desc.data = data
self.sync_item_and_plots(item)
# Signal callbacks # Signal callbacks
def on_make_new_plot(self, *args, **kwargs): def on_make_new_subwin(self, name, desc):
self.make_subwin(MDISubPlot, *args, **kwargs) DescType = type(desc)
MDISubType = DESC_TYPE_TO_MDI_SUB_TYPE[DescType]
self.make_subwin(MDISubType, name, desc)
def on_dclick_list_item(self, item): def on_dclick_list_item(self, item):
self.plot_single_item(item) self.plot_single_item(item)
@@ -172,8 +210,10 @@ class MainWindow(QMainWindow):
for fn in fns: for fn in fns:
data = read_dict(fn) data = read_dict(fn)
for k, v in data.items(): for name, cfg in data.items():
self.add_new_desc_to_list(k, v) tn = cfg.pop("type")
DescType = DESC_TYPES[tn]
self.add_new_desc_to_list(DescType, name, cfg)
def on_file_save(self): def on_file_save(self):
@@ -191,28 +231,42 @@ class MainWindow(QMainWindow):
# Plumbing # Plumbing
def add_new_desc_to_list(self, name, cfg): def add_new_desc_to_list(self, DescType, name, cfg):
desc = PlotDescription(name, **cfg) desc = DescType(name, **cfg)
self.lst.set(name, desc) self.lst.set(name, desc)
return desc return desc
def sync_item_and_plots(self, item):
name, desc = item.key, item.value
alarm = True
for sub in self.mdi.subWindowList():
if name in sub.plots:
plot = sub.plots[name]
plot.setData(*desc.data)
alarm = False
item.timestamps.modification.update()
item.set_alarm(alarm)
def plot_single_item(self, item): def plot_single_item(self, item):
item.timestamps.access.update() item.timestamps.access.update()
item.set_alarm(False) item.set_alarm(False)
name, desc = item.key, item.value name, desc = item.key, item.value
self.activate_or_make_subwin(MDISubPlot, name, desc) DescType = type(desc)
MDISubType = DESC_TYPE_TO_MDI_SUB_TYPE[DescType]
self.activate_or_make_subwin(MDISubType, name, desc)
def plot_multiple_items(self, items): def plot_multiple_items(self, items):
for i in items: for i in items:
i.timestamps.access.update() i.timestamps.access.update()
i.set_alarm(False) i.set_alarm(False)
items = (i for i in items if isinstance(i.value, PlotDescription)) #TODO: for now, only overlay plots
descs = {i.key: i.value for i in items} descs = {i.key: i.value for i in items}
names = descs.keys() names = descs.keys()
name = " | ".join(names) name = " | ".join(names)
self.activate_or_make_subwin(MDISubMultiPlot, name, descs) self.activate_or_make_subwin(MDISubMultiPlot, name, descs)
#TODO: the following two could be methods to MDIArea? #TODO: the following two could be methods of MDIArea?
def activate_or_make_subwin(self, MDISubType, name, *args, **kwargs): def activate_or_make_subwin(self, MDISubType, name, *args, **kwargs):
sub = self.mdi.findSubWindow(name) sub = self.mdi.findSubWindow(name)

View File

@@ -1,5 +1,6 @@
from .mdiarea import MDIArea, MDIWindowMode from .mdiarea import MDIArea, MDIWindowMode
from .mdisubplot import MDISubPlot, MDISubMultiPlot from .mdisubplot import MDISubPlot, MDISubMultiPlot
from .mdisubimg import MDISubImage

38
grum/mdi/mdisubimg.py Normal file
View File

@@ -0,0 +1,38 @@
import pyqtgraph as pg
from .mdisubwin import MDISubWindow
from ..theme import pg_plot_style
class MDISubImage(MDISubWindow):
def __init__(self, name, desc, *args, **kwargs):
super().__init__(name, *args, **kwargs)
self.pw = pw = pg.ImageView(view=pg.PlotItem()) # for axis ticks and labels, view needs to be a PlotItem
self.setWidget(pw)
# connect to plot mouse-over event
pw.scene.sigMouseMoved.connect(self.on_hover)
style = pg_plot_style()
plot = desc.make_plot(self.pw, style)
self.plots = {name: plot}
self.image = desc.data
def on_hover(self, event):
coord = self.pw.imageItem.mapFromScene(event)
x = coord.x()
y = coord.y()
x = int(x)
y = int(y)
try:
z = self.image[x, y]
except IndexError:
return
z = round(z, 3)
self.setToolTip(f"x = {x}\ny = {y}\nz = {z}")

View File

@@ -4,12 +4,17 @@ from PyQt5.QtWidgets import QMdiSubWindow
from .. import assets from .. import assets
SUB_WIN_WIDTH = 640
SUB_WIN_HEIGHT = 480
class MDISubWindow(QMdiSubWindow): class MDISubWindow(QMdiSubWindow):
def __init__(self, title, *args, **kwargs): def __init__(self, title, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.setWindowTitle(title) self.setWindowTitle(title)
self.setWindowIcon(assets.char()) self.setWindowIcon(assets.char())
self.resize(SUB_WIN_WIDTH, SUB_WIN_HEIGHT)
# without this, the SubWindow is not removed from the subWindowList # without this, the SubWindow is not removed from the subWindowList
self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_DeleteOnClose)

View File

@@ -16,4 +16,10 @@ class RPCClient(xrc.ServerProxy):
return head + help return head + help
def __dir__(self):
d1 = super().__dir__()
d2 = self.utils.info().keys()
return [*d1, *d2]

View File

@@ -2,7 +2,7 @@ from PyQt5.QtCore import QUrl
try: try:
from PyQt5.QtWebKitWidgets import QWebView from PyQt5.QtWebKitWidgets import QWebView
except ImportError: except (ImportError, ModuleNotFoundError):
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView

View File

@@ -4,9 +4,9 @@ version = 0.0.1
description = GUI for Remote Unified Monitoring description = GUI for Remote Unified Monitoring
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
url = https://gitlab.psi.ch/augustin_s/grum url = https://gitea.psi.ch/SwissFEL/grum
project_urls = project_urls =
Bug Tracker = https://gitlab.psi.ch/augustin_s/grum/issues Bug Tracker = https://gitea.psi.ch/SwissFEL/grum/issues
classifiers = classifiers =
Programming Language :: Python :: 3 Programming Language :: Python :: 3
License :: OSI Approved :: MIT License License :: OSI Approved :: MIT License
@@ -16,7 +16,7 @@ classifiers =
package_dir = package_dir =
= . = .
packages = find: packages = find:
python_requires = >=3.8 python_requires = >=3.6
[options.packages.find] [options.packages.find]
where = . where = .

View File

@@ -2,7 +2,7 @@ from setuptools import setup
if __name__ == "__main__": if __name__ == "__main__":
setup( setup(
install_requires=["pyqt5", "pyqtgraph", "h5py"], install_requires=["pyqt5", "pyqtgraph", "h5py", "PyQtWebEngine"],
entry_points={"console_scripts": ["grum=grum:main"]}, entry_points={"console_scripts": ["grum=grum:main"]},
) )

View File

@@ -1,27 +0,0 @@
from grum.dictlist.dictlistwidget import DictListWidget
from grum.menus.rclickmenu import RClickMenu
class DictListWidgetMock(DictListWidget):
def __init__(self) -> None:
self.items = {}
self.nkeep = None
def get_DictListWidgetMock():
return DictListWidgetMock()
# def test_defaults():
# dlw = get_DictListWidgetMock()
# assert dlw.items == {}
# assert dlw.nkeep == None
# def test_add_menu():
# dlw = get_DictListWidgetMock()
# dlw._add_menu()
# assert dlw.menu == RClickMenu(dlw)

View File

@@ -14,13 +14,14 @@ from grum.mainwin import MainWindow
from grum.mdi import MDIArea, MDISubMultiPlot, MDISubPlot from grum.mdi import MDIArea, MDISubMultiPlot, MDISubPlot
from grum.menus import BarMenu from grum.menus import BarMenu
from grum.menus.rclickmenu import RClickMenu from grum.menus.rclickmenu import RClickMenu
from grum.plotdesc import PlotDescription from grum.descs import Description, PlotDescription
from grum.rpc import RPCServerThread from grum.rpc import RPCServerThread
class TestMainWin: class TestMainWin:
def setup_method(self): def setup_method(self):
print("setup")
self.app = QApplication(sys.argv) self.app = QApplication(sys.argv)
theme.apply(self.app) theme.apply(self.app)
# ctrl_c.setup(self.app) # ctrl_c.setup(self.app)
@@ -29,8 +30,10 @@ class TestMainWin:
def teardown_method(self): def teardown_method(self):
print("teardown")
self.mw.rst.wait_for_stop() self.mw.rst.wait_for_stop()
self.app.quit() self.app.quit()
print("app quit called")
del self.mw del self.mw
del self.app del self.app
@@ -44,7 +47,7 @@ class TestMainWin:
for key in mw.lst.lst.items: for key in mw.lst.lst.items:
assert isinstance(mw.lst.lst.get(key), DictListItem) assert isinstance(mw.lst.lst.get(key), DictListItem)
assert isinstance(mw.lst.lst.get(key).value, PlotDescription) assert isinstance(mw.lst.lst.get(key).value, Description)
assert isinstance(mw.lst.menu, RClickMenu) assert isinstance(mw.lst.menu, RClickMenu)
assert isinstance(mw.menu_settings, BarMenu) assert isinstance(mw.menu_settings, BarMenu)
@@ -62,7 +65,7 @@ class TestMainWin:
xlabel = "xlabel" xlabel = "xlabel"
ylabel = "ylabel" ylabel = "ylabel"
cfg = {"title": title, "xlabel": xlabel, "ylabel": ylabel} cfg = {"title": title, "xlabel": xlabel, "ylabel": ylabel}
spy_sig_make_new_plot = QSignalSpy(mw.sig_make_new_plot) spy_sig_make_new_subwin = QSignalSpy(mw.sig_make_new_subwin)
mw.new_plot(name, cfg=cfg) mw.new_plot(name, cfg=cfg)
@@ -73,28 +76,28 @@ class TestMainWin:
assert mw.lst.lst.get(name).value.ylabel == ylabel assert mw.lst.lst.get(name).value.ylabel == ylabel
assert mw.menu_settings.checkboxes["Open new plots"].isChecked() assert mw.menu_settings.checkboxes["Open new plots"].isChecked()
assert len(spy_sig_make_new_plot) == 1 # assert called once assert len(spy_sig_make_new_subwin) == 1 # assert called once
assert spy_sig_make_new_plot[0][0] == name # assert called with name assert spy_sig_make_new_subwin[0][0] == name # assert called with name
assert isinstance(spy_sig_make_new_plot[0][1], PlotDescription) assert isinstance(spy_sig_make_new_subwin[0][1], PlotDescription)
mw.menu_settings.checkboxes["Open new plots"].setChecked(False) mw.menu_settings.checkboxes["Open new plots"].setChecked(False)
assert mw.menu_settings.checkboxes["Open new plots"].isChecked() == False assert mw.menu_settings.checkboxes["Open new plots"].isChecked() == False
spy_sig_make_new_plot = QSignalSpy(mw.sig_make_new_plot) spy_sig_make_new_subwin = QSignalSpy(mw.sig_make_new_subwin)
mw.new_plot("new_name", cfg) mw.new_plot("new_name", cfg)
assert len(spy_sig_make_new_plot) == 0 # assert not called assert len(spy_sig_make_new_subwin) == 0 # assert not called
mw.menu_settings.checkboxes["Open new plots"].setChecked(True) mw.menu_settings.checkboxes["Open new plots"].setChecked(True)
assert mw.menu_settings.checkboxes["Open new plots"].isChecked() == True assert mw.menu_settings.checkboxes["Open new plots"].isChecked() == True
spy_sig_make_new_plot = QSignalSpy(mw.sig_make_new_plot) spy_sig_make_new_subwin = QSignalSpy(mw.sig_make_new_subwin)
new_name_item = mw.lst.lst.get("new_name") new_name_item = mw.lst.lst.get("new_name")
sub = MDISubPlot("new_name", new_name_item.value) sub = MDISubPlot("new_name", new_name_item.value)
mw.mdi.add(sub) mw.mdi.add(sub)
mw.new_plot("new_name", cfg) mw.new_plot("new_name", cfg)
assert len(spy_sig_make_new_plot) == 0 # assert not called assert len(spy_sig_make_new_subwin) == 0 # assert not called
def test_append_data(self): def test_append_data(self):
@@ -119,17 +122,19 @@ class TestMainWin:
assert sine_item.set_alarm.call_args[0][0] == False assert sine_item.set_alarm.call_args[0][0] == False
def test_on_make_new_plot(self): def test_on_make_new_subwin(self):
mw = self.mw mw = self.mw
mw.make_subwin = mock.MagicMock() mw.make_subwin = mock.MagicMock()
args = (1, 2, "name") name = "test"
kwargs = {"title": "plot_title"} cfg = {"title": "title"}
mw.on_make_new_plot(args, kwargs) desc = PlotDescription(name, *cfg)
mw.make_subwin.assert_called_once_with(MDISubPlot, args, kwargs) mw.on_make_new_subwin(name, desc)
mw.make_subwin.assert_called_once_with(MDISubPlot, name, desc)
def test_on_dclick_list_item(self): def test_on_dclick_list_item(self):
@@ -165,19 +170,6 @@ class TestMainWin:
mw.plot_multiple_items.assert_called_once_with([sine_item, cosine_item]) mw.plot_multiple_items.assert_called_once_with([sine_item, cosine_item])
def test_on_sort_by_name(self):
mw = self.mw
mw.lst = DictList()
mw.new_plot("bb", {})
mw.new_plot("dd", {})
mw.new_plot("aa", {})
mw.new_plot("cc", {})
assert mw.lst.lst.items == 111
assert [key for key in mw.lst.lst.items.keys()] == ['bb', 'dd', 'aa', 'cc']
mw.on_sort_by_name()
assert mw.lst.lst.items == 111
def test_plot_single_item(self): def test_plot_single_item(self):
mw = self.mw mw = self.mw
sine_item = mw.lst.lst.get("sine") sine_item = mw.lst.lst.get("sine")

View File

@@ -6,7 +6,7 @@ import pyqtgraph as pg
from grum import theme from grum import theme
from grum.mainwin import MainWindow from grum.mainwin import MainWindow
from grum.mdi.mdisubplot import MDISubPlot from grum.mdi.mdisubplot import MDISubPlot
from grum.plotdesc import PlotDescription from grum.descs import PlotDescription
from grum.theme import pg_plot_style from grum.theme import pg_plot_style
@@ -78,6 +78,7 @@ def test_to_dict():
"xs": [1, 2], "xs": [1, 2],
"ylabel": "plot_ylabel", "ylabel": "plot_ylabel",
"ys": [3, 4], "ys": [3, 4],
"type": "plot"
} }