""" This file controls the view for the interface part based on a MVC model

Marjorie Roscian CCI 2017-2018

"""

from Interface.PhytoClusSoft import *
from PyQt5.QtWidgets import QInputDialog, QFileDialog, QTableWidgetItem
from PyQt5 import QtWidgets
from Analysis.MainExecution import *
from Interface.FinalTable import *


class ControlMain(QtWidgets.QMainWindow, Ui_PhytoClus):

    """ This class controls the main window"""
    def __init__(self):
        super(ControlMain, self).__init__()
        self.setupUi(self)
        self.filename = ''
        self.foldname = ''

    def loadCSV(self):
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        self.filename, _ = QFileDialog.getOpenFileName(self, "Load the CSV File", "", "CSV files (*.csv)",
                                                       options=options)
        if self.filename:
            print(self.filename)
        print(type(self.filename))

    def loadPicture(self):
        self.foldname = str(QFileDialog.getExistingDirectory(self, "Select Pictures Directory"))
        if self.foldname:
            print(self.foldname)

    def run4prof(self):
        return True

    def run5prof(self):
        return True

    def start(self):
        if self.run5prof() is True:
            main_exe_5prof(self.filename)
        else:
            main_exe_4prof(self.filename)

    def getint(self):
        num, ok = QInputDialog.getInt(self, "BIC results", "Choose the number of groups")
        if ok:
            print(num)
            num = int(num)
            print(type(num))
        return num


class ControlTable(QtWidgets.QMainWindow, Ui_FinalTable):

    """ This file controls the final table """
    def __init__(self, final_table):
        super(ControlTable, self).__init__()
        self.setupUi(self)
        self.fillTable(final_table)

    def sendtoDataBase(self, final_table):
        """ Not implemented for now"""
        print(final_table)

    def close(self):
        """ Not implemented for now"""
        print('Close')

    def fillTable(self, final_table):
        for row in np.arange(0, len(final_table)):
            for col in np.arange(0, 12):
                self.tableWidget.setItem(row, col, QTableWidgetItem(final_table[row, col]))