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

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


# Implementing NewDecorator
class PyDecoratorDialog(ui.NewDecorator):
    """Create or edit a decorator
    with this dialog"""
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """init dialog"""
        super(PyDecoratorDialog, self).__init__(parent)
        self._container = container
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(rc.GetBitmap("decorator"))
        self.SetIcon(icon)

    def CopyAttributes(self, decorator):
        """Get the atributes"""
        decorator._name = self._name
        decorator._call = self._call
        decorator.note = self._note

    def SetAttributes(self, decorator):
        """Set the attributes"""
        if type(decorator) is tuple:
            self._name = decorator[0]
            self._call = decorator[1]
            self._note = wx.EmptyString
        else:
            self._name = decorator._name
            self._call = decorator._call
            self._note = decorator.note
        self.m_textCtrl79.SetValue(self._name)
        if self._call:
            self.m_textCtrl80.SetValue(self._call)
        else:
            self.m_textCtrl80.SetValue(wx.EmptyString)
        #self.m_richText1.SetValue(decorator.note)
        self.SetTitle("Edit decorator")

    def Validate(self):
        """Validate dialog"""
        self._name = self.m_textCtrl79.GetValue().strip()
        if len(self._name) == 0:
            wx.MessageBox("decorator name missing", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        self._call = self.m_textCtrl80.GetValue().strip()
        self._note = wx.EmptyString
        return True

    def get_kwargs(self):
        """return arguments for object instance"""
        return  {'parent': self._container, 'name': self._name,
            'call': self._call, 'note': self._note}

    # Handlers for NewDecorator events.
    def OnCancel(self, event):
        """Handle cancel"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        "Handle Ok "
        if self.Validate():
            self.EndModal(wx.ID_OK)
