diff --git a/pydm/widgets/archiver_time_plot.py b/pydm/widgets/archiver_time_plot.py index 242156244..5c94b70ce 100644 --- a/pydm/widgets/archiver_time_plot.py +++ b/pydm/widgets/archiver_time_plot.py @@ -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 @@ -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 @@ -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.""" @@ -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. diff --git a/pydm/widgets/timeplot.py b/pydm/widgets/timeplot.py index 52a23f9e7..58ed04038 100644 --- a/pydm/widgets/timeplot.py +++ b/pydm/widgets/timeplot.py @@ -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