import re
import sys
import weakref

from lib.helpers import timing
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QShortcut
from ui.test_test import Test_Test


class Test_Fail(Test_Test):
    def __init__(self, components=None, recipe=None, step=None, pieces=None, run_once=False, reset_on_start=True, enable_override=False):
        super().__init__(components=components, recipe=recipe, step=step, pieces=pieces, run_once=run_once, reset_on_start=reset_on_start, enable_override=enable_override)
        self.continue_b.clicked.connect(lambda checked, self=weakref.ref(self): self().ok.emit(None))

    def start(self, recipe=None, step=None, pieces=None):
        show = super().start(recipe=recipe, step=step, pieces=pieces)
        if show is False:
            return show
        self.visualize()
        # TESTING
        if "--test" in sys.argv:
            self.test_timer = QTimer()
            self.test_timer.setSingleShot(True)
            self.test_timer.timeout.connect(self.continue_b.click)
            self.test_timer.start(500)
        # /TESTING
        return show

    # def stop(self):
    #     super().stop()

    # def reset(self):
    #     super().reset()
