From 28c4a69ea13804b96744a3a56afeb5cd0a24ea7b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 Aug 2020 19:52:35 +0200 Subject: [PATCH] added ConfigWidget for reimplementing Qt methods --- .../config_setting/widgets/widgets.py | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/pype/tools/config_setting/config_setting/widgets/widgets.py b/pype/tools/config_setting/config_setting/widgets/widgets.py index a15edf58ff..89f6782cfd 100644 --- a/pype/tools/config_setting/config_setting/widgets/widgets.py +++ b/pype/tools/config_setting/config_setting/widgets/widgets.py @@ -1,4 +1,4 @@ -from Qt import QtWidgets, QtCore +from Qt import QtWidgets, QtCore, QtGui class ModifiedIntSpinBox(QtWidgets.QSpinBox): @@ -38,7 +38,43 @@ class ClickableWidget(QtWidgets.QLabel): super(ClickableWidget, self).mouseReleaseEvent(event) -class ExpandingWidget(QtWidgets.QWidget): +class ConfigWidget(QtWidgets.QWidget): + allow_actions = True + + def mouseReleaseEvent(self, event): + if self.allow_actions and event.button() == QtCore.Qt.RightButton: + menu = QtWidgets.QMenu() + + actions_mapping = {} + if self.child_modified: + action = QtWidgets.QAction("Discard changes") + actions_mapping[action] = self._discard_changes + menu.addAction(action) + + if ( + not self.any_parent_overriden() + and (self.is_overriden or self.child_overriden) + ): + # TODO better label + action = QtWidgets.QAction("Remove override") + actions_mapping[action] = self._remove_overrides + menu.addAction(action) + + if not actions_mapping: + action = QtWidgets.QAction("< No action >") + actions_mapping[action] = None + menu.addAction(action) + + result = menu.exec_(QtGui.QCursor.pos()) + if result: + to_run = actions_mapping[result] + if to_run: + to_run() + return + super(ConfigWidget, self).mouseReleaseEvent(event) + + +class ExpandingWidget(ConfigWidget): def __init__(self, label, parent): super(ExpandingWidget, self).__init__(parent) self.setObjectName("ExpandingWidget")