Skip to content

Commit

Permalink
ENH: add option to create a new RBV if one does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Oct 22, 2024
1 parent 73e0f3b commit d8288e6
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions superscore/widgets/page/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Widgets for visualizing and editing core model dataclasses
"""
import logging
from typing import Callable, Optional, Union
from typing import Optional, Union

import qtawesome as qta
from qtpy import QtWidgets
Expand All @@ -12,7 +12,7 @@
from superscore.control_layers._base_shim import EpicsData
from superscore.model import (Collection, Nestable, Parameter, Readback,
Setpoint, Severity, Snapshot, Status)
from superscore.type_hints import AnyEpicsType
from superscore.type_hints import AnyEpicsType, OpenPageSlot
from superscore.widgets.core import DataWidget, Display, NameDescTagsWidget
from superscore.widgets.manip_helpers import (insert_widget,
match_line_edit_text_width)
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
data: Nestable,
client: Client,
editable: bool = False,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs
):
super().__init__(*args, data=data, **kwargs)
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(
*args,
client: Client,
editable: bool = False,
open_page_slot: Optional[Callable] = None,
open_page_slot: Optional[OpenPageSlot] = None,
**kwargs
):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -188,12 +188,11 @@ def setup_ui(self):
self.timeout_spinbox.valueChanged.connect(self.update_timeout)

try:
self.bridge.readback.pv_name
self.bridge.readback
except AttributeError:
self.rbv_widget.hide()
else:
self.rbv_pv_label.setText(self.data.readback.pv_name)
self.open_rbv_button.clicked.connect(self.open_rbv_page)
self.setup_rbv_widget()

def get_edata(self) -> None:
if self._edata_thread and self._edata_thread.isRunning():
Expand Down Expand Up @@ -268,9 +267,24 @@ def update_timeout(self, *args, **kwargs):
if hasattr(self.data, "timeout"):
self.bridge.timeout.put(self.timeout_spinbox.value())

def open_rbv_page(self):
def open_rbv_page(self) -> DataWidget:
if self.open_page_slot:
self.open_page_slot(self.data.readback)
widget = self.open_page_slot(self.data.readback)
widget.bridge.pv_name.changed_value.connect(self.rbv_pv_label.setText)

def create_rbv(self):
new_rbv = Readback(pv_name='<MY:PV>')
self.bridge.readback.put(new_rbv)
self.open_rbv_page()

def setup_rbv_widget(self):
if self.data.readback is None:
# Setup create-new button
self.rbv_pv_label.setText("[None]")
self.open_rbv_button.clicked.connect(self.create_rbv)
else:
self.rbv_pv_label.setText(self.data.readback.pv_name)
self.open_rbv_button.clicked.connect(self.open_rbv_page)


class ParameterPage(BaseParameterPage):
Expand Down

0 comments on commit d8288e6

Please sign in to comment.