"""! @package easyQtGui
Python module for _easyQtGui definings.
Here is defined the main plugin class from wich to derive the specialization.
In addition threr are auxiliary classes to facilitate the implementation of
object useful for data management.
"""
import _easyQtGUI

from collections.abc import MutableMapping

class PyWidgetProperty(MutableMapping):
  def __init__(self,qt_object):
      self.__qt_object = qt_object
      self.__properties = _easyQtGUI.properties(self.__qt_object)

  def __delitem__(self,key):
      pass

  def __getitem__(self,key):
      return _easyQtGUI.property(self.__qt_object,key) 

  def __setitem__(self,key,value):
      return _easyQtGUI.setProperty(self.__qt_object,key,value)

  def __len__(self):
      return len(self.__properties)

  def __iter__(self):
      return iter(self.__properties)

  def keys(self):
      return self.__properties

  def values(self):
      return tuple( self.__getitem__(k) for k in self.keys() )

  def items(self):
      return list(zip(self.keys(),self.values()))

class PyWidget(object):
  def __init__(self,qt_object):
      self.__qtobject     = qt_object
      self.__signals    = _easyQtGUI.signals(self.__qtobject)
      self.__slots      = _easyQtGUI.slots(self.__qtobject)
      self.__methods    = _easyQtGUI.methods(self.__qtobject)
      self.__invokable  = self.__slots + self.__methods

      self.properties   = PyWidgetProperty(self.__qtobject)

  def findChildren(self,pattern):
      return findChildren(pattern,self.__qtobject)

  def keys(self):
      return self.properties.keys()

  def qtobject(self):
      return self.__qtobject

  def slots(self):
      return self.__slots

  def methods(self):
      return self.__methods

  def signals(self):
      return self.__signals

  def emit(self,signal):
      return _easyQtGUI.emit(self.__object,signal)

  def invoke(self,method,args=()):
      return _easyQtGUI.invokeMethod(self.__qtobject,method,args)


def connect(sender,signal,receiver,slot=None):
    if slot is None:
        return _easyQtGUI.connect(sender.qtobject(),signal,receiver)
    else:
        return _easyQtGUI.connect(sender.qtobject(),signal,receiver.qtobject(),slot)

def loadUi(file):
    o = _easyQtGUI.loadUi(file)
    return PyWidget(o) if o is not None else None

def findChildren(pattern,parent=None):
    children=_easyQtGUI.findChildren(parent,pattern)
    return tuple( PyWidget(c) for c in children ) if children is not None else ()

def dirDialog(*args):
    return _easyQtGUI.dirDialog(*args)

def inputDialog(*args):
    return _easyQtGUI.inputDialog(*args)

def messageBox(*args):
    return _easyQtGUI.messageBox(*args)

def openFileDialog(*args):
    return _easyQtGUI.openFileDialog(*args)

def saveFileDialog(*args):
    return _easyQtGUI.saveFileDialog(*args)
