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

import wx
import wxx
import app


# Implementing FindText
class FindText(app.FindText):
    """
    This dialog allows to search for text.
    Press F3 for search again for more occurrences.
    Press Shift + F3 for searching back.
    """
    @wxx.SetInfo(__doc__)
    def __init__(self, parent):
        """Initialize dialog"""
        super(FindText, self).__init__(parent)

    def Validate(self):
        """Process OnOk event"""
        self.seach_text = self.m_search_string.GetValue()
        if not len(self.seach_text):
            wx.MessageBox("Search text must be non empty", "Error",
                wx.OK | wx.CENTER | wx.ICON_ERROR, self)
            return False
        return True

    # Handlers for FindText events.
    def OnCancel(self, event):
        """Cancel seach"""
        self.EndModal(wx.ID_CANCEL)

    def OnOK(self, event):
        """Begin search"""
        if self.Validate():
            self.EndModal(wx.ID_OK)
