Utilities

PyDM comes with a set of utility methods ranging from simple replacement of protocol in a string, handling macro substitution in files, etc.

General

class pydm.utilities.IconFont(*args, **kwargs)[source]

IconFont represents an icon font. Users will generally want to use IconFont.icon() to get a QIcon object for the character they want.

font(size: int) Optional[QFont][source]

Load the font at a given pixel size.

Returns:

The font, if available. If a QApplication is not yet created, None will be returned.

Return type:

QtGui.QFont or None

get_char_for_name(name: str) str[source]

Get a character icon for the given name from the character map.

Parameters:

name (str) – The user-friendly icon name.

Returns:

The Qt-facing icon text to use with the font.

Return type:

str

icon(name, color=None) Optional[QIcon][source]

Retrieve the icon given a name and color.

Parameters:
  • name (str) – The Icon string identifier. Icon strings can be found at: https://fontawesome.com/icons?d=gallery

  • color (QColor, Optional) – The base color to use when constructing the Icon. Default is QColor(90, 90, 90).

Returns:

The desired Icon. None if a QApplication is not yet available.

Return type:

QIcon

load_font(ttf_filename, charmap_filename)[source]

Load font from ttf_filename with a mapping defined in charmap_filename.

pydm.utilities.close_widget_connections(widget)[source]

Disconnect the inner channels of widgets on the given widget.

Parameters:

widget (QWidget) – The widget which will be iterated over for channel disconnection.

pydm.utilities.convert(unit, desired)[source]

Find the conversion rate of two different unit strings.

Parameters:
  • unit (str) – The current unit string

  • desired (str) – The desired unit string

Returns:

The relation between unit and desired or None if not found.

Return type:

float or None

pydm.utilities.establish_widget_connections(widget)[source]

Connect the inner channels of widgets on the given widget.

Parameters:

widget (QWidget) – The widget which will be iterated over for channel connection.

pydm.utilities.find_unit_options(unit)[source]

Find the options for a given unit.

Parameters:

unit (str) – The unit string

Returns:

The list of similar units in crescent order or None if not found.

Return type:

list or None

pydm.utilities.find_unittype(unit)[source]

Find the type of a unit string.

Parameters:

unit (str) – The unit string

Returns:

tp – The unit type name or None if not found.

Return type:

str

pydm.utilities.parsed_address(address)[source]

Returns the given address parsed into a 6-tuple. The parsing is done by urllib.parse.urlparse

Parameters:

address (str) – The address from which to remove the address prefix.

Returns:

parsed_address

Return type:

tuple

pydm.utilities.protocol_and_address(address)[source]

Returns the Protocol and Address pieces of a Channel Address

Parameters:

address (str) – The address from which to remove the address prefix.

Returns:

  • protocol (str) – The protocol used. None in case the protocol is not specified.

  • addr (str) – The piece of the address without the protocol.

pydm.utilities.remove_protocol(addr)[source]

Removes the first occurrence of the protocol string (‘://’) from the string addr

Parameters:

addr (str) – The address from which to remove the address prefix.

Return type:

str

Icons

class pydm.utilities.iconfont.IconFont(*args, **kwargs)[source]

IconFont represents an icon font. Users will generally want to use IconFont.icon() to get a QIcon object for the character they want.

font(size: int) Optional[QFont][source]

Load the font at a given pixel size.

Returns:

The font, if available. If a QApplication is not yet created, None will be returned.

Return type:

QtGui.QFont or None

get_char_for_name(name: str) str[source]

Get a character icon for the given name from the character map.

Parameters:

name (str) – The user-friendly icon name.

Returns:

The Qt-facing icon text to use with the font.

Return type:

str

icon(name, color=None) Optional[QIcon][source]

Retrieve the icon given a name and color.

Parameters:
  • name (str) – The Icon string identifier. Icon strings can be found at: https://fontawesome.com/icons?d=gallery

  • color (QColor, Optional) – The base color to use when constructing the Icon. Default is QColor(90, 90, 90).

Returns:

The desired Icon. None if a QApplication is not yet available.

Return type:

QIcon

load_font(ttf_filename, charmap_filename)[source]

Load font from ttf_filename with a mapping defined in charmap_filename.

Macro

pydm.utilities.macro.parse_macro_string(macro_string)[source]

Parses a macro string and returns a dictionary. First, this method attempts to parse the string as JSON. If that fails, it attempts to parse it as an EPICS-style macro string. The parsing algorithm for that case is very closely based on macParseDefns in libCom/macUtil.c

pydm.utilities.macro.substitute_in_file(file_path, macros)[source]

Substitute the macros given by ${name} at the given file with the entries on the macros dictionary.

Parameters:
  • file_path (str) – The path to the file in which to substitute

  • macros (dict) – Dictionary containing macro name as key and value as what will be substituted.

Returns:

file – File-like object with the proper substitutions.

Return type:

io.StringIO

Colors

pydm.utilities.colors.hex_from_svg_color(color_string)[source]

Returns the HEX color based on its SVG equivalent.

Parameters:

color_string (str) – The SVG color string. E.g. black

Returns:

The HEX color string.

Return type:

str

pydm.utilities.colors.svg_color_from_hex(hex_string, hex_on_fail=False)[source]

Returns the SVG color based on its HEX equivalent.

Parameters:
  • hex_string (str) – The color code in hex. E.g. #000000

  • hex_on_fail (bool, Optional) – Whether or not to return the hex_string when an invalid color is submitted. Default is False.

Returns:

The SVG color string.

Return type:

str

Units

pydm.utilities.units.convert(unit, desired)[source]

Find the conversion rate of two different unit strings.

Parameters:
  • unit (str) – The current unit string

  • desired (str) – The desired unit string

Returns:

The relation between unit and desired or None if not found.

Return type:

float or None

pydm.utilities.units.find_unit(unit)[source]

Find the conversion of a unit string.

Parameters:

unit (str) – The unit string

Returns:

The unit value relative to the standard or None if not found.

Return type:

float or None

pydm.utilities.units.find_unit_options(unit)[source]

Find the options for a given unit.

Parameters:

unit (str) – The unit string

Returns:

The list of similar units in crescent order or None if not found.

Return type:

list or None

pydm.utilities.units.find_unittype(unit)[source]

Find the type of a unit string.

Parameters:

unit (str) – The unit string

Returns:

tp – The unit type name or None if not found.

Return type:

str