Skip to content

Commit fb3618d

Browse files
John-Holt-TessellaTom-Willemsen
authored andcommitted
Hack to make imports work see #4350
1 parent 50cd5e8 commit fb3618d

File tree

2 files changed

+369
-4
lines changed

2 files changed

+369
-4
lines changed

base/uk.ac.stfc.isis.ibex.opis/resources/HV/Scripts/DisplayChannels.py

Lines changed: 183 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,186 @@
1-
from ChannelUtilities import get_summary_channels, get_available_channels, get_max_crates, get_channel_pv_name
2-
from DisplayUtilities import get_cleared_group_widget, create_channel_widget_model
1+
# These should be imported but imports have stopped working, removed until this is fixed see ticket 4350
2+
#from ChannelUtilities import get_summary_channels, get_available_channels, get_max_crates, get_channel_pv_name
3+
#from DisplayUtilities import get_cleared_group_widget, create_channel_widget_model
4+
5+
6+
#### ChannelUtilities.py start #################################
7+
8+
from org.csstudio.opibuilder.scriptUtil import PVUtil
9+
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil
10+
11+
def get_available_channels(crate_name_pvs, this_display,
12+
get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
13+
"""
14+
Generator for the available Caen channels
15+
16+
Args:
17+
crate_name_pvs: The PVs containing the names of the crates
18+
this_display: The display that contains the macros for the maximum number of crates, slots and channels
19+
get_string_from_pv: Method used to get strings from PVs
20+
log: Method to send strings to the logs
21+
22+
Yields:
23+
A tuple of crate (string), slot (int), channel (int)
24+
"""
25+
for crate_name_pv in crate_name_pvs:
26+
try:
27+
crate = get_string_from_pv(crate_name_pv)
28+
except Exception, e:
29+
log("Unable to get crate name for PV: " + crate_name_pv + " , error: " + str(e))
30+
continue
31+
32+
if len(crate) == 0:
33+
continue
34+
35+
for slot in range(get_max_slots(this_display)):
36+
for channel in range(get_max_channels(this_display)):
37+
yield crate, slot, channel
38+
39+
40+
def get_summary_channels(channel_list_pv, get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
41+
"""
42+
Gets the list of channels from the HVCaen.
43+
44+
Args:
45+
channel_list_pv: The PV containing the list of channels.
46+
get_string_from_pv: Function for extracting a string from a named PV
47+
log: Function accepting a string that is written to a log
48+
49+
Returns:
50+
A list of available channels, or an empty list if getting the channels fails.
51+
"""
52+
53+
def channel_formatter(channel):
54+
formatted_channel = channel.replace(" ", "")
55+
if formatted_channel.endswith(','):
56+
formatted_channel = formatted_channel[:-1]
57+
return formatted_channel
58+
59+
channels = list()
60+
try:
61+
if channel_list_pv.getValue().getData().size() > 0: # default method throws uncaught java exception if empty
62+
channels = [channel_formatter(chan) for chan in get_string_from_pv(channel_list_pv).split(' ')]
63+
except Exception, e: # Jython slightly different to standard Python
64+
log("Unable to get channel list for HVCaen: " + str(e)) # Jython str has no 'format'
65+
return channels
66+
67+
def _get_max(this_display, macro, default_value, upper_limit=None):
68+
"""
69+
70+
Args:
71+
this_display: The display. The returned value should be available via a macro.
72+
macro: The macro containing the value
73+
default_value: The value to use if the macro isn't specified
74+
upper_limit: The absolute maximum value the property can take
75+
log: Where to send messages
76+
77+
Returns:
78+
The value of the macro
79+
"""
80+
max_value = this_display.getPropertyValue("macros").getMacrosMap().get(macro)
81+
82+
try:
83+
max_value = int(max_value)
84+
except (TypeError, ValueError):
85+
max_value = default_value
86+
87+
if max_value is None:
88+
max_value = default_value
89+
90+
if upper_limit is not None:
91+
max_value = min(max_value, upper_limit)
92+
93+
return max_value
94+
95+
96+
def get_max_crates(this_display):
97+
"""
98+
The absolute maximum value is 15, determined by the limitations of EPICS MMBO records.
99+
100+
Args:
101+
this_display: The display. The returned value should be available via a macro.
102+
103+
Returns:
104+
The maximum number of crates supported by the OPI
105+
"""
106+
return _get_max(this_display, "MAX_CRATES", 2, 15)
107+
108+
109+
def get_max_slots(this_display):
110+
"""
111+
Args:
112+
this_display: The display. The returned value should be available via a macro.
113+
114+
Returns:
115+
The maximum number of slots supported by the OPI
116+
"""
117+
return _get_max(this_display, "MAX_SLOTS", 5)
118+
119+
120+
def get_max_channels(this_display):
121+
"""
122+
Args:
123+
this_display: The display. The returned value should be available via a macro.
124+
125+
Returns:
126+
The maximum number of channels supported by the OPI
127+
"""
128+
return _get_max(this_display, "MAX_CHANNELS", 25)
129+
130+
131+
def get_channel_pv_name(crate, slot, channel):
132+
"""
133+
Gets the PV name for a given channel
134+
135+
Args:
136+
crate: The name of the crate
137+
slot: The slot number
138+
channel: The channel number
139+
140+
Returns:
141+
The PV name for accessing the given channel
142+
"""
143+
return crate + ":" + str(slot) + ":" + str(channel)
144+
#### ChannelUtilities.py end #################################
145+
#### DisplayUtilities.py start#############################
146+
from org.csstudio.opibuilder.scriptUtil import WidgetUtil
147+
148+
def get_cleared_group_widget(this_display):
149+
"""
150+
Gets the widget called 'group' and clears its children.
151+
152+
Args:
153+
this_display: The CSS display component
154+
155+
Returns:
156+
The group widget having had its children removed
157+
158+
"""
159+
group_widget = this_display.getWidget('group')
160+
group_widget.removeAllChildren()
161+
return group_widget
162+
163+
def create_channel_widget_model(name, is_summary):
164+
"""
165+
Creates a widget to display information about a given channel
166+
167+
Args:
168+
name: Name of the channel
169+
is_summary: Is this a summary? If so use the summary OPI template, else use the maintenance template
170+
171+
Returns:
172+
The target widget
173+
"""
174+
model = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer")
175+
model.setPropertyValue("opi_file",
176+
"HVChannelMonitorSummary.opi" if is_summary else "HVChannelSummaryMaintenance.opi")
177+
model.setPropertyValue("auto_size", True)
178+
model.setPropertyValue("zoom_to_fit", False)
179+
model.setPropertyValue("border_style", 0)
180+
model.setPropertyValue("name", name)
181+
model.addMacro("SEL", name)
182+
return model
183+
#### DisplayUtilities.py end #################################
3184

4185
def add_channel_widgets(this_display, this_pvs):
5186
"""

base/uk.ac.stfc.isis.ibex.opis/resources/HV/Scripts/DisplaySummary.py

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,189 @@
1-
from ChannelUtilities import get_summary_channels
2-
from DisplayUtilities import get_cleared_group_widget, create_channel_widget_model
1+
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil
2+
3+
# These should be imported but imports have stopped working, removed until this is fixed see ticket 4350
4+
#from ChannelUtilities import get_summary_channels
5+
#from DisplayUtilities import get_cleared_group_widget, create_channel_widget_model
6+
7+
8+
#### ChannelUtilities.py start #################################
9+
10+
from org.csstudio.opibuilder.scriptUtil import PVUtil
11+
from org.csstudio.opibuilder.scriptUtil import ConsoleUtil
12+
13+
def get_available_channels(crate_name_pvs, this_display,
14+
get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
15+
"""
16+
Generator for the available Caen channels
17+
18+
Args:
19+
crate_name_pvs: The PVs containing the names of the crates
20+
this_display: The display that contains the macros for the maximum number of crates, slots and channels
21+
get_string_from_pv: Method used to get strings from PVs
22+
log: Method to send strings to the logs
23+
24+
Yields:
25+
A tuple of crate (string), slot (int), channel (int)
26+
"""
27+
for crate_name_pv in crate_name_pvs:
28+
try:
29+
crate = get_string_from_pv(crate_name_pv)
30+
except Exception, e:
31+
log("Unable to get crate name for PV: " + crate_name_pv + " , error: " + str(e))
32+
continue
33+
34+
if len(crate) == 0:
35+
continue
36+
37+
for slot in range(get_max_slots(this_display)):
38+
for channel in range(get_max_channels(this_display)):
39+
yield crate, slot, channel
40+
41+
42+
def get_summary_channels(channel_list_pv, get_string_from_pv=PVUtil.getString, log=ConsoleUtil.writeError):
43+
"""
44+
Gets the list of channels from the HVCaen.
45+
46+
Args:
47+
channel_list_pv: The PV containing the list of channels.
48+
get_string_from_pv: Function for extracting a string from a named PV
49+
log: Function accepting a string that is written to a log
50+
51+
Returns:
52+
A list of available channels, or an empty list if getting the channels fails.
53+
"""
54+
55+
def channel_formatter(channel):
56+
formatted_channel = channel.replace(" ", "")
57+
if formatted_channel.endswith(','):
58+
formatted_channel = formatted_channel[:-1]
59+
return formatted_channel
60+
61+
channels = list()
62+
try:
63+
if channel_list_pv.getValue().getData().size() > 0: # default method throws uncaught java exception if empty
64+
channels = [channel_formatter(chan) for chan in get_string_from_pv(channel_list_pv).split(' ')]
65+
except Exception, e: # Jython slightly different to standard Python
66+
log("Unable to get channel list for HVCaen: " + str(e)) # Jython str has no 'format'
67+
return channels
68+
69+
def _get_max(this_display, macro, default_value, upper_limit=None):
70+
"""
71+
72+
Args:
73+
this_display: The display. The returned value should be available via a macro.
74+
macro: The macro containing the value
75+
default_value: The value to use if the macro isn't specified
76+
upper_limit: The absolute maximum value the property can take
77+
log: Where to send messages
78+
79+
Returns:
80+
The value of the macro
81+
"""
82+
max_value = this_display.getPropertyValue("macros").getMacrosMap().get(macro)
83+
84+
try:
85+
max_value = int(max_value)
86+
except (TypeError, ValueError):
87+
max_value = default_value
88+
89+
if max_value is None:
90+
max_value = default_value
91+
92+
if upper_limit is not None:
93+
max_value = min(max_value, upper_limit)
94+
95+
return max_value
96+
97+
98+
def get_max_crates(this_display):
99+
"""
100+
The absolute maximum value is 15, determined by the limitations of EPICS MMBO records.
101+
102+
Args:
103+
this_display: The display. The returned value should be available via a macro.
104+
105+
Returns:
106+
The maximum number of crates supported by the OPI
107+
"""
108+
return _get_max(this_display, "MAX_CRATES", 2, 15)
109+
110+
111+
def get_max_slots(this_display):
112+
"""
113+
Args:
114+
this_display: The display. The returned value should be available via a macro.
115+
116+
Returns:
117+
The maximum number of slots supported by the OPI
118+
"""
119+
return _get_max(this_display, "MAX_SLOTS", 5)
120+
121+
122+
def get_max_channels(this_display):
123+
"""
124+
Args:
125+
this_display: The display. The returned value should be available via a macro.
126+
127+
Returns:
128+
The maximum number of channels supported by the OPI
129+
"""
130+
return _get_max(this_display, "MAX_CHANNELS", 25)
131+
132+
133+
def get_channel_pv_name(crate, slot, channel):
134+
"""
135+
Gets the PV name for a given channel
136+
137+
Args:
138+
crate: The name of the crate
139+
slot: The slot number
140+
channel: The channel number
141+
142+
Returns:
143+
The PV name for accessing the given channel
144+
"""
145+
return crate + ":" + str(slot) + ":" + str(channel)
146+
#### ChannelUtilities.py end #################################
147+
#### DisplayUtilities.py start#############################
148+
from org.csstudio.opibuilder.scriptUtil import WidgetUtil
149+
150+
def get_cleared_group_widget(this_display):
151+
"""
152+
Gets the widget called 'group' and clears its children.
153+
154+
Args:
155+
this_display: The CSS display component
156+
157+
Returns:
158+
The group widget having had its children removed
159+
160+
"""
161+
group_widget = this_display.getWidget('group')
162+
group_widget.removeAllChildren()
163+
return group_widget
164+
165+
def create_channel_widget_model(name, is_summary):
166+
"""
167+
Creates a widget to display information about a given channel
168+
169+
Args:
170+
name: Name of the channel
171+
is_summary: Is this a summary? If so use the summary OPI template, else use the maintenance template
172+
173+
Returns:
174+
The target widget
175+
"""
176+
model = WidgetUtil.createWidgetModel("org.csstudio.opibuilder.widgets.linkingContainer")
177+
model.setPropertyValue("opi_file",
178+
"HVChannelMonitorSummary.opi" if is_summary else "HVChannelSummaryMaintenance.opi")
179+
model.setPropertyValue("auto_size", True)
180+
model.setPropertyValue("zoom_to_fit", False)
181+
model.setPropertyValue("border_style", 0)
182+
model.setPropertyValue("name", name)
183+
model.addMacro("SEL", name)
184+
return model
185+
#### DisplayUtilities.py end #################################
186+
3187

4188
def create_channels_summary(this_display, this_pvs):
5189
"""

0 commit comments

Comments
 (0)