from cefbrowser.cefbrowser import CEFBrowser
from signage.fader import NodeBehavior


class BrowserNode(NodeBehavior, CEFBrowser):
    hidden = False

    def on_pre_enter(self):
        self._browser.WasHidden(False)
        self.hidden = False

    def on_leave(self):
        self._browser.WasHidden(True)
        self.hidden = True

    def _realign(self, *largs):
        if self.hidden:
            self._browser.WasHidden(False)

        super(BrowserNode, self)._realign(*largs)

        if self.hidden:
            self._browser.WasHidden(True)
