Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Archiver Timeplot address setters #1061

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions pydm/widgets/archiver_time_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import OrderedDict
from typing import List, Optional
from pyqtgraph import DateAxisItem, ErrorBarItem
from pydm.utilities import remove_protocol
from pydm.widgets.channel import PyDMChannel
from pydm.widgets.timeplot import TimePlotCurveItem
from pydm.widgets import PyDMTimePlot
Expand Down Expand Up @@ -40,7 +41,7 @@ class ArchivePlotCurveItem(TimePlotCurveItem):
archive_data_received_signal = Signal()

def __init__(self, channel_address: Optional[str] = None, use_archive_data: bool = True, **kws):
super(ArchivePlotCurveItem, self).__init__(channel_address, **kws)
super(ArchivePlotCurveItem, self).__init__(**kws)
self.use_archive_data = use_archive_data
self.archive_channel = None
self.archive_points_accumulated = 0
Expand All @@ -52,8 +53,7 @@ def __init__(self, channel_address: Optional[str] = None, use_archive_data: bool
self.error_bar_item = ErrorBarItem()
self.error_bar_needs_set = True

if channel_address is not None and use_archive_data:
self.setArchiveChannel(channel_address)
self.address = channel_address

def to_dict(self) -> OrderedDict:
"""Returns an OrderedDict representation with values for all properties needed to recreate this curve."""
Expand All @@ -65,20 +65,32 @@ def to_dict(self) -> OrderedDict:
dic_.update(super(ArchivePlotCurveItem, self).to_dict())
return dic_

def setArchiveChannel(self, address: str) -> None:
@property
def address(self):
return super().address

@address.setter
def address(self, new_address: str) -> None:
"""Creates the channel for the input address for communicating with the archiver appliance plugin."""
archiver_prefix = "archiver://pv="
if address.startswith("ca://"):
archive_address = address.replace("ca://", archiver_prefix, 1)
elif address.startswith("pva://"):
archive_address = address.replace("pva://", archiver_prefix, 1)
else:
archive_address = archiver_prefix + address
TimePlotCurveItem.address.__set__(self, new_address)

if not new_address:
self.archive_channel = None
return
elif self.archive_channel and new_address == self.archive_channel.address:
return

# Prepare new address to use the archiver plugin and create the new channel
archive_address = "archiver://pv=" + remove_protocol(new_address)
self.archive_channel = PyDMChannel(
address=archive_address, value_slot=self.receiveArchiveData, value_signal=self.archive_data_request_signal
)

# Clear the archive data of the previous channel and redraw the curve
if self.archive_points_accumulated:
self.initializeArchiveBuffer()
self.redrawCurve()

@Slot(np.ndarray)
def receiveArchiveData(self, data: np.ndarray) -> None:
"""Receive data from archiver appliance and place it into the archive data buffer.
Expand Down
13 changes: 11 additions & 2 deletions pydm/widgets/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,23 @@ def address(self):
return self.channel.address

@address.setter
def address(self, new_address):
if new_address is None or len(str(new_address)) < 1:
def address(self, new_address: str):
"""Creates the channel for the input address for communicating with the address' plugin."""
if not new_address:
self.channel = None
return
elif self.channel and new_address == self.channel.address:
return

self.channel = PyDMChannel(
address=new_address, connection_slot=self.connectionStateChanged, value_slot=self.receiveNewValue
)

# Clear the data from the previous channel and redraw the curve
if self.points_accumulated:
self.initialize_buffer()
self.redrawCurve()

@property
def plotByTimeStamps(self):
return self._plot_by_timestamps
Expand Down
Loading