def __init__(self):
     super().__init__()
     ParentStack.push(self)
     Button(label="A")
     Button(label="C")
     # Allow next item(s) to be inserted between A and C
     self.layout.insert_index = 1
     assert ParentStack.pop() == self
    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)
Beispiel #3
0
 def __init__(
     self,
     optionName: str,
     title: str = None,
     description: str = None,
     style=None,
 ):
     defaultStyle = {"padding": 10}
     if style is not None:
         defaultStyle.update(style)
     super().__init__(style=defaultStyle)
     parent = ParentStack.top()
     optionsOnPanel = None
     while parent and optionsOnPanel is None:
         parent = parent.getParent()
         optionsOnPanel = getattr(parent, "optionsOnPanel", None)
     if optionsOnPanel is not None:
         optionsOnPanel.add(optionName)
     with self:
         self.layout.add(OptionUI.create_group(
             self,
             optionName,
             title,
         ), )
         if description is not None:
             Text(description, style={"marginTop": 10})
Beispiel #4
0
    def __init__(self, parent=None, *, options=None):
        autoParent = False
        if parent is None:
            parent = ParentStack.top()
            autoParent = True

        super().__init__(parent, gettext("Reset to defaults"))
        self.activated.connect(self.__on_reset_to_defaults)
        settings = get_settings(self)

        self.remove_listener = settings.add_listener(self)
        # FIXME: Implement
        # self.destroy.connect(settings.add_listener(self))
        if autoParent:
            parent.layout.add(self)

        # Add automatically discovered settings
        optionsOnPanel = None
        while parent and optionsOnPanel is None:
            parent = parent.getParent()
            optionsOnPanel = getattr(parent, "optionsOnPanel", None)
        options = options or []
        if optionsOnPanel is not None:
            options.extend(optionsOnPanel)
            # for optionName in optionsOnPanel:
            #     self.options[optionName] = settings.get(optionName)

        self.options = {option: settings.get(option) for option in options}
        self.update_enabled_state()
    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)
    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)
Beispiel #7
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)
Beispiel #8
0
 def __init__(self, visible=True):
     parent = ParentStack.top()
     super().__init__(parent)
     parent.layout.add(self)
     self.set_background_color(Color.from_hex("#ff0000"))
     # FIXME
     self.set_min_height(30)
     self.set_min_width(30)
     if not visible:
         self.set_visible(False)
    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)
Beispiel #10
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)
    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)
    def __init__(self, parent=None):
        ParentStack.push(self)

        super().__init__(title=gettext("Flexbox test window"),
                         style={"display": "flex"})

        # OpenRetroPrefsPanel()
        # with VerticalFlexContainer():
        #     OpenRetroPrefsPanel()

        # with VerticalFlexContainer(self):

        with FlexContainer(
                style={
                    "backgroundColor": "#ffcccc",
                    "flexDirection": "column",
                    "padding": 10,
                    "width": 640,
                    # "height": 480,
                }):
            Button(label="A", style={"alignSelf": "flex-start"})
            Button(label="B", style={"alignSelf": "center"})
            Button(label="C", style={"alignSelf": "flex-end"})

        # with FlexContainer(style={
        #     "backgroundColor": "#ffcccc",
        #     "paddingLeft": 10,
        #     "paddingRight": 10,
        # }):
        #     Button(label="A")
        #     Button(label="B")

        # with FlexContainer(style={
        #     "backgroundColor": "#ffcccc",
        #     "paddingLeft": 10,
        #     "paddingRight": 10,
        # }):
        #     Button(label="A")
        #     Button(label="B")
        #     Button(label="C")

        # with FlexContainer(style={
        #     "paddingLeft": 10,
        # }):
        #     Button(label="A")
        #     Button(label="B")
        #     Button(label="C")
        #     Button(label="D")

        with VerticalFlexContainer(style={
                "backgroundColor": "#ccffcc",
                "padding": 10,
        }):
            Button(
                label="D is a button with a really long label",
                style={"marginBottom": 10},
            )
            Button(
                label="E",
                style={
                    "marginBottom": 10,
                    "marginLeft": 20,
                    "marginRight": 10,
                },
            )
            Button(label="F")
            # Button(label="C", style={"flexGrow": 1})

        with FlexContainer(style={
                "backgroundColor": "#ccccff",
                "flexGrow": 1,
                "padding": 10,
        }):
            Button(label="G", style={"flexGrow": 1})
            Button(
                label="H is much longer than both G and I",
                style={"flexGrow": 1},
            )
            Button(label="I")

        with FlexContainer(style={
                "backgroundColor": "#ffcccc",
                "padding": 10,
        }):
            Button(
                label=
                "J has a really long label, let's see what happens if we try to cut it off",
                style={
                    "flexGrow": 1,
                    "maxWidth": 200
                },
            )
            Button(label="K (longer)", style={"flexGrow": 1})
            Button(label="L", style={"flexGrow": 1})

        with FlexContainer(style={
                "backgroundColor": "#ccffcc",
                "padding": 10,
        }):
            Button(label="M", style={"height": 100})
            Button(label="N")
            Button(label="O", style={"maxHeight": 50})
            with VerticalFlexContainer(style={
                    "backgroundColor": "#ccffcc",
                    "padding": 10,
            }):
                Button(
                    label="D is a button with a really long label",
                    style={"marginBottom": 10},
                )
                Button(
                    label="E",
                    style={
                        "marginBottom": 10,
                        "marginLeft": 20,
                        "marginRight": 10,
                    },
                )
                Button(label="F")
            Button(
                label="Big",
                style={
                    "flexGrow": 1,
                    "margin": -10,
                    "marginLeft": 0
                },
            )

        with FlexContainer(style={
                "backgroundColor": "#ccccff",
                "padding": 10,
        }):
            Button(label="P", style={"margin": 10})
            Button(label="Q", style={"margin": 20})
            Button(label="R", style={"margin": 30})
            Button(label="P", style={"height": 30, "margin": 10})
            Button(label="Q", style={"height": 30, "margin": 20})
            Button(label="R", style={"height": 30, "margin": 30})

        # with FlexContainer(style={
        #     "backgroundColor": "#ccccff",
        #     "padding": 10,
        # }):

        with FlexContainer(style={
                "backgroundColor": "#ffcccc",
        }):
            Button(label="S",
                   style={
                       "flexGrow": 1,
                       "height": 30,
                       "margin": 10
                   })
            Button(label="T",
                   style={
                       "flexGrow": 1,
                       "height": 30,
                       "margin": 20
                   })
            Button(label="U",
                   style={
                       "flexGrow": 1,
                       "height": 30,
                       "margin": 30
                   })

        with FlexContainer(
                style={
                    "alignItems": "center",
                    "backgroundColor": "#ccffcc",
                    "height": 100,
                    "padding": 10,
                }):
            Button(label="v",
                   style={
                       "flexGrow": 1,
                       "height": 30,
                       "margin": 10
                   })
            Button(
                label="W",
                style={
                    "flexGrow": 1,
                    "height": 30,
                    "margin": 10,
                    "marginBottom": 60,
                },
            )
            Button(
                label="X",
                style={
                    "flexGrow": 1,
                    "height": 30,
                    "margin": 10,
                    "marginRight": 150,
                    "marginBottom": 110,
                },
            )
            pass

        # with VerticalFlexContainer(style={
        #     "backgroundColor": "#00ff00",
        #     "paddingLeft": 10,
        #     "paddingRight": 10,
        # }):
        #     Button(label="D")
        #     Button(label="E", style={
        #         "alignSelf": "flex-start"
        #     })
        #     Button(label="E", style={
        #         "alignSelf": "center"
        #     })
        #     Button(label="F", style={
        #         "alignSelf": "flex-end"
        #     })

        with InsertWidgetTest():
            Button(label="B")

        assert ParentStack.pop() == self

        WindowResizeHandle(self)
    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)