Skip to content

Commit 1f31aef

Browse files
committed
Added GetObjectDialog widget
1 parent 837a50e commit 1f31aef

File tree

14 files changed

+722
-38
lines changed

14 files changed

+722
-38
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"envFile": "${workspaceFolder}/.env",
2727
"python": "${config:python.defaultInterpreterPath}",
2828
"justMyCode": false,
29+
"env": {
30+
"QT_COLOR_MODE": "light",
31+
}
2932
},
3033
{
3134
"name": "Run current file (unattended)",

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# DataLab Simple Client Releases #
22

3+
## Version 0.6.0 ##
4+
5+
💥 Changes:
6+
7+
* Remote API (`SimpleRemoteProxy`):
8+
* Added `get_group_titles_with_object_infos` method
9+
10+
* New `widgets` module:
11+
* New `GetObjectDialog` class:
12+
* Ready-to-use dialog box to retrieve an object from a DataLab server
13+
* `from cdlclient.widgets import GetObjectDialog`
14+
* See example in `cdlclient/tests/get_object_dialog.py`
15+
316
## Version 0.5.0 ##
417

518
💥 Changes:

cdlclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
from cdlclient.baseproxy import SimpleBaseProxy # noqa: F401
1818
from cdlclient.remote import SimpleRemoteProxy # noqa: F401
1919

20-
__version__ = "0.5.0"
20+
__version__ = "0.6.0"
2121
__docurl__ = "https://cdlclient.readthedocs.io/en/latest/"
2222
__homeurl__ = "https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/"

cdlclient/baseproxy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ def delete_metadata(self, refresh_plot: bool = True) -> None:
266266
refresh_plot (bool | None): Refresh plot. Defaults to True.
267267
"""
268268

269+
@abc.abstractmethod
270+
def get_group_titles_with_object_infos(
271+
self,
272+
) -> tuple[list[str], list[list[str]], list[list[str]]]:
273+
"""Return groups titles and lists of inner objects uuids and titles.
274+
275+
Returns:
276+
Tuple: groups titles, lists of inner objects uuids and titles
277+
"""
278+
269279
@abc.abstractmethod
270280
def get_object_titles(self, panel: str | None = None) -> list[str]:
271281
"""Get object (signal/image) list for current panel.
@@ -542,6 +552,16 @@ def delete_metadata(self, refresh_plot: bool = True) -> None:
542552
"""
543553
self._cdl.delete_metadata(refresh_plot)
544554

555+
def get_group_titles_with_object_infos(
556+
self,
557+
) -> tuple[list[str], list[list[str]], list[list[str]]]:
558+
"""Return groups titles and lists of inner objects uuids and titles.
559+
560+
Returns:
561+
Tuple: groups titles, lists of inner objects uuids and titles
562+
"""
563+
return self._cdl.get_group_titles_with_object_infos()
564+
545565
def get_object_titles(self, panel: str | None = None) -> list[str]:
546566
"""Get object (signal/image) list for current panel.
547567
Objects are sorted by group number and object index in group.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Licensed under the terms of the BSD 3-Clause
4+
# (see cdlclient/LICENSE for details)
5+
6+
"""
7+
DataLab Remote client get object dialog example
8+
"""
9+
10+
# guitest: show
11+
12+
from guidata.qthelpers import qt_app_context
13+
14+
from cdlclient import SimpleRemoteProxy
15+
from cdlclient.widgets import GetObjectDialog
16+
17+
18+
def test_dialog():
19+
"""Test connection dialog"""
20+
proxy = SimpleRemoteProxy()
21+
proxy.connect()
22+
with qt_app_context():
23+
dlg = GetObjectDialog(None, "Get object", proxy)
24+
if dlg.exec():
25+
obj_uuid = dlg.get_current_object_uuid()
26+
obj = proxy.get_object(obj_uuid)
27+
print(str(obj))
28+
29+
30+
if __name__ == "__main__":
31+
test_dialog()

cdlclient/tests/imagefile_to_code.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,16 @@
33

44
# guitest: skip
55

6-
import os
76
import os.path as osp
87

98
from guidata.qthelpers import qt_app_context
109
from qtpy import QtCore as QC
1110
from qtpy import QtGui as QG
1211
from qtpy import QtWidgets as QW
1312

14-
PKG_PATH = osp.join(osp.dirname(__file__), os.pardir, os.pardir)
15-
RES_PATH = osp.join(PKG_PATH, "resources")
16-
WIDGETS_PATH = osp.join(PKG_PATH, "cdlclient", "widgets")
17-
18-
19-
def imagefile_to_base64(filename: str) -> bytes:
20-
"""Convert image file to Base64-encoded bytes
21-
22-
Args:
23-
filename: image filename
24-
25-
Returns:
26-
Base64-encoded bytes
27-
"""
28-
image = QG.QImage(filename)
29-
data = QC.QByteArray()
30-
buf = QC.QBuffer(data)
31-
image.save(buf, "PNG")
32-
return data.toBase64().data()
13+
from cdlclient.widgets.qthelpers import PKG_PATH, imagefile_to_python_module
3314

34-
35-
def imagefile_to_python_module(filename: str, destmod: str) -> None:
36-
"""Convert image file to Python module
37-
38-
Args:
39-
filename: image filename
40-
destmod: destination module name
41-
"""
42-
data = imagefile_to_base64(filename)
43-
destmod_path = osp.join(WIDGETS_PATH, destmod + ".py")
44-
with open(destmod_path, "wb") as fn:
45-
fn.write("# -*- coding: utf-8 -*-\n\n".encode("utf-8"))
46-
fn.write("# pylint: skip-file\n\n".encode("utf-8"))
47-
fn.write("DATA = b'".encode("utf-8"))
48-
fn.write(data)
49-
fn.write("'".encode("utf-8"))
15+
RES_PATH = osp.join(PKG_PATH, "resources")
5016

5117

5218
def test_conv(filename: str, destmod: str) -> None:
@@ -75,3 +41,4 @@ def test_conv(filename: str, destmod: str) -> None:
7541

7642
if __name__ == "__main__":
7743
test_conv(osp.join(RES_PATH, "DataLab-Banner-200.png"), "datalab_banner")
44+
test_conv(osp.join(RES_PATH, "DataLab-Banner-200.png"), "datalab_banner")

cdlclient/tests/remoteclient_app.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from cdlclient import SimpleRemoteProxy
2626
from cdlclient.tests.remoteclient_base import AbstractClientWindow
2727
from cdlclient.tests.remoteclient_unit import multiple_commands
28-
from cdlclient.widgets import ConnectionDialog
28+
from cdlclient.widgets import ConnectionDialog, GetObjectDialog
2929

3030
APP_NAME = "Remote client test"
3131

@@ -100,6 +100,7 @@ def add_additional_buttons(self):
100100
add_btn("Get object titles", self.get_object_titles, 10)
101101
add_btn("Get object uuids", self.get_object_uuids, 10)
102102
add_btn("Get object", self.get_object)
103+
add_btn("Get object using dialog box", self.get_object_dialog)
103104

104105
@try_send_command()
105106
def exec_multiple_cmd(self):
@@ -145,6 +146,17 @@ def get_object(self):
145146
else:
146147
self.host.log("🏴‍☠️ Object list is empty!")
147148

149+
@try_send_command()
150+
def get_object_dialog(self):
151+
"""Get object (signal/image) using dialog box"""
152+
if self.cdl is not None:
153+
dialog = GetObjectDialog(self, "Get object from DataLab", self.cdl)
154+
if dialog.exec():
155+
uuid = dialog.get_current_object_uuid()
156+
obj = self.cdl.get_object(uuid)
157+
self.host.log(f"Object '{obj.title}'")
158+
self.host.log(str(obj))
159+
148160
def add_signals(self):
149161
"""Add signals to DataLab"""
150162
if self.cdl is not None:

cdlclient/widgets/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
# pylint: disable=unused-import
1414
from cdlclient.widgets.connection import ConnectionDialog # noqa: F401
15+
from cdlclient.widgets.objectdialog import GetObjectDialog # noqa: F401

0 commit comments

Comments
 (0)