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¶
-
pydm.utilities.
find_display_in_path
(file, mode=None, path=None, pathext=None)[source]¶ Look for a display file in a given path. This is basically a wrapper on top of the
which
command defined below so we don’t need to keep redefining thePYDM_DISPLAYS_PATH
variable.- Parameters
file (str) – The file name.
mode (int) – The mode required for the file, defaults to os.F_OK | os.R_OK. Which ensure that the file exists and we can read it.
path (str) – The PATH string.
- Returns
Returns the full path to the file or None in case it was not found.
- Return type
str
-
pydm.utilities.
is_pydm_app
(app=None)[source]¶ Check whether or not QApplication.instance() is a PyDMApplication.
- Parameters
app (QApplication, Optional) – The app to inspect. If no application is provided the current running QApplication will be queried.
- Returns
True if it is a PyDMApplication, False otherwise.
- Return type
bool
-
pydm.utilities.
is_qt_designer
()[source]¶ Check whether or not running inside Qt Designer.
- Returns
True if inside Designer, False otherwise.
- Return type
bool
-
pydm.utilities.
path_info
(path_str)[source]¶ Retrieve basic information about the given path.
- Parameters
path_str (str) – The path from which to extract information.
- Returns
base dir, file name, list of args
- Return type
tuple
-
pydm.utilities.
which
(cmd, mode=1, path=None, pathext=None)[source]¶ Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file. mode defaults to os.F_OK | os.X_OK. path defaults to the result of os.environ.get(“PATH”), or can be overridden with a custom search path. Note: This function was backported from the Python 3 source code and modified to deal with the case in which we WANT to look at the path even with a relative path.
-
pydm.utilities.remove_protocol.
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.
Icons¶
-
class
pydm.utilities.iconfont.
IconFont
[source]¶ IconFont represents an icon font. Users will generally want to use IconFont.icon() to get a QIcon object for the character they want.
-
icon
(name, color=None)[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.
- Return type
QIcon
-
Macro¶
-
pydm.utilities.macro.
find_base_macros
(widget)[source]¶ Find and return the first set of defined base_macros from this widget or its ancestors.
-
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