import os

import clarabot_nano.core.error
from clarabot_nano.core.__main__ import main


class _ErrorFrame(clarabot_nano.core.error.ErrorFrame):
    def __init__(self, error):
        with open(os.environ["CBNANO_TEST_GUI_ERROR_FEEDBACK_PATH"], "w+") as f:
            f.write(error)
        super(_ErrorFrame, self).__init__(error)
        import wx

        self._close_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self._on_close_timeout, self._close_timer)
        self._close_timer.StartOnce(500)

    def _on_close_timeout(self, event):
        self.Close()


clarabot_nano.core.error.ErrorFrame = _ErrorFrame

if __name__ == "__main__":
    main()
