|
| 1 | +"""Hook to call whenever a publish tree node is clicked (Qt tree item). |
| 2 | +
|
| 3 | +`.tk_multi_publish2` related wordings and phrases used: |
| 4 | +
|
| 5 | +- "tree node", or "node" for short: |
| 6 | +
|
| 7 | + - An instance of a subclass of |
| 8 | + `.tk_multi_publish2.publish_tree_widget.tree_node_base.TreeNodeBase` |
| 9 | +
|
| 10 | + - Which itself subclasses `.QTreeWidgetItem` |
| 11 | +
|
| 12 | +- "widget" of the node |
| 13 | +
|
| 14 | + - Behaves like a delegate, but not actually using the Qt delegate system |
| 15 | + from model/view architecture |
| 16 | +
|
| 17 | + - An instance of a subclass of |
| 18 | + `.tk_multi_publish2.publish_tree_widget.custom_widget_base.CustomWidgetBase` |
| 19 | +
|
| 20 | + - Which itself subclasses `.QFrame` |
| 21 | +
|
| 22 | +- Publish "api" associated with the node, if any: |
| 23 | +
|
| 24 | + - `.tk_multi_publish2.api.item.PublishItem` for a `.TreeNodeItem` |
| 25 | + - `.tk_multi_publish2.api.task.PublishTask` for a `.TreeNodeTask` |
| 26 | + - otherwise `None`, i.e. for `.TreeNodeContext` and `.TreeNodeSummary` |
| 27 | +
|
| 28 | +""" |
| 29 | + |
| 30 | +from typing import TypeVar, Union |
| 31 | +import sgtk |
| 32 | +from sgtk.platform.qt import QtCore, QtGui |
| 33 | + |
| 34 | +HookBaseClass = sgtk.get_hook_baseclass() |
| 35 | + |
| 36 | +TreeNode = TypeVar("TreeNode", bound=QtGui.QTreeWidgetItem) |
| 37 | +CustomTreeWidget = TypeVar("CustomTreeWidget", bound=QtGui.QFrame) |
| 38 | +API = Union[TypeVar("PublishItem"), TypeVar("PublishTask"), None] |
| 39 | + |
| 40 | + |
| 41 | +class TreeNodeClicked(HookBaseClass): |
| 42 | + @staticmethod |
| 43 | + def flipped_state(check_state: QtCore.Qt.CheckState) -> QtCore.Qt.CheckState: |
| 44 | + """Flips a unchecked state to checked and any other state to unchecked.""" |
| 45 | + return ( |
| 46 | + QtCore.Qt.Checked |
| 47 | + if check_state == QtCore.Qt.Unchecked |
| 48 | + else QtCore.Qt.Unchecked |
| 49 | + ) |
| 50 | + |
| 51 | + def single( |
| 52 | + self, |
| 53 | + node: TreeNode, |
| 54 | + widget: CustomTreeWidget, |
| 55 | + api: API, |
| 56 | + buttons: QtCore.Qt.MouseButtons, |
| 57 | + modifiers: QtCore.Qt.KeyboardModifiers, |
| 58 | + ): # type: (...) -> None |
| 59 | + """Single click callback on a `.TreeNodeBase` (a `.QtGui.QTreeWidgetItem`).""" |
| 60 | + |
| 61 | + def double( |
| 62 | + self, |
| 63 | + node: TreeNode, |
| 64 | + widget: CustomTreeWidget, |
| 65 | + api: API, |
| 66 | + buttons: QtCore.Qt.MouseButtons, |
| 67 | + modifiers: QtCore.Qt.KeyboardModifiers, |
| 68 | + ): # type: (...) -> None |
| 69 | + """Double click callback on a `.TreeNodeBase` (a `.QtGui.QTreeWidgetItem`).""" |
| 70 | + if buttons == QtCore.Qt.LeftButton: |
| 71 | + # Ensure expansion states are correctly updated |
| 72 | + node.setExpanded(node.isExpanded()) |
0 commit comments