from threading import Thread
import traceback
from pathlib import Path
from src.ui.application import Application


class UIThread(Thread):
    # TODO: add typings
    def __init__(self, context):
        Thread.__init__(self)
        self.context = context

    def run(self):
        try:
            app = Application(self.context)
            app.mainloop()
        except Exception:
            Path('.pilotng-ui.log').write_text(
                traceback.format_exc(), encoding='utf-8',
            )
