Пример #1
0
 def wire_events(self):
     self.imp.add_listener(events.QuitEvent().create([self.on_quit]))
     self.imp.add_listener(events.VideoResizeEvent().create(
         [self.on_resize]))
     self.imp.add_listener(events.KeyDownEvent().create([self.on_quit]))
     self.imp.add_listener(
         events.UserEvent(events.UserEvents.UNIT_TEST).create(
             [self.on_unit_test]))
     events.UserEvent(events.UserEvents.UNIT_TEST).post()
Пример #2
0
 def wire_events(self):
     imp.IMP().add_delegate(events.QuitEvent().listen(self.on_quit))
     imp.IMP().add_delegate(events.WindowResizedEvent().listen(
         self.on_resize))
     imp.IMP().add_delegate(
         events.KeyDownEvent(pygame.K_ESCAPE).listen(self.on_pause))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.GAME_OVER).listen(self.on_game_over))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.UNDO_STACK_CLEARED).listen(
             self.on_redo_undo_changed))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.REDO_STACK_CLEARED).listen(
             self.on_redo_undo_changed))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.UNDO_ENABLED).listen(
             self.on_redo_undo_changed))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.REDO_ENABLED).listen(
             self.on_redo_undo_changed))
     imp.IMP().add_delegate(
         events.UserEvent(CustomEvent.UPDATE_SCORE).listen(
             self.on_update_score))
Пример #3
0
	def wire_events(self):
		imp.IMP().add_listener(events.KeyDownEvent(pygame.K_r).listen(self.on_refresh))
Пример #4
0
	def wire_events(self):
		imp.IMP().add_listener(events.KeyDownEvent(pygame.K_r).listen(self.on_refresh))
		imp.IMP().add_listener(events.KeyDownEvent(pygame.K_EQUALS).listen(self.on_plus_scale))
		imp.IMP().add_listener(events.KeyDownEvent(pygame.K_MINUS).listen(self.on_minus_scale))
Пример #5
0
    def update(self):
        for control in self.controls:
            control.update()

    def draw(self, surface):
        border_color = self.get_style('default_border').color
        self.window_border.draw(surface, border_color)
        self.window.draw(surface, self.get_style('window_back').color)
        self.header.draw(surface, self.get_style('header').color)
        self.lbl_text.draw(surface, self.get_style('default_text').color)
        self.line.draw(surface, border_color)
        for control in self.controls:
            control.draw(surface)


if __name__ == '__main__':
    import unit_test, pygame
    test = unit_test.UnitTest()
    width, height = unit_test.WINDOW_SIZE
    slider = controls.Slider()
    btn_ok = controls.Button('OK', on_click=lambda event: print('Pressed Ok.'))
    window = Window('Test Window', (width // 2 - 100, height // 2 - 100),
                    (200, 100))
    slider.set_position((10, 15))
    btn_ok.set_position((200 - btn_ok.w - 5, 80 - btn_ok.h - 5))
    window.set_controls([slider, btn_ok])
    imp.IMP().add_listener(
        events.KeyDownEvent(pygame.K_s).create(
            lambda event: window.set_enabled(not window.is_enabled)))
    test.register([window])
    test.run()
Пример #6
0
	def wire_events(self):
		imp.IMP().add_listener(events.KeyDownEvent(pygame.K_r).create(self.on_reset))
Пример #7
0
    def set_bottom(event):
        sidebar.set_window_side(WindowSide.BOTTOM)

    btn_bottom.on_click = set_bottom

    def reset(event):
        if stop_watch.is_running:
            btn_start.set_text('START')
        stop_watch.reset()

    btn_reset.on_click = reset

    def start_stop(event):
        if stop_watch.is_running:
            btn_start.set_text('START')
            stop_watch.stop()
        else:
            btn_start.set_text('STOP')
            stop_watch.start()

    btn_start.on_click = start_stop

    imp.IMP().add_listener(
        events.UserEvent(CustomEvent.SLIDER_TICK).create(
            lambda event: slider_value.set_counter(event.value)))
    imp.IMP().add_listener(
        events.KeyDownEvent(pygame.K_s).create(
            lambda event: sidebar.set_enabled(not sidebar.is_enabled)))

    unit_test.register([sidebar])
    unit_test.run()