# Path: friture/defaults.py
# DEFAULT_DOCKS = [2,  # FFT Spectrum,
#                  3,  # spectrogram
#                  4]  # octave spectrum
# 
# Path: friture/dock.py
# class Dock(QtWidgets.QWidget):
# 
#     def __init__(self, parent, name, qml_engine, widgetId=None):
#         super().__init__(parent)
# 
#         self.dockmanager = parent.dockmanager
#         self.audiobuffer = parent.audiobuffer
# 
#         self.setObjectName(name)
# 
#         self.control_bar = ControlBar(self)
# 
#         self.control_bar.combobox_select.activated.connect(self.indexChanged)
#         self.control_bar.settings_button.clicked.connect(self.settings_slot)
#         self.control_bar.close_button.clicked.connect(self.closeClicked)
# 
#         #self.dockwidget = QtWidgets.QWidget(self)
#         self.layout = QtWidgets.QVBoxLayout(self)
#         self.layout.addWidget(self.control_bar)
#         self.layout.setContentsMargins(0, 0, 0, 0)
#         # self.dockwidget.setLayout(self.layout)
# 
#         # self.setWidget(self.dockwidget)
# 
#         self.widgetId = None
#         self.audiowidget = None
#         self.qml_engine = qml_engine
# 
#         if widgetId is None:
#             widgetId = widgetIds()[0]
# 
#         self.widget_select(widgetId)
# 
#     # note that by default the closeEvent is accepted, no need to do it explicitely
#     def closeEvent(self, event):
#         self.dockmanager.close_dock(self)
# 
#     def closeClicked(self, checked):
#         self.close()
# 
#     # slot
#     def indexChanged(self, index):
#         if index > len(widgetIds()):
#             index = widgetIds()[0]
# 
#         self.widget_select(widgetIds()[index])
# 
#     # slot
#     def widget_select(self, widgetId):
#         if self.widgetId == widgetId:
#             return
# 
#         if self.audiowidget is not None:
#             self.audiowidget.close()
#             self.audiowidget.deleteLater()
# 
#         if widgetId not in widgetIds():
#             widgetId = widgetIds()[0]
# 
#         self.widgetId = widgetId
# 
#         constructor = getWidgetById(widgetId)["Class"]
#         if len(signature(constructor).parameters) == 2:
#             self.audiowidget = constructor(self, self.qml_engine)
#         else:
#             self.audiowidget = constructor(self)
# 
#         self.audiowidget.set_buffer(self.audiobuffer)
#         self.audiobuffer.new_data_available.connect(self.audiowidget.handle_new_data)
# 
#         self.layout.addWidget(self.audiowidget)
# 
#         index = widgetIds().index(widgetId)
#         self.control_bar.combobox_select.setCurrentIndex(index)
# 
#     def canvasUpdate(self):
#         if self.audiowidget is not None:
#             self.audiowidget.canvasUpdate()
# 
#     def pause(self):
#         if self.audiowidget is not None:
#             self.audiowidget.pause()
# 
#     def restart(self):
#         if self.audiowidget is not None:
#             self.audiowidget.restart()
# 
#     # slot
#     def settings_slot(self, checked):
#         self.audiowidget.settings_called(checked)
# 
#     # method
#     def saveState(self, settings):
#         settings.setValue("type", self.widgetId)
#         self.audiowidget.saveState(settings)
# 
#     # method
#     def restoreState(self, settings):
#         self.audiowidget.restoreState(settings)


import logging
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow
from friture.defaults import DEFAULT_DOCKS
from friture.dock import Dock
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Friture.  If not, see <http://www.gnu.org/licenses/>.




class DockManager(QtCore.QObject):

    def __init__(self, parent):
        super().__init__(parent)

        self.logger = logging.getLogger(__name__)

        # the parent must of the QMainWindow so that docks are created as children of it
        assert isinstance(parent, QMainWindow)

        self.docks = []

    # slot
    def new_dock(self):
        # the dock objectName is unique
        docknames = [dock.objectName() for dock in self.docks]
        dockindexes = [int(str(name).partition(' ')[-1]) for name in docknames]
        if len(dockindexes) == 0:
            index = 1
        else:
            index = max(dockindexes) + 1
        name = "Dock %d" % index

# Path: friture/defaults.py
# DEFAULT_DOCKS = [2,  # FFT Spectrum,
#                  3,  # spectrogram
#                  4]  # octave spectrum
# 
# Path: friture/dock.py
# class Dock(QtWidgets.QWidget):
# 
#     def __init__(self, parent, name, qml_engine, widgetId=None):
#         super().__init__(parent)
# 
#         self.dockmanager = parent.dockmanager
#         self.audiobuffer = parent.audiobuffer
# 
#         self.setObjectName(name)
# 
#         self.control_bar = ControlBar(self)
# 
#         self.control_bar.combobox_select.activated.connect(self.indexChanged)
#         self.control_bar.settings_button.clicked.connect(self.settings_slot)
#         self.control_bar.close_button.clicked.connect(self.closeClicked)
# 
#         #self.dockwidget = QtWidgets.QWidget(self)
#         self.layout = QtWidgets.QVBoxLayout(self)
#         self.layout.addWidget(self.control_bar)
#         self.layout.setContentsMargins(0, 0, 0, 0)
#         # self.dockwidget.setLayout(self.layout)
# 
#         # self.setWidget(self.dockwidget)
# 
#         self.widgetId = None
#         self.audiowidget = None
#         self.qml_engine = qml_engine
# 
#         if widgetId is None:
#             widgetId = widgetIds()[0]
# 
#         self.widget_select(widgetId)
# 
#     # note that by default the closeEvent is accepted, no need to do it explicitely
#     def closeEvent(self, event):
#         self.dockmanager.close_dock(self)
# 
#     def closeClicked(self, checked):
#         self.close()
# 
#     # slot
#     def indexChanged(self, index):
#         if index > len(widgetIds()):
#             index = widgetIds()[0]
# 
#         self.widget_select(widgetIds()[index])
# 
#     # slot
#     def widget_select(self, widgetId):
#         if self.widgetId == widgetId:
#             return
# 
#         if self.audiowidget is not None:
#             self.audiowidget.close()
#             self.audiowidget.deleteLater()
# 
#         if widgetId not in widgetIds():
#             widgetId = widgetIds()[0]
# 
#         self.widgetId = widgetId
# 
#         constructor = getWidgetById(widgetId)["Class"]
#         if len(signature(constructor).parameters) == 2:
#             self.audiowidget = constructor(self, self.qml_engine)
#         else:
#             self.audiowidget = constructor(self)
# 
#         self.audiowidget.set_buffer(self.audiobuffer)
#         self.audiobuffer.new_data_available.connect(self.audiowidget.handle_new_data)
# 
#         self.layout.addWidget(self.audiowidget)
# 
#         index = widgetIds().index(widgetId)
#         self.control_bar.combobox_select.setCurrentIndex(index)
# 
#     def canvasUpdate(self):
#         if self.audiowidget is not None:
#             self.audiowidget.canvasUpdate()
# 
#     def pause(self):
#         if self.audiowidget is not None:
#             self.audiowidget.pause()
# 
#     def restart(self):
#         if self.audiowidget is not None:
#             self.audiowidget.restart()
# 
#     # slot
#     def settings_slot(self, checked):
#         self.audiowidget.settings_called(checked)
# 
#     # method
#     def saveState(self, settings):
#         settings.setValue("type", self.widgetId)
#         self.audiowidget.saveState(settings)
# 
#     # method
#     def restoreState(self, settings):
#         self.audiowidget.restoreState(settings)


# Path: friture/dockmanager.py
import logging
from PyQt5 import QtCore
from PyQt5.QtWidgets import QMainWindow
from friture.defaults import DEFAULT_DOCKS
from friture.dock import Dock

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Friture.  If not, see <http://www.gnu.org/licenses/>.




class DockManager(QtCore.QObject):

    def __init__(self, parent):
        super().__init__(parent)

        self.logger = logging.getLogger(__name__)

        # the parent must of the QMainWindow so that docks are created as children of it
        assert isinstance(parent, QMainWindow)

        self.docks = []

    # slot
    def new_dock(self):
        # the dock objectName is unique
        docknames = [dock.objectName() for dock in self.docks]
        dockindexes = [int(str(name).partition(' ')[-1]) for name in docknames]
        if len(dockindexes) == 0:
            index = 1
        else:
            index = max(dockindexes) + 1
        name = "Dock %d" % index

        new_dock = Dock(self.parent(), name, self.parent().qml_engine)