|
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 ################################# |
3 | 184 |
|
4 | 185 | def add_channel_widgets(this_display, this_pvs): |
5 | 186 | """ |
|
0 commit comments