设置矩形数据 / Set rectangle data Args: value: 矩形数据,可以是 Rect、tuple、list 或 numpy.ndarray Rectangle data, can be Rect, tuple, list, or numpy.ndarray Returns: bool: 是否成功 / Whether successful Raises: ValueError: 如果数据格式不正确 T
(self, value: RectType)
| 572 | return Rect(x, y, w, h) |
| 573 | |
| 574 | def set(self, value: RectType) -> bool: |
| 575 | """设置矩形数据 / Set rectangle data |
| 576 | |
| 577 | Args: |
| 578 | value: 矩形数据,可以是 Rect、tuple、list 或 numpy.ndarray |
| 579 | Rectangle data, can be Rect, tuple, list, or numpy.ndarray |
| 580 | |
| 581 | Returns: |
| 582 | bool: 是否成功 / Whether successful |
| 583 | |
| 584 | Raises: |
| 585 | ValueError: 如果数据格式不正确 |
| 586 | TypeError: 如果类型不支持 |
| 587 | """ |
| 588 | if isinstance(value, numpy.ndarray): # pyright: ignore[reportUnnecessaryIsInstance] |
| 589 | if value.ndim != 1: |
| 590 | raise ValueError("value must be a 1D array") |
| 591 | if value.shape[0] != 4: |
| 592 | raise ValueError("value must have 4 elements") |
| 593 | if value.dtype != numpy.int32: |
| 594 | raise ValueError("value must be of type numpy.int32") |
| 595 | elif isinstance(value, tuple) or isinstance(value, list): |
| 596 | if len(value) != 4: |
| 597 | raise ValueError("value must have 4 elements") |
| 598 | value = numpy.array(value, dtype=numpy.int32) |
| 599 | elif isinstance(value, Rect): # pyright: ignore[reportUnnecessaryIsInstance] |
| 600 | pass |
| 601 | else: |
| 602 | raise TypeError("value must be a Rect, numpy.ndarray, tuple or list") |
| 603 | |
| 604 | return bool(Library.framework().MaaRectSet(self._handle, value[0], value[1], value[2], value[3])) |
| 605 | |
| 606 | _api_properties_initialized: bool = False |
| 607 |
no test coverage detected