|
2 | 2 | import numpy as np
|
3 | 3 | import weakref
|
4 | 4 | import threading
|
| 5 | +import warnings |
5 | 6 |
|
6 | 7 | from typing import Optional, Callable
|
7 | 8 | from urllib.parse import ParseResult
|
@@ -105,103 +106,106 @@ def remove_listener(self, channel, destroying: Optional[bool] = False) -> None:
|
105 | 106 | QObject is destroyed, setting this to True ensures we do not try to do the disconnection a second time.
|
106 | 107 | If set to False, any active signals/slots on the channel will be manually disconnected here.
|
107 | 108 | """
|
108 |
| - if self._should_disconnect(channel.connection_slot, destroying): |
109 |
| - try: |
110 |
| - self.connection_state_signal.disconnect(channel.connection_slot) |
111 |
| - except TypeError: |
112 |
| - pass |
| 109 | + with warnings.catch_warnings(): |
| 110 | + warnings.simplefilter("ignore", category=RuntimeWarning) |
113 | 111 |
|
114 |
| - if self._should_disconnect(channel.value_slot, destroying): |
115 |
| - for signal_type in (int, float, str, bool, object): |
| 112 | + if self._should_disconnect(channel.connection_slot, destroying): |
116 | 113 | try:
|
117 |
| - self.new_value_signal[signal_type].disconnect(channel.value_slot) |
118 |
| - # If the signal exists (always does in this case since we define it for all 'signal_type' earlier) |
119 |
| - # but doesn't match slot, TypeError is thrown. We also don't need to catch KeyError/IndexError here, |
120 |
| - # since those are only thrown when signal type doesn't exist. |
| 114 | + self.connection_state_signal.disconnect(channel.connection_slot) |
121 | 115 | except TypeError:
|
122 | 116 | pass
|
123 | 117 |
|
124 |
| - if self._should_disconnect(channel.severity_slot, destroying): |
125 |
| - try: |
126 |
| - self.new_severity_signal.disconnect(channel.severity_slot) |
127 |
| - except (KeyError, TypeError): |
128 |
| - pass |
129 |
| - |
130 |
| - if self._should_disconnect(channel.write_access_slot, destroying): |
131 |
| - try: |
132 |
| - self.write_access_signal.disconnect(channel.write_access_slot) |
133 |
| - except (KeyError, TypeError): |
134 |
| - pass |
135 |
| - |
136 |
| - if self._should_disconnect(channel.enum_strings_slot, destroying): |
137 |
| - try: |
138 |
| - self.enum_strings_signal.disconnect(channel.enum_strings_slot) |
139 |
| - except (KeyError, TypeError): |
140 |
| - pass |
141 |
| - |
142 |
| - if self._should_disconnect(channel.unit_slot, destroying): |
143 |
| - try: |
144 |
| - self.unit_signal.disconnect(channel.unit_slot) |
145 |
| - except (KeyError, TypeError): |
146 |
| - pass |
147 |
| - |
148 |
| - if self._should_disconnect(channel.upper_ctrl_limit_slot, destroying): |
149 |
| - try: |
150 |
| - self.upper_ctrl_limit_signal.disconnect(channel.upper_ctrl_limit_slot) |
151 |
| - except (KeyError, TypeError): |
152 |
| - pass |
153 |
| - |
154 |
| - if self._should_disconnect(channel.lower_ctrl_limit_slot, destroying): |
155 |
| - try: |
156 |
| - self.lower_ctrl_limit_signal.disconnect(channel.lower_ctrl_limit_slot) |
157 |
| - except (KeyError, TypeError): |
158 |
| - pass |
159 |
| - |
160 |
| - if self._should_disconnect(channel.upper_alarm_limit_slot, destroying): |
161 |
| - try: |
162 |
| - self.upper_alarm_limit_signal.disconnect(channel.upper_alarm_limit_slot) |
163 |
| - except (KeyError, TypeError): |
164 |
| - pass |
165 |
| - |
166 |
| - if self._should_disconnect(channel.lower_alarm_limit_slot, destroying): |
167 |
| - try: |
168 |
| - self.lower_alarm_limit_signal.disconnect(channel.lower_alarm_limit_slot) |
169 |
| - except (KeyError, TypeError): |
170 |
| - pass |
171 |
| - |
172 |
| - if self._should_disconnect(channel.upper_warning_limit_slot, destroying): |
173 |
| - try: |
174 |
| - self.upper_warning_limit_signal.disconnect(channel.upper_warning_limit_slot) |
175 |
| - except (KeyError, TypeError): |
176 |
| - pass |
177 |
| - |
178 |
| - if self._should_disconnect(channel.lower_warning_limit_slot, destroying): |
179 |
| - try: |
180 |
| - self.lower_warning_limit_signal.disconnect(channel.lower_warning_limit_slot) |
181 |
| - except (KeyError, TypeError): |
182 |
| - pass |
183 |
| - |
184 |
| - if self._should_disconnect(channel.prec_slot, destroying): |
185 |
| - try: |
186 |
| - self.prec_signal.disconnect(channel.prec_slot) |
187 |
| - except (KeyError, TypeError): |
188 |
| - pass |
189 |
| - |
190 |
| - if self._should_disconnect(channel.timestamp_slot, destroying): |
191 |
| - try: |
192 |
| - self.timestamp_signal.disconnect(channel.timestamp_slot) |
193 |
| - except (KeyError, TypeError): |
194 |
| - pass |
195 |
| - |
196 |
| - if not destroying and channel.value_signal is not None and hasattr(self, "put_value"): |
197 |
| - for signal_type in (str, int, float, np.ndarray, dict): |
| 118 | + if self._should_disconnect(channel.value_slot, destroying): |
| 119 | + for signal_type in (int, float, str, bool, object): |
| 120 | + try: |
| 121 | + self.new_value_signal[signal_type].disconnect(channel.value_slot) |
| 122 | + # If the signal exists (always does in this case since we define it for all 'signal_type' earlier) |
| 123 | + # but doesn't match slot, TypeError is thrown. We also don't need to catch KeyError/IndexError here, |
| 124 | + # since those are only thrown when signal type doesn't exist. |
| 125 | + except TypeError: |
| 126 | + pass |
| 127 | + |
| 128 | + if self._should_disconnect(channel.severity_slot, destroying): |
| 129 | + try: |
| 130 | + self.new_severity_signal.disconnect(channel.severity_slot) |
| 131 | + except (KeyError, TypeError): |
| 132 | + pass |
| 133 | + |
| 134 | + if self._should_disconnect(channel.write_access_slot, destroying): |
198 | 135 | try:
|
199 |
| - channel.value_signal[signal_type].disconnect(self.put_value) |
200 |
| - # When signal type can't be found, PyQt5 throws KeyError here, but PySide6 index error. |
201 |
| - # If signal type exists but doesn't match the slot, TypeError gets thrown. |
202 |
| - except (KeyError, IndexError, TypeError): |
| 136 | + self.write_access_signal.disconnect(channel.write_access_slot) |
| 137 | + except (KeyError, TypeError): |
203 | 138 | pass
|
204 | 139 |
|
| 140 | + if self._should_disconnect(channel.enum_strings_slot, destroying): |
| 141 | + try: |
| 142 | + self.enum_strings_signal.disconnect(channel.enum_strings_slot) |
| 143 | + except (KeyError, TypeError): |
| 144 | + pass |
| 145 | + |
| 146 | + if self._should_disconnect(channel.unit_slot, destroying): |
| 147 | + try: |
| 148 | + self.unit_signal.disconnect(channel.unit_slot) |
| 149 | + except (KeyError, TypeError): |
| 150 | + pass |
| 151 | + |
| 152 | + if self._should_disconnect(channel.upper_ctrl_limit_slot, destroying): |
| 153 | + try: |
| 154 | + self.upper_ctrl_limit_signal.disconnect(channel.upper_ctrl_limit_slot) |
| 155 | + except (KeyError, TypeError): |
| 156 | + pass |
| 157 | + |
| 158 | + if self._should_disconnect(channel.lower_ctrl_limit_slot, destroying): |
| 159 | + try: |
| 160 | + self.lower_ctrl_limit_signal.disconnect(channel.lower_ctrl_limit_slot) |
| 161 | + except (KeyError, TypeError): |
| 162 | + pass |
| 163 | + |
| 164 | + if self._should_disconnect(channel.upper_alarm_limit_slot, destroying): |
| 165 | + try: |
| 166 | + self.upper_alarm_limit_signal.disconnect(channel.upper_alarm_limit_slot) |
| 167 | + except (KeyError, TypeError): |
| 168 | + pass |
| 169 | + |
| 170 | + if self._should_disconnect(channel.lower_alarm_limit_slot, destroying): |
| 171 | + try: |
| 172 | + self.lower_alarm_limit_signal.disconnect(channel.lower_alarm_limit_slot) |
| 173 | + except (KeyError, TypeError): |
| 174 | + pass |
| 175 | + |
| 176 | + if self._should_disconnect(channel.upper_warning_limit_slot, destroying): |
| 177 | + try: |
| 178 | + self.upper_warning_limit_signal.disconnect(channel.upper_warning_limit_slot) |
| 179 | + except (KeyError, TypeError): |
| 180 | + pass |
| 181 | + |
| 182 | + if self._should_disconnect(channel.lower_warning_limit_slot, destroying): |
| 183 | + try: |
| 184 | + self.lower_warning_limit_signal.disconnect(channel.lower_warning_limit_slot) |
| 185 | + except (KeyError, TypeError): |
| 186 | + pass |
| 187 | + |
| 188 | + if self._should_disconnect(channel.prec_slot, destroying): |
| 189 | + try: |
| 190 | + self.prec_signal.disconnect(channel.prec_slot) |
| 191 | + except (KeyError, TypeError): |
| 192 | + pass |
| 193 | + |
| 194 | + if self._should_disconnect(channel.timestamp_slot, destroying): |
| 195 | + try: |
| 196 | + self.timestamp_signal.disconnect(channel.timestamp_slot) |
| 197 | + except (KeyError, TypeError): |
| 198 | + pass |
| 199 | + |
| 200 | + if not destroying and channel.value_signal is not None and hasattr(self, "put_value"): |
| 201 | + for signal_type in (str, int, float, np.ndarray, dict): |
| 202 | + try: |
| 203 | + channel.value_signal[signal_type].disconnect(self.put_value) |
| 204 | + # When signal type can't be found, PyQt5 throws KeyError here, but PySide6 index error. |
| 205 | + # If signal type exists but doesn't match the slot, TypeError gets thrown. |
| 206 | + except (KeyError, IndexError, TypeError): |
| 207 | + pass |
| 208 | + |
205 | 209 | self.listener_count = self.listener_count - 1
|
206 | 210 | if self.listener_count < 1:
|
207 | 211 | self.close()
|
|
0 commit comments