class TestCheckbox(TestPygletGUI, GenericButtonTest):
    def setUp(self):
        TestPygletGUI.setUp(self)
        self.button = Checkbox(label="test")
        GenericButtonTest.setUp(self)

    def test_get_path(self):
        self.assertEqual(self.button.get_path(), ['checkbox', 'unchecked'])
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.get_path(), ['checkbox', 'checked'])
class TestCheckbox(TestPygletGUI, GenericButtonTest):
    def setUp(self):
        TestPygletGUI.setUp(self)
        self.button = Checkbox(label="test")
        GenericButtonTest.setUp(self)

    def test_get_path(self):
        self.assertEqual(self.button.get_path(), ['checkbox', 'unchecked'])
        self.button.on_mouse_press(0, 0, None, None)
        self.assertEqual(self.button.get_path(), ['checkbox', 'checked'])
    def manager(self):

        self.managerList += [
            Manager(HorizontalContainer(
                [OneTimeButton(label="Continuar",
                               on_release=self.nextWindow)]),
                    window=self,
                    batch=self.batch,
                    theme=getTheme(),
                    anchor=ANCHOR_BOTTOM_RIGHT,
                    offset=(-80, 5),
                    is_movable=False)
        ]

        self.managerList += [
            Manager(VerticalContainer([
                Checkbox(label="El CPU Inicia        ",
                         on_press=self.setCPUStarts,
                         is_pressed=self.CPUStarts),
                Checkbox(label="El CPU es blancas",
                         on_press=self.setCPUPlayWhite,
                         is_pressed=self.CPUPlayWhite),
                Label(""),
                Label("Enroque de negras"),
                Checkbox(label="Lado de la Reina ",
                         on_press=self.setBlackQueenCastling,
                         is_pressed=self.blackQueenCastling),
                Checkbox(label="Lado del Rey       ",
                         on_press=self.setBlackKingCastling,
                         is_pressed=self.blackKingCastling),
                Label(""),
                Label("Enroque de blancas"),
                Checkbox(label="Lado de la Reina ",
                         on_press=self.setWhiteQueenCastling,
                         is_pressed=self.whiteQueenCastling),
                Checkbox(label="Lado del Rey       ",
                         on_press=self.setWhiteKingCastling,
                         is_pressed=self.whiteKingCastling)
            ]),
                    window=self,
                    batch=self.batch,
                    theme=getTheme(),
                    anchor=ANCHOR_RIGHT,
                    offset=(-50, -95),
                    is_movable=False)
        ]
 def __init__(self):
     g.keybindingsWindowOpened = True
     self.resW = g.SCREEN_WIDTH
     self.resH = g.SCREEN_HEIGHT
     self.fullscreen = g.FULLSCREEN
     self.vsync = g.VSYNC
     self.screenSelected = g.SCREENSELECTED
     screens = pyglet.window.get_platform().get_default_display(
     ).get_screens()
     screenopts = []
     for i in range(len(screens)):
         screenopts.append(str(i))
     if int(self.screenSelected) >= 0 and int(
             self.screenSelected) < len(screens):
         screenopts.insert(0, str(self.screenSelected))
     options = []
     modes = pyglet.window.get_platform().get_default_display(
     ).get_default_screen().get_modes()
     for i in modes:
         if i.width >= 1024 and i.height >= 720:
             opt = str(int(i.width)) + ':' + str(int(i.height))
             if opt not in options:
                 options.append(opt)
     options.insert(0, str(g.SCREEN_WIDTH) + ':' + str(g.SCREEN_HEIGHT))
     titleText = Label("Video Settings",
                       color=g.loginFontColor,
                       font_size=g.theme["font_size"] + 2)
     windowTypeInfo = Label("Window mode")
     if g.FULLSCREEN:
         windowType = Dropdown(['Fullscreen', 'Windowed'],
                               on_select=self.selection)
     else:
         windowType = Dropdown(['Windowed', 'Fullscreen'],
                               on_select=self.selection)
     horz = HorizontalContainer([windowTypeInfo, windowType])
     resolutionInfo = Label("Resolution")
     resolutionType = Dropdown(options, on_select=self.resSelect)
     horz1 = HorizontalContainer([resolutionInfo, resolutionType])
     vsyncBtn = Checkbox("VSync",
                         on_press=self.vsyncSelect,
                         is_pressed=self.vsync,
                         align=HALIGN_LEFT)
     resolutionInfo = Label("Monitor")
     resolutionType = Dropdown(screenopts, on_select=self.screenSelect)
     horz3 = HorizontalContainer([resolutionInfo, resolutionType])
     discardBtn = HighlightedButton(label="Discard",
                                    on_release=self.delete,
                                    width=120,
                                    height=30)
     saveBtn = HighlightedButton(label="Save",
                                 on_release=self.onSave,
                                 width=120,
                                 height=30)
     horzBtn = HorizontalContainer([discardBtn, saveBtn])
     Manager.__init__(self,
                      Frame(
                          VerticalContainer([
                              titleText, horz, horz1, vsyncBtn, horz3,
                              horzBtn
                          ])),
                      window=g.screen,
                      batch=g.guiBatch,
                      theme=g.theme,
                      is_movable=False)
 def setUp(self):
     TestPygletGUI.setUp(self)
     self.button = Checkbox(label="test")
     GenericButtonTest.setUp(self)
Exemple #6
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)
 def setUp(self):
     TestPygletGUI.setUp(self)
     self.button = Checkbox(label="test")
     GenericButtonTest.setUp(self)
Exemple #8
0
            "unchecked": {
                "image": {
                    "source": "checkbox.png"
                }
            }
        }
    },
    resources_path='../theme/')


def f(y):
    print("\nholaMundo\n" + str(y))


# Set up a Manager
Manager(VerticalContainer([
    Button(label="Persistent button", on_press=f),
    OneTimeButton(label="One time button"),
    Checkbox(label="Checkbox"),
    GroupButton(group_id='1', label="Group 1:Button 1"),
    GroupButton(group_id='1', label="Group 1:Button 2"),
    GroupButton(group_id='2', label="Group 2:Button 1"),
    GroupButton(group_id='2', label="Group 2:Button 2"),
    GroupButton(group_id='2', label="Group 2:Button 3"),
]),
        window=window,
        batch=batch,
        theme=theme)

pyglet.app.run()
Exemple #9
0
    def viewer(self):
        elems = {}

        # Title
        elems['title'] = Label('Customize Material')

        # Particle shape setting
        elems['shape'] = HoriCont([
            GroupButton(group_id='shape', label='Circle', is_pressed=True),
            GroupButton(group_id='shape', label='Square')
        ])

        # Size setting
        """ Temporarily removed to work on same-size optimization
        r_display = Label('3.0 m')
        r_slider = HoriSlide(on_set=lambda x: self.lbl_slider(x,
                                                              r_display,
                                                              after=' m'),
                             min_value=1,
                             max_value=10,
                             value=3)

        elems['radius'] = HoriCont([r_display, r_slider])
        """

        # Mass setting
        m_display = Label('1.00 kg')
        m_slider = HoriSlide(on_set=lambda x: self.lbl_slider(
            x, m_display, digits=4, after=' kg'),
                             min_value=1,
                             max_value=100,
                             value=1)
        elems['mass'] = HoriCont([m_display, m_slider])

        max_vel = 50
        # Velocity_x setting
        vx_lbl = Label('X velocity:')
        vx_display = Label('0.0 m/s')
        vx_slider = HoriSlide(on_set=lambda x: self.lbl_slider(
            x, vx_display, digits=3, after=' m/s'),
                              min_value=-1 * max_vel,
                              max_value=max_vel,
                              value=0)
        elems['x_velocity'] = VertCont(
            [vx_lbl, HoriCont([vx_display, vx_slider])])

        # Velocity_y setting
        vy_lbl = Label('Y velocity:')
        vy_display = Label('0.0 m/s')
        vy_slider = HoriSlide(on_set=lambda x: self.lbl_slider(
            x, vy_display, digits=3, after=' m/s'),
                              min_value=-1 * max_vel,
                              max_value=max_vel,
                              value=0)
        elems['y_velocity'] = VertCont(
            [vy_lbl, HoriCont([vy_display, vy_slider])])

        # Color setting
        red_in = TextInput(
            ' 255',
            length=4,
            max_length=4,
            on_input=lambda x: self.color_input(x, 'red', red_in))
        green_in = TextInput(
            ' 0',
            length=4,
            max_length=4,
            on_input=lambda x: self.color_input(x, 'green', green_in))
        blue_in = TextInput(
            ' 0',
            length=4,
            max_length=4,
            on_input=lambda x: self.color_input(x, 'blue', blue_in))
        elems['color'] = HoriCont([red_in, green_in, blue_in])

        # Gravity setting
        elems['gravity'] = Checkbox('Has gravity', is_pressed=False)

        self.elems = elems

        sidebar = Frame(VertCont(self.get_elem_list(), padding=20))

        return sidebar
 def __init__(self):
     g.gameSettingsWindowOpened = True
     self.mouseoverPaint = g.selectPaint
     self.hoverPaint = g.hoverPaint
     self.musicEnabled = g.MUSIC
     self.musicVolume = g.MUSICVOLUME
     self.soundEnabled = g.SOUND
     self.soundVolume = g.SOUNDVOLUME
     titleText = Label("Game Settings",
                       color=g.loginFontColor,
                       font_size=g.theme["font_size"] + 2)
     mouseoverBtn = Checkbox("Paint tile select",
                             on_press=self.mouseoverSelect,
                             is_pressed=self.mouseoverPaint,
                             align=HALIGN_LEFT,
                             width=24,
                             height=24)
     hoverBtn = Checkbox("Paint hover players",
                         on_press=self.hoverSelect,
                         is_pressed=self.hoverPaint,
                         align=HALIGN_LEFT)
     audioEnabled = Checkbox("Enable music",
                             on_press=self.musicSelect,
                             is_pressed=self.musicEnabled,
                             align=HALIGN_LEFT)
     musicVolume = Label("Music volume")
     musicSlider = HorizontalSlider(on_set=self.musicVolumeChange,
                                    value=self.musicVolume)
     self.musicVolumeNumber = Label('%.2f' % self.musicVolume)
     soundEnabled = Checkbox("Enable sounds",
                             on_press=self.soundSelect,
                             is_pressed=self.soundEnabled,
                             align=HALIGN_LEFT)
     soundVolume = Label("Sound volume")
     soundSlider = HorizontalSlider(on_set=self.soundVolumeChange,
                                    value=self.soundVolume)
     self.soundVolumeNumber = Label('%.2f' % self.soundVolume)
     horz2 = HorizontalContainer(
         [musicVolume, musicSlider, self.musicVolumeNumber], padding=0)
     horz3 = HorizontalContainer(
         [soundVolume, soundSlider, self.soundVolumeNumber], padding=0)
     discardBtn = HighlightedButton(label="Discard",
                                    on_release=self.delete,
                                    width=120,
                                    height=30)
     saveBtn = HighlightedButton(label="Save",
                                 on_release=self.onSave,
                                 width=120,
                                 height=30)
     horzBtn = HorizontalContainer([discardBtn, saveBtn])
     Manager.__init__(self,
                      Frame(
                          VerticalContainer([
                              titleText, mouseoverBtn, hoverBtn,
                              audioEnabled, horz2, soundEnabled, horz3,
                              horzBtn
                          ])),
                      window=g.screen,
                      batch=g.guiBatch,
                      theme=g.theme,
                      is_movable=False)