
"""
     CCP4Object.py: CCP4 GUI Project
     Copyright (C) 2010 University of York

     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 Aug 2010 -Wrapper for QtCore.QObject complementing CCP4Object
"""

from PyQt4 import QtCore

class CObject(QtCore.QObject):
    def __init__(self,parent=None,name=None):
      #print 'CObject',name
      QtCore.QObject.__init__(self,parent)
      if name is not None: self.setObjectName(name)

    def emitSignal(self,signal='finished',status=None):
      if status is not None:
        self.emit(QtCore.SIGNAL(signal),status)
      else:
        self.emit(QtCore.SIGNAL(signal))

    def connectSignal(self,origin=None,signal='',handler=None):
      self.connect(origin,QtCore.SIGNAL(signal),handler)
      
    def disConnectSignal(self,origin=None,signal='',handler=None):
      self.disconnect(origin,QtCore.SIGNAL(signal),handler)

    def emitDataChanged(self):
      #print 'in CObject.emitDataChanged',self.objectName()
      self.emit(QtCore.SIGNAL('dataChanged'))

    '''
    def getName(self):
      if self.parent() is None:
        return None
      else:
        for key,obj in self.parent()._value.items():
          print 'CObject.getName',key,obj
          if obj is not None and obj == self:
            return key
        return None
    '''

    def objectName(self):
      name = QtCore.QObject.objectName(self)
      if name is None:
        return None
      else:
        return str(name)
    
    def className(self):
      return str(self.__class__.__name__)
      

