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

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

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


# Implementing NewPyModule
class PyModuleDialog(ui.NewPyModule):
    """
    This is the module setup dialog.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent, container):
        """Initialize dialog"""
        super(PyModuleDialog, self).__init__(parent)
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(rc.GetBitmap("py_module"))
        self.SetIcon(icon)
        self._container = container

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

    def SetAttributes(self, obj):
        """Transfer attributes to dialog"""
        self.SetTitle("Edit module")
        self._origin = obj
        self.m_moduleName.SetValue(obj.name)
        self.m_richText1.SetValue(obj.note)

    def CopyAttributes(self, module):
        """Transfer attributes to module"""
        module._name = self._name
        module.note = self._note

    def Validate(self):
        """Process OnOk event"""
        self._name = self.m_moduleName.GetValue().strip()
        if len(self._name) == 0:
            wx.MessageBox("Module name must be non empty", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        self._note = self.m_richText1.GetValue()
        return True

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