示例#1
0
    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)
示例#2
0
    def __init__(self):
        self.sessions = Config().load_from_file()

        top_node = UIParentNode(self.sessions, key_handler=self.on_key_press)
        self.walker = urwid.TreeWalker(top_node)
        self.listbox = UITreeListBox(self.walker)

        restore_ui_state(self.listbox, self.sessions)

        urwid.connect_signal(self.walker, "modified",
                             lambda: on_focus_change(self.listbox))
        header = urwid.Text("Redial")
        footer = init_footer(self.listbox)

        self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'),
                                header=urwid.AttrWrap(header, 'head'),
                                footer=footer)

        # Set screen to 256 color mode
        screen = urwid.raw_display.Screen()
        screen.set_terminal_properties(256)
        self.loop = urwid.MainLoop(self.view, palette, screen)

        # instance attributes
        self.command = None
        self.command_return_key = None
        self.log = None
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
 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)
示例#6
0
    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()
示例#7
0
    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)
示例#8
0
    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')
示例#9
0
 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)
示例#10
0
 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):
     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):
        """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)
示例#13
0
    def __init__(self):
        self.walker = urwid.TreeWalker(MachineGroupNode(u'/'))
        super(MachineList, self).__init__(self.walker)

        urwid.connect_signal(self.walker, 'modified', self.walker_modified)

        # Some vi-style keys for easier navigation
        self._command_map['j'] = urwid.CURSOR_DOWN
        self._command_map['k'] = urwid.CURSOR_UP
        self._command_map['ctrl f'] = urwid.CURSOR_PAGE_DOWN
        self._command_map['ctrl b'] = urwid.CURSOR_PAGE_UP
    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"))
示例#15
0
    def update(self):
        """Refresh the data and redraw this widget.

        Preserves the current focus and collapse/expand state.

        """
        # update the data store
        # TODO: this can be done incrementally using deltas
        #       once this interface is available
        snapshot = self.get_snapshot()
        if snapshot is False:
            return False
        data = snapshot['data']

        # update the workflow status message
        header = [get_workflow_status_str(data)]
        status_summary = get_task_status_summary(snapshot['data'])
        if status_summary:
            header.extend([' ('] + status_summary + [' )'])
        if not all(self.filter_states.values()):
            header.extend([' ', '*filtered* "R" to reset', ' '])
        self.set_header(header)

        # global update - the nuclear option - slow but simple
        # TODO: this can be done incrementally by adding and
        #       removing nodes from the existing tree
        topnode = TuiParentNode(snapshot)

        # NOTE: because we are nuking the tree we need to manually
        # preserve the focus and collapse status of tree nodes

        # record the old focus
        _, old_node = self.listbox._body.get_focus()

        # nuke the tree
        self.tree_walker = urwid.TreeWalker(topnode)
        self.listbox._set_body(self.tree_walker)

        # get the new focus
        _, new_node = self.listbox._body.get_focus()

        # preserve the focus or walk to the nearest parent
        closest_focus = find_closest_focus(self, old_node, new_node)
        self.listbox._body.set_focus(closest_focus)

        #  preserve the collapse/expand status of all nodes
        translate_collapsing(self, old_node, new_node)

        # schedule the next run of this update method
        if self.loop:
            self.loop.set_alarm_in(self.UPDATE_INTERVAL, self._update)

        return True
示例#16
0
 def __init__(self, data=None):
     self.topnode = UIParentNode(data)
     walker = urwid.TreeWalker(self.topnode)
     State.walker = walker
     urwid.connect_signal(walker, "modified", on_focus_change)
     self.listbox = UITreeListBox(walker)
     State.listbox = self.listbox
     self.listbox.offset_rows = 1
     self.header = urwid.Text("Redial")
     self.footer = self.initFooter()
     self.loop = None
     self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'),
                             header=urwid.AttrWrap(self.header, 'head'),
                             footer=self.footer)
示例#17
0
    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,
        )
示例#18
0
    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])
示例#19
0
文件: tui.py 项目: usb-tools/ViewSB
    def __init__(self, ascii_only):
        """ Initializes the UI for the TUI widget. """

        super().__init__()
        self.ascii_only = ascii_only

        # For now: create a really inefficient in-memory packet store,
        # and anchor our tree-view to that.
        self.packet_store = TUIPacketCollection(self)
        self.root_node = VSBRootNode(self.packet_store, self)

        # Generate the TreeList that's we'll use the display our packets.
        # This is the main viewport into the USB data.
        self.dynamic_view = urwid.TreeWalker(self.root_node)
        self.packet_list = urwid.AttrWrap(
            PacketListBox(self.dynamic_view, self.packet_focus_changed),
            'packets')
        self.packet_list.offset_rows = 1

        # Create the "decoded packet view" box.
        self.decoder_rows = urwid.SimpleListWalker([])
        decoder_rows_list = urwid.AttrWrap(urwid.ListBox(self.decoder_rows),
                                           'decoder')

        # Create the "raw hex data" box.
        self.hex_data_rows = urwid.SimpleListWalker([])
        hexdump_rows_list = urwid.AttrWrap(urwid.ListBox(self.hex_data_rows),
                                           'hexdump')

        # Right panel.
        right_panel = urwid.Pile([('weight', 3, decoder_rows_list),
                                  ('pack', urwid.Text(('body', ""))),
                                  hexdump_rows_list])

        # Create the outer UI chrome for our text UI.
        # TODO: generate the footer text dynamically?
        self.header = VSBPacketWidget.get_row_headers(style='head')
        self.columns = urwid.Columns(
            [('weight', 2, self.packet_list), right_panel], dividechars=1)
        self.footer = urwid.Text(self.DEFAULT_FOOTER_TEXT)
        self.view = urwid.Frame(
            body=urwid.AttrWrap(self.columns, 'body'),
            header=urwid.AttrWrap(self.header, 'head'),
            footer=urwid.AttrWrap(self.footer, 'foot'),
        )
示例#20
0
 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,
     )
示例#21
0
    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
示例#22
0
    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)
示例#23
0
文件: tui.py 项目: whitevirus/ViewSB
    def __init__(self, title=None):
        """ Initializes the UI for the TUI widget. """

        # If no title is provided, use the default one.
        if title is None:
            title = self.DEFAULT_VIEW_TITLE

        # For now: create a really inefficient in-memory packet store,
        # and anchor our tree-view to that.
        self.packet_store = TUIPacketCollection(self)
        self.root_node = VSBPacketNode(self.packet_store, self)

        # Generate the TreeList that's we'll use the display our packets.
        # This is the main viewport into the USB data.
        self.dynamic_view = urwid.TreeWalker(self.root_node)
        self.packet_list = urwid.AttrWrap(
            PacketListBox(self.dynamic_view, self.packet_focus_changed),
            'packets')
        self.packet_list.offset_rows = 1

        # Create the "decoded packet view" box.
        self.decoder_rows = urwid.SimpleListWalker([])
        decoder_rows_list = urwid.AttrWrap(urwid.ListBox(self.decoder_rows),
                                           'decoder')

        # Create the outer UI chrome for our text UI.
        # TODO: generate the footer text dynamically?
        self.header = urwid.Text("  " + title)
        self.columns = urwid.Columns(
            [('weight', 2, self.packet_list), decoder_rows_list],
            dividechars=1)
        self.footer = urwid.Text(self.DEFAULT_FOOTER_TEXT)
        self.view = urwid.Frame(
            body=urwid.AttrWrap(self.columns, 'body'),
            header=urwid.AttrWrap(self.header, 'head'),
            footer=urwid.AttrWrap(self.footer, 'foot'),
        )
示例#24
0
    def reload(self, fetch=True):
        if fetch:
            self.fetch_current_state()
        self.build_inst_tree()

        cur_node = self.current_node
        if cur_node:
            start_key = cur_node.path
        else:
            start_key = '/'
            # start_key = PathItem(*self.chan_list[0][2:]).path

        self.start_key = start_key
        self.start_node = self.inst_tree[start_key]

        self.walker = urwid.TreeWalker(self.start_node)
        if self.listbox is not None:
            self.listbox.body = self.walker

        for node in self.inst_tree.values():
            if isinstance(node, FluidFontNode) and not node in (
                    self.top_node, self.start_node,
                    self.start_node.get_parent()):
                node.get_widget().fold()
示例#25
0
 def buildFrame(self):
     topnode = CommentNode(self.comments)
     return urwid.TreeListBox(urwid.TreeWalker(topnode))
示例#26
0
    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)
示例#27
0
    def __init__(self, device):

        super(DeviceListBox, self).__init__(
            urwid.TreeListBox(urwid.TreeWalker(DeviceNode(device))),
            self._get_size(device))
        self.device = device
示例#28
0
文件: menu.py 项目: disco0/public
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
示例#29
0
文件: ui.py 项目: binaryflesh/raiden
 def _task_widget(self):
     tree = TaskTreeNode(self._runner.root_task,
                         key=self._runner.root_task.id)
     return uwd.TreeListBox(uwd.TreeWalker(tree))
示例#30
0
 def __init__(self):
     self.treetop = JIDParent(sconsole.static.tree_seed())
     self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.treetop))
     self.listbox.offset_rows = 1