<reponame>mcnuggetsx20/QPanel
from lib.ini import base_class
from PyQt5.QtCore import QSize, QTimer

class TEXT():
    def __init__(self, 
            text='',
            size=None,
            func=None,
            interval=None,
            key_functions={},
            on=False,
            **kwargs,
        ):
        
        self.init = base_class(**kwargs)
        self.text=text
        self.size=size
        self.label=None
        self.interval=interval
        self.func=func
        self.key_functions=key_functions
        self.label=self.init.label
        self.on=on

    def h2r(self, h):
        return 'rgba' + str(tuple(int(h.lstrip('#')[i:i+2], 16) for i in (0, 2, 4)))

    def update(self):

        if self.func==None:
            a = self.text
        else:
            a = self.func()
        self.label.setText(a)
        self.label.adjustSize()
        if self.init.underline!=None:
            self.init.underline.label.resize(QSize(self.label.size().width(), self.init.underline.size[1]))

    def spawn(self):
        self.label=self.init.label

        if self.init.underline!=None:
            self.init.underline.spawn()

        if self.size!=None:
            self.label.resize(QSize(self.size[0], self.size[1]))

        if self.func != None:
            self.update()
            if self.interval != None:
                self.timer=QTimer(self.label)
                self.timer.timeout.connect(self.update)
                self.timer.start(self.interval)
        else:
            self.update()

        self.label.adjustSize()

    def kill(self):
        if self.label!=None:
            self.label.setText('')
            self.label.resize(0,0)
            self.label=None
            if self.init.underline != None:
                self.init.underline.kill()
            if self.interval!=None:
                self.timer.stop()

from lib.ini import base_class
from PyQt5.QtCore import QSize, QTimer

class TEXT():
    def __init__(self, 
            text='',
            size=None,
            func=None,
            interval=None,
            key_functions={},
            on=False,
            **kwargs,
        ):
        
        self.init = base_class(**kwargs)
        self.text=text
        self.size=size
        self.label=None
        self.interval=interval
        self.func=func
        self.key_functions=key_functions
        self.label=self.init.label
        self.on=on

    def h2r(self, h):
        return 'rgba' + str(tuple(int(h.lstrip('#')[i:i+2], 16) for i in (0, 2, 4)))

    def update(self):

        if self.func==None:
            a = self.text
        else:
            a = self.func()
        self.label.setText(a)
        self.label.adjustSize()
        if self.init.underline!=None:
            self.init.underline.label.resize(QSize(self.label.size().width(), self.init.underline.size[1]))

    def spawn(self):
        self.label=self.init.label

        if self.init.underline!=None:
            self.init.underline.spawn()

        if self.size!=None:
            self.label.resize(QSize(self.size[0], self.size[1]))

        if self.func != None:
            self.update()
            if self.interval != None:
                self.timer=QTimer(self.label)
                self.timer.timeout.connect(self.update)
                self.timer.start(self.interval)
        else:
            self.update()

        self.label.adjustSize()

    def kill(self):
        if self.label!=None:
            self.label.setText('')
            self.label.resize(0,0)
            self.label=None
            if self.init.underline != None:
                self.init.underline.kill()
            if self.interval!=None:
                self.timer.stop()