class StreamsView(urwid.Frame): def __init__(self, streams_btn_list: List[Any], view: Any) -> None: self.view = view self.log = urwid.SimpleFocusListWalker(streams_btn_list) self.streams_btn_list = streams_btn_list list_box = urwid.ListBox(self.log) self.search_box = StreamSearchBox(self) urwid.connect_signal(self.search_box, 'change', self.update_streams) super(StreamsView, self).__init__(list_box, header=urwid.LineBox(self.search_box, tlcorner=u'─', tline=u'─', lline=u'', trcorner=u'─', blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─')) self.search_lock = threading.Lock() @asynch def update_streams(self, search_box: Any, new_text: str) -> None: if not self.view.controller.editor_mode: return # wait for any previously started search to finish to avoid # displaying wrong stream list. self.search_lock.acquire() streams_display = self.streams_btn_list.copy() for stream in self.streams_btn_list: if not stream.caption.lower().startswith(new_text): streams_display.remove(stream) self.log.clear() self.log.extend(streams_display) self.view.controller.update_screen() self.search_lock.release() def mouse_event(self, size: Any, event: str, button: int, col: int, row: int, focus: Any) -> Any: if event == 'mouse press': if button == 4: self.keypress(size, 'up') return True elif button == 5: self.keypress(size, 'down') return True return super(StreamsView, self).mouse_event(size, event, button, col, row, focus) def keypress(self, size: Tuple[int, int], key: str) -> str: if is_command_key('SEARCH_STREAMS', key): self.set_focus('header') return key elif is_command_key('GO_BACK', key): self.search_box.set_edit_text("Search streams") self.log.clear() self.log.extend(self.streams_btn_list) self.set_focus('body') self.view.controller.update_screen() return key return super(StreamsView, self).keypress(size, key)
def __init__(self, streams_btn_list: List[Any], view: Any) -> None: self.view = view self.log = urwid.SimpleFocusListWalker(streams_btn_list) self.streams_btn_list = streams_btn_list list_box = urwid.ListBox(self.log) self.search_box = StreamSearchBox(self) urwid.connect_signal(self.search_box, 'change', self.update_streams) super(StreamsView, self).__init__(list_box, header=urwid.LineBox( self.search_box, tlcorner=u'─', tline=u'─', lline=u'', trcorner=u'─', blcorner=u'─', rline=u'', bline=u'─', brcorner=u'─' )) self.search_lock = threading.Lock()