def on_keypress(self, evt): if evt.key == "ESC": remove_child(self.parent, self) if self.file_menu and has_child(self.container, self.file_menu): self.file_menu.close() evt.stop_propagation() elif evt.key in [ "LEFT_ARROW", "RIGHT_ARROW", "UP_ARROW", "DOWN_ARROW", "\r" ]: # route these events to the menu fire_event(self.file_menu, evt) else: query = self.text_field.get_text() self.file_menu.remove_items() if len(query) > 0: matches = [] for file in self.files: filename = self.get_filename(file) if fuzzy_contain(filename, query): result = fuzzy_match_5(filename, query) matches.append((file, result)) else: matches = [] if len(matches) > 0: for code_file, result in sorted(matches, key=lambda m: m[1][0], reverse=True): filename = self.get_filename(code_file) match_positions = result[1] filename_display = sstring("") last_idx = -1 for pos in match_positions: filename_display += sstring(filename[last_idx + 1:pos]) filename_display += sstring(filename[pos], [BRIGHT_MAGENTA, BOLD]) last_idx = pos filename_display += sstring(filename[last_idx + 1:]) self.file_menu.add_item( MenuItem(filename_display, self.on_file_selected, key=code_file["id"])) x, y = self.region.offset width, height = self.size cwidth, cheight = self.container.size self.file_menu.layout( BoxConstraints(min_width=width, max_width=width, max_height=cheight)) if not has_child(self.container, self.file_menu): add_child(self.container, self.file_menu, abs_pos=(x, y + height - 1), abs_size=self.file_menu.size) else: if has_child(self.container, self.file_menu): remove_child(self.container, self.file_menu)
def close_window(self, window): remove_child(self.board, window) remove_listener(window, "window_move_start", self.on_window_move_start) remove_listener(window, "window_focus", self.on_window_focus) remove_listener(window, "maximize", self.on_window_maximize) remove_listener(window, "close", self.on_window_close) remove_listener(window, "window_resize_start", self.on_window_resize_start) fire_event(self, Event("close_window", window=window))
def on_keypress(self, evt): if evt.key == "ESC": remove_child(self.parent, self) evt.stop_propagation() elif evt.key == "\r": text = self.text_field.get_text() step_num = None try: step_num = int(text) except: return fire_event(self, Event("select", value=step_num))
def close(self): remove_child(self.parent, self)
def close(self): if self.parent is None: return remove_child(self.parent, self) fire_event(self, Event("close", element=self))