curses_ui.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:huhamhire-hosts 作者: jiangsile 项目源码 文件源码
def show_funclist(self, pos, item_sup, item_inf):
        """
        Draw `function selection list` frame with a index number of the item
        selected and the range of items to be displayed.

        :param pos: Index of selected item in `function selection list`.
        :type pos: int or None
        :param item_sup: Upper bound of item index from `function selection
            list`.
        :type item_sup: int
        :param item_inf: Lower bound of item index from `function selection
            list`.
        :type item_inf: int
        """
        # Set UI variable
        screen = self._stdscr.subwin(18, 26, 2, 26)
        screen.bkgd(' ', curses.color_pair(4))
        normal = curses.A_NORMAL
        select = curses.color_pair(5)
        select += curses.A_BOLD
        list_height = 15
        # Set local variable
        ip = self.settings[1][1]
        item_len = len(self.choice[ip])
        # Function list
        items_show = self.choice[ip][item_sup:item_inf]
        items_selec = self._funcs[ip][item_sup:item_inf]
        for p, item in enumerate(items_show):
            sel_ch = '+' if items_selec[p] else ' '
            item_str = ("[%s] %s" % (sel_ch, item[3])).ljust(23)
            item_pos = pos - item_sup if pos is not None else None
            highlight = select if p == item_pos else normal
            if item_len > list_height:
                if item_inf - item_sup == list_height - 2:
                    screen.addstr(4 + p, 2, item_str, highlight)
                elif item_inf == item_len:
                    screen.addstr(4 + p, 2, item_str, highlight)
                elif item_sup == 0:
                    screen.addstr(3 + p, 2, item_str, highlight)
            else:
                screen.addstr(3 + p, 2, item_str, highlight)
        if item_len > list_height:
            if item_inf - item_sup == list_height - 2:
                screen.addstr(3, 2, " More  ".center(23, '.'), normal)
                screen.addch(3, 15, curses.ACS_UARROW)
                screen.addstr(17, 2, " More  ".center(23, '.'), normal)
                screen.addch(17, 15, curses.ACS_DARROW)
            elif item_inf == item_len:
                screen.addstr(3, 2, " More  ".center(23, '.'), normal)
                screen.addch(3, 15, curses.ACS_UARROW)
            elif item_sup == 0:
                screen.addstr(17, 2, " More  ".center(23, '.'), normal)
                screen.addch(17, 15, curses.ACS_DARROW)
        else:
            for line_i in range(list_height - item_len):
                screen.addstr(17 - line_i, 2, ' ' * 23, normal)
        if not items_show:
            screen.addstr(4, 2, "No data file!".center(23), normal)
        screen.refresh()
        self._item_sup, self._item_inf = item_sup, item_inf
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号