diff --git a/pype/tools/launcher/delegates.py b/pype/tools/launcher/delegates.py index 8e1ec2004e..95ccde6445 100644 --- a/pype/tools/launcher/delegates.py +++ b/pype/tools/launcher/delegates.py @@ -6,13 +6,17 @@ class ActionDelegate(QtWidgets.QStyledItemDelegate): extender_bg_brush = QtGui.QBrush(QtGui.QColor(100, 100, 100, 160)) extender_fg = QtGui.QColor(255, 255, 255, 160) - def __init__(self, group_role, *args, **kwargs): + def __init__(self, group_roles, *args, **kwargs): super(ActionDelegate, self).__init__(*args, **kwargs) - self.group_role = group_role + self.group_roles = group_roles def paint(self, painter, option, index): super(ActionDelegate, self).paint(painter, option, index) - is_group = index.data(self.group_role) + is_group = False + for group_role in self.group_roles: + is_group = index.data(group_role) + if is_group: + break if not is_group: return diff --git a/pype/tools/launcher/models.py b/pype/tools/launcher/models.py index f76e26afde..3fb201702e 100644 --- a/pype/tools/launcher/models.py +++ b/pype/tools/launcher/models.py @@ -109,6 +109,7 @@ class TaskModel(QtGui.QStandardItemModel): class ActionModel(QtGui.QStandardItemModel): ACTION_ROLE = QtCore.Qt.UserRole GROUP_ROLE = QtCore.Qt.UserRole + 1 + VARIANT_GROUP_ROLE = QtCore.Qt.UserRole + 2 def __init__(self, dbcon, parent=None): super(ActionModel, self).__init__(parent=parent) @@ -200,7 +201,7 @@ class ActionModel(QtGui.QStandardItemModel): item = QtGui.QStandardItem(icon, action.label) item.setData(actions, self.ACTION_ROLE) - item.setData(True, self.GROUP_ROLE) + item.setData(True, self.VARIANT_GROUP_ROLE) items_by_order[order].append(item) for action in single_actions: diff --git a/pype/tools/launcher/widgets.py b/pype/tools/launcher/widgets.py index 82435e8681..7ab0a3f8ea 100644 --- a/pype/tools/launcher/widgets.py +++ b/pype/tools/launcher/widgets.py @@ -95,7 +95,10 @@ class ActionBar(QtWidgets.QWidget): view.setModel(model) # TODO better group delegate - delegate = ActionDelegate(model.GROUP_ROLE, self) + delegate = ActionDelegate( + [model.GROUP_ROLE, model.VARIANT_GROUP_ROLE], + self + ) view.setItemDelegate(delegate) layout.addWidget(view) @@ -119,58 +122,68 @@ class ActionBar(QtWidgets.QWidget): return is_group = index.data(self.model.GROUP_ROLE) - if not is_group: + is_variant_group = index.data(self.model.VARIANT_GROUP_ROLE) + if not is_group and not is_variant_group: action = index.data(self.model.ACTION_ROLE) self.action_clicked.emit(action) return actions = index.data(self.model.ACTION_ROLE) - by_variant_label = collections.defaultdict(list) - orders = [] - for action in actions: - # Lable variants - label = getattr(action, "label", None) - label_variant = getattr(action, "label_variant", None) - if label_variant and not label: - label_variant = None - - if not label_variant: - orders.append(action) - continue - - if label not in orders: - orders.append(label) - by_variant_label[label].append(action) menu = QtWidgets.QMenu(self) actions_mapping = {} - for action_item in orders: - actions = by_variant_label.get(action_item) - if not actions: - action = action_item - elif len(actions) == 1: - action = actions[0] - else: - action = None - - if action: + if is_variant_group: + for action in actions: menu_action = QtWidgets.QAction( lib.get_action_label(action) ) menu.addAction(menu_action) actions_mapping[menu_action] = action - continue - - sub_menu = QtWidgets.QMenu(label, menu) + else: + by_variant_label = collections.defaultdict(list) + orders = [] for action in actions: - menu_action = QtWidgets.QAction( - lib.get_action_label(action) - ) - sub_menu.addAction(menu_action) - actions_mapping[menu_action] = action + # Lable variants + label = getattr(action, "label", None) + label_variant = getattr(action, "label_variant", None) + if label_variant and not label: + label_variant = None - menu.addMenu(sub_menu) + if not label_variant: + orders.append(action) + continue + + if label not in orders: + orders.append(label) + by_variant_label[label].append(action) + + for action_item in orders: + actions = by_variant_label.get(action_item) + if not actions: + action = action_item + elif len(actions) == 1: + action = actions[0] + else: + action = None + + if action: + menu_action = QtWidgets.QAction( + lib.get_action_label(action) + ) + menu.addAction(menu_action) + actions_mapping[menu_action] = action + continue + + sub_menu = QtWidgets.QMenu(label, menu) + for action in actions: + menu_action = QtWidgets.QAction( + lib.get_action_label(action) + ) + sub_menu.addAction(menu_action) + actions_mapping[menu_action] = action + + menu.addMenu(sub_menu) result = menu.exec_(QtGui.QCursor.pos()) if result: