"""Subclass of NewDestructor, which is generated by wxFormBuilder."""

import wx
import wxx
from activity.models.ui import ui as ui
import app.resources as rc


# Implementing NewDestructor
class DestructorDialog(ui.NewDestructor):
    """
    This dialog allows the edition of class or struct destructor.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """Initialization"""
        super(DestructorDialog, self).__init__(parent)
        self._container = container
        self._class = container.inner_class
        self.m_choice2.SetFocus()
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(rc.GetBitmap("destructor"))
        self.SetIcon(icon)

    def CopyAttributes(self, dtor):
        """Transfer attributes to dtor"""
        dtor._name = self._name
        dtor._access = self._access
        dtor._inline = self._inline
        dtor._virtual = self._virtual
        dtor._pure = self._pure
        dtor._declare = self._declare
        dtor._implement = self._implement
        dtor._calling = self._calling
        if self._calling:
            dtor._callingText = self._callingText
        dtor.note = self._note

    def SetAttributes(self, dtor):
        """Transfer attributes from existing constructor"""
        self._container = dtor.parent
        self._class = dtor.inner_class
        self._name = dtor._name
        self._access = dtor._access
        iSel = self.m_choice2.FindString(self._access)
        self.m_choice2.Select(iSel)
        self._inline = dtor._inline
        self.m_checkBox31.SetValue(self._inline)
        self._virtual = dtor._virtual
        self.m_checkBox41.SetValue(self._virtual)
        self._pure = dtor._pure
        self.m_checkBox104.SetValue(self._pure)
        self._declare = dtor._declare
        self.m_checkBox92.SetValue(self._declare)
        self._implement = dtor._implement
        self.m_checkBox93.SetValue(self._implement)
        self._calling = dtor._calling
        self.m_checkBox6.SetValue(self._calling)
        self.m_comboBox1.Enable(self._calling)
        if self._calling:
            self._callingText = dtor._callingText
            iSel = self.m_comboBox1.FindString(self._callingText)
            self.m_comboBox1.Select(iSel)
        self._note = dtor.note
        self.m_richText1.SetValue(self._note)
        self.SetTitle("Edit destructor")

    def Validate(self):
        """Validation"""
        self._name = self._class._name
        iSel = self.m_choice2.GetSelection()
        self._access = self.m_choice2.GetString(iSel)
        self._inline = self.m_checkBox31.IsChecked()
        self._virtual = self.m_checkBox41.IsChecked()
        self._pure = self.m_checkBox104.IsChecked()
        self._declare = self.m_checkBox92.IsChecked()
        self._implement = self.m_checkBox93.IsChecked()
        self._calling = self.m_checkBox6.IsChecked()
        if self._calling:
            iSel = self.m_comboBox1.GetSelection()
            self._callingText = self.m_comboBox1.GetString(iSel)
        self._note = self.m_richText1.GetValue()
        return True

    def get_kwargs(self):
        """Returns the kwargs needed for this object"""
        kwargs = {}
        kwargs['parent'] = self._container
        kwargs['name'] = self._name
        kwargs['access'] = self._access
        kwargs['inline'] = self._inline
        kwargs['virtual'] = self._virtual
        kwargs['pure'] = self._pure
        kwargs['declare'] = self._declare
        kwargs['implement'] = self._implement
        kwargs['calling'] = self._calling
        kwargs['callspec'] = (self._calling and self._callingText) or ''
        kwargs['note'] = self._note
        return kwargs

    def OnCancel(self, event):
        """Implement OnCance"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        """Implement OnOk"""
        if self.Validate():
            self.EndModal(wx.ID_OK)


