class MainCarousel(Carousel): pongLoopTick = None # Pong animation loop game = None # Pong game overview = None # Overview panel def __init__(self): # Create carousel - doesn't work so well in .kv Carousel.__init__(self, direction='right', loop='true', scroll_distance=80, scroll_timeout=100) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game) def on_index(self, *args): slideIndex = args[1] print("slide #{}".format(args[1])) if 2 == slideIndex: self.pongLoopTick = Clock.schedule_interval( self.game.update, 1.0 / 60.0) elif None != self.pongLoopTick: Clock.unschedule(self.pongLoopTick) self.pongLookTick = None super(MainCarousel, self).on_index(self, args)
def build(self): game = PongGame() game.serve_ball() print("now playing") #target = partial(game.update,model = model(get_weights_from_encoded(final_best_individual)))).start() self.event = Clock.schedule_interval( partial(game.update, model=model(get_weights_from_encoded(trained_individual))), SPEED) return game
class MainCarousel(Carousel): pongLoopTick = None # Pong animation loop game = None # Pong game overview = None # Overview panel is_idle = False def __init__(self, **kwargs): # Create carousel - doesn't work so well in .kv Carousel.__init__(self, direction='right', loop='true', scroll_distance=80, scroll_timeout=100, **kwargs) self.config = MyConfig() self.backlight = BacklightFactory.Make(self.config) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game) self.idle_clock = Clock.schedule_once( self.on_idle, float(self.config.switch_off_time)) Window.bind(on_motion=self.on_motion) # Setup screen saver def on_motion(self, *args): # Switch back light back on print("On Motion") self.idle_clock.cancel() if (self.is_idle): self.is_idle = False self.backlight.switch_on() self.idle_clock = Clock.schedule_once( self.on_idle, float(self.config.switch_off_time)) def on_idle(self, dt): # Switch off back light power print("On Idle") self.backlight.switch_off() self.is_idle = True def on_index(self, *args): slideIndex = args[1] print("slide #{}".format(args[1])) if 2 == slideIndex: self.pongLoopTick = Clock.schedule_interval( self.game.update, 1.0 / 60.0) elif None != self.pongLoopTick: Clock.unschedule(self.pongLoopTick) self.pongLookTick = None super(MainCarousel, self).on_index(self, args)
class MainCarousel(Carousel): pongLoopTick = None # Pong animation loop game = None # Pong game overview = None # Overview panel is_idle = False def __init__(self, **kwargs): # Create carousel - doesn't work so well in .kv Carousel.__init__(self,direction='right',loop='true',scroll_distance=80,scroll_timeout=100,**kwargs) self.config = MyConfig() self.backlight = BacklightFactory.Make(self.config) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game) self.idle_clock = Clock.schedule_once(self.on_idle, float(self.config.switch_off_time)) Window.bind(on_motion=self.on_motion) # Setup screen saver def on_motion(self, *args): # Switch back light back on print("On Motion") self.idle_clock.cancel() if (self.is_idle): self.is_idle = False self.backlight.switch_on() self.idle_clock = Clock.schedule_once(self.on_idle, float(self.config.switch_off_time)) def on_idle(self, dt): # Switch off back light power print("On Idle") self.backlight.switch_off() self.is_idle = True def on_index(self, *args): slideIndex = args[1] print ("slide #{}".format(args[1])) if 2 == slideIndex: self.pongLoopTick = Clock.schedule_interval(self.game.update, 1.0/60.0) elif None != self.pongLoopTick: Clock.unschedule(self.pongLoopTick) self.pongLookTick = None super(MainCarousel, self).on_index(self, args)
class MainCarousel(Carousel): pongLoopTick = None # Pong animation loop game = None # Pong game overview = None # Overview panel def __init__(self): # Create carousel - doesn't work so well in .kv Carousel.__init__(self,direction='right',loop='true',scroll_distance=80,scroll_timeout=100) self.overview = Overview() self.add_widget(self.overview) self.add_widget(Label(text='Hello World2')) self.game = PongGame() self.game.serve_ball() self.add_widget(self.game) def on_index(self, *args): slideIndex = args[1] print ("slide #{}".format(args[1])) if 2 == slideIndex: self.pongLoopTick = Clock.schedule_interval(self.game.update, 1.0/60.0) elif None != self.pongLoopTick: Clock.unschedule(self.pongLoopTick) self.pongLookTick = None super(MainCarousel, self).on_index(self, args)
def build(self): game = PongGame() game.serve_ball() threading.Thread(target=partial(main_function, "", game)).start() return game