async def consume_io__process_screenshot_a(self, source_agent_path, cmd): files = sorted(config.SCREENSHOT_DIR.glob("*.png")) file = files[-1] if file == self.last_screenshot: print(ansi.info("No new screenshot to process.")) return self.last_screenshot = file print(ansi.info("Setting up screenshot processing.")) # save_str = json_stringify(self.chart.data) # if save_str != self.last_save: # self.save() self.process_screenshot(file)
async def handle__slideshow__next__a(self, envelope, chart_idx, overlay_idx): if self.lock.locked(): return await self.lock.acquire( ) # This lock prevents the program from exploding if the user continuously holds n. try: self.check_chart_idx(chart_idx) self.check_overlay_idx(overlay_idx) del chart_idx # Avoid bugs where we update self.chart_idx then use chart_idx. del overlay_idx overlays = self.get_overlays(self.chart_idx) if (self.overlay_idx + 1 < len(overlays)): self.overlay_idx += 1 print( f""" {ansi.info("Loading next overlay")} {overlays[self.overlay_idx]}""" ) await self.send_message_outward_a( "slideshow.overlay.switch", *arguments(chart_idx=self.chart_idx, overlay_idx=self.overlay_idx, change_direction=1)) else: if self.chart_idx + 1 == len(self.chart_source_files): # We are out of slides. print(ansi.info("At end, out of slides...")) return self.chart_idx += 1 self.overlay_idx = 0 await self.update_chart_a(1) finally: # Wait a bit before releasing lock to advance at an orderly pace when user holds n. asyncio.ensure_future(self.release_lock())
async def handle__slideshow__previous__a(self, envelope, chart_idx, overlay_idx): if self.lock.locked(): return await self.lock.acquire() try: self.check_chart_idx(chart_idx) self.check_overlay_idx(overlay_idx) del chart_idx # Avoid bugs where we update self.chart_idx then use chart_idx. del overlay_idx change_direction = -1 overlays = self.get_overlays(self.chart_idx) if (self.overlay_idx > 0): self.overlay_idx -= 1 print( f""" {ansi.info("Loading previous overlay")} {overlays[self.overlay_idx]}""" ) await self.send_message_outward_a( "slideshow.overlay.switch", *arguments(chart_idx=self.chart_idx, overlay_idx=self.overlay_idx, change_direction=-1)) else: # TODO: handle beginning of presentation if self.chart_idx == 0: # already at beginning print(ansi.info("At beginning")) return self.chart_idx -= 1 self.overlay_idx = len(self.get_overlays(self.chart_idx)) - 1 await self.update_chart_a(-1) finally: asyncio.ensure_future(self.release_lock())
def process_screenshot(self, file): i = sum( 1 for i in config.OVERLAY_DIR.glob(f"{self.last_save_file.stem}*")) outfile = config.OVERLAY_DIR / f"{self.last_save_file.stem}__overlay{i}.svg" self.last_overlay_outfile = outfile p = Process(target=process_overlay, args=(file, outfile)) p.start() print(ansi.info(f" Output file: {outfile}"))
async def update_chart_a(self, change_direction=None): print(ansi.info(f"Loading source file {self.chart_idx}")) print(f" == {self.chart_source_files[self.chart_idx]}") self.load_chart() overlays = self.get_overlays(self.chart_idx) # print(f" Loading overlay {overlays[self.overlay_idx]}") await self.send_message_outward_a( "slideshow.chart.switch", *arguments( state=self.chart.data, chart_idx=self.chart_idx, overlay_idx=self.overlay_idx, change_direction=change_direction, ))