Пример #1
0
    def test_on_style_change(self):
        lookup = StyleLookup()

        changes = []

        lookup.on_style_change.subscribe(changes.append)

        self.assertEqual([], changes)

        lookup.set_color("color1", RGBA(1, 0, 0, 1))
        lookup.set_color("color1",
                         RGBA(1, 0, 0,
                              1))  # Should ignore duplicated requests.

        self.assertEqual(
            [ColorChangeEvent(lookup, "color1", Some(RGBA(1, 0, 0, 1)))],
            changes)

        lookup.set_color("color2", RGBA(0, 1, 0, 1))

        self.assertEqual(
            [ColorChangeEvent(lookup, "color2", Some(RGBA(0, 1, 0, 1)))],
            changes[1:])

        lookup.set_color("color2", RGBA(0, 1, 1, 1))

        self.assertEqual(
            [ColorChangeEvent(lookup, "color2", Some(RGBA(0, 1, 1, 1)))],
            changes[2:])

        font = ToyFontFace("Sans")

        lookup.set_font("font1", font)

        self.assertEqual([FontChangeEvent(lookup, "font1", Some(font))],
                         changes[3:])

        lookup.clear_color("color1")
        lookup.clear_font("font1")

        self.assertEqual([ColorChangeEvent(lookup, "color1", Nothing)],
                         changes[4:5])
        self.assertEqual([FontChangeEvent(lookup, "font1", Nothing)],
                         changes[5:])

        padding = Insets(5, 5, 5, 5)

        lookup.set_insets("padding", padding)

        self.assertEqual([InsetsChangeEvent(lookup, "padding", Some(padding))],
                         changes[6:])

        lookup.clear_insets("padding")

        self.assertEqual([InsetsChangeEvent(lookup, "padding", Nothing)],
                         changes[7:])
Пример #2
0
        def test_style(lookup: StyleLookup):
            button.validate()

            lookup.set_font("NonExistentKey", fonts["Font1"])
            lookup.set_insets("NonExistentKey", Insets(10, 10, 10, 10))

            self.assertEqual(True, button.valid)

            lookup.set_font(StyleKeys.Text, fonts["Font1"])

            self.assertEqual(False, button.valid)

            button.validate()
            lookup.set_insets(StyleKeys.Padding, Insets(10, 10, 10, 10))

            self.assertEqual(False, button.valid)
Пример #3
0
    def test_lookup_font(self):
        lookup = StyleLookup()

        sans = ToyFontFace("Sans")
        serif = ToyFontFace("Serif")

        label_key = "label"
        button_key = "button"

        lookup.set_font(label_key, sans)
        lookup.set_font(button_key, serif)

        self.assertEqual(Nothing, lookup.get_font("dialog"))
        self.assertEqual(sans, lookup.get_font(label_key).unwrap())
        self.assertEqual(serif, lookup.get_font(button_key).unwrap())

        lookup.clear_font(label_key)

        self.assertEqual(Nothing, lookup.get_font(label_key))