Ejemplo n.º 1
0
    def __init__(self, label="", *, style=None, onClick=None, enabled=True):
        parent = ParentStack.top()
        print("parent of button is", parent)
        super().__init__(parent, label)

        default_style = Style({})
        if style is not None:
            default_style.update(style)
        self.style = default_style

        fill = True

        # self.set_min_height(30)
        self.set_min_width(80)

        parent.layout.add(self, fill=fill)

        if onClick is not None:
            self.activated.connect(onClick)

        if isObservable(enabled):
            self.addEventListener(
                "destroy", Disposer(enabled.subscribe(self.onEnableNext))
            )
        else:
            self.set_enabled(enabled)
class FlexContainer(fsui.Panel):
    def __init__(self, parent=None, *, style=None):
        self.style = Style({"flexDirection": "row"})
        if style is not None:
            self.style.update(style)
        if parent is None:
            parent = ParentStack.top()
        super().__init__(parent)
        self.layout = FlexLayout(self)

        # flex_direction = self.style.get("flexDirection")
        # if flex_direction == "row":
        #     self.layout.direction = 0
        # elif flex_direction == "column":
        #     self.layout.direction = 1
        # else:
        #     raise Exception(f"Unsupported flexDirection {flex_direction}")

        # self.set_background_color(fsui.Color(0xff, 0x99, 0x99))
        backgroundColor = self.style.get("backgroundColor")
        if backgroundColor:
            self.set_background_color(fsui.Color.from_hex(backgroundColor))
        # if isinstance(parent, fsui.Window):
        parent.layout.add(self, fill=True, expand=True)
        # else:
        #     parent.layout.add(self)

    def __enter__(self):
        ParentStack.stack.append(self)

    def __exit__(self, exception_type, exception_value, exception_traceback):
        assert ParentStack.stack.pop() == self
Ejemplo n.º 3
0
    def __init__(self, label="", *, parent=None, style=None):
        parent = parent or ParentStack.top()
        super().__init__(parent)
        if isObservable(label):
            self.addEventListener("destroy",
                                  Disposer(label.subscribe(self.set_text)))
        else:
            self.set_text(label)

        # print("parent of button is", parent)

        # if hasattr(label, "subscribe"):
        #     # label.subscribe(MethodObserver(self.onLabelObservableChanged))
        #     label.subscribe(self.onLabelObservableChanged)
        # if hasattr(label, "current"):
        #     label_value = label.current
        # else:
        #     label_value = label

        # self.label = label
        # self.__super_called = False
        # if hasattr(label, "subscribe"):
        #     self.label_value =""
        #     print("\n\nSUBSCRIBING TO", label)
        #     disposable = label.subscribe(self.onLabelObservableChanged)
        #     # self.destroyed.connect(lambda: disposable.dispose())
        # else:
        #     self.label_value = label
        #     disposable = None

        # self.__super_called = True

        # if disposable is not None:
        #     def dispose():
        #         print("dispose")
        #         disposable.dispose()
        #     # self.destroyed.connect(lambda: disposable.dispose())
        #     self.destroyed.connect(dispose)

        # if isObservable(label):
        #     disposable = label.subscribe(self.set_text)
        #     self.addEventListener("destroy", lambda: disposable.dispose())

        default_style = Style({})
        if style is not None:
            default_style.update(style)
        self.style = default_style

        fontWeight = self.style.get("fontWeight")
        if fontWeight:
            font = self.get_font()
            font.set_weight(fontWeight)
            self.set_font(font)

        fill = True
        parent.layout.add(self, fill=fill)
Ejemplo n.º 4
0
    def __init__(self, size=20, *, style=None):
        parent = ParentStack.top()
        super().__init__(parent)

        default_style = Style({})
        if style is not None:
            default_style.update(style)
        self.style = default_style

        parent.layout.add(self)
Ejemplo n.º 5
0
    def __init__(self, parent: Widget = None, *, style=None):
        parent = parent or ParentStack.top()
        super().__init__(parent)
        self.style = Style({}, style)

        backgroundColor = self.style.get("backgroundColor")
        if backgroundColor:
            self.set_background_color(fsui.Color.from_hex(backgroundColor))

        parent.layout.add(self)
Ejemplo n.º 6
0
    def __init__(self, text="", *, type="text", style=None):
        parent = ParentStack.top()
        passwordMode = type == "password"
        super().__init__(parent, text, passwordMode=passwordMode)

        default_style = Style({})
        if style is not None:
            default_style.update(style)
        self.style = default_style

        parent.layout.add(self)
Ejemplo n.º 7
0
    def __init__(self, parent=None, *args, style=None, **kwargs):
        super().__init__(parent=parent, *args, **kwargs)

        self.style = Style({"flexDirection": "column"}, style)

        backgroundColor = self.style.get("backgroundColor")
        if backgroundColor is not None:
            self.set_background_color(Color.from_hex(backgroundColor))

        flex_layout = FlexLayout(self)
        for child in self.layout.children:
            flex_layout.add(child.element)
        self.layout = flex_layout
Ejemplo n.º 8
0
    def __init__(self,
                 parent: Widget = None,
                 text="",
                 *,
                 readOnly: bool = False,
                 style=None):
        parent = parent or ParentStack.top()
        super().__init__(parent, text, read_only=readOnly)
        self.style = Style({}, style)

        parent.layout.add(self)
Ejemplo n.º 9
0
    def __init__(self, text="", *, parent: Widget = None, style=None):
        parent = parent or ParentStack.top()
        super().__init__(parent, text)
        self.style = Style({}, style)

        parent.layout.add(self)