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)
예제 #2
0
 def on_click(self, evt):
     line_no = self.get_line_for_y(evt.y)
     snapshot = self.nav.fast_forward(self.code_file["id"], line_no,
                                      self.snapshot["id"])
     fire_event(self,
                Event("goto_snapshot",
                      snapshot_id=snapshot and snapshot["id"]),
                bubble=True)
예제 #3
0
 def on_rightmousedown(self, evt):
     line_no = self.get_line_for_y(evt.y)
     snapshot = self.nav.rewind(self.code_file["id"], line_no,
                                self.snapshot["id"])
     fire_event(self,
                Event("goto_snapshot",
                      snapshot_id=snapshot and snapshot["id"]),
                bubble=True)
예제 #4
0
 def on_click(self, evt):
     yoffset = self.region.offset[1] - self.region.origin[1]
     x, y = self.region.relative_pos(evt.x, evt.y)
     i = yoffset + y
     hit = self.snapshots[i]
     fire_event(self,
                Event("goto_snapshot", snapshot_id=hit["id"]),
                bubble=True)
 def add_window(self, window, **params):
     add_listener(window, "window_move_start", self.on_window_move_start)
     add_listener(window, "window_focus", self.on_window_focus)
     add_listener(window, "maximize", self.on_window_maximize)
     add_listener(window, "close", self.on_window_close)
     add_listener(window, "window_resize_start",
                  self.on_window_resize_start)
     add_child(self.board, window, **params)
     fire_event(self, Event("add_window", window=window))
 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))
예제 #8
0
 def on_keypress(self, evt):
     if evt.key == "UP_ARROW":
         # optimization: can use binary search
         for hit in reversed(self.snapshots):
             if hit["id"] < self.current_snapshot_id:
                 fire_event(self,
                            Event("goto_snapshot", snapshot_id=hit["id"]),
                            bubble=True)
                 break
     elif evt.key == "DOWN_ARROW":
         for hit in self.snapshots:
             if hit["id"] > self.current_snapshot_id:
                 fire_event(self,
                            Event("goto_snapshot", snapshot_id=hit["id"]),
                            bubble=True)
                 break
예제 #9
0
 def open(self):
     pos = self.region.offset
     x, y = pos
     cwidth, cheight = self.container.size
     self.menu.layout(BoxConstraints(
         max_width = cwidth - x,
         max_height = cheight - y
     ))
     size = self.menu.size
     self.menu.set_highlighted(0)
     add_child(self.container, self.menu, abs_pos=pos, abs_size=size)
     focus(self.menu)
     self.is_open = True
     self.label.set_styles([BG_BRIGHT_CYAN])
     fire_event(self, Event("open", menu_button=self, menu=self.menu))
     add_listener_once(get_root(), "click", lambda e: self.menu.close())
예제 #10
0
 def on_mousedown(self, evt):
     x, y = self.region.offset
     width, height = self.size
     if evt.x == x + width - 1 and evt.y == y + height - 1:
         fire_event(
             self.window,
             Event("window_resize_start",
                   window=self.window,
                   direction="both",
                   x=evt.x,
                   y=evt.y))
     elif evt.x == x + width - 1:
         fire_event(
             self.window,
             Event("window_resize_start",
                   window=self.window,
                   direction="x",
                   x=evt.x))
     elif evt.y == y + height - 1:
         fire_event(
             self.window,
             Event("window_resize_start",
                   window=self.window,
                   direction="y",
                   y=evt.y))
예제 #11
0
 def on_keypress(self, evt):
     # we need focus...
     if evt.key == "DOWN_ARROW":
         self.set_highlighted(self.highlighted + 1)
         if self.highlighted >= len(self.vbox.children):
             self.set_highlighted(0)
     elif evt.key == "UP_ARROW":
         self.set_highlighted(self.highlighted - 1)
         if self.highlighted < 0:
             self.set_highlighted(len(self.vbox.children) - 1)
         repaint(self)
     elif evt.key in ["RIGHT_ARROW", "\t"]:
         fire_event(self, Event("next", menu=self))
     elif evt.key in ["LEFT_ARROW", "REVERSE_TAB"]:
         fire_event(self, Event("previous", menu=self))
     elif evt.key in ["ESC"]:
         self.close()
     elif evt.key == "\r":
         item = self.vbox.children[self.highlighted]
         item.select()
     elif len(evt.key) == 1 and evt.key.isalpha():
         self.highlight_next_starting_with(evt.key)
예제 #12
0
 def close(self):
     if self.parent is None:
         return
     remove_child(self.parent, self)
     fire_event(self, Event("close", element=self))
예제 #13
0
 def on_menu_close(self, evt):
     self.is_open = False
     self.label.set_styles(None)
     repaint(self.label)
     fire_event(self, Event("close", menu_button=self, menu=self.menu))
예제 #14
0
 def select(self):
     event = Event("select", value=self)
     fire_event(self, event)
예제 #15
0
 def expand(self):
     if self.expanded:
         return
     self.expanded = True
     fire_event(self, Event("expand", tree=self), bubble=True)
예제 #16
0
 def hits_button_clicked(self, evt):
     line_no = self.code_lines_pane.current_line
     code_file = self.code_lines_pane.code_file
     fire_event(self,
                Event("hits_request", code_file=code_file, line_no=line_no))
예제 #17
0
 def collapse(self):
     if not self.expanded:
         return
     self.expanded = False
     fire_event(self, Event("collapse", tree=self), bubble=True)
예제 #18
0
 def on_title_label_mousedown(self, evt):
     fire_event(self,
                Event("window_move_start", window=self, x=evt.x, y=evt.y))
     fire_event(self, Event("window_focus", window=self))
예제 #19
0
 def on_click(self, evt):
     fire_event(self, Event("window_focus", window=self))
 def on_file_selected(self, evt):
     fire_event(self, Event("select", value=evt.value.key))
예제 #21
0
 def on_start_move(self, evt):
     fire_event(
         self.window,
         Event("window_move_start", window=self.window, x=evt.x, y=evt.y))
     fire_event(self.window, Event("window_focus", window=self.window))
예제 #22
0
 def on_max_button_click(self, evt):
     fire_event(self.window, Event("maximize", window=self.window))
예제 #23
0
 def on_close_button_click(self, evt):
     fire_event(self.window, Event("close", window=self.window))