def update(self, frame_no: int) -> Any: if len(self.cache.pools) != self.pool_count: raise ResizeScreenError("resizing because of a differing pool count") if len(self.cache.jobs) != self.job_count: raise ResizeScreenError("resizing because of a differing job count") self.render_base("status", [[now(), "| " + self.cache.endpoint]]) self.render_base("pools", self.cache.render_pools()) self.render_base("jobs", self.cache.render_jobs()) self.render_base("tasks", self.cache.render_tasks()) self.render_base("messages", self.cache.messages) super(TopView, self).update(frame_no)
def demo(screen): dashboard = Dashboard(screen) confirm = Confirm(screen) action_choice = Action_choice(screen) show_paste = Show_paste(screen) scenes = [ Scene([dashboard], -1, name="dashboard"), Scene([action_choice], -1, name="action_choice"), Scene([confirm], -1, name="confirm"), Scene([show_paste], -1, name="show_paste"), ] screen.set_scenes(scenes) time_cooldown = time.time() # Cooldown before refresh global TABLES while True: #Stop on resize if screen.has_resized(): screen._scenes[screen._scene_index].exit() raise ResizeScreenError("Screen resized", screen._scenes[screen._scene_index]) if time.time() - time_cooldown > args.refresh: cleanRedis() for key, val in iter(fetchQueueData().items()): #fetch data and put it into the tables TABLES[key] = val TABLES["logs"] = format_string(printarrayLog, TABLES_PADDING["logs"]) #refresh dashboad only if the scene is active (no value selected) if current_selected_value == 0: dashboard._update(None) screen.refresh() time_cooldown = time.time() screen.draw_next_frame() time.sleep(0.02) #time between screen refresh (For UI navigation, not data actualisation)
def demo(s): s.clear() # Update the screen instance for drawing tools dtools.set_screen(s) # The window needs to re-calculate all the row and column dimensions main_window.set_screen(s) main_window.configure_row(0, height=3) main_window.configure_row(3, height=3) main_window.configure_column(1, weight=2) # Render the window onto the screen main_window.render(s) while True: if s.has_resized(): raise ResizeScreenError("yes") event = s.get_event() if event: main_window.parse_event(s, event) s.refresh() # This will ping all the windows regions if needed, used for constantly refreshing regions main_window.ping(s) sleep(1. / 60)
def test_resize(self): """ Check that we can create a ResizeScreenError """ scene = Scene([MockEffect()]) message = "Test message" error = ResizeScreenError(message, scene) self.assertEqual(error.scene, scene) self.assertEqual(str(error), message)
def render(self, screen): self._screen = screen # Since we are using a horizontal graph (bars go vertical)... # --> term_width is the number of buckets # --> term_height is the max amplitude for a bucket frequencies, channel_data = next(self._rgen) if len(frequencies) < 2: return if self._screen.has_resized(): raise ResizeScreenError(message="Resized Screen") term_width = self._screen.width term_height = self._screen.height channel_sums = np.array(list(map(np.sum, zip(*channel_data)))) channel_sums_binned = common.to_bins(channel_sums, term_width) for x, bheight in enumerate(channel_sums_binned): if self._vtype == "graph": # print bars/lines if not self._old_data is None: old_height = self._old_data[x] old_fallof = int(old_height - 1) # falloff each iteration should always be at least 1 new_height = max(old_fallof, bheight) # account for fallof before comparison if old_height < new_height: # draw from old height to new height self._screen.move(x, term_height - term_height*old_height) self._screen.draw(x, term_height - term_height*new_height, char=self._char) else: # erase from old height to new height self._screen.move(x, term_height - term_height*old_height) self._screen.draw(x, term_height - term_height*new_height, char=" ") elif bheight > 0.001: # Draw a whole line self._screen.move(x, 0) self._screen.draw(x, term_height - term_height*bheight, char=" ") self._screen.move(x, term_height - term_height*bheight) self._screen.draw(x, term_height, char=self._char) else: self._screen.move(x, 0) self._screen.draw(x, term_height, char=" ") else: # scope, print discrete points if not self._old_data is None: old_height = self._old_data[x] self._screen.print_at(" ", x, term_height - int(term_height*old_height)) self._screen.print_at(self._char, x, term_height - int(term_height*bheight)) self._old_data = channel_sums_binned self._screen.refresh()
def no_while_play(self, stop_on_resize=False, unhandled_input=None, start_scene=None, repeat=True, allow_int=False): try: self.draw_next_frame(repeat=repeat) if self.has_resized(): if stop_on_resize: self._scenes[self._scene_index].exit() raise ResizeScreenError("Screen resized", self._scenes[self._scene_index]) except StopApplication: # Time to stop - just exit the function. return
def play( self, stop_on_resize=False, unhandled_input=None, start_scene=None, repeat=True, allow_int=False, ): self.reset = [Slide(self, _reset(self.screen), 7, 0)] self.slides = [ Slide(self, self.get_effects(slide), slide.fg_color, slide.bg_color) for slide in self.slides ] # Initialise the Screen for animation. self.screen.set_scenes(self.slides, unhandled_input=unhandled_input, start_scene=start_scene) self.screen.clear_buffer(self.slides[0].fg_color, 0, self.slides[0].bg_color) # Mainline loop for animations try: while True: if self.current_slide == len(self.slides): self.screen.set_scenes(self.reset) while True: a = time.time() self.screen.draw_next_frame(repeat=repeat) b = time.time() if b - a < 0.05: # Just in case time has jumped (e.g. time change), ensure we only delay for 0.05s pause = min(0.05, a + 0.05 - b) if allow_int: self.screen.wait_for_input(pause) else: time.sleep(pause) event = self.screen.get_event() if isinstance(event, KeyboardEvent): if event.key_code == ord("r"): self.current_slide = 0 self.screen.set_scenes( [self.slides[self.current_slide]]) self.screen.clear_buffer( self.slides[self.current_slide].fg_color, 0, self.slides[self.current_slide].bg_color, ) break else: raise StopApplication("Stop slideshow") a = time.time() self.screen.draw_next_frame(repeat=repeat) if self.screen.has_resized(): if stop_on_resize: self.screen._scenes[self.screen._scene_index].exit() raise ResizeScreenError( "Screen resized", self.screen._scenes[self.screen._scene_index], ) b = time.time() if b - a < 0.05: # Just in case time has jumped (e.g. time change), ensure we only delay for 0.05s pause = min(0.05, a + 0.05 - b) if allow_int: self.screen.wait_for_input(pause) else: time.sleep(pause) except StopApplication: # Time to stop - just exit the function. self.screen.clear() return