Skip to content

Commit 2a9df96

Browse files
committed
Added more plugin examples
1 parent 258589c commit 2a9df96

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

cdl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"""
77
DataLab
8-
============
8+
=======
99
1010
DataLab is a generic signal and image processing software based on Python
1111
scientific libraries (such as NumPy, SciPy or scikit-image) and Qt graphical
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Empty plugin example
5+
====================
6+
7+
This is an empty example of a DataLab plugin.
8+
9+
It adds a new menu entry in "Plugins" menu, with a sub-menu "Empty plugin (example)".
10+
This sub-menu contains one action, "Do nothing".
11+
"""
12+
13+
import cdl.plugins
14+
15+
16+
class EmptyPlugin(cdl.plugins.PluginBase):
17+
"""DataLab Example Plugin"""
18+
19+
PLUGIN_INFO = cdl.plugins.PluginInfo(
20+
name="Empty plugin (example)",
21+
version="1.0.0",
22+
description="This is an empty example plugin",
23+
)
24+
25+
def do_nothing(self) -> None:
26+
"""Do nothing"""
27+
self.show_info("Do nothing")
28+
29+
def create_actions(self) -> None:
30+
"""Create actions"""
31+
acth = self.imagepanel.acthandler
32+
with acth.new_menu(self.PLUGIN_INFO.name):
33+
# Note: in the following call, `select_condition` is by default `None`,
34+
# so the action is enabled only if at least one image is selected.
35+
acth.new_action("Do nothing", triggered=self.do_nothing)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Image format Plugin for DataLab (example)
5+
=========================================
6+
7+
This plugin is an example of how to add a new image file format to DataLab.
8+
9+
It provides a new image file format, Dürr NDT XYZ, from Dürr NDT GmbH & Co. KG
10+
(see `Dürr NDT website <https://www.duerr-ndt.com/>`_).
11+
"""
12+
13+
import numpy as np
14+
15+
from cdl.core.io.base import FormatInfo
16+
from cdl.core.io.image.base import ImageFormatBase
17+
18+
19+
class XYZImageFormat(ImageFormatBase):
20+
"""Object representing Dürr NDT XYZ image file type"""
21+
22+
FORMAT_INFO = FormatInfo(
23+
name="Dürr NDT",
24+
extensions="*.xyz",
25+
readable=True,
26+
writeable=False,
27+
)
28+
29+
@staticmethod
30+
def read_data(filename: str) -> np.ndarray:
31+
"""Read data and return it
32+
33+
Args:
34+
filename (str): path to XYZ file
35+
36+
Returns:
37+
np.ndarray: image data
38+
"""
39+
with open(filename, "rb") as fdesc:
40+
cols = int(np.fromfile(fdesc, dtype=np.uint16, count=1)[0])
41+
rows = int(np.fromfile(fdesc, dtype=np.uint16, count=1)[0])
42+
arr = np.fromfile(fdesc, dtype=np.uint16, count=cols * rows)
43+
arr = arr.reshape((rows, cols))
44+
return np.fliplr(arr)

0 commit comments

Comments
 (0)