class TestSlider(TestPygletGUI): def setUp(self): TestPygletGUI.setUp(self) self.slider = HorizontalSlider(min_value=0, max_value=10) self.manager = Manager(self.slider, window=self.window, batch=self.batch, theme=self.theme) def test_set_value(self): self.slider.set_knob_pos(0.5) self.assertEqual(self.slider.value, 5) def test_mouse_slide(self): # push the slider to the minimum self.slider.on_mouse_press(0, 0, None, None) self.assertEqual(self.slider.value, 0) # push the slider to the maximum self.slider.on_mouse_press(10000, 0, None, None) self.assertEqual(self.slider.value, 10) def tearDown(self): self.manager.delete() super(TestSlider, self).tearDown()
"source": "slider-knob.png" }, "offset": [-5, -11] }, "padding": [8, 8, 8, 8], "step": { "image": { "source": "slider-step.png" }, "offset": [-2, -8] }, "bar": { "image": { "source": "slider-bar.png", "frame": [8, 8, 8, 0], "padding": [8, 8, 8, 8] } } } }, resources_path='../theme/') # Set up a Manager Manager(VerticalContainer([HorizontalSlider(), HorizontalSlider(steps=10)]), window=window, batch=batch, theme=theme) pyglet.app.run()
global GROWTH GROWTH = 24 - (float(x - bar_x) / bar_width) print(GROWTH, (float(x - bar_x) / bar_width)) return True def f(value): print(value) global GROWTH if value <= 2: H.zoom_mode = False else: H.zoom_mode = True GROWTH = 100 - value L = Letters(text=letters) HS = HorizontalSlider(value=12, min_value=1.0, max_value=99.9, width=150, on_set=f) Manager(VerticalContainer([HS, L]), window=window, batch=batch, theme=theme) Manager.set_position(L, x=SCREENSIZE-300, y=SCREENSIZE-50) Manager.set_position(HS, x=SCREENSIZE-300, y=SCREENSIZE-100) # @clock def drawArray(someArray): vertPoints = someArray[:, :2].flatten().astype(ctypes.c_float) gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertPoints.ctypes.data) gl.glDrawArrays(gl.GL_POINTS, 0, len(vertPoints) // 2) @window.event def on_draw(): gl.glPointSize(H.pointsize) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) drawArray(H.field)
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.slider = HorizontalSlider(min_value=0, max_value=10) self.manager = Manager(self.slider, window=self.window, batch=self.batch, theme=self.theme)
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)