Skip to content

Commit fac4b76

Browse files
committed
New toggle_auto_refresh/toggle_show_titles methods
1 parent ef27ec1 commit fac4b76

File tree

5 files changed

+80
-4
lines changed

5 files changed

+80
-4
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"[python]": {
2222
"editor.codeActionsOnSave": {
23-
"source.organizeImports": true
23+
"source.organizeImports": "explicit"
2424
},
2525
"editor.defaultFormatter": "ms-python.black-formatter"
2626
},

CHANGELOG.md

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

3+
## Version 0.7.0 ##
4+
5+
💥 Changes:
6+
7+
* Added `toggle_auto_refresh` method to `SimpleRemoteProxy`
8+
* Added `toggle_show_titles` method to `SimpleRemoteProxy`
9+
310
## Version 0.6.0 ##
411

512
💥 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.6.0"
20+
__version__ = "0.7.0"
2121
__docurl__ = "https://cdlclient.readthedocs.io/en/latest/"
2222
__homeurl__ = "https://github.com/Codra-Ingenierie-Informatique/DataLabSimpleClient/"

cdlclient/baseproxy.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ def set_current_panel(self, panel: str) -> None:
117117
def reset_all(self) -> None:
118118
"""Reset all application data"""
119119

120+
@abc.abstractmethod
121+
def toggle_auto_refresh(self, state: bool) -> None:
122+
"""Toggle auto refresh state.
123+
124+
Args:
125+
state (bool): Auto refresh state
126+
"""
127+
128+
@abc.abstractmethod
129+
def toggle_show_titles(self, state: bool) -> None:
130+
"""Toggle show titles state.
131+
132+
Args:
133+
state (bool): Show titles state
134+
"""
135+
120136
@abc.abstractmethod
121137
def save_to_h5_file(self, filename: str) -> None:
122138
"""Save to a DataLab HDF5 file.
@@ -465,6 +481,53 @@ def reset_all(self) -> None:
465481
"""Reset all application data"""
466482
self._cdl.reset_all()
467483

484+
def toggle_auto_refresh(self, state: bool) -> None:
485+
"""Toggle auto refresh state.
486+
487+
Args:
488+
state (bool): Auto refresh state
489+
"""
490+
self._cdl.toggle_auto_refresh(state)
491+
492+
# Returns a context manager to temporarily disable autorefresh
493+
def context_no_refresh(self) -> Callable:
494+
"""Return a context manager to temporarily disable auto refresh.
495+
496+
Returns:
497+
Context manager
498+
499+
Example:
500+
501+
>>> with proxy.context_no_refresh():
502+
... proxy.add_image("image1", data1)
503+
... proxy.compute_fft()
504+
... proxy.compute_wiener()
505+
... proxy.compute_ifft()
506+
... # Auto refresh is disabled during the above operations
507+
"""
508+
509+
class NoRefreshContextManager:
510+
"""Context manager to temporarily disable auto refresh"""
511+
512+
def __init__(self, cdl: SimpleAbstractCDLControl) -> None:
513+
self._cdl = cdl
514+
515+
def __enter__(self) -> None:
516+
self._cdl.toggle_auto_refresh(False)
517+
518+
def __exit__(self, exc_type, exc_value, traceback) -> None:
519+
self._cdl.toggle_auto_refresh(True)
520+
521+
return NoRefreshContextManager(self)
522+
523+
def toggle_show_titles(self, state: bool) -> None:
524+
"""Toggle show titles state.
525+
526+
Args:
527+
state (bool): Show titles state
528+
"""
529+
self._cdl.toggle_show_titles(state)
530+
468531
def save_to_h5_file(self, filename: str) -> None:
469532
"""Save to a DataLab HDF5 file.
470533

doc/remote_example.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,24 @@
2828

2929
# %% Executing commands in DataLab (...)
3030

31+
proxy.toggle_auto_refresh(False) # Turning off auto-refresh
3132
x = np.array([1.0, 2.0, 3.0])
3233
y = np.array([4.0, 5.0, -1.0])
3334
proxy.add_signal("toto", x, y)
3435

3536
# %% Executing commands in DataLab (...)
3637

3738
proxy.compute_derivative()
39+
proxy.toggle_auto_refresh(True) # Turning on auto-refresh
3840

3941
# %% Executing commands in DataLab (...)
4042

4143
proxy.set_current_panel("image")
4244

43-
# %% Executing commands in DataLab (...)
45+
# %% Executing a lot of commands without refreshing DataLab
4446

45-
proxy.compute_fft()
47+
z = np.random.rand(400, 400)
48+
proxy.add_image("foobar", z)
49+
with proxy.context_no_refresh():
50+
for _idx in range(100):
51+
proxy.compute_fft()

0 commit comments

Comments
 (0)