def setUp(self):
        super(TestGridContainer, self).setUp()

        self.container = GridContainer(
            [[Viewer(width=50, height=50),
              Viewer(width=50, height=50)],
             [Viewer(width=50, height=50),
              Viewer(width=50, height=50)]])

        self.manager = Manager(self.container,
                               window=self.window,
                               batch=self.batch,
                               theme=self.theme)
Пример #2
0
    def setUp(self):
        super().setUp()

        self.container = GridContainer([[Viewer(width=50, height=50), Viewer(width=50, height=50)],
                                     [Viewer(width=50, height=50), Viewer(width=50, height=50)]])

        self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)
Пример #3
0
class TestGridContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    a grid container.
    """

    def setUp(self):
        super().setUp()

        self.container = GridContainer([[Viewer(width=50, height=50), Viewer(width=50, height=50)],
                                     [Viewer(width=50, height=50), Viewer(width=50, height=50)]])

        self.manager = Manager(self.container, window=self.window, batch=self.batch, theme=self.theme)

    def test_top_down_draw(self):
        """
        Tests that the container's size was set correctly
        and the positions of its content is correct.
        """
        # manager size is correct
        self.assertEqual(self.container.width, 100 + self.container.padding)
        self.assertEqual(self.container.height, 100 + self.container.padding)

        # widget is centered in the window
        self.assertEqual(self.container.x, self.window.width // 2 - self.container.width // 2)
        self.assertEqual(self.container.y, self.window.height // 2 - self.container.height // 2)

    def test_bottom_up_draw(self):
        """
        Tests that the manager's size is modified
        if we set a new size to the widget.
        """
        self.container.content[0][0].width = 60
        self.container.content[0][0].height = 60
        self.container.content[0][0].parent.reset_size()

        # container width was set
        self.assertEqual(self.container.width, 110 + self.container.padding)
        # container height was set
        self.assertEqual(self.container.height, 110 + self.container.padding)

        # container was re-centered in the window
        self.assertEqual(self.container.x, self.window.width // 2 - self.container.width // 2)
        self.assertEqual(self.container.y, self.window.height // 2 - self.container.height // 2)

    def test_add_row(self):
        """
        Tests that if we add a row with 3 columns,
        we have the correct sizes.
        """
        self.container.add_row([Viewer(width=50, height=50),
                                Viewer(width=50, height=50),
                                Viewer(width=50, height=50)])

        self.assertEqual(self.container.width, 150 + 2 * self.container.padding)
        self.assertEqual(self.container.height, 150 + 2 * self.container.padding)

    def test_add_column(self):
        """
        Tests that if we add a column with 3 rows,
        we have the correct sizes.
        """
        self.container.add_column([Viewer(width=50, height=50),
                                   Viewer(width=50, height=50),
                                   Viewer(width=50, height=50)])

        self.assertEqual(self.container.width, 150 + 2 * self.container.padding)
        self.assertEqual(self.container.height, 150 + 2 * self.container.padding)

    def test_substitute_element(self):
        self.container.set(1, 1, Viewer(width=100, height=50))

        self.assertEqual(self.container.width, 150 + self.container.padding)
        self.assertEqual(self.container.height, 100 + self.container.padding)

    def tearDown(self):
        self.manager.delete()
        super().tearDown()
Пример #4
0
    def __init__(self, *, window, **kwargs):
        self.vertex_list = None
        batch = pyglet.graphics.Batch()
        controller.window = window
        controller.manager = self

        with open('theme/theme.json') as f:
            theme = Theme(load(f), resources_path='./theme')

        super().__init__(VerticalContainer([
            Frame(
                Wrapper(
                    VerticalContainer([
                        SectionHeader("Map Tablet to MIDI outputs"),
                        HorizontalContainer([
                            Label("Controller tablet"),
                            binding_devices.bind(
                                Dropdown(controller.tablet_names), 'tablet'),
                        ]),
                        HorizontalContainer([
                            Label("Map pointer"),
                            bind_tablet_key.bind(
                                Dropdown(controller.tablet_cursor_names),
                                'cursor'),
                            Label("with"),
                            Label("active button"),
                            bind_tablet_key.bind(
                                Dropdown(controller.tablet_button_names),
                                'button'),
                            Label("as:")
                        ]),
                        GridContainer([
                            [
                                bind_tablet_x.bind(Button("X"), 'enabled'),
                                Label("to channel"),
                                bind_tablet_x.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_tablet_x.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_tablet_x.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_tablet_x.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_tablet_x.bind(TextInput(), 'range_from'),
                                Label("to"),
                                bind_tablet_x.bind(TextInput(), 'range_to'),
                                Label("threshold"),
                                bind_tablet_x.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'threshold'),
                            ],
                            [
                                bind_tablet_y.bind(Button("Y"), 'enabled'),
                                Label("to channel"),
                                bind_tablet_y.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_tablet_y.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_tablet_y.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_tablet_y.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_tablet_y.bind(TextInput(), 'range_from'),
                                Label("to"),
                                bind_tablet_y.bind(TextInput(), 'range_to'),
                                Label("threshold"),
                                bind_tablet_y.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'threshold'),
                            ],
                            [
                                bind_tablet_p.bind(Button("Pressure"),
                                                   'enabled'),
                                Label("to channel"),
                                bind_tablet_p.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_tablet_p.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_tablet_p.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_tablet_p.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_tablet_p.bind(TextInput(), 'range_from'),
                                Label("to"),
                                bind_tablet_p.bind(TextInput(), 'range_to'),
                                Label("threshold"),
                                bind_tablet_p.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=1.0,
                                                     steps=20), 'threshold'),
                            ],
                        ]),
                    ]))),
            Frame(
                Wrapper(
                    VerticalContainer([
                        SectionHeader("Map Mouse to MIDI outputs"),
                        HorizontalContainer([
                            Label("Map mouse with active button"),
                            bind_mouse_key.bind(
                                Dropdown(controller.mouse_button_names),
                                'button'),
                            Label("as:"),
                        ]),
                        GridContainer([
                            [
                                bind_mouse_x.bind(Button("X"), 'enabled'),
                                Label("to channel"),
                                bind_mouse_x.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_mouse_x.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_mouse_x.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_mouse_x.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_mouse_x.bind(TextInput(), 'range_from'),
                                Label("to"),
                                bind_mouse_x.bind(TextInput(), 'range_to'),
                                Label("threshold"),
                                bind_mouse_x.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'threshold'),
                            ],
                            [
                                bind_mouse_y.bind(Button("Y"), 'enabled'),
                                Label("to channel"),
                                bind_mouse_y.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_mouse_y.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_mouse_y.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_mouse_y.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_mouse_y.bind(TextInput(), 'range_from'),
                                Label("to"),
                                bind_mouse_y.bind(TextInput(), 'range_to'),
                                Label("threshold"),
                                bind_mouse_y.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'threshold'),
                            ],
                        ]),
                        HorizontalContainer([
                            Label("Map mouse wheel as:"),
                        ]),
                        GridContainer([
                            [
                                bind_mouse_wheel_x.bind(
                                    Button("X"), 'enabled'),
                                Label("to channel"),
                                bind_mouse_wheel_x.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_mouse_wheel_x.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_mouse_wheel_x.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_mouse_wheel_x.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_mouse_wheel_x.bind(
                                    TextInput(), 'range_from'),
                                Label("to"),
                                bind_mouse_wheel_x.bind(
                                    TextInput(), 'range_to'),
                                Label("step"),
                                bind_mouse_wheel_x.bind(TextInput(), 'step'),
                                Label("value"),
                                bind_mouse_wheel_x.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'value'),
                                bind_mouse_wheel_x.bind(
                                    Checkbox('pull back'), 'pull_back'),
                            ],
                            [
                                bind_mouse_wheel_y.bind(
                                    Button("Y"), 'enabled'),
                                Label("to channel"),
                                bind_mouse_wheel_y.bind(
                                    Dropdown(controller.midi_channels),
                                    'channel'),
                                Label("as"),
                                HorizontalContainer([
                                    bind_mouse_wheel_y.bind(
                                        Dropdown(
                                            controller.midi_message_types),
                                        'message_type'),
                                    bind_mouse_wheel_y.widget(
                                        HorizontalContainer([
                                            Label("for"),
                                            bind_mouse_wheel_y.bind(
                                                Dropdown(controller.
                                                         midi_control_types),
                                                'control_type'),
                                        ],
                                                            hidden=True),
                                        'control_group'),
                                ]),
                                Label("ranging from"),
                                bind_mouse_wheel_y.bind(
                                    TextInput(), 'range_from'),
                                Label("to"),
                                bind_mouse_wheel_y.bind(
                                    TextInput(), 'range_to'),
                                Label("step"),
                                bind_mouse_wheel_y.bind(TextInput(), 'step'),
                                Label("value"),
                                bind_mouse_wheel_y.bind(
                                    HorizontalSlider(min_value=0.0,
                                                     max_value=100.0,
                                                     steps=20), 'value'),
                                bind_mouse_wheel_y.bind(
                                    Checkbox('pull back'), 'pull_back'),
                            ],
                        ]),
                    ]))),
            HorizontalContainer([
                binding_buttons.bind(Button(label="Tablet Input On"),
                                     'tablet_on'),
                binding_buttons.bind(Button(label="Mouse Input On"),
                                     'mouse_on'),
                Button(label="Fullscreen",
                       on_press=controller.toggle_fullscreen),
                OneTimeButton('All Notes Off',
                              on_release=controller.midi_all_notes_off),
                OneTimeButton('Hide', on_release=controller.toggle_gui)
            ]),
            Frame(
                Wrapper(
                    VerticalContainer([
                        SectionHeader("Output Device"),
                        GridContainer([
                            [
                                Label("Output MIDI port"),
                                binding_devices.bind(
                                    Dropdown(controller.midi_ports),
                                    'output_midi_port_name'),
                            ],
                        ]),
                        HorizontalContainer([
                            binding_buttons.bind(
                                Button(label="MIDI Output On"),
                                'midi_output_on'),
                            binding_buttons.bind(Button(label="Log Output"),
                                                 'log_output_on'),
                            binding_buttons.bind(Button(label="Log Input"),
                                                 'log_input_on'),
                        ]),
                    ]))),
            Frame(
                Wrapper(
                    VerticalContainer([
                        SectionHeader("Status"),
                        Label("Input:", bold=True),
                        binding_labels.bind(Label("---"), 'touch_status'),
                        binding_labels.bind(Label("---"), 'mouse_status'),
                        Label("Output:", bold=True),
                        binding_labels.bind(Label("---"), 'output_status'),
                    ]))),
        ]),
                         theme=theme,
                         window=window,
                         batch=batch,
                         **kwargs)

        controller.start_listen_bindings()
        controller.update_widgets()

        @window.event
        def on_resize(width, height):
            controller.clear_scale_cache()
            controller.note_labels.clear()
            controller.calculate_grid()

        # if __debug__:
        #     fps_display = pyglet.clock.ClockDisplay()

        @window.event
        def on_draw():
            window.clear()

            if self.vertex_list:
                self.vertex_list.draw(pyglet.gl.GL_QUADS)

            if controller.gui_visible:
                batch.draw()

            for label in controller.note_labels:
                label.draw()

            # if __debug__:
            #     fps_display.draw()

        @window.event
        def on_text(text):
            controller.on_keyboard_input(text)
Пример #5
0
                    "padding": [18, 18, 8, 6]
                },
                "text_color": [0, 0, 0, 255]
            },
            "up": {
                "image": {
                    "source": "button.png",
                    "frame": [6, 5, 6, 3],
                    "padding": [18, 18, 8, 6]
                }
            }
        }
    },
    resources_path='../theme/')

hlay = HorizontalContainer(content=[
    VerticalContainer(
        content=[Button("(1,1)"), Button("(1,2)")]),
    VerticalContainer(
        content=[Button("(2,1)"), Button("(2,2)")])
])

grid = GridContainer([[Button("(1,1)"), Button("(1,2)")],
                      [Button("(2,1)"), Button("(2,2)")]])

vlay = VerticalContainer([hlay, grid])

Manager(vlay, window=window, batch=batch, theme=theme)

pyglet.app.run()
class TestGridContainer(TestPygletGUI):
    """
    This test case tests basic functionality of
    a grid container.
    """
    def setUp(self):
        super(TestGridContainer, self).setUp()

        self.container = GridContainer(
            [[Viewer(width=50, height=50),
              Viewer(width=50, height=50)],
             [Viewer(width=50, height=50),
              Viewer(width=50, height=50)]])

        self.manager = Manager(self.container,
                               window=self.window,
                               batch=self.batch,
                               theme=self.theme)

    def test_top_down_draw(self):
        """
        Tests that the container's size was set correctly
        and the positions of its content is correct.
        """
        # manager size is correct
        self.assertEqual(self.container.width, 100 + self.container.padding)
        self.assertEqual(self.container.height, 100 + self.container.padding)

        # widget is centered in the window
        self.assertEqual(self.container.x,
                         self.window.width // 2 - self.container.width // 2)
        self.assertEqual(self.container.y,
                         self.window.height // 2 - self.container.height // 2)

    def test_bottom_up_draw(self):
        """
        Tests that the manager's size is modified
        if we set a new size to the widget.
        """
        self.container.content[0][0].width = 60
        self.container.content[0][0].height = 60
        self.container.content[0][0].parent.reset_size()

        # container width was set
        self.assertEqual(self.container.width, 110 + self.container.padding)
        # container height was set
        self.assertEqual(self.container.height, 110 + self.container.padding)

        # container was re-centered in the window
        self.assertEqual(self.container.x,
                         self.window.width // 2 - self.container.width // 2)
        self.assertEqual(self.container.y,
                         self.window.height // 2 - self.container.height // 2)

    def test_add_row(self):
        """
        Tests that if we add a row with 3 columns,
        we have the correct sizes.
        """
        self.container.add_row([
            Viewer(width=50, height=50),
            Viewer(width=50, height=50),
            Viewer(width=50, height=50)
        ])

        self.assertEqual(self.container.width,
                         150 + 2 * self.container.padding)
        self.assertEqual(self.container.height,
                         150 + 2 * self.container.padding)

    def test_add_column(self):
        """
        Tests that if we add a column with 3 rows,
        we have the correct sizes.
        """
        self.container.add_column([
            Viewer(width=50, height=50),
            Viewer(width=50, height=50),
            Viewer(width=50, height=50)
        ])

        self.assertEqual(self.container.width,
                         150 + 2 * self.container.padding)
        self.assertEqual(self.container.height,
                         150 + 2 * self.container.padding)

    def test_substitute_element(self):
        self.container.set(1, 1, Viewer(width=100, height=50))

        self.assertEqual(self.container.width, 150 + self.container.padding)
        self.assertEqual(self.container.height, 100 + self.container.padding)

    def tearDown(self):
        self.manager.delete()
        super(TestGridContainer, self).tearDown()