def __init__(self, pl): classtree_root = RDF_ParentNode(pl, RDFS.Resource, None, **tree_views['class_hierarchy']) classtreewin = ur.TreeListBox(ur.TreeWalker(classtree_root)) classtreewin.offset_rows = 1 instancetree_root = RDF_ParentNode(pl, RDFS.Resource, None, **tree_views['class_hierarchy']) instancetreewin = ur.TreeListBox(ur.TreeWalker(instancetree_root)) instancetreewin.offset_rows = 1 pile = ur.Pile([classtreewin, instancetreewin]) ur.WidgetWrap.__init__(self, pile)
def refresh(self): self.txt_refresh.set_text('Refresh {0}s'.format( self.controller.connector_refresh_thread.get_refresh_time())) if self.controller.connector_refresh_thread.is_paused(): self.txt_mode.set_text('PAUSE') self.map_mode.set_attr_map({None: 'mode_pause'}) else: self.txt_mode.set_text('PLAY') self.map_mode.set_attr_map({None: 'mode_play'}) conn = self.controller.connector.consumme() if conn: self.txt_cluster_name.set_text(conn.cluster_name) self.txt_cluster_status.set_text(conn.cluster_status) self.map_cluster_status.set_attr_map( {None: 'cluster_' + conn.cluster_status}) self.txt_cluster_nodes.set_text("{0} nodes".format( conn.number_of_nodes)) if not conn.is_error(): content = urwid.TreeWalker(RootNode(self.controller)) body = urwid.TreeListBox(content) self.frm_main.contents['body'] = (urwid.AttrWrap(body, 'body'), None) else: self.txt_body.set_text("Error: {0}".format(conn.get_error())) self.frm_main.contents['body'] = (urwid.AttrWrap( self.fil_body, 'body'), None)
def change_directory(self, directory): if not os.path.isabs(directory): directory = os.path.join(self.top_dir, directory) directory = os.path.normpath(directory) if not os.path.isdir(directory): return if self.root and not directory.startswith(self.root): return self.top_dir = directory self.tree_root = DirectoryNode(self, self.top_dir) self.listbox = urwid.TreeListBox(PositionsTreeWalker(self.tree_root)) # select first item, if present try: self.listbox.set_focus( self.listbox.body.get_next(self.listbox.get_focus()[1])[1] or self.listbox.get_focus()[1]) except IndexError: pass # for i in range(1 if self.no_parent_dir else 2): # try: # self.listbox.set_focus( # self.listbox.body.get_next( # self.listbox.get_focus()[1] # )[1] or self.listbox.get_focus()[1] # ) # except IndexError: # break self.listbox.offset_rows = 1 urwid.connect_signal(self.listbox.body, "modified", self.on_modified) self.placeholder.original_widget = self.listbox
def open_file(self, button): if self.configured or not self.filename is None: self.close() footer_text = [ ('title', "Directory Browser"), " ", ('key', "UP"), ",", ('key', "DOWN"), ",", ('key', "PAGE UP"), ",", ('key', "PAGE DOWN"), " ", ('key', "SPACE"), " ", ('key', "+"), ",", ('key', "-"), " ", ('key', "LEFT"), " ", ('key', "HOME"), " ", ('key', "END"), " ", ('key', "Q"), ] cwd = os.getcwd() store_initial_cwd(cwd) header = urwid.Text("Open File") listbox = urwid.TreeListBox(urwid.TreeWalker(self.DirectoryNode(cwd))) listbox.offset_rows = 1 footer = urwid.AttrWrap(urwid.Text(footer_text), 'foot') view = self.DirectoryBrowser( self.open_file_callback, urwid.AttrWrap(listbox, 'body'), header=urwid.AttrWrap(header, 'head'), footer=footer) self.set_body(view)
def __init__(self, chat_widget, close_callback=None): self.chat_widget = chat_widget self.ui = chat_widget.ui self.close_callback = close_callback items = [] for server in sorted(chat_widget.discord.servers, key=lambda s: s.name): node = {"name": server.name, 'server_tree': self, 'server': server, "children": []} for ch in server.channels: if ch.type == discord.ChannelType.text: node['children'].append({ 'name': ch.name, 'server_tree': self, 'channel': ch }) nodeobj = TreeNodeServer(node) nodeobj.expanded = False items.append(nodeobj) self.w_listbox = urwid.TreeListBox(TreeWalker(items)) self.__super.__init__(self.w_listbox)
def __init__(self): self.start_node = self.listbox = self.walker = self.inst_tree = None self.active_channels = { 0, } self.mouse_bookmarks = set() self.reload() self.listbox = urwid.TreeListBox(self.walker) self.header = urwid.Text('FluidSynth Instruments') self.channels = urwid.Text('') self.help = urwid.Text('') self.footer = urwid.Columns([ urwid.Padding(self.help, 'left', width=('relative', 100)), urwid.Padding(self.channels, 'right', width=16, min_width=16), ]) la = urwid.AttrWrap(self.listbox, 'body') ha = urwid.AttrWrap(self.header, 'head') fa = urwid.AttrWrap(self.footer, 'foot') self.view = urwid.Frame(la, header=ha, footer=fa) self.metronome = None self.beats_per_minute = 80 self.update_footer()
def __init__(self, data=None): dirname = os.path.dirname(__file__) filename = os.path.join(dirname, '../other/ascii_logo.txt') with open(filename, 'r') as f: self.header = urwid.Text(u"".join(f.readlines()), align='center') self.trace_tree = urwid.TreeListBox( urwid.TreeWalker(TraceParentNode(data))) self.trace_tree.offset_rows = 1 self.res_box = urwid.LineBox( urwid.Padding(self.trace_tree, left=1, right=1)) self.members = urwid.Padding(urwid.AttrWrap( urwid.Text(self.footer_members), 'foot'), left=1, right=1) self.commands = urwid.Padding(urwid.AttrWrap( urwid.Text(self.footer_commands, align='right'), 'foot'), left=1, right=1) self.footer = urwid.Columns([self.members, self.commands]) # Assembler les widgets pour construire le layout self.layout = urwid.Frame(header=urwid.AttrWrap(self.header, 'head'), body=urwid.AttrWrap(self.res_box, 'body'), footer=self.footer)
def __init__(self, root=None, dir_sort=None, file_sort=None, ignore_files=False, ignore_directories=False, expand_empty=False): self.root = root or os.getcwd() if not isinstance(dir_sort, (tuple, list)): dir_sort = (dir_sort, False) if not isinstance(file_sort, (tuple, list)): file_sort = (file_sort, False) self.dir_sort = dir_sort self.file_sort = file_sort self.ignore_files = ignore_files self.ignore_directories = ignore_directories self.expand_empty = expand_empty self.last_selection = None cwd = os.getcwd() self.tree_root = DirectoryNode(self, self.root) self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.tree_root)) self.listbox.offset_rows = 1 urwid.connect_signal( self.listbox.body, "modified", self.on_modified ) super().__init__(self.listbox)
def __init__(self, reg, screen=None): self.reg = reg self.client = None self.loop = None self.screen = None self.stack = 0 self.tree_walker = None # create the template topnode = TuiParentNode(dummy_flow({'id': 'Loading...'})) self.listbox = urwid.TreeListBox(urwid.TreeWalker(topnode)) header = urwid.Text('\n') footer = urwid.AttrWrap( # urwid.Text(self.FOOTER_TEXT), urwid.Text(list_bindings()), 'foot') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(header, 'head'), footer=footer) self.filter_states = {state: True for state in TASK_STATUSES_ORDERED} if isinstance(screen, html_fragment.HtmlGenerator): # the HtmlGenerator only captures one frame # so we need to pre-populate the GUI before # starting the event loop self.update()
def __init__(self): cwd = os.getcwd() store_initial_cwd(cwd) self.listbox = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(cwd))) self.listbox.offset_rows = 1 urwid.AttrMap.__init__(self, self.listbox, 'body')
def __init__(self, data=None): self.topnode = ExampleParentNode(data) self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.topnode)) self.listbox.offset_rows = 1 self.header = urwid.Text("") self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(self.header, 'head'), footer=self.footer)
def __init__(self): cwd = os.getcwd() store_initial_cwd(cwd) self.header = urwid.Text("") self.listbox = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(cwd))) self.listbox.offset_rows = 1 self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(self.header, 'head'), footer=self.footer)
def __init__(self, category_list): ''' Constructor ''' assert category_list self.category_list = category_list self.listbox = urwid.TreeListBox(urwid.TreeWalker(CategoryNode('test'))) self.header = urwid.AttrWrap(urwid.Text(self.header_text), 'head') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=self.header)
def __init__(self): """Get TOAST Cloud Object Storage information""" #self.object_storage = TCObjectStorageClient() #self.object_storage.get_objects('/') """Get local filesystem information""" cwd = os.getcwd() store_initial_cwd(cwd) self.header = urwid.Text("") self.left_listbox = urwid.TreeListBox( urwid.TreeWalker(DirectoryNode(cwd))) self.left_listbox.offset_rows = 1 #self.right_listbox = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(cwd))) self.right_listbox = urwid.TreeListBox(urwid.TreeWalker(AccountNode())) self.right_listbox.offset_rows = 1 self.listbox = urwid.Columns([self.left_listbox, self.right_listbox]) self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(self.header, 'head'), footer=self.footer)
def __init__(self, on_selected: Callable[[str], None]): working_directory = os.getcwd() set_initial_top_level(working_directory) set_callback(on_selected) self.body = urwid.TreeListBox( urwid.TreeWalker(_DirectoryNode(working_directory))) self.body.offset_rows = 1 self.footer = urwid.Text(self.footer_text) self.view = urwid.Frame(urwid.AttrWrap(self.body, "body"), footer=urwid.AttrWrap(self.footer, "footer"))
def __init__(self, _app, start_dir): global app global browser app = _app browser = self header = urwid.AttrWrap(urwid.Text("File Browser", "center"), "title") main = urwid.Text(("hotkey", "Main"), "left") hcols = urwid.Columns([main, header, urwid.Text("")]) tree = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(start_dir))) self._w = urwid.Frame( urwid.AttrWrap(tree, "cm_body"), header=hcols, footer=None, )
def __init__(self, ksobj=None): self.topnode = KaitaiParentNode(None, ksobj, key=kshelp.objToStr(ksobj)) self.walker = urwid.TreeWalker(self.topnode) self.listbox = urwid.TreeListBox(self.walker) self.listbox.offset_rows = 0 self.header = urwid.Text("") self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(self.header, 'head'), footer=self.footer) urwid.connect_signal(self.walker, "modified", callback_tree_modified, weak_args=[self.listbox, self.footer])
def __init__(self, chat_widget, close_callback=None): self.chat_widget = chat_widget self.ui = chat_widget.ui self.close_callback = close_callback items = [] for server in sorted(chat_widget.discord.servers, key=lambda s: s.name): node = {"name": server.name, 'server_tree': self, 'server': server, "children": []} for ch in server.channels: if ch.type == discord.ChannelType.text: node['children'].append({ 'name': ch.name, 'server_tree': self, 'channel': ch }) nodeobj = TreeNodeServer(node) nodeobj.expanded = False items.append(nodeobj) if len(chat_widget.discord.private_channels) > 0: node = {"name": "Private Chats", 'server_tree': self, 'server': None, "children": []} for ch in chat_widget.discord.private_channels: name = '' if ch.type == discord.ChannelType.private: name = ch.user.display_name elif ch.type == discord.ChannelType.group: name = ch.name or ', '.join(u.display_name for u in ch.recipients) else: continue node['children'].append({ 'name': name, 'server_tree': self, 'channel': ch }) nodeobj = TreeNodeServer(node) nodeobj.expanded = False items.append(nodeobj) self.w_listbox = urwid.TreeListBox(TreeWalker(items)) self.__super.__init__(self.w_listbox)
def __init__(self, obj): self.obj = obj self.root_node = DirectoryNode(self, FIRST_KEY, obj) self.header = urwid.Text("") self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.root_node)) self.listbox._command_map._command.update({ "h": "cursor left", "j": "cursor down", "k": "cursor up", "l": "cursor right", }) self.listbox.offset_rows = 1 self.footer = SEdit(self, "") self.view = urwid.Frame( urwid.AttrWrap(self.listbox, "body"), header=urwid.AttrWrap(self.header, "head"), footer=self.footer, )
def switch_states(self, state): # this method is run to switch states, it reassigns what content is in the Frame if state == 'editor': self.top.contents['header'] = (self.status, None) self.top.contents['body'] = (self.body_col, None) self.top.contents['footer'] = (self.foot_col, None) if self.layout: self.top.contents['footer'] = (self.status, None) self.top.contents['header'] = (self.foot_col, None) elif state == 'openfile': path = strip_path(self.listbox.fname) self.browser = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(path, self))) self.top.contents['header'] = (self.oftbar, None) self.top.contents['body'] = (self.browser, None) self.top.contents['footer'] = (self.ofbbar, None) self.ofbbar.set_text('') self.state = state
def __init__(self, filename): self.stats = pstats.Stats(filename).stats self.stat_infos = {} self.roots = self.construct_tree() # we unfortunately need to construct this child dictionary by hand to # get the root to behave the way we want self.root_children = {stat_info.key_tuple: stat_info for stat_info in self.roots} self.root = StatInfo( ('Filename', "Line Number", 'Function'), ('Number of Calls', 'Number of Calls', 'Total Time', 'Cumulative Time') ) self.root.children_dictionary = self.root_children # We can have many roots (i.e. line info that is not called by other # things in the data). We construct a separate tree view for each one header = urwid.AttrWrap(urwid.Text("Steelix"), 'head') footer = urwid.Text("+/- to expand/collapse entries, q to quit") listbox = urwid.TreeListBox(urwid.TreeWalker(StatNode(self.root))) listbox.offset_rows = 1 self.view = urwid.Frame(listbox, header=header, footer=footer)
def buildFrame(self): topnode = CommentNode(self.comments) return urwid.TreeListBox(urwid.TreeWalker(topnode))
def keypress(self, k): # this method handles any keypresses that are unhandled by other widgets foc = self.top.focus_position # these conditionals will only be run if other widgets didnt handle them already, if right # or left keypresses go unhandled we know we are at the beginning or end of a line if k == 'left': self.loop.process_input(['up']) self.listbox.focus.set_edit_pos(len(self.listbox.focus.edit_text)) elif k == 'right' and self.state != 'openfile': self.loop.process_input(['down']) self.listbox.focus.set_edit_pos(0) elif k == 'backspace': # Right here we run combine_previous() to combine the # current text line with the one prior. This function # returns the length of the previous line. We have to wait to set the edit_pos # because self.loop.process_input changes the edit_pos if self.listbox.focus_position != 0: self.line_nums.sub() self.listbox.combine_previous() self.cur_tab.undo.log('backspace', [self.listbox.focus_position, self.listbox.focus.edit_pos], 1) elif k == 'delete': self.listbox.combine_next() self.cur_tab.undo.log('backspace', [self.listbox.focus_position, self.listbox.focus.edit_pos], 1) # this keypress opens up the configuration file so it can be edited elif k == self.config['config']: self.listbox.populate(CONFIG_PATH) # this keypress saves the changes of the config file and updates everything elif k == self.config['delline']: if self.listbox.focus_position == 0 and len(self.listbox.lines) == 1: self.listbox.focus.set_edit_text('') return self.cur_tab.undo.log(self.listbox.focus.edit_text+'\n', [self.listbox.focus_position, 0], 1) self.line_nums.sub() self.listbox.del_line() elif k == self.config['layout']: self.toggle_layout() elif k == self.config['linenum']: self.toggle_line_numbers() elif k == self.config['terminal']: self.toggle_term() elif k == self.config['open']: self.new_files = [] self.browser = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(self.cwd, self))) self.browser.offset_rows = 1 self.switch_states('openfile') # this keypress only registers when enter is pressed in the open file state, otherwise the # editor would have handled it. This means we need to open the selected files if there are any # and set the state back to editor mode elif k == 'enter': if self.state == 'openfile': self.switch_states('editor') if len(self.new_files) > 0: for fname in self.new_files: self.listbox.populate(fname) else: self.listbox.populate(self.file_names[0]) self.new_files = [] self.save_tabs() elif k == self.config['find']: self.finding = True self.top.contents['footer'] = (self.fedit, None) elif k == self.config['undo']: self.cur_tab.undo.undo() self.update_line_numbers() elif k == 'ctrl x': # get outta here! raise urwid.ExitMainLoop() # user needs help... so give them this help file I guess. elif k == 'esc': self.listbox.populate(HELP_PATH)
def _task_widget(self): tree = TaskTreeNode(self._runner.root_task, key=self._runner.root_task.id) return uwd.TreeListBox(uwd.TreeWalker(tree))
def __init__(self): # set up all the empty lists, dicts and strings needed # also create the widgets that will be used later self.cwd = os.getcwd() self.tab_info = {} self.file_names = [] self.palette = [] self.tabs = [] self.cur_tab = None self.finding = False self.show_term = False self.show_lnums = True self.state = '' self.rows = 0 # this variable represents the UI layout. if this value is False # then the tabs are on bottom and status is on top. when this value # is True then the layout is switched! self.layout = False self.configure() self.stext = ('header', ['SCUM ', ('key', 'ESC'), ' Help ', ('key', 'ctrl s'), ' Save ', ('key', 'ctrl o'), ' Open ', ('key', 'ctrl x'), ' Exit' ]) self.openfile_stext = ('header', ['Open File: Arrows to navigate ', ('key', 'Space'), ' Select ', ('key', 'Enter'), ' Open ']) # editor state GUI self.bbar = urwid.Text('') self.tbar = urwid.Text(self.stext) self.tbar_text = self.tbar.text self.status = urwid.AttrMap(self.tbar, 'header') self.listbox = TextList(self) urwid.AttrMap(self.listbox, 'body') self.line_nums = LineNumbers(self) self.body_col = urwid.Columns([(3, self.line_nums), self.listbox], focus_column=1) self.foot_col = urwid.Columns(self.tabs) self.foot = urwid.AttrMap(self.foot_col, 'footer') self.finder = FindField(self) self.fedit = urwid.AttrMap(self.finder, 'footer') # openfile state GUI self.new_files = [] self.openfile_top = urwid.Text(self.openfile_stext) self.oftbar = urwid.AttrMap(self.openfile_top, 'header') self.browser = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(self.cwd, self))) self.browser.offset_rows = 1 urwid.AttrWrap(self.browser, 'browse') self.openfile_bottom = urwid.Text(' ') self.ofbbar = urwid.AttrWrap(self.openfile_bottom, 'footer') self.top = urwid.Frame(self.body_col, header=self.status, footer=self.foot_col) self.update_top_bar() self.state = 'editor' self.term = ToggleTerm(self) self.termbox = urwid.LineBox(self.term) self.pile = urwid.Pile([self.top]) self.open_tabs() if len(self.tabs) == 0: self.listbox.populate(START_PATH)
def __init__(self): self.treetop = JIDParent(sconsole.static.tree_seed()) self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.treetop)) self.listbox.offset_rows = 1
def __init__(self, device): super(DeviceListBox, self).__init__( urwid.TreeListBox(urwid.TreeWalker(DeviceNode(device))), self._get_size(device)) self.device = device
def menu_session(hed, subhed, xdg_menu): session = Session() class EntryWidget(urwid.TreeWidget): def selectable(self): return True @session.catch def get_display_text(self): entry = self.get_node().get_value().DesktopEntry name = entry.getName() comment = entry.getComment() if comment: return f"{name} - {comment}" else: return name @session.catch def load_inner_widget(self): # TODO: Does this need to be a button if we can't actually # select it? button = urwid.Button(self.get_display_text()) return button @session.catch def keypress(self, size, key): key = super().keypress(size, key) if key == "enter": session.succeed(self.get_node().get_value().DesktopEntry) return key class EntryNode(urwid.TreeNode): @session.catch def load_widget(self): return EntryWidget(self) class MenuWidget(urwid.TreeWidget): @session.catch def get_display_text(self): menu_entry = self.get_node().get_value() return f"{menu_entry.getName()}:" class MenuNode(urwid.ParentNode): @session.catch def load_widget(self): return MenuWidget(self) @session.catch def load_child_keys(self): entity = self.get_value() if isinstance(entity, xdg.Menu.Menu): return list(range(len(list(entity.getEntries())))) else: return [] @session.catch def load_child_node(self, key): child = list(self.get_value().getEntries())[key] depth = self.get_depth() + 1 is_session = isinstance(child, xdg.Menu.Menu) cls = MenuNode if is_session else EntryNode node = cls(child, parent=self, key=key, depth=depth) return node root = MenuNode(xdg_menu) list_box = urwid.TreeListBox(urwid.TreeWalker(root)) session.xdg_menu = xdg_menu session.entry_widget_cls = EntryWidget session.entry_node_cls = EntryNode session.session_widget_cls = MenuWidget session.session_node_cls = MenuNode session.root = root session.list_box = list_box session.header = urwid.Columns( [urwid.Text(hed, align="left"), urwid.Text(subhed, align="right")] ) session.footer = urwid.Text( "Nav: up/down, page up/page down, home/end 🌹 Collapse/expand: +/- 🌹" "Select: [enter] 🌹 Bail: q/Q" ) # TODO: It would be cool if there was an API that made it more obvious # that we were "finalizing" the session session.widget = urwid.Frame(list_box, header=session.header, footer=session.footer) session.loop_kwarg["unhandled_input"] = on_q(session.succeed) return session
def turn_tree(self): self.home.body = urwid.TreeListBox( urwid.TreeWalker(self.listwalker.make_tree()))
def sidebar(self): return urwid.TreeListBox( urwid.TreeWalker(TeamOverviewNode(self.team_overview)))