import sys

from PyQt5 import QtCore, QtWidgets, QtGui
from pyqtgraph.dockarea import DockArea, Dock

from data_tab import DataTable, DropArea, DataTab

PROJECT_NAME = 'Testbeam Analysis'


class AnalysisWindow(QtWidgets.QMainWindow):

    def __init__(self, parent=None):
        ''' TODO: DOCSTRING'''
        super(AnalysisWindow, self).__init__(parent)

        self._init_UI()

    def _init_UI(self):
        ''' TODO: DOCSTRING'''

        # Main window settings
        self.setWindowTitle(PROJECT_NAME)
        self.screen = QtWidgets.QDesktopWidget().screenGeometry()
        self.resize(0.75 * self.screen.width(), 0.75 * self.screen.height())
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        # Add widgets to main window
        self._init_menu()
        self._init_tabs()

        self.statusBar().showMessage(
            "Hello and welcome to a simple and easy to use testbeam analysis!",
            4000)

    def _init_tabs(self):
        # Add tabs and widgets for the different analysis steps
        self.tab_order = ('Files', 'Setup', 'Noisy Pixel', 'Clustering',
                          'Correlations', 'Pre-alignment', 'Track finding', 'Alignment',
                          'Track fitting', 'Track Analysis')
        self.tab_widgets = {}

        # Add QTabWidget for tabs
        tabs = QtWidgets.QTabWidget()
        self.setCentralWidget(tabs)

        # Add DockArea to each tab
        for name in self.tab_order:
            if name == 'Files':
                self.tab_widgets[name] = DockArea()
            else:
                self.tab_widgets[name] = QtWidgets.QWidget()
                layout_widget = QtWidgets.QVBoxLayout()
                layout_buttons = QtWidgets.QHBoxLayout()
                layout_buttons.addWidget(QtWidgets.QPushButton('Test'))
                layout_buttons.addWidget(QtWidgets.QPushButton('Test2'))
                layout_buttons_2 = QtWidgets.QHBoxLayout()
                layout_buttons_2.addWidget(QtWidgets.QPushButton('Test3'))
                layout_buttons_2.addWidget(QtWidgets.QPushButton('Test4'))
                layout_widget.addLayout(layout_buttons)
                layout_widget.addLayout(layout_buttons_2)
                self.tab_widgets[name].setLayout(layout_widget)
            tabs.addTab(self.tab_widgets[name], name)

        # Init tab number 1 with data
        self.data_tab = DataTab(parent=self.tab_widgets[self.tab_order[0]])

    def _init_menu(self):
        self.file_menu = QtWidgets.QMenu('&File', self)
        self.file_menu.addAction('&Quit', self.file_quit,
                                 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
        self.menuBar().addMenu(self.file_menu)

        self.help_menu = QtWidgets.QMenu('&Help', self)
        self.menuBar().addSeparator()
        self.menuBar().addMenu(self.help_menu)

        # self.help_menu.addAction('&About', self.about)

    def file_quit(self):
        self.close()

    def closeEvent(self, _):
        self.file_quit()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    font = QtGui.QFont()
    font.setPointSize(12)
    app.setFont(font)
    aw = AnalysisWindow()
    aw.show()
    sys.exit(app.exec_())

@@ -3,16 +3,31 @@
 port sys
+%0Aimport logging
 %0A%0Afrom P
@@ -106,14 +106,8 @@
 Area
-, Dock
 %0A%0Afr
@@ -113,20 +113,16 @@
 rom data
-_tab
  import 
@@ -132,65 +132,411 @@
 aTab
-le, DropArea, DataTab%0A%0APROJECT_NAME = 'Testbeam Analysis'
+%0Afrom testbeam_analysis.gui import tab_widget%0A%0APROJECT_NAME = 'Testbeam Analysis'%0A%0A%0A# For testing until widget provide this info%0Asetup = %7B'n_pixel': (10, 10),%0A         'pixel_size': (100, 100),%0A         'dut_name': 'myDUT'%7D%0A%0Aoptions = %7B'working_directory': '',%0A           'input_hits_file': 'test_DUT0.h5',%0A           'output_mask_file': 'tt',%0A           'chunk_size': 1000000,%0A           'plot': False%7D
 %0A%0A%0Ac
@@ -1324,17 +1324,23 @@
  Add tab
-s
+_widget
  and wid
@@ -1603,38 +1603,8 @@
 is')
-%0A        self.tab_widgets = %7B%7D
 %0A%0A  
@@ -1633,17 +1633,23 @@
  for tab
-s
+_widget
 %0A       
@@ -1730,23 +1730,18 @@
   # 
-Add DockArea to
+Initialize
  eac
@@ -1834,66 +1834,108 @@
     
-self.tab_widgets%5Bname%5D = DockArea()%0A            else:%0A    
+continue%0A                widget = DockArea()%0A                self.data_tab = DataTab(parent=widget)%0A
     
@@ -1946,52 +1946,35 @@
     
-s
 el
-f.tab_widgets%5Bname%5D = QtWidgets.QWidget()
+if name == 'Noisy Pixel':
 %0A   
@@ -1982,31 +1982,24 @@
             
-layout_
 widget = QtW
@@ -1999,498 +1999,460 @@
 t = 
-QtWidgets.QVBoxLayout()%0A                layout_buttons = QtWidgets.QHBoxLayout()%0A                layout_buttons.addWidget(QtWidgets.QPushButton('Test'))%0A                layout_buttons.addWidget(QtWidgets.QPushButton('Test2'))%0A                layout_buttons_2 = QtWidgets.QHBoxLayout()%0A                layout_buttons_2.addWidget(QtWidgets.QPushButton('Test3'))%0A                layout_buttons_2.addWidget(QtWidgets.QPushButton('Test4'))%0A                layout_widget.addLayout(layout_buttons)
+tab_widget.NoisyPixelsTab(parent=tabs,%0A                                                   setup=setup,%0A                                                   options=options)%0A            elif name == 'Clustering':%0A                widget = tab_widget.ClusterPixelsTab(parent=tabs,%0A                                                     setup=setup,%0A                                                     options=options)%0A            elif name == 'Correlations':
 %0A   
@@ -2468,168 +2468,311 @@
     
-layout_widget.addLayout(layout_buttons_2)%0A                self.tab_widgets%5Bname%5D.setLayout(layout_widget)%0A            tabs.addTab(self.tab_widgets%5Bname%5D
+widget = tab_widget.CorrelateClusterTab(parent=tabs,%0A                                                        setup=setup,%0A                                                        options=options)%0A            else:%0A                #                 logging.warning('GUI for %25s not implemented yet'
 , name)%0A
 %0A   
@@ -2767,25 +2767,24 @@
 , name)%0A
-%0A
         
 # Init t
@@ -2779,112 +2779,61 @@
     
-# Init tab number 1 with data%0A        self.data_tab = DataTab(parent=self.tab_widgets%5Bself.tab_order%5B0%5D%5D
+        continue%0A            tabs.addTab(widget, name
 )%0A%0A 

use autogui