python类Padding()的实例源码

rosbag-record-param-generator.py 文件源码 项目:my_ros_tools 作者: groundmelon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def create(cls, node_name, topics):
        return urwid.Padding(NodeCheckBox(node_name, topics), align='left', left=0)
bigtext.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def padding_values(self, size, focus):
        maxcol = size[0]
        width, ignore = self.original_widget.pack(size, focus=focus)
        if maxcol > width:
            self.align = "left"
        else:
            self.align = "right"
        return urwid.Padding.padding_values(self, size, focus)
graph.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def main_window(self):
        self.graph = self.bar_graph()
        self.graph_wrap = urwid.WidgetWrap( self.graph )
        vline = urwid.AttrWrap( urwid.SolidFill(u'\u2502'), 'line')
        c = self.graph_controls()
        w = urwid.Columns([('weight',2,self.graph_wrap),
            ('fixed',1,vline), c],
            dividechars=1, focus_column=2)
        w = urwid.Padding(w,('fixed left',1),('fixed right',0))
        w = urwid.AttrWrap(w,'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w,'line')
        w = self.main_shadow(w)
        return w
bigtext.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def padding_values(self, size, focus):
        maxcol = size[0]
        width, ignore = self.original_widget.pack(size, focus=focus)
        if maxcol > width:
            self.align = "left"
        else:
            self.align = "right"
        return urwid.Padding.padding_values(self, size, focus)
graph.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def main_window(self):
        self.graph = self.bar_graph()
        self.graph_wrap = urwid.WidgetWrap( self.graph )
        vline = urwid.AttrWrap( urwid.SolidFill(u'\u2502'), 'line')
        c = self.graph_controls()
        w = urwid.Columns([('weight',2,self.graph_wrap),
            ('fixed',1,vline), c],
            dividechars=1, focus_column=2)
        w = urwid.Padding(w,('fixed left',1),('fixed right',0))
        w = urwid.AttrWrap(w,'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w,'line')
        w = self.main_shadow(w)
        return w
dialog.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, text, height, width, body=None):
        width = int(width)
        if width <= 0:
            width = ('relative', 80)
        height = int(height)
        if height <= 0:
            height = ('relative', 80)

        self.body = body
        if body is None:
            # fill space with nothing
            body = urwid.Filler(urwid.Divider(),'top')

        self.frame = urwid.Frame( body, focus_part='footer')
        if text is not None:
            self.frame.header = urwid.Pile( [urwid.Text(text),
                urwid.Divider()] )
        w = self.frame

        # pad area around listbox
        w = urwid.Padding(w, ('fixed left',2), ('fixed right',2))
        w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1))
        w = urwid.AttrWrap(w, 'body')

        # "shadow" effect
        w = urwid.Columns( [w,('fixed', 2, urwid.AttrWrap(
            urwid.Filler(urwid.Text(('border','  ')), "top")
            ,'shadow'))])
        w = urwid.Frame( w, footer =
            urwid.AttrWrap(urwid.Text(('border','  ')),'shadow'))

        # outermost border area
        w = urwid.Padding(w, 'center', width )
        w = urwid.Filler(w, 'middle', height )
        w = urwid.AttrWrap( w, 'border' )

        self.view = w
test_decoration.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def petest(self, desc, align, width):
        self.assertRaises(urwid.PaddingError, lambda:
            urwid.Padding(None, align, width))
test_decoration.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def mctest(self, desc, left, right, size, cx, innercx):
        class Inner:
            def __init__(self, desc, innercx):
                self.desc = desc
                self.innercx = innercx
            def move_cursor_to_coords(self,size,cx,cy):
                assert cx==self.innercx, desc
        i = Inner(desc,innercx)
        p = urwid.Padding(i, ('fixed left',left),
            ('fixed right',right))
        p.move_cursor_to_coords(size, cx, 0)
treetools.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_indented_widget(self):
        widget = self.get_inner_widget()
        if not self.is_leaf:
            widget = urwid.Columns([('fixed', 1,
                [self.unexpanded_icon, self.expanded_icon][self.expanded]),
                widget], dividechars=1)
        indent_cols = self.get_indent_cols()
        return urwid.Padding(widget,
            width=('relative', 100), left=indent_cols)
fm.py 文件源码 项目:doubanfm-py 作者: nekocode 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _setup_ui(self):
        email = input('???? (Email??): ')
        password = getpass.getpass('????: ')

        api = DoubanFMApi()
        api.login(email, password)
        songs = api.get_redheart_songs()

        # ??
        self.title = urwid.Text('')
        self._update_title()
        divider = urwid.Divider()
        header = urwid.Padding(urwid.Pile([divider, self.title, divider]), left=4, right=4)

        # ????
        index = 0
        for song in songs:
            self.btns.append(SongButton(song, self._on_item_pressed, index))
            index += 1
        self.song_listbox = SongListBox(self.btns)

        # ??
        self.main = urwid.Padding(
            urwid.Frame(self.song_listbox, header=header, footer=divider),
            left=4, right=4)

        # ??????
        urwid.register_signal(
            SongListBox, ['exit', 'stop', 'next_song', 'change_mode'])
        urwid.connect_signal(self.song_listbox, 'exit', self._on_exit)
        urwid.connect_signal(self.song_listbox, 'stop', self.stop_song)
        urwid.connect_signal(self.song_listbox, 'next_song', self.next_song)
        urwid.connect_signal(self.song_listbox, 'change_mode', self.change_mode)

        self.loop = urwid.MainLoop(self.main, palette=self.palette)
        self.loop.screen.set_terminal_properties(colors=256)
terminal.py 文件源码 项目:terminal-leetcode 作者: chishui 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def make_header(self):
        if self.leetcode.is_login:
            columns = [
                ('fixed', 15, urwid.Padding(urwid.AttrWrap(
                    urwid.Text('%s' % config.username),
                    'head', ''))),
                urwid.AttrWrap(urwid.Text('You have solved %d / %d problems. ' %
                    (len(self.leetcode.solved), len(self.leetcode.quizzes))), 'head', ''),
            ]
            return urwid.Columns(columns)
        else:
            text = urwid.AttrWrap(urwid.Text('Not login'), 'head')
        return text
result.py 文件源码 项目:terminal-leetcode 作者: chishui 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def make_success_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Accepted'), 'accepted')
        columns = urwid.Columns([(20, status_header), (20, status)])
        runtime = urwid.Text('Run time: %s' % self.result['status_runtime'])
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        list_items = [
                result_header,
                blank, columns,
                blank, runtime
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
chatframe.py 文件源码 项目:ChatMaster3000 作者: pkrll 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, delegate):
        """
            init
        """
        self.delegate = delegate
        # Create the components of the frame:
        # * The title and the clock in the header
        titleBar = TitleBar(("titleBar", "ChatMaster 3000"), align="center")
        clock = urwid.AttrMap(Clock(self.delegate, align="right"), "titleBar")
        # The actual title bar. The title has a relative width, while clock has a set width of 5 columns wide.
        self.titleBar = ColumnView([('weight', 1, titleBar), (5, clock)])

        self.chatLog = ChatWindow()
        self.chatBox = ChatBox("> ", self)
        # Create the channel list and set its label
        self.channelList = ChannelList()
        self.channelList.body.insert(0, urwid.Text(("channelList-text-bold", "Channels:")))
        # Wrap them with a display attribute. This will enable color application.
        header = self.titleBar.wrapWithAttribute("titleBar")
        footer = self.chatBox.wrapWithAttribute("footer")
        chatLog = self.chatLog.wrapWithAttribute("body")
        channelList = self.channelList.wrapWithAttribute("channelList")
        # Create a border between the channel list and the chat log
        channelListWithPadding = urwid.Padding(channelList, align="left", width=("relative", 95))
        channelListWithPadding = urwid.AttrMap(channelListWithPadding, "border")
        # Put them both in a columns widget
        self.columnView = ColumnView([(15, channelListWithPadding), ('weight', 1, chatLog)])
        # Call the super class and let it handle the heavy lifting.
        super(ChatFrame, self).__init__(self.columnView, header=header, footer=footer, focus_part='footer')
display.py 文件源码 项目:sshchan 作者: einchan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def unhandled(self, key):
        """Input not handled by any other widgets.

        @key - string representing key that was pressed.

        Most key presses inside sshchan should be handled by this function.
        Buttons don't need handling here, they respond to Enter, Space or
        mouse clicks.
        """
        # Refresh screen dimensions in case terminal is resized.
        self.loop.dimensions = self.loop.screen.get_cols_rows()
        # Calculate width and margins of Padding based on terminal size.
        self.width = self.loop.dimensions[0] // 2
        self.margin = int((self.loop.dimensions[0] - self.width) * 0.60)

        if key in ("Q", "q"):
            self.quit_prompt()
        elif key == "tab":
            # Switch focus from body to top bar and vice versa.
            if self.loop.baseWidget.focus_position == "header":
                self.loop.baseWidget.focus_position = "body"
            else:
                self.loop.baseWidget.focus_position = "header"
        elif key in ("H", "h"):
            # Disable MOTD flag.
            self.motd_flag = False
            if not self.help_flag:
                self.loop.Widget = self.show_help()
        elif key in ("B", "b"):
            if not self.list_visible and self.motd_flag:
                # If board list isn't currently being displayed, let's show it.
                self.list_visible = True
                self.loop.frameBody.extend(self.list_boards())
            elif self.list_visible and self.motd_flag:
                # Board list was being displayed, get rid of it.
                for i in range(self.boards_count):
                    self.loop.frameBody.pop()
                self.list_visible = False
        elif key == "esc":
            # If not on the main screen, ESC goes back, otherwise try to quit.
            if not self.motd_flag:
                self.button_press(None, "back")
            else:
                self.quit_prompt()

        # Urwid expects the handler function to return True after it's done.
        return True
display.py 文件源码 项目:sshchan 作者: einchan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_board(self):
        index = self.board.get_index()
        new_btn = ur.AttrMap(
            ur.Button("New thread", self.reply_box, -1), "green", "b_green")
        thread_list = ur.SimpleFocusListWalker(
            [ur.Padding(new_btn, "center", ("relative", 40)), self.parent.div])

        for thread in index:
            # Check subject, because empty subject with set color attribute
            # produces wrong output.
            subject = ("reverse_red", thread[1])
            if subject[1] == "":
                subject = (None, "")

            op = self.parse_post(thread[2])

            post_info = ur.Text([("reverse_green", op["name"]),
                                 " " + op["stamp"] + " ", subject, " No. " +
                                 op["id"]])
            reply_btn = ur.AttrMap(CleanButton(
                "Reply", self.print_thread, op["id"]), None, "reverse")

            replies = []
            if len(thread) > 3:
                for i in range(3, 6):
                    try:
                        reply = self.parse_post(thread[i])
                        replies_info = ur.Text(
                            [("green", reply["name"]), " " + reply["stamp"]])
                        no_btn = CleanButton(
                            "No. " + reply["id"],
                            self.print_thread,
                            reply["id"])

                        replies_header = ur.Padding(ur.Columns(
                            [("pack", replies_info), ("pack", no_btn)],
                            1), left=1)
                        reply_text = ur.Padding(reply["text"], left=1)

                        replies.extend(
                            [replies_header, reply_text, self.parent.div])
                    except IndexError:
                        break

            header = ur.AttrMap(ur.Columns(
                [("pack", post_info), ("pack", reply_btn)], 1), "reverse")

            thread_buf = [header, op["text"], self.parent.div]
            thread_buf.extend(replies)
            thread_list.extend(thread_buf)

        body = ur.ListBox(thread_list)
        if len(thread_list) > 0:
            body.set_focus(0)

        self.loop.Widget = ur.Frame(
            body, self.parent.header, self.parent.footer, "body")
gui.py 文件源码 项目:projects 作者: tiborsimon 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def select_project(project_list, path_callback):
    max_width = len(max(project_list, key=len))
    f = ProjectSelector(project_list, 'normal', 'highlighted', 'selected')

    def refresh_list(key=''):
        if key:
            if key in ('delete', 'backspace'):
                f.remove_key()
            else:
                if key in 'abcdefghijklmnopqrstuvwxyz- .0123456789':
                    f.add_key(key)
        s = f.render()
        txt.set_text(s)

    def exit_on_q(key):
        if key.__class__ is not str:
            return
        if key in ('Q',):
            raise urwid.ExitMainLoop()
        if key == 'up':
            f.up()
        if key == 'down':
            f.down()
        if key == 'enter':
            path_callback(f.select())
            raise urwid.ExitMainLoop()
        key = key.lower()
        refresh_list(key)

    palette = [
        ('normal', 'light gray', ''),
        ('selected', 'yellow, bold', ''),
        ('highlighted', 'black, bold', 'yellow'),
        ('quit button', 'light red, bold', ''),
        ('enter button', 'light green, bold', '')
    ]

    txt = urwid.Text('', align='left')
    fill = urwid.Filler(txt)
    pad = urwid.Padding(fill, align='center', width=max_width+4)
    box = urwid.LineBox(pad, title="Projects")

    footer = urwid.Text(['Start typing to search. Use arrow keys to navigate. Press (', ('enter button', 'Enter'), ') to select project. ', 'Press (', ('quit button', 'Q'), ') to exit.'])
    frame = urwid.Frame(body=box, footer=footer)

    loop = urwid.MainLoop(frame, palette, unhandled_input=exit_on_q)
    refresh_list()
    loop.run()
story.py 文件源码 项目:boartty 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, app, story_view, task):
        super(TaskRow, self).__init__(urwid.Pile([]))
        self.app = app
        self.story_view = story_view
        self.task_key = task.key
        self._note = u''
        self.taskid = mywid.TextButton(self._note)
        urwid.connect_signal(self.taskid, 'click',
                             lambda b:self.editNote(b))
        self.project = ProjectButton(self.app)
        urwid.connect_signal(self.project, 'changed',
                             lambda b:self.updateProject(b))
        self.status = StatusButton(self.app)
        urwid.connect_signal(self.status, 'changed',
                             lambda b:self.updateStatus(b))
        self._title = u''
        self.title = mywid.TextButton(self._title)
        urwid.connect_signal(self.title, 'click',
                             lambda b:self.editTitle(b))
        self.assignee = AssigneeButton(self.app)
        urwid.connect_signal(self.assignee, 'changed',
                             lambda b:self.updateAssignee(b))
        self.description = urwid.Text(u'')
        self.columns = urwid.Columns([], dividechars=1)

        for (widget, attr, packing) in [
                (self.taskid, 'task-id', ('given', 4, False)),
                (self.project, 'task-project', ('weight', 1, False)),
                (self.title, 'task-title', ('weight', 2, False)),
                (self.status, 'task-status', ('weight', 1, False)),
                (self.assignee, 'task-assignee', ('weight', 1, False)),
        ]:
            w = urwid.AttrMap(urwid.Padding(widget, width='pack'), attr,
                              focus_map={'focused': 'focused-'+attr})
            self.columns.contents.append((w, packing))
        self.pile = urwid.Pile([self.columns])
        self.note = urwid.Text(u'')
        self.note_visible = False
        self.note_columns = urwid.Columns([], dividechars=1)
        self.note_columns.contents.append((urwid.Text(u''), ('given', 1, False)))
        self.note_columns.contents.append((self.note, ('weight', 1, False)))
        self._w = urwid.AttrMap(self.pile, None)#, focus_map=self.task_focus_map)
        self.refresh(task)
story.py 文件源码 项目:boartty 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, app, story_key):
        super(StoryView, self).__init__(urwid.Pile([]))
        self.log = logging.getLogger('boartty.view.story')
        self.searchInit()
        self.app = app
        self.story_key = story_key
        self.task_rows = {}
        self.event_rows = {}
        self.hide_events = True
        self.marked_seen = False
        self.title_label = urwid.Text(u'', wrap='clip')
        self.creator_label = mywid.TextButton(u'', on_press=self.searchCreator)
        self.tags_label = urwid.Text(u'', wrap='clip')
        self.created_label = urwid.Text(u'', wrap='clip')
        self.updated_label = urwid.Text(u'', wrap='clip')
        self.status_label = urwid.Text(u'', wrap='clip')
        self.permalink_label = mywid.TextButton(u'', on_press=self.openPermalink)
        story_info = []
        story_info_map={'story-data': 'focused-story-data'}
        for l, v in [("Title", self.title_label),
                     ("Creator", urwid.Padding(urwid.AttrMap(self.creator_label, None,
                                                           focus_map=story_info_map),
                                             width='pack')),
                     ("Tags", urwid.Padding(urwid.AttrMap(self.tags_label, None,
                                                           focus_map=story_info_map),
                                             width='pack')),
                     ("Created", self.created_label),
                     ("Updated", self.updated_label),
                     ("Status", self.status_label),
                     ("Permalink", urwid.Padding(urwid.AttrMap(self.permalink_label, None,
                                                               focus_map=story_info_map),
                                                 width='pack')),
                     ]:
            row = urwid.Columns([(12, urwid.Text(('story-header', l), wrap='clip')), v])
            story_info.append(row)
        story_info = urwid.Pile(story_info)
        self.description = DescriptionBox(app, u'')
        self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([]))
        self._w.contents.append((self.app.header, ('pack', 1)))
        self._w.contents.append((urwid.Divider(), ('pack', 1)))
        self._w.contents.append((self.listbox, ('weight', 1)))
        self._w.set_focus(2)

        self.listbox.body.append(story_info)
        self.listbox.body.append(urwid.Divider())
        self.listbox_tasks_start = len(self.listbox.body)
        self.listbox.body.append(urwid.Divider())
        self.listbox.body.append(self.description)
        self.listbox.body.append(urwid.Divider())

        self.refresh()
        self.listbox.set_focus(3)


问题


面经


文章

微信
公众号

扫码关注公众号