|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | +from __future__ import annotations |
| 15 | + |
14 | 16 | import copy |
15 | 17 | import json |
16 | 18 | import logging |
17 | 19 | import os |
18 | | -from typing import List |
| 20 | +from typing import Any, Callable, List |
| 21 | + |
| 22 | +from nuke_parser.nkview.qt import QtCore, QtWidgets |
19 | 23 |
|
20 | 24 | LOG = logging.getLogger(__name__) |
21 | 25 |
|
@@ -61,3 +65,34 @@ def recentlyOpened() -> List[str]: |
61 | 65 | return [] |
62 | 66 | with open(_NKVIEW_SETTINGS, "r") as f: |
63 | 67 | return copy.deepcopy(json.load(f).get("recently_opened", [])) |
| 68 | + |
| 69 | + |
| 70 | +class WaitCursorContext(object): |
| 71 | + """Qt working cursor context.""" |
| 72 | + |
| 73 | + def __enter__(self) -> WaitCursorContext: |
| 74 | + """Start Working cursor.""" |
| 75 | + QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) |
| 76 | + return self |
| 77 | + |
| 78 | + def __exit__(self, exc_type, exc_val, exc_tb): |
| 79 | + """Restore cursor.""" |
| 80 | + QtWidgets.QApplication.restoreOverrideCursor() |
| 81 | + |
| 82 | + |
| 83 | +def qt_cursor(func: Callable[[Any], Any]) -> Callable[[Any], Any]: |
| 84 | + """Decorator to add Qt cursor wheel on function call. |
| 85 | +
|
| 86 | + Args: |
| 87 | + func: Function to decorate. |
| 88 | +
|
| 89 | + Returns: |
| 90 | + Wrapper function. |
| 91 | +
|
| 92 | + """ |
| 93 | + # pylint: disable=missing-return-doc |
| 94 | + def wrapper(*args, **kwargs) -> Any: |
| 95 | + with WaitCursorContext(): |
| 96 | + return func(*args, **kwargs) |
| 97 | + |
| 98 | + return wrapper |
0 commit comments