added ConfigWidget for reimplementing Qt methods

This commit is contained in:
iLLiCiTiT 2020-08-26 19:52:35 +02:00
parent e5960d7fa0
commit 28c4a69ea1

View file

@ -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")