def update_widgets(self, update_dir=True, update_file=True, update_select=True): """ Update self.dir_widget, self.file_widget or self.select_widget, corresponding to which of the paramters are set to True. """ if update_dir or update_file: (dirlist, filelist) = self._dirfiles(self.directory) if update_dir: # Directory widget: widget_list = [ AttrWrap(SelText(dir), None, self.attr[1]) for dir in dirlist ] self.dir_widget.box_widget.body = SimpleListWalker(widget_list) if update_file: # File widget: widget_list = [ AttrWrap(SelText(dir), None, self.attr[1]) for dir in filelist ] self.file_widget.box_widget.body = SimpleListWalker(widget_list) if update_select: # Selection widget: selected_file = join(self.directory, self.file) self.select_widget.set_edit_text(selected_file)
def __init__(self, choice_callback=None, command_callback=None, help_callback=None): self.palette = [ ('brick', 'light red', 'black'), ('rubble', 'yellow', 'black'), ('wood', 'light green', 'black'), ('concrete', 'white', 'black'), ('stone', 'light cyan', 'black'), ('marble', 'light magenta', 'black'), ('jack', 'dark gray', 'white'), ('msg_info', 'white', 'black'), ('msg_err', 'light red', 'black'), ('msg_debug', 'light green', 'black'), ] self.choice_callback = choice_callback self.command_callback = command_callback self.help_callback = help_callback self.screen = None self.loop = None self.called_loop_stop = False self.reactor_stop_fired = False self.quit_flag = False self.edit_msg = "Make selection ('q' to quit): " self.roll_list = SimpleListWalker([]) self.game_log_list = SimpleListWalker([]) self.choices_list = SimpleListWalker([]) self.state_text = SimpleListWalker([Text('Connecting...')]) self.edit_widget = Edit(self.edit_msg) self.roll = ListBox(self.roll_list) self.game_log = ListBox(self.game_log_list) self.choices = ListBox(self.choices_list) self.state = ListBox(self.state_text) self.left_frame = Pile([ LineBox(self.state), (13, LineBox(self.choices)), ]) self.right_frame = Pile([LineBox(self.game_log), LineBox(self.roll)]) self.state.set_focus(len(self.state_text) - 1) self.columns = Columns([('weight', 0.75, self.left_frame), ('weight', 0.25, self.right_frame)]) self.frame_widget = Frame(footer=self.edit_widget, body=self.columns, focus_part='footer') self.exc_info = None
def _build_widget(self, **kwargs): total_items = [] for _item in self.radio_items.keys(): desc = AttrWrap( Text(" {}".format( self.radio_items[_item][1])), 'input', 'input focus') total_items.append( AttrWrap(self.radio_items[_item][0], 'input', 'input focus')) total_items.append(AttrWrap(desc, 'input')) total_items.append(Divider('-')) self.input_lbox = ListBox(SimpleListWalker(total_items[:-1])) self.add_buttons() self.container_box_adapter = BoxAdapter(self.input_lbox, len(total_items)) self.container_lbox = ListBox( [self.container_box_adapter, Divider(), self.btn_pile]) return LineBox( BoxAdapter(self.container_lbox, height=len(total_items) + 3), title=self.title)
def __init__(self, num_rows=20, w=(14, 14, 18, 16, 16, 16, 20)): """ @method __init__ Initializes the widget """ self.m_process_list = ProcessList(w) self.prev_sort_item = None self.w_status = HeaderButton('Status', 'status', self.handle_click) self.w_pid = HeaderButton('PID', 'pid', self.handle_click) self.w_name = HeaderButton('Name', 'name', self.handle_click) self.w_cpu = HeaderButton('CPU %', 'cpu_perc', self.handle_click) self.w_mem = HeaderButton('MEM %', 'mem_perc', self.handle_click) self.w_up = HeaderButton('Uptime', 'uptime', self.handle_click) self.w_pname = HeaderButton('Process', 'pname', self.handle_click) self.w_cpu.activate() self.prev_sort_item = self.w_cpu self.header_buttons = h = [ self.w_status, self.w_pid, self.w_name, self.w_cpu, self.w_mem, self.w_up, self.w_pname ] m_header = AttrMap( Columns([('fixed', w[i], h[i]) for i in range(0, len(h))]), 'invert') m_lb = ListBox( SimpleListWalker( [m_header, BoxAdapter(self.m_process_list, num_rows)])) super(ProcessTable, self).__init__(m_lb, None) self.update()
def create_interface(self): self.screen = Screen() self.screen.start() self.screen.register_palette([ ("title", "white", "dark blue", "standout"), ("line", "light gray", "black"), ("help", "white", "dark blue")] ) self.body = ListBox(SimpleListWalker([])) self.lines = self.body.body self.title = Text(MAIN_TITLE) self.header = AttrWrap(self.title, "title") self.help = AttrWrap( Text(HELP_STRINGS["main"]), "help" ) self.input = Edit(caption="%s> " % self.ircchannel) self.footer = Pile([self.help, self.input]) self.top = Frame(self.body, self.header, self.footer)
def __init__(self, contents, offset=1): """ Arguments: `contents` is a list with the elements contained in the `ScrollableListBox`. `offset` is the number of position that `scroll_up` and `scroll_down` shift the cursor. """ self.offset = offset ListBox.__init__(self, SimpleListWalker(contents))
def render_component(self, props): def make_todo(id, completed, text): def on_click(): props['on_todo_click'](id) return Todo( on_click=on_click, completed=completed, text=text, ) return ListBox( SimpleListWalker([make_todo(**todo) for todo in props['todos']]))
def __init__(self, name): self.name = name self._connected = False self._parent = None self.status = {} self.children = [] self.input_history = None self.output_walker = SimpleListWalker([]) self.input_text = "" self.auto_scroll = True self.read_line_index = -1
def _insert_charm_selections(self): first_index = 0 bgroup = [] for i, charm_class in enumerate(self.charms): charm = charm_class if charm.name() and not first_index: first_index = i r = RadioButton(bgroup, charm.name()) r.text_label = charm.name() self.boxes.append(r) # Add input widget for specifying NumUnits self.count_editor = IntEdit("Number of units to add: ", 1) self.boxes.append(self.count_editor) wrapped_boxes = self._wrap_focus(self.boxes) items = ListBox(SimpleListWalker(wrapped_boxes)) items.set_focus(first_index) return (len(self.boxes), BoxAdapter(items, len(self.boxes)))
def _build_widget(self, **kwargs): total_items = [] for _item in self.input_items.keys(): total_items.append( AttrWrap(self.input_items[_item], 'input', 'input focus')) self.input_lbox = ListBox(SimpleListWalker(total_items)) # Add buttons self.add_buttons() self.container_box_adapter = BoxAdapter(self.input_lbox, len(total_items)) self.container_lbox = ListBox( [self.container_box_adapter, Divider(), self.btn_pile]) return LineBox(BoxAdapter(self.container_lbox, height=len(total_items) + 1 + len(self.btn_pile.contents)), title=self.title)
def __init__(self, phones): self.phone_edit = EnterEdit('Phone:', '') self.chan_edit = EnterEdit('Chanl:', '') self.call_id_edit = EnterEdit('SipID:', '') self.text_edit = EnterEdit('Find:', '') connect_signal(self.phone_edit, 'enter', self.on_change, 'phone') connect_signal(self.chan_edit, 'enter', self.on_change, 'chan') connect_signal(self.call_id_edit, 'enter', self.on_change, 'call_id') connect_signal(self.text_edit, 'enter', self.on_change, 'text') self.phones_text = Text([('key', 'F4'), ' Phones']) self.head = Pile([ AttrWrap(Text([('key', 'F3'), ' Search']), 'bar'), AttrWrap(self.phone_edit, 'no', 'selection'), AttrWrap(self.chan_edit, 'no', 'selection'), AttrWrap(self.call_id_edit, 'no', 'selection'), Divider('-'), AttrWrap(self.text_edit, 'no', 'selection'), AttrWrap(self.phones_text, 'bar'), ]) self.items = SimpleListWalker([]) self.set_results(phones) self.listbox = ListBox(self.items) self.frame = Frame(self.listbox, header=self.head)
""" return datetime.fromtimestamp(self.pget_uptime()).strftime(f) """ Testing """ if __name__ == '__main__': def exit(p): if p is 'q': raise ExitMainLoop() def refresh(loop, data): p1.update() p2.update() loop.set_alarm_in(1, refresh) p1 = Process(1, lambda x: x, lambda: x) p2 = Process(os.getpid(), lambda x: x, lambda: x) lb = ListBox(SimpleListWalker([p1, p2])) m = MainLoop(lb, palette=[('reversed', 'standout', ''), ('popbg', 'white', 'dark blue')], pop_ups=True, unhandled_input=exit) m.set_alarm_in(1, refresh) m.run()
def __init__(self, content): self.walker = SimpleListWalker(content) super(SimpleListBox, self).__init__(self.walker)
def __init__(self, contents): self.list_walker = SimpleListWalker(contents) ListBox.__init__(self, self.list_walker)
def __init__(self, tags): tag_widgets = self._create_tag_widgets(tags) self.list_content = SimpleListWalker(tag_widgets) ListBox.__init__(self, self.list_content)
def parse_tag_from_node(node): from .tags import parse_tag_from_node body = [parse_tag_from_node(PyQuery(child)) for child in node.children()] walker = SimpleListWalker(body) return ListBox(walker)
def _build_widget(self): lw = SimpleListWalker([x for x in self.contents]) return ListBox(lw)