"""
     tasks/splitMtz/CTaskSplitMtz.py: CCP4 GUI Project
     Copyright (C) 2012 STFC

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
"""

"""
     Liz Potterton August 2012 - gui for mtz split
"""

from PyQt4 import QtGui,QtCore
from CCP4ErrorHandling import *
import CCP4TaskWidget
import CCP4Widgets

class CTaskSplitMtz(CCP4TaskWidget.CTaskWidget):

# Subclass CTaskWidget to give specific task window
  TASKNAME = 'splitMtz'
  TASKVERSION = 0.0
  TASKMODULE='data_entry'
  TASKTITLE='Import and Split MTZ into experimental data objects'
  SHORTTASKTITLE='Import and Split MTZ'
  DESCRIPTION = 'Select groups of columns from the MTZ file (csplitmtz)'
  WHATNEXT = []

  ERROR_CODES = { 200 : { 'description' : 'There are no selected column groups' } }
  
  def __init__(self,parent):
    CCP4TaskWidget.CTaskWidget.__init__(self,parent)


  def drawContents(self):                    
    folder = self.openFolder(folderFunction='inputData',title='Input Data',followFrom=False)
    
    self.createLine(  [ 'subtitle', 'Select experimental data file'] )
    self.createLine ( [ 'widget','HKLIN' ] )
    self.connect(self._container.inputData.HKLIN,QtCore.SIGNAL('dataChanged'),self.handleSelectHklin)
    self.createLine(  [ 'subtitle', 'Select column groups'] )
    self.createLine([ 'widget', 'COLUMNGROUPLIST'])

  def handleSelectHklin(self):
    #print 'CTaskSplitMtz.handleSelectHklin',self._container.inputData.HKLIN
    self._container.inputData.HKLIN.loadFile()
    self._container.inputData.COLUMNGROUPLIST.set(self._container.inputData.HKLIN.fileContent.getColumnGroups())
    
  def fix(self):
    self.getWidget('COLUMNGROUPLIST').updateModelFromView()
    nSelected = self.getWidget('COLUMNGROUPLIST').numberSelected()
    if nSelected == 0:
      return CErrorReport(self.__class__,200,stack=False)
    else:
      return  CErrorReport()
