Skip to content

Commit

Permalink
Merge pull request #1018 from slaclab/ESROGUE-680
Browse files Browse the repository at this point in the history
Add ability to pull a list value out in a pydm widget
  • Loading branch information
slacrherbst authored Jul 31, 2024
2 parents 50f80b4 + bc0b026 commit a3fff48
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ dependencies:
- matplotlib
- pytest
- pytest-cov
- pyqt=5.12
10 changes: 6 additions & 4 deletions python/pyrogue/_Variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def varUpdate(self,path,varValue):

class VariableValue(object):
""" """
def __init__(self, var, read=False):
self.value = var.get(read=read)
def __init__(self, var, read=False, index=-1):
self.value = var.get(read=read,index=index)
self.valueDisp = var.genDisp(self.value)
self.disp = var.disp
self.enum = var.enum
Expand Down Expand Up @@ -572,7 +572,7 @@ def write(self, *, verify=True, check=True):
pass

@pr.expose
def getVariableValue(self,read=True):
def getVariableValue(self,read=True,index=-1):
"""
Return the value after performing a read from hardware if applicable.
Hardware read is blocking. An error will result in a logged exception.
Expand All @@ -582,6 +582,8 @@ def getVariableValue(self,read=True):
----------
read : bool
(Default value = True)
index : int
(Default value = -1)
Returns
-------
Expand All @@ -590,7 +592,7 @@ def getVariableValue(self,read=True):
Listeners will be informed of the update.
"""
return VariableValue(self,read=read)
return VariableValue(self,read=read,index=index)

@pr.expose
def value(self, index=-1):
Expand Down
21 changes: 13 additions & 8 deletions python/pyrogue/pydm/data_plugins/rogue_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@


def parseAddress(address):
# "rogue://index/<path>/<mode>"
# "rogue://index/<path>/<mode>/<index>"
# or
# "rogue://host:port/<path>/<mode>"
# Mode: 'Value', 'Disp', 'Name' or 'Path'
# "rogue://host:port/<path>/<mode>/<index>"
# Mode: 'value', 'disp', 'name' or 'path'
envList = os.getenv('ROGUE_SERVERS')

if envList is None:
Expand All @@ -58,12 +58,13 @@ def parseAddress(address):
port = int(data_server[1])
path = data[1]
mode = 'value' if (len(data) < 3) else data[2]
index = -1 if (len(data) < 4) else int(data[3])

return (host,port,path,mode)
return (host,port,path,mode,index)


def nodeFromAddress(address):
host, port, path, mode = parseAddress(address)
host, port, path, mode, index = parseAddress(address)
client = VirtualClient(host, port)
return client.root.getNode(path)

Expand All @@ -75,7 +76,7 @@ def __init__(self, channel, address, protocol=None, parent=None):

self.app = QApplication.instance()

self._host, self._port, self._path, self._mode = parseAddress(channel.address)
self._host, self._port, self._path, self._mode, self._index = parseAddress(channel.address)

self._cmd = False
self._int = False
Expand Down Expand Up @@ -114,6 +115,10 @@ def linkState(self, state):


def _updateVariable(self,path,varValue):

if self._index != -1:
varValue = self._node.getVariableValue(read=False, index=self._index)

if self._mode == 'name':
self.new_value_signal[str].emit(self._node.name)
elif self._mode == 'path':
Expand Down Expand Up @@ -153,7 +158,7 @@ def put_value(self, new_value):
if self._cmd:
self._node.__call__(val)
else:
self._node.setDisp(val)
self._node.setDisp(val,index=self._index)


def add_listener(self, channel):
Expand Down Expand Up @@ -204,7 +209,7 @@ def add_listener(self, channel):
self.new_value_signal[str].emit(self._node.path)
else:
self.write_access_signal.emit(self._cmd or self._node.mode!='RO')
self._updateVariable(self._node.path,self._node.getVariableValue(read=False))
self._updateVariable(self._node.path,self._node.getVariableValue(read=False, index=self._index))

else:
self.new_value_signal[str].emit(self._node.name)
Expand Down
8 changes: 4 additions & 4 deletions python/pyrogue/pydm/examples/rogue_plugin_test.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_6">
<property name="sizePolicy">
Expand Down Expand Up @@ -105,7 +105,7 @@
</property>
<property name="yAxes">
<stringlist>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Plot Scatter&quot;, &quot;minRange&quot;: -1.0, &quot;maxRange&quot;: 1.0, &quot;autoRange&quot;: true, &quot;logMode&quot;: false}</string>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Plot Scatter&quot;, &quot;minRange&quot;: -1.04, &quot;maxRange&quot;: 1.04, &quot;autoRange&quot;: true, &quot;logMode&quot;: false}</string>
</stringlist>
</property>
<property name="curves">
Expand All @@ -125,7 +125,7 @@
</property>
<property name="yAxes">
<stringlist>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Plot Time&quot;, &quot;minRange&quot;: -1.0, &quot;maxRange&quot;: 1.0, &quot;autoRange&quot;: true, &quot;logMode&quot;: null}</string>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Plot Time&quot;, &quot;minRange&quot;: -1.04, &quot;maxRange&quot;: 1.04, &quot;autoRange&quot;: true, &quot;logMode&quot;: null}</string>
</stringlist>
</property>
<property name="curves">
Expand All @@ -151,7 +151,7 @@
</property>
<property name="yAxes">
<stringlist>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Array Waveform&quot;, &quot;minRange&quot;: -1.0, &quot;maxRange&quot;: 1.0, &quot;autoRange&quot;: true, &quot;logMode&quot;: false}</string>
<string>{&quot;name&quot;: &quot;Axis 1&quot;, &quot;orientation&quot;: &quot;left&quot;, &quot;label&quot;: &quot;Test Array Waveform&quot;, &quot;minRange&quot;: -1.04, &quot;maxRange&quot;: 1.04, &quot;autoRange&quot;: true, &quot;logMode&quot;: false}</string>
</stringlist>
</property>
<property name="curves">
Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/generic_file_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self,save=False):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/node_info_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/read_node_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/read_recursive_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/write_node_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down
2 changes: 1 addition & 1 deletion python/pyrogue/pydm/tools/write_recursive_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self):
ExternalTool.__init__(self, icon=icon, name=name, group=group, use_with_widgets=use_with_widgets)

def call(self, channels, sender):
addr, port, path, mode = parseAddress(channels[0].address)
addr, port, path, mode, index = parseAddress(channels[0].address)
self._client = VirtualClient(addr, port)
node = self._client.root.getNode(path)

Expand Down

0 comments on commit a3fff48

Please sign in to comment.