textual icon indicating copy to clipboard operation
textual copied to clipboard

Add the ability of changing class attributes at the moment of widget Instanciation.

Open wiseaidev opened this issue 3 years ago • 0 comments

edit: I wasn't aware of how that Reactive descriptor works. Now, I am familiar with how it works.

I think it is worth allowing programmers to have control over the value of class attributes at the moment of widget Instanciation. Take the following as an example:

class AwesomeWidget(Widget):

    content: Reactive[str] = Reactive(default="")
    name: Reactive[str] = Reactive(default="")

I need to have the ability to provide values at the Instanciation phase:

awesome_widget = AwesomeWidget(name='awesome widget', content='awesone content')

Probably it can be accomplished by doing something similar to attrs:

class AwesomeWidget(Widget):

    content: Reactive[str] = Reactive(default="", init=True)
    name: Reactive[str] = Reactive(default="", init=True)

edit: i knew that it can be done with __init__, but i don't want to add boilerplate to the code base:

class AwesomeWidget(Widget):

    content: Reactive[str] = Reactive(default="", init=True)
    name: Reactive[str] = Reactive(default="", init=True)

    def __init__(self, name: str, content: str):
        super().__init__(name)
        self.content = content
        self.name = name

wiseaidev avatar Mar 29 '22 18:03 wiseaidev