0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

feat(image_widget): all toolbar actions added

This commit is contained in:
2024-07-19 22:16:41 +02:00
committed by wyzula_j
parent c15035b6b7
commit 501eb923f1
7 changed files with 109 additions and 13 deletions

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="m311.5-154.02-47.74-47.74 116.94-116.7H74.02v-68.37H380.7L263.76-503.76l47.74-47.74 198.98 198.74L311.5-154.02Zm337-254.72L449.76-607.48 648.5-806.22l47.74 47.74-116.7 116.94h306.68v68.37H579.54l116.7 116.69-47.74 47.74Z"/>
</svg>

After

Width:  |  Height:  |  Size: 351 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="M725.93-155.93q0-118.18-45-222.09t-122-180.91q-77-77-180.91-122t-222.09-45v-68.14q132.68 0 248.61 50.23 115.92 50.23 202.5 136.75 86.57 86.53 136.8 202.53 50.23 116.01 50.23 248.63h-68.14Z"/>
</svg>

After

Width:  |  Height:  |  Size: 319 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="M473.54-344.48v-63.59h187.18v63.59H473.54Zm81.92 230.46v-56.15h-81.92v-63.59h81.92v-56.39h63.58v176.13h-63.58Zm103.58-56.15v-63.59h187.18v63.59H659.04Zm41.68-116.92v-177.13h63.58v56.15h81.92v63.59H764.3v57.39h-63.58ZM841.22-540h-68.46q-22.98-101.89-103.94-170.83-80.95-68.93-188.89-68.93-125.29 0-212.37 87.18T180.48-480q0 78.61 36.59 143.32 36.58 64.7 96.95 104.46v-108.26h66.46v226.46H154.02v-66.46h117.41q-71.56-48.72-114.48-127.36-42.93-78.64-42.93-172.16 0-76.22 28.86-142.78 28.86-66.57 78.29-116.04 49.42-49.47 116.01-78.43 66.58-28.97 142.82-28.97 136.52 0 237.87 87.8Q819.22-670.63 841.22-540Z"/>
</svg>

After

Width:  |  Height:  |  Size: 733 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="M435-72.11q-49.67-7-95.99-25.36-46.31-18.36-86.55-49.55l49.21-49.74q31.76 24 65.29 37.26 33.52 13.26 68.04 19.02v68.37Zm90 0v-68.37q109.28-21.24 181.07-102.9 71.78-81.66 71.78-197.71 0-124.37-84.11-210.87t-208.72-86.5h-18.8L540.67-664l-49.74 49.74L332.2-773l158.73-158.74 49.74 49.26-75.41 75.65h19.28q75.48 0 141.34 28.72t114.98 78.56q49.12 49.83 77.24 116.29 28.12 66.46 28.12 142.17 0 142.39-90.8 245.07Q664.63-93.35 525-72.11ZM189.46-209.78q-28.96-38.72-47.82-86.3-18.86-47.57-25.62-100.01h68.89q5 37.76 18.38 72.17 13.38 34.4 36.14 64.16l-49.97 49.98Zm-73.44-276.31q6.52-50.71 25-97.29 18.48-46.58 48.44-87.77l50.21 48.26q-22.76 33-36.14 67.52-13.38 34.52-18.62 69.28h-68.89Z"/>
</svg>

After

Width:  |  Height:  |  Size: 811 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 -960 960 960" width="48px" fill="#FFFFFF">
<path d="M527-72.11v-68.37q34.52-5.76 68.04-19.02 33.53-13.26 65.29-37.26l49.21 49.74q-40.24 31.19-86.55 49.55Q576.67-79.11 527-72.11Zm-90 0Q297.37-93.35 206.7-196.02q-90.68-102.68-90.68-245.07 0-75.71 28-142.17t77.12-116.29q49.12-49.84 114.98-78.56 65.86-28.72 141.34-28.72h19.28l-75.41-75.65 49.74-49.26L629.8-773 471.07-614.26 421.33-664l74.69-74.46h-19.04q-124.61 0-208.72 86.5t-84.11 210.87q0 116.05 71.78 197.71 71.79 81.66 181.07 102.9v68.37Zm335.54-137.67-49.97-49.98q22.76-29.76 36.14-64.16 13.38-34.41 18.38-72.17h69.13q-7 52.44-25.86 100.01-18.86 47.58-47.82 86.3Zm73.68-276.31h-69.13q-5.24-34.76-18.62-69.28t-36.14-67.52l50.21-48.26q29.96 41.19 48.44 87.77 18.48 46.58 25.24 97.29Z"/>
</svg>

After

Width:  |  Height:  |  Size: 815 B

View File

@ -52,6 +52,7 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover:
"wave": self.wave,
"bar": self.bar,
"cm": self.colormap,
"im": self.im,
}
)
@ -158,12 +159,10 @@ class JupyterConsoleWindow(QWidget): # pragma: no cover:
self.fig0 = self.d0.add_widget("BECFigure")
data = np.random.rand(10, 2)
self.fig0.plot(data, label="2d Data")
self.fig0.image("eiger", vrange=(0, 100))
self.d1 = self.dock.add_dock(name="dock_1", position="right")
self.fig1 = self.d1.add_widget("BECFigure")
self.fig1.plot(x_name="samx", y_name="bpm4i")
self.fig1.plot(x_name="samx", y_name="bpm3a")
self.im = self.fig1.image("eiger")
self.d2 = self.dock.add_dock(name="dock_2", position="bottom")
self.wave = self.d2.add_widget("BECWaveformWidget", row=0, col=0)

View File

@ -67,7 +67,20 @@ class BECImageWidget(BECWidget, QWidget):
checkable=True,
),
"separator_2": SeparatorAction(),
"FFT": IconAction(icon_path="transform.svg", tooltip="Toggle FFT", checkable=True),
"FFT": IconAction(icon_path="compare.svg", tooltip="Toggle FFT", checkable=True),
"log": IconAction(
icon_path="line_curve.svg", tooltip="Toggle log scale", checkable=True
),
"transpose": IconAction(
icon_path="transform.svg", tooltip="Transpose Image", checkable=True
),
"rotate_right": IconAction(
icon_path="rotate_right.svg", tooltip="Rotate image clockwise by 90 deg"
),
"rotate_left": IconAction(
icon_path="rotate_left.svg", tooltip="Rotate image counterclockwise by 90 deg"
),
"reset": IconAction(icon_path="reset_settings.svg", tooltip="Reset Image Settings"),
"separator_3": SeparatorAction(),
"axis_settings": IconAction(
icon_path="settings.svg", tooltip="Open Configuration Dialog"
@ -83,17 +96,20 @@ class BECImageWidget(BECWidget, QWidget):
self.image = self.fig.image()
self.image.apply_config(config)
self.rotation = 0
self.config = config
self._hook_actions()
# TODO test commands
self.image.add_monitor_image("eiger")
# self.image.add_monitor_image("eiger")
def _hook_actions(self):
self.toolbar.widgets["connect"].action.triggered.connect(self._connect_action)
# sepatator
self.toolbar.widgets["save"].action.triggered.connect(self.export)
# sepatator
self.toolbar.widgets["drag_mode"].action.triggered.connect(self.enable_mouse_pan_mode)
self.toolbar.widgets["rectangle_mode"].action.triggered.connect(
self.enable_mouse_rectangle_mode
@ -102,7 +118,14 @@ class BECImageWidget(BECWidget, QWidget):
self.toolbar.widgets["auto_range_image"].action.triggered.connect(
self.toogle_image_autorange
)
# sepatator
self.toolbar.widgets["FFT"].action.triggered.connect(self.toogle_fft)
self.toolbar.widgets["log"].action.triggered.connect(self.toogle_log)
self.toolbar.widgets["transpose"].action.triggered.connect(self.toogle_transpose)
self.toolbar.widgets["rotate_left"].action.triggered.connect(self.rotate_left)
self.toolbar.widgets["rotate_right"].action.triggered.connect(self.rotate_right)
self.toolbar.widgets["reset"].action.triggered.connect(self.reset_settings)
# sepatator
self.toolbar.widgets["axis_settings"].action.triggered.connect(self.show_axis_settings)
###################################
@ -112,7 +135,8 @@ class BECImageWidget(BECWidget, QWidget):
def _connect_action(self):
monitor_combo = self.toolbar.widgets["monitor"].device_combobox
monitor_name = monitor_combo.currentText()
self.add_monitor_image(monitor_name)
# self.add_monitor_image(monitor_name)
self.set_monitor_image(monitor_name)
monitor_combo.setStyleSheet("QComboBox { background-color: " "; }")
def show_axis_settings(self):
@ -160,6 +184,39 @@ class BECImageWidget(BECWidget, QWidget):
"""
self.image.set_fft(enable, name)
def set_transpose(self, enable: bool = False, name: str = None):
"""
Set the transpose of the image.
If name is not specified, then set transpose for all images.
Args:
enable(bool): Whether to transpose the monitor data before displaying.
name(str): The name of the image. If None, apply to all images.
"""
self.image.set_transpose(enable, name)
def set_rotation(self, deg_90: int = 0, name: str = None):
"""
Set the rotation of the image.
If name is not specified, then set rotation for all images.
Args:
deg_90(int): The rotation angle of the monitor data before displaying.
name(str): The name of the image. If None, apply to all images.
"""
self.image.set_rotation(deg_90, name)
def set_log(self, enable: bool = False, name: str = None):
"""
Set the log of the image.
If name is not specified, then set log for all images.
Args:
enable(bool): Whether to perform log on the monitor data.
name(str): The name of the image. If None, apply to all images.
"""
self.image.set_log(enable, name)
###################################
# User Access Methods from Plotbase
###################################
@ -289,6 +346,38 @@ class BECImageWidget(BECWidget, QWidget):
checked = self.toolbar.widgets["FFT"].action.isChecked()
self.set_fft(checked)
@SafeSlot()
def toogle_log(self):
checked = self.toolbar.widgets["log"].action.isChecked()
self.set_log(checked)
@SafeSlot()
def toogle_transpose(self):
checked = self.toolbar.widgets["transpose"].action.isChecked()
self.set_transpose(checked)
@SafeSlot()
def rotate_left(self):
self.rotation = (self.rotation + 1) % 4
self.set_rotation(self.rotation)
@SafeSlot()
def rotate_right(self):
self.rotation = (self.rotation - 1) % 4
self.set_rotation(self.rotation)
@SafeSlot()
def reset_settings(self):
self.set_log(False)
self.set_fft(False)
self.set_transpose(False)
self.rotation = 0
self.set_rotation(0)
self.toolbar.widgets["FFT"].action.setChecked(False)
self.toolbar.widgets["log"].action.setChecked(False)
self.toolbar.widgets["transpose"].action.setChecked(False)
@SafeSlot()
def toogle_image_autorange(self):
"""
@ -296,13 +385,6 @@ class BECImageWidget(BECWidget, QWidget):
"""
checked = self.toolbar.widgets["auto_range_image"].action.isChecked()
self.image.set_autorange(checked)
# self.autorange_checked = checked
# if self.autorange_checked:
# print("Auto range is enabled")
# self.image.set_autorange(True)
# else:
# print("Auto range is disabled")
# self.image.set_autorange(False)
@SafeSlot()
def enable_mouse_rectangle_mode(self):