28 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
14 changed files with 145 additions and 76 deletions

View File

@@ -6,7 +6,7 @@ stages:
- pip install pytest pytest-random-order pytest-cov
- pip install -e ./
- apt-get update
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6 libxdamage1
tests:
stage: Tests
@@ -24,8 +24,10 @@ tests:
artifacts:
when: always
reports:
cobertura: coverage.xml
junit: report-junit.xml
junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
tests-3.6:
stage: OptionalTests

View File

@@ -1,6 +1,6 @@
# 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
@@ -22,11 +22,11 @@ Via the RPC server, new plots can be created and new data appended to existing p
- `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 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

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

View File

@@ -1,14 +1,18 @@
import numpy as np
import pyqtgraph as pg
from .desc import Description
class ImageDescription:
class ImageDescription(Description):
def __init__(self, name, title=None, xlabel=None, ylabel=None, image=None):
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):
@@ -27,22 +31,22 @@ class ImageDescription:
def make_plot(self, plotwidget, style):
res = plotwidget.setImage(self.data)
res = plotwidget.setImage(self.data, levels=self.levels)
if self.title:
plotwidget.setTitle(self.title)
if self.xlabel:
plotwidget.setLabel("bottom", self.xlabel)
plotwidget.getView().setLabel("bottom", self.xlabel)
if self.ylabel:
plotwidget.setLabel("left", self.ylabel)
plotwidget.getView().setLabel("left", self.ylabel)
if self.cmap:
cm = pg.colormap.get(self.cmap)
plotwidget.setColorMap(cm)
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,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):
self.name = name
@@ -45,8 +47,4 @@ class PlotDescription:
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
from .plotdesc import PlotDescription
from .descs import PlotDescription, ImageDescription
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,23 +2,27 @@ from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QMainWindow, QSplitter
from . import assets
from .descs import DESC_TYPES, Description, ImageDescription, PlotDescription
from .dictlist import DictList
from .exampledata import exampledata
from .h5filedlg import open_h5_files_dialog, save_h5_file_dialog
from .io import write_dict, read_dict
from .mdi import MDIArea, MDISubMultiPlot, MDISubPlot, MDISubImage, MDIWindowMode
from .menus import BarMenu
from .plotdesc import PlotDescription
from .imgdesc import ImageDescription
from .rpc import RPCServerThread
from .shortcut import shortcut
from .webview import WebView
DESC_TYPE_TO_MDI_SUB_TYPE = {
ImageDescription: MDISubImage,
PlotDescription: MDISubPlot
}
class MainWindow(QMainWindow):
sig_make_new_plot = pyqtSignal(str, PlotDescription)
sig_make_new_image = pyqtSignal(str, ImageDescription)
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):
super().__init__(*args, **kwargs)
@@ -86,14 +90,13 @@ class MainWindow(QMainWindow):
if not offline:
self.rst = rst = RPCServerThread(host, port, doc_title_suffix=title)
rst.start()
rst.server.register_function(self.new_image)
rst.server.register_function(self.new_plot)
rst.server.register_function(self.append_data)
rst.server.register_function(self.extend_data)
rst.server.register_function(self.set_data)
rst.server.register_function(self.new_image)
self.sig_make_new_plot.connect(self.on_make_new_plot)
self.sig_make_new_image.connect(self.on_make_new_image)
self.sig_make_new_subwin.connect(self.on_make_new_subwin)
def keyPressEvent(self, event):
@@ -103,16 +106,30 @@ class MainWindow(QMainWindow):
# 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):
"""
Create a new plot <name> using the configuration dict <cfg>.
The configuration is forwarded to the constructor of PlotDescription.
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 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):
"""
@@ -144,28 +161,13 @@ class MainWindow(QMainWindow):
desc.data = data
self.sync_item_and_plots(item)
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.
"""
desc = self.add_new_desc_to_list(name, cfg, Desc=ImageDescription) #TODO: clean up Desc argument
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_image.emit(name, desc)
# Signal callbacks
def on_make_new_plot(self, *args, **kwargs):
self.make_subwin(MDISubPlot, *args, **kwargs)
def on_make_new_image(self, *args, **kwargs):
self.make_subwin(MDISubImage, *args, **kwargs)
def on_make_new_subwin(self, name, desc):
DescType = type(desc)
MDISubType = DESC_TYPE_TO_MDI_SUB_TYPE[DescType]
self.make_subwin(MDISubType, name, desc)
def on_dclick_list_item(self, item):
self.plot_single_item(item)
@@ -208,9 +210,10 @@ class MainWindow(QMainWindow):
for fn in fns:
data = read_dict(fn)
for k, v in data.items():
Desc = ImageDescription if "image" in v else PlotDescription #TODO
self.add_new_desc_to_list(k, v, Desc=Desc)
for name, cfg in data.items():
tn = cfg.pop("type")
DescType = DESC_TYPES[tn]
self.add_new_desc_to_list(DescType, name, cfg)
def on_file_save(self):
@@ -228,8 +231,8 @@ class MainWindow(QMainWindow):
# Plumbing
def add_new_desc_to_list(self, name, cfg, Desc=PlotDescription): #TODO
desc = Desc(name, **cfg)
def add_new_desc_to_list(self, DescType, name, cfg):
desc = DescType(name, **cfg)
self.lst.set(name, desc)
return desc
@@ -248,20 +251,22 @@ class MainWindow(QMainWindow):
item.timestamps.access.update()
item.set_alarm(False)
name, desc = item.key, item.value
MDISubType = MDISubImage if isinstance(desc, ImageDescription) else MDISubPlot #TODO
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):
for i in items:
i.timestamps.access.update()
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}
names = descs.keys()
name = " | ".join(names)
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):
sub = self.mdi.findSubWindow(name)

View File

@@ -7,7 +7,7 @@ class MDISubImage(MDISubWindow):
def __init__(self, name, desc, *args, **kwargs):
super().__init__(name, *args, **kwargs)
self.pw = pw = pg.ImageView()
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

View File

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

View File

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

View File

@@ -4,9 +4,9 @@ version = 0.0.1
description = GUI for Remote Unified Monitoring
long_description = file: README.md
long_description_content_type = text/markdown
url = https://gitlab.psi.ch/augustin_s/grum
url = https://gitea.psi.ch/SwissFEL/grum
project_urls =
Bug Tracker = https://gitlab.psi.ch/augustin_s/grum/issues
Bug Tracker = https://gitea.psi.ch/SwissFEL/grum/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License

View File

@@ -14,7 +14,7 @@ from grum.mainwin import MainWindow
from grum.mdi import MDIArea, MDISubMultiPlot, MDISubPlot
from grum.menus import BarMenu
from grum.menus.rclickmenu import RClickMenu
from grum.plotdesc import PlotDescription
from grum.descs import Description, PlotDescription
from grum.rpc import RPCServerThread
@@ -47,7 +47,7 @@ class TestMainWin:
for key in mw.lst.lst.items:
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.menu_settings, BarMenu)
@@ -65,7 +65,7 @@ class TestMainWin:
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)
@@ -76,28 +76,28 @@ class TestMainWin:
assert mw.lst.lst.get(name).value.ylabel == ylabel
assert mw.menu_settings.checkboxes["Open new plots"].isChecked()
assert len(spy_sig_make_new_plot) == 1 # assert called once
assert spy_sig_make_new_plot[0][0] == name # assert called with name
assert isinstance(spy_sig_make_new_plot[0][1], PlotDescription)
assert len(spy_sig_make_new_subwin) == 1 # assert called once
assert spy_sig_make_new_subwin[0][0] == name # assert called with name
assert isinstance(spy_sig_make_new_subwin[0][1], PlotDescription)
mw.menu_settings.checkboxes["Open new plots"].setChecked(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)
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)
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")
sub = MDISubPlot("new_name", new_name_item.value)
mw.mdi.add(sub)
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):
@@ -122,17 +122,19 @@ class TestMainWin:
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.make_subwin = mock.MagicMock()
args = (1, 2, "name")
kwargs = {"title": "plot_title"}
name = "test"
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):

View File

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