"""
    pipelines/pohaser_pipeline/wrappers/pointless_reindexToMatch/script/pointless_reindexToMatch_gui.py
    Copyright (C) 2014 Newcastle University
    Author: Martin Noble
    
    """

from CCP4TaskWidget import CTaskWidget
from PyQt4 import QtCore

#-------------------------------------------------------------------
class pointless_reindexToMatch_gui(CTaskWidget):
    #-------------------------------------------------------------------
    
    # Subclass CTaskWidget to give specific task window
    TASKMODULE=['expt_data_utility']
    TASKTITLE='Reindex or  change spacegroup'
    DESCRIPTION = '''Reindex to match reference data/coordinates and/or change space group of reflections or Free R set (Pointless)'''
    TASKNAME = 'pointless_reindexToMatch'
    TASKVERSION = 0.1
    RANK = 2
    
    def drawContents(self):
        self.openFolder(folderFunction='inputData', title='Input')
        self.createLine(['subtitle','Objects to manipulate'])
        self.openSubFrame(frame=True)
        self.createLine(['widget','-browseDb',True,'F_SIGF'])
        self.createLine(['widget','-browseDb',True,'FREERFLAG'])
        self.closeSubFrame()
        self.createLine(['subtitle','Spacegroup and indexing'])
        self.createLine(['label','Define new indexing and spacegroup using','stretch','widget','REFERENCE'])
        self.createLine(['widget','HKLIN_FOBS_REF'],toggle=['REFERENCE','open',['HKLIN_FOBS_REF']])
        self.createLine(['widget','HKLIN_FC_REF'],toggle=['REFERENCE','open',['HKLIN_FC_REF']])
        self.createLine(['widget','HKLIN_FMAP_REF'],toggle=['REFERENCE','open',['HKLIN_FMAP_REF']])
        self.createLine(['widget','XYZIN_REF'],toggle=['REFERENCE','open',['XYZIN_REF']])
        self.openSubFrame(toggle=['REFERENCE','open',['SPECIFY']])
        self.createLine(['widget','CHOOSE_SPACEGROUP'])
        self.createLine(['widget','REINDEX_OPERATOR'])
        self.closeSubFrame()

    def isValid(self):
        invalidElements = super(pointless_reindexToMatch_gui, self).isValid()
        #Length of "solution elements" list can take any value if SOLIN is not set
        if not str(self.container.controlParameters.REFERENCE) == 'HKLIN_FOBS_REF':
            if self.container.inputData.HKLIN_FOBS_REF in invalidElements:
                invalidElements.remove(self.container.inputData.HKLIN_FOBS_REF)
                self.container.inputData.HKLIN_FOBS_REF.unSet()
        if not str(self.container.controlParameters.REFERENCE) == 'HKLIN_FC_REF':
            if self.container.inputData.HKLIN_FC_REF in invalidElements:
                invalidElements.remove(self.container.inputData.HKLIN_FC_REF)
                self.container.inputData.HKLIN_FC_REF.unSet()
        if not str(self.container.controlParameters.REFERENCE) == 'HKLIN_FMAP_REF':
            if self.container.inputData.HKLIN_FMAP_REF in invalidElements:
                invalidElements.remove(self.container.inputData.HKLIN_FMAP_REF)
                self.container.inputData.HKLIN_FMAP_REF.unSet()
        if not str(self.container.controlParameters.REFERENCE) == 'XYZIN_REF':
            if self.container.inputData.XYZIN_REF in invalidElements:
                invalidElements.remove(self.container.inputData.XYZIN_REF)
                self.container.inputData.XYZIN_REF.unSet()
        return invalidElements

