mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
fix work with checkstate constants
This commit is contained in:
parent
0aa011184b
commit
679becc3a8
7 changed files with 91 additions and 23 deletions
|
|
@ -35,6 +35,7 @@ from openpype.tools.utils import (
|
|||
ErrorMessageBox,
|
||||
lib as tools_lib
|
||||
)
|
||||
from openpype.tools.utils.lib import checkstate_int_to_enum
|
||||
from openpype.tools.utils.delegates import (
|
||||
VersionDelegate,
|
||||
PrettyTimeDelegate
|
||||
|
|
@ -47,6 +48,13 @@ from openpype.tools.utils.views import (
|
|||
TreeViewSpinner,
|
||||
DeselectableTreeView
|
||||
)
|
||||
from openpype.tools.utils.constants import (
|
||||
LOCAL_PROVIDER_ROLE,
|
||||
REMOTE_PROVIDER_ROLE,
|
||||
LOCAL_AVAILABILITY_ROLE,
|
||||
REMOTE_AVAILABILITY_ROLE,
|
||||
CHECKED_INT,
|
||||
)
|
||||
from openpype.tools.assetlinks.widgets import SimpleLinkView
|
||||
|
||||
from .model import (
|
||||
|
|
@ -60,15 +68,6 @@ from .model import (
|
|||
from . import lib
|
||||
from .delegates import LoadedInSceneDelegate
|
||||
|
||||
from openpype.tools.utils.constants import (
|
||||
LOCAL_PROVIDER_ROLE,
|
||||
REMOTE_PROVIDER_ROLE,
|
||||
LOCAL_AVAILABILITY_ROLE,
|
||||
REMOTE_AVAILABILITY_ROLE
|
||||
)
|
||||
|
||||
CHECKED_INT = getattr(QtCore.Qt.Checked, "value", 2)
|
||||
|
||||
|
||||
class OverlayFrame(QtWidgets.QFrame):
|
||||
def __init__(self, label, parent):
|
||||
|
|
@ -1068,9 +1067,10 @@ class FamilyListView(QtWidgets.QListView):
|
|||
checked_families = []
|
||||
for row in range(model.rowCount()):
|
||||
index = model.index(row, 0)
|
||||
if index.data(QtCore.Qt.CheckStateRole) in (
|
||||
QtCore.Qt.Checked, CHECKED_INT
|
||||
):
|
||||
checked = checkstate_int_to_enum(
|
||||
index.data(QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if checked == QtCore.Qt.Checked:
|
||||
family = index.data(QtCore.Qt.DisplayRole)
|
||||
checked_families.append(family)
|
||||
|
||||
|
|
@ -1104,13 +1104,15 @@ class FamilyListView(QtWidgets.QListView):
|
|||
self.blockSignals(True)
|
||||
|
||||
for index in indexes:
|
||||
index_state = index.data(QtCore.Qt.CheckStateRole)
|
||||
index_state = checkstate_int_to_enum(
|
||||
index.data(QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if index_state == state:
|
||||
continue
|
||||
|
||||
new_state = state
|
||||
if new_state is None:
|
||||
if index_state == QtCore.Qt.Checked:
|
||||
if index_state in QtCore.Qt.Checked:
|
||||
new_state = QtCore.Qt.Unchecked
|
||||
else:
|
||||
new_state = QtCore.Qt.Checked
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from qtpy import QtCore, QtWidgets
|
||||
|
||||
from openpype.tools.utils.lib import checkstate_int_to_enum
|
||||
|
||||
|
||||
class ComboItemDelegate(QtWidgets.QStyledItemDelegate):
|
||||
"""
|
||||
|
|
@ -87,7 +89,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
return
|
||||
|
||||
index_flags = current_index.flags()
|
||||
state = current_index.data(QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
current_index.data(QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
new_state = None
|
||||
|
||||
if event.type() == QtCore.QEvent.MouseButtonRelease:
|
||||
|
|
@ -184,7 +188,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
def value(self):
|
||||
items = list()
|
||||
for idx in range(self.count()):
|
||||
state = self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if state == QtCore.Qt.Checked:
|
||||
items.append(
|
||||
self.itemData(idx, role=QtCore.Qt.UserRole)
|
||||
|
|
@ -194,7 +200,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
def checked_items_text(self):
|
||||
items = list()
|
||||
for idx in range(self.count()):
|
||||
state = self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if state == QtCore.Qt.Checked:
|
||||
items.append(self.itemText(idx))
|
||||
return items
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from qtpy import QtWidgets, QtCore, QtGui
|
|||
|
||||
from openpype.style import get_objected_colors
|
||||
from openpype.widgets.nice_checkbox import NiceCheckbox
|
||||
from openpype.tools.utils.lib import html_escape
|
||||
from openpype.tools.utils.lib import html_escape, checkstate_int_to_enum
|
||||
from .widgets import AbstractInstanceView
|
||||
from ..constants import (
|
||||
INSTANCE_ID_ROLE,
|
||||
|
|
@ -272,6 +272,7 @@ class InstanceListGroupWidget(QtWidgets.QFrame):
|
|||
state(QtCore.Qt.CheckState): Checkstate of checkbox. Have 3
|
||||
variants Unchecked, Checked and PartiallyChecked.
|
||||
"""
|
||||
|
||||
if self.checkstate() == state:
|
||||
return
|
||||
self._ignore_state_change = True
|
||||
|
|
@ -279,7 +280,8 @@ class InstanceListGroupWidget(QtWidgets.QFrame):
|
|||
self._ignore_state_change = False
|
||||
|
||||
def checkstate(self):
|
||||
"""CUrrent checkstate of "active" checkbox."""
|
||||
"""Current checkstate of "active" checkbox."""
|
||||
|
||||
return self.toggle_checkbox.checkState()
|
||||
|
||||
def _on_checkbox_change(self, state):
|
||||
|
|
@ -887,6 +889,7 @@ class InstanceListView(AbstractInstanceView):
|
|||
self._instance_view.setExpanded(proxy_index, expanded)
|
||||
|
||||
def _on_group_toggle_request(self, group_name, state):
|
||||
state = checkstate_int_to_enum(state)
|
||||
if state == QtCore.Qt.PartiallyChecked:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from qtpy import QtCore, QtGui, QtWidgets
|
||||
from openpype.tools.utils.lib import checkstate_int_to_enum
|
||||
|
||||
|
||||
class ComboItemDelegate(QtWidgets.QStyledItemDelegate):
|
||||
|
|
@ -108,7 +109,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
return
|
||||
|
||||
index_flags = current_index.flags()
|
||||
state = current_index.data(QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
current_index.data(QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
new_state = None
|
||||
|
||||
if event.type() == QtCore.QEvent.MouseButtonRelease:
|
||||
|
|
@ -311,7 +314,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
def value(self):
|
||||
items = list()
|
||||
for idx in range(self.count()):
|
||||
state = self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if state == QtCore.Qt.Checked:
|
||||
items.append(
|
||||
self.itemData(idx, role=QtCore.Qt.UserRole)
|
||||
|
|
@ -321,7 +326,9 @@ class MultiSelectionComboBox(QtWidgets.QComboBox):
|
|||
def checked_items_text(self):
|
||||
items = list()
|
||||
for idx in range(self.count()):
|
||||
state = self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
state = checkstate_int_to_enum(
|
||||
self.itemData(idx, role=QtCore.Qt.CheckStateRole)
|
||||
)
|
||||
if state == QtCore.Qt.Checked:
|
||||
items.append(self.itemText(idx))
|
||||
return items
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
from qtpy import QtCore
|
||||
|
||||
|
||||
UNCHECKED_INT = getattr(QtCore.Qt.Unchecked, "value", 0)
|
||||
PARTIALLY_CHECKED_INT = getattr(QtCore.Qt.PartiallyChecked, "value", 1)
|
||||
CHECKED_INT = getattr(QtCore.Qt.Checked, "value", 2)
|
||||
|
||||
DEFAULT_PROJECT_LABEL = "< Default >"
|
||||
PROJECT_NAME_ROLE = QtCore.Qt.UserRole + 101
|
||||
PROJECT_IS_ACTIVE_ROLE = QtCore.Qt.UserRole + 102
|
||||
|
|
|
|||
|
|
@ -20,9 +20,33 @@ from openpype.lib import filter_profiles, Logger
|
|||
from openpype.settings import get_project_settings
|
||||
from openpype.pipeline import registered_host
|
||||
|
||||
from .constants import CHECKED_INT, UNCHECKED_INT
|
||||
|
||||
log = Logger.get_logger(__name__)
|
||||
|
||||
|
||||
def checkstate_int_to_enum(state):
|
||||
if not isinstance(state, int):
|
||||
return state
|
||||
if state == CHECKED_INT:
|
||||
return QtCore.Qt.Checked
|
||||
|
||||
if state == UNCHECKED_INT:
|
||||
return QtCore.Qt.Unchecked
|
||||
return QtCore.Qt.PartiallyChecked
|
||||
|
||||
|
||||
def checkstate_enum_to_int(state):
|
||||
if isinstance(state, int):
|
||||
return state
|
||||
if state == QtCore.Qt.Checked:
|
||||
return 0
|
||||
if state == QtCore.Qt.PartiallyChecked:
|
||||
return 1
|
||||
return 2
|
||||
|
||||
|
||||
|
||||
def center_window(window):
|
||||
"""Move window to center of it's screen."""
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,27 @@ class NiceCheckbox(QtWidgets.QFrame):
|
|||
def isChecked(self):
|
||||
return self._checked
|
||||
|
||||
def _checkstate_int_to_enum(self, state):
|
||||
if not isinstance(state, int):
|
||||
return state
|
||||
|
||||
if state == 2:
|
||||
return QtCore.Qt.Checked
|
||||
if state == 1:
|
||||
return QtCore.Qt.PartiallyChecked
|
||||
return QtCore.Qt.Unchecked
|
||||
|
||||
def _checkstate_enum_to_int(self, state):
|
||||
if isinstance(state, int):
|
||||
return state
|
||||
if state == QtCore.Qt.Checked:
|
||||
return 2
|
||||
if state == QtCore.Qt.PartiallyChecked:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def setCheckState(self, state):
|
||||
state = self._checkstate_int_to_enum(state)
|
||||
if self._checkstate == state:
|
||||
return
|
||||
|
||||
|
|
@ -176,7 +196,7 @@ class NiceCheckbox(QtWidgets.QFrame):
|
|||
elif state == QtCore.Qt.Unchecked:
|
||||
self._checked = False
|
||||
|
||||
self.stateChanged.emit(self.checkState())
|
||||
self.stateChanged.emit(self._checkstate_enum_to_int(self.checkState()))
|
||||
|
||||
if self._animation_timer.isActive():
|
||||
self._animation_timer.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue