1
1
import math
2
2
import numpy as np
3
+ from typing import Any
3
4
4
5
import logging
5
6
import warnings
8
9
9
10
10
11
class DisplayFormat (object ):
12
+ """Display format for showing data in a PyDM widget."""
13
+ #: The default display format.
11
14
Default = 0
15
+ #: Show the data as a string.
12
16
String = 1
17
+ #: Show numerical values as floating point (base 10, decimal) values.
13
18
Decimal = 2
19
+ #: Show numerical values in scientific / exponential notation.
14
20
Exponential = 3
21
+ #: Show numerical values in base 16 (hexadecimal) notation.
15
22
Hex = 4
23
+ #: Show numerical values in base 2 (binary) notation.
16
24
Binary = 5
17
25
18
26
19
- def parse_value_for_display (value , precision , display_format_type = DisplayFormat .Default , string_encoding = "utf_8" , widget = None ):
27
+ def parse_value_for_display (
28
+ value : Any ,
29
+ precision : int ,
30
+ display_format_type : int = DisplayFormat .Default ,
31
+ string_encoding : str = "utf_8" ,
32
+ widget = None ,
33
+ ):
34
+ """
35
+ Format a value to show it in a widget, based on the display format type.
36
+
37
+ Parameters
38
+ ----------
39
+ value : Any
40
+ The value to convert to a string.
41
+ precision : int
42
+ Precision of floating point values to use.
43
+ display_format_type : int, optional
44
+ Display format type to use.
45
+ string_encoding : str, optional
46
+ Encoding to use for strings.
47
+ widget : QtWidgets.QWidget, optional
48
+ Widget to get a name from for conversion errors.
49
+
50
+ Returns
51
+ -------
52
+ str
53
+ Formatted version of ``value``.
54
+ """
20
55
if value is None :
21
56
return ""
22
57
try :
@@ -37,7 +72,7 @@ def parse_value_for_display(value, precision, display_format_type=DisplayFormat.
37
72
if zeros .size > 0 :
38
73
value = value [:zeros [0 ]]
39
74
r = value .tobytes ().decode (string_encoding )
40
- except :
75
+ except Exception :
41
76
logger .error ("Could not decode {0} using {1} at widget named '{2}'." .format (
42
77
value , string_encoding , widget_name ))
43
78
return value
0 commit comments