Utility Functions

Utility functions for typhon

class typhon.utils.GrabKindItem(attr, component, signal)
property attr

Alias for field number 0

property component

Alias for field number 1

property signal

Alias for field number 2

class typhon.utils.TyphonBase(*args, **kwargs)[source]

Base widget for all Typhon widgets that interface with devices

add_device(device)[source]

Add a new device to the widget

Parameters

device (ophyd.Device) –

classmethod from_device(device, parent=None, **kwargs)[source]

Create a new instance of the widget for a Device

Shortcut for:

tool = TyphonBase(parent=parent)
tool.add_device(device)
Parameters
  • device (ophyd.Device) –

  • parent (QWidget) –

paintEvent(self, QPaintEvent)[source]
typhon.utils.channel_from_signal(signal)[source]

Create a PyDM address from arbitrary signal type

typhon.utils.channel_name(pv, protocol='ca')[source]

Create a valid PyDM channel from a PV name

typhon.utils.clean_attr(attr)[source]

Create a nicer, human readable alias from a Python attribute name

typhon.utils.clean_name(device, strip_parent=True)[source]

Create a human readable name for a device

Parameters
  • device (ophyd.Device) –

  • strip_parent (bool or Device) – Remove the parent name of the device from name. If strip_parent is True, the name of the direct parent of the device is stripped. If a device is provided the name of that device is used. This allows specification for removal at any point of the device schema

typhon.utils.clear_layout(layout)[source]

Clear a QLayout

typhon.utils.flatten_tree(param)[source]

Flatten a tree of parameters

typhon.utils.grab_kind(device, kind)[source]

Grab all signals of a specific Kind from a Device instance

Parameters
  • device (ophyd.Device) – The device instance to introspect

  • kind (Kind or str) – The kind to search for

Returns

signals – Keyed on attribute name, the signals dict contains GrabKindItem named tuples, which have attributes {attr, component, signal}.

Return type

dict

typhon.utils.is_signal_ro(signal)[source]

Return whether the signal is read-only

In the future this may be easier to do through improvements to introspection in the ophyd library. Until that day we need to check classes

typhon.utils.load_suite(path, cfg=None)[source]

” Load a file saved via Typhon

Parameters
  • path (str) – Path to file describing the TyphonSuite. This needs to be of the format created by the save_suite() function.

  • cfg (str, optional) – Location of happi configuration file to use to load devices. If not entered the $HAPPI_CFG environment variable will be used.

Returns

suite

Return type

TyphonSuite

typhon.utils.make_identifier(name)[source]

Make a Python string into a valid Python identifier

typhon.utils.raise_to_operator(exc)[source]

Utility function to show an Exception to a user

typhon.utils.random_color()[source]

Return a random hex color description

typhon.utils.reload_widget_stylesheet(widget, cascade=False)[source]

Reload the stylesheet of the provided widget

typhon.utils.save_suite(suite, file_or_buffer)[source]

Create a file capable of relaunching the TyphonSuite

Parameters
  • suite (TyphonSuite) –

  • file_or_buffer (str or file-like) – Either a path to the file or a handle that supports write

typhon.utils.use_stylesheet(dark=False, widget=None)[source]

Use the Typhon stylesheet

Parameters

dark (bool, optional) – Whether or not to use the QDarkStyleSheet theme. By default the light theme is chosen.