"""
A panel for displaying all actions in a blueprint, adding new actions,
inspecting, and editing actions. Combines ActionEditorWidget, ActionTreeWidget
and ActionPaletteWidget into one widget.
"""


from functools import partial

import pulse
from pulse.vendor.Qt import QtCore, QtWidgets
from pulse.prefs import optionVarProperty

from .core import PulseWindow, BlueprintUIModel
from .actiontree import ActionTreeWidget, ActionPaletteWidget
from .actioneditor import ActionEditorWidget


__all__ = [
    'ActionsViewWidget',
    'ActionsViewWindow',
]


class ActionsViewWidget(QtWidgets.QWidget):
    """
    A panel for displaying all actions in a blueprint, adding new actions,
    inspecting, and editing actions. Combines ActionEditorWidget,
    ActionTreeWidget and ActionPaletteWidgets.
    """

    def __init__(self, parent=None):
        super(ActionsViewWidget, self).__init__(parent=parent)

        self.blueprintModel = BlueprintUIModel.getDefaultModel()

        self.setupUi(self)
        self.setupMenuBar(self)

    def setupUi(self, parent):
        layout = QtWidgets.QVBoxLayout(parent)
        self.setLayout(layout)

        actionsSplitter1 = QtWidgets.QSplitter(parent)
        actionsSplitter1.setOrientation(QtCore.Qt.Orientation.Vertical)

        actionsSplitter2 = QtWidgets.QSplitter(parent)
        actionsSplitter2.setOrientation(QtCore.Qt.Orientation.Horizontal)

        # actions tree
        actionTree = ActionTreeWidget(parent)
        actionTree.layout().setMargin(0)
        actionsSplitter2.addWidget(actionTree)

        # actions palette
        actionPalette = ActionPaletteWidget(parent)
        actionPalette.layout().setMargin(0)
        actionsSplitter2.addWidget(actionPalette)

        actionsSplitter1.addWidget(actionsSplitter2)

        # action editor
        actionEditor = ActionEditorWidget(parent)
        actionEditor.layout().setMargin(0)
        actionsSplitter1.addWidget(actionEditor)

        layout.addWidget(actionsSplitter1)

    def setupMenuBar(self, parent):
        self.menuBar = QtWidgets.QMenuBar(parent)
        self.layout().setMenuBar(self.menuBar)

        actionsMenu = self.menuBar.addMenu("Actions")

        initActions = QtWidgets.QAction("Initialize Default Actions", parent)
        initActions.setStatusTip(
            "Initialize the Blueprint to the default set of actions.")
        initActions.triggered.connect(
            self.blueprintModel.initializeBlueprintToDefaultActions)
        actionsMenu.addAction(initActions)


class ActionsViewWindow(PulseWindow):
    pass

@@ -2557,13 +2557,529 @@
 w):%0A
+%0A
     
-pass
+OBJECT_NAME = 'pulseActionsViewWindow'%0A    PREFERRED_SIZE = QtCore.QSize(400, 300)%0A    STARTING_SIZE = QtCore.QSize(400, 300)%0A    MINIMUM_SIZE = QtCore.QSize(400, 300)%0A%0A    WINDOW_MODULE = 'pulse.views.actionsview'%0A%0A    def __init__(self, parent=None):%0A        super(ActionsViewWindow, self).__init__(parent=parent)%0A%0A        self.setWindowTitle('Pulse Action Editor')%0A%0A        layout = QtWidgets.QVBoxLayout(self)%0A        self.setLayout(layout)%0A%0A        widget = ActionsViewWidget(self)%0A        layout.addWidget(widget)
 %0A

implement ActionsViewWindow