MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / LineEditExtended

Class LineEditExtended

pyxrf/gui_module/useful_widgets.py:78–155  ·  view source on GitHub ↗

LineEditExtended allows to mark the displayed value as invalid by setting its `valid` property to False. By default, the text color is changed to Light Red. It also emits `focusOut` signal at `self.focusOutEvent`.

Source from the content-addressed store, hash-verified

76
77
78class LineEditExtended(QLineEdit):
79 """
80 LineEditExtended allows to mark the displayed value as invalid by setting
81 its `valid` property to False. By default, the text color is changed to Light Red.
82 It also emits `focusOut` signal at `self.focusOutEvent`.
83 """
84
85 # Emitted at focusOutEvent
86 focusOut = Signal()
87
88 def __init__(self, *args, **kwargs):
89 super().__init__(*args, **kwargs)
90 self._valid = True
91 self._style_sheet_valid = "" # By default, clear the style sheet
92 self._style_sheet_invalid = "color: rgb(255, 0, 0);"
93 self._update_valid_status()
94
95 def _update_valid_status(self):
96 if self._valid:
97 super().setStyleSheet(self._style_sheet_valid)
98 else:
99 super().setStyleSheet(self._style_sheet_invalid)
100
101 def setStyleSheet(self, style_sheet, *, valid=True):
102 """
103 Set style sheet for valid/invalid states. If call with one parameter, the function
104 works the same as `setStyleSheet` of QWidget. If `valid` is set to `False`, the
105 supplied style sheet will be applied only if 'invalid' state is activated. The
106 style sheets for the valid and invalid states are independent and can be set
107 separately.
108
109 The default behavior: 'valid' state - clear style sheet, 'invalid' state -
110 use the style sheet `"color: rgb(255, 0, 0);"`
111
112 Parameters
113 ----------
114 style_sheet: str
115 style sheet
116 valid: bool
117 True - activate 'valid' state, False - activate 'invalid' state
118 """
119 if valid:
120 self._style_sheet_valid = style_sheet
121 else:
122 self._style_sheet_invalid = style_sheet
123 self._update_valid_status()
124
125 def getStyleSheet(self, *, valid):
126 """
127 Return the style sheet used 'valid' or 'invalid' state.
128
129 Parameters
130 ----------
131 valid: bool
132 True/False - return the style sheet that was set for 'valid'/'invalid' state.
133 """
134 if valid:
135 return self._style_sheet_valid

Callers 12

_setup_action_buttonsMethod · 0.85
_setup_headerMethod · 0.85
_setup_tableMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
_setup_settingsMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
initializeMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected