示例#1
0
    def test_drag_overlapping(self):
        bottom = Frame(self.context)
        bottom.draggable = True
        bottom.bounds = Bounds(10, 10, 50, 50)
        bottom.set_color(StyleKeys.Background, RGBA(1, 0, 0, 1))

        top = Frame(self.context)
        top.draggable = True
        top.bounds = Bounds(20, 20, 50, 50)
        top.set_color(StyleKeys.Background, RGBA(0, 0, 1, 1))

        self.mouse.move_to(Point(30, 30))
        self.mouse.press(MouseButton.LEFT)
        self.mouse.move_to(Point(50, 50))
        self.mouse.release(MouseButton.LEFT)

        self.context.process()

        self.assertImage("drag_overlapping_top", self.context)

        self.mouse.move_to(Point(20, 20))
        self.mouse.press(MouseButton.LEFT)
        self.mouse.move_to(Point(40, 40))
        self.mouse.release(MouseButton.LEFT)

        self.context.process()

        self.assertImage("drag_overlapping_bottom", self.context)
示例#2
0
    def test_drag(self):
        window = Frame(self.context)
        window.draggable = True
        window.resizable = True
        window.bounds = Bounds(10, 10, 50, 50)

        self.mouse.move_to(Point(30, 30))
        self.mouse.press(MouseButton.RIGHT)

        self.mouse.move_to(Point(40, 40))
        self.mouse.release(MouseButton.RIGHT)

        self.context.process()

        self.assertImage("drag_with_right_button", self.context)

        window.bounds = Bounds(10, 10, 50, 50)

        self.mouse.move_to(Point(20, 20))
        self.mouse.press(MouseButton.LEFT)

        self.mouse.move_to(Point(30, 40))
        self.mouse.release(MouseButton.LEFT)

        self.context.process()

        self.assertImage("drag_with_left_button", self.context)

        window.bounds = Bounds(10, 10, 50, 50)

        self.mouse.move_to(Point(10, 10))

        self.mouse.press(MouseButton.LEFT)
        self.mouse.press(MouseButton.MIDDLE)

        self.mouse.move_to(Point(40, 30))

        self.mouse.release(MouseButton.MIDDLE)

        self.mouse.move_to(Point(20, 50))

        self.context.process()

        self.assertImage("drag_with_2_buttons", self.context)

        self.mouse.release(MouseButton.LEFT)

        window.bounds = Bounds(10, 10, 50, 50)
        window.draggable = False

        self.mouse.move_to(Point(30, 30))
        self.mouse.press(MouseButton.LEFT)
        self.mouse.move_to(Point(50, 30))
        self.mouse.release(MouseButton.LEFT)

        self.context.process()

        self.assertImage("drag_non_draggable", self.context)
示例#3
0
    def test_resize_with_min_size(self):
        window = Frame(self.context)
        window.draggable = True
        window.resizable = True

        window.minimum_size_override = Some(Dimension(30, 30))

        def resize(drag_from: Point, drag_to: Point, expected: Bounds) -> None:
            window.bounds = Bounds(20, 20, 60, 60)

            self.mouse.move_to(drag_from)
            self.mouse.press(MouseButton.LEFT)
            self.mouse.move_to(drag_to)
            self.mouse.release(MouseButton.LEFT)

            self.context.process()

            self.assertEqual(expected, window.bounds)

        resize(Point(40, 25), Point(40, 95), Bounds(20, 50, 60, 30))
        resize(Point(75, 25), Point(5, 95), Bounds(20, 50, 30, 30))
        resize(Point(75, 40), Point(5, 40), Bounds(20, 20, 30, 60))
        resize(Point(75, 75), Point(5, 5), Bounds(20, 20, 30, 30))
        resize(Point(40, 75), Point(40, 5), Bounds(20, 20, 60, 30))
        resize(Point(25, 75), Point(95, 5), Bounds(50, 20, 30, 30))
        resize(Point(25, 40), Point(95, 40), Bounds(50, 20, 30, 60))
        resize(Point(25, 25), Point(95, 95), Bounds(50, 50, 30, 30))
示例#4
0
    def test_resize_to_collapse(self):
        window = Frame(self.context)
        window.draggable = True
        window.resizable = True

        def resize(drag_from: Point, drag_to: Point, expected: Bounds) -> None:
            window.bounds = Bounds(20, 20, 60, 60)

            self.mouse.move_to(drag_from)
            self.mouse.press(MouseButton.LEFT)
            self.mouse.move_to(drag_to)
            self.mouse.release(MouseButton.LEFT)

            self.context.process()

            self.assertEqual(expected, window.bounds)

        resize(Point(40, 25), Point(40, 95), Bounds(20, 80, 60, 0))
        resize(Point(75, 25), Point(5, 95), Bounds(20, 80, 0, 0))
        resize(Point(75, 40), Point(5, 40), Bounds(20, 20, 0, 60))
        resize(Point(75, 75), Point(5, 5), Bounds(20, 20, 0, 0))
        resize(Point(40, 75), Point(40, 5), Bounds(20, 20, 60, 0))
        resize(Point(25, 75), Point(95, 5), Bounds(80, 20, 0, 0))
        resize(Point(25, 40), Point(95, 40), Bounds(80, 20, 0, 60))
        resize(Point(25, 25), Point(95, 95), Bounds(80, 80, 0, 0))
示例#5
0
    def start(self, args: dict):
        from alleycat.ui.blender import UI

        self.context = UI().create_context()

        window = Frame(self.context, BorderLayout())
        window.bounds = Bounds(160, 70, 280, 200)

        panel = Panel(self.context, HBoxLayout())
        panel.set_color(StyleKeys.Background, RGBA(0.3, 0.3, 0.3, 0.8))

        window.add(panel, padding=Insets(10, 10, 10, 10))

        icon = Canvas(self.context, self.context.toolkit.images["cat.png"])
        icon.minimum_size_override = Some(Dimension(64, 64))

        panel.add(icon)

        label = Label(self.context, text_size=18)
        label.set_color(StyleKeys.Text, RGBA(1, 1, 1, 1))

        panel.add(label)

        button1 = LabelButton(self.context, text_size=16, text="Button 1")
        button2 = LabelButton(self.context, text_size=16, text="Button 2")

        buttons = Panel(self.context,
                        HBoxLayout(spacing=10, direction=BoxDirection.Reverse))

        buttons.add(button2)
        buttons.add(button1)

        window.add(buttons, Border.Bottom, Insets(0, 10, 10, 10))

        def handle_button(button: str):
            if len(button) > 0:
                label.text = f"{button} is pressed"
                panel.set_color(StyleKeys.Background, RGBA(1, 0, 0, 1))
            else:
                label.text = ""
                panel.set_color(StyleKeys.Background, RGBA(0.1, 0.1, 0.1, 0.8))

        button1_active = button1.observe("active").pipe(
            ops.map(lambda v: "Button 1" if v else ""))
        button2_active = button2.observe("active").pipe(
            ops.map(lambda v: "Button 2" if v else ""))

        button_active = rx.combine_latest(button1_active, button2_active).pipe(
            ops.map(lambda v: v[0] + v[1]))

        button_active.subscribe(handle_button,
                                on_error=self.context.error_handler)

        window.draggable = True
        window.resizable = True
示例#6
0
    def test_resize(self):
        window = Frame(self.context)
        window.draggable = True
        window.resizable = True

        def resize(name: str, drag_from: Point, drag_to: Point) -> None:
            window.bounds = Bounds(20, 20, 60, 60)

            self.mouse.move_to(drag_from)
            self.mouse.press(MouseButton.LEFT)
            self.mouse.move_to(drag_to)
            self.mouse.release(MouseButton.LEFT)

            self.context.process()

            self.assertImage(name, self.context)

        resize("resize_North", Point(40, 25), Point(40, 10))
        resize("resize_Northeast", Point(75, 25), Point(90, 10))
        resize("resize_East", Point(75, 40), Point(90, 40))
        resize("resize_Southeast", Point(75, 75), Point(90, 90))
        resize("resize_South", Point(40, 75), Point(40, 90))
        resize("resize_Southwest", Point(25, 75), Point(10, 90))
        resize("resize_West", Point(25, 40), Point(10, 40))
        resize("resize_Northwest", Point(25, 25), Point(10, 10))

        resize("resize_North_shrink", Point(40, 25), Point(40, 40))
        resize("resize_Northeast_shrink", Point(75, 25), Point(60, 40))
        resize("resize_East_shrink", Point(75, 40), Point(60, 40))
        resize("resize_Southeast_shrink", Point(75, 75), Point(60, 60))
        resize("resize_South_shrink", Point(40, 75), Point(40, 50))
        resize("resize_Southwest_shrink", Point(25, 75), Point(40, 60))
        resize("resize_West_shrink", Point(25, 40), Point(40, 40))
        resize("resize_Northwest_shrink", Point(25, 25), Point(40, 40))

        window.resizable = False

        resize("resize_non_resizable", Point(40, 25), Point(40, 10))