Python curses 模块,A_NORMAL 实例源码

我们从Python开源项目中,提取了以下45个代码示例,用于说明如何使用curses.A_NORMAL

项目:botany    作者:jifunks    | 项目源码 | 文件源码
def draw_menu(self):
        # Actually draws the menu and handles branching
        request = ""
        try:
            while request is not "exit":
                self.draw()
                request = self.get_user_input()
                self.handle_request(request)
            self.__exit__()

        # Also calls __exit__, but adds traceback after
        except Exception as exception:
            self.screen.clear()
            self.screen.addstr(0, 0, "Enlarge terminal!", curses.A_NORMAL)
            self.screen.refresh()
            self.__exit__()
            #traceback.print_exc()
项目:bittyband    作者:yam655    | 项目源码 | 文件源码
def refresh_line(self, line, *, no_refresh=False):
        if self.invalidate:
            self.refresh()
            return
        if len(self.logic.get_order()) == 0:
            return
        max_y, max_x = self.stdscr.getmaxyx()
        row = line - self.top
        if row < 0 or row >= max_y:
            return
        bit = self.logic.get_order()[line]
        if hasattr(self.logic, "get_line"):
            title = self.logic.get_line(bit, max_x - _INDICATOR_OFFSET * 2)
        else:
            title = bit[:max_x - _INDICATOR_OFFSET * 2]
        if line == self.active:
            self.stdscr.addstr(row, 0, ">  ", curses.A_REVERSE)
            self.stdscr.addstr(row, _INDICATOR_OFFSET, title, curses.A_REVERSE)
            self.stdscr.chgat(row, 0, curses.A_REVERSE)
        else:
            self.stdscr.addstr(row, _INDICATOR_OFFSET, title)
            self.stdscr.chgat(row, 0, curses.A_NORMAL)
        if not no_refresh:
            self.stdscr.refresh()
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def tick(self, scr, steps):
        height, width = scr.getmaxyx()
        if self.advances(steps):
            # if window was resized and char is out of bounds, reset
            self.out_of_bounds_reset(width, height)
            # make previous char curses.A_NORMAL
            if USE_COLORS:
                scr.addstr(self.y, self.x, self.char, curses.color_pair(COLOR_CHAR_NORMAL))
            else:
                scr.addstr(self.y, self.x, self.char, curses.A_NORMAL)

            # choose new char and draw it A_REVERSE if not out of bounds
            self.char = random.choice(FallingChar.matrixchr).encode(encoding)
            self.y += 1
            if not self.out_of_bounds_reset(width, height):
                if USE_COLORS:
                    scr.addstr(self.y, self.x, self.char, curses.color_pair(COLOR_CHAR_HIGHLIGHT))
                else:
                    scr.addstr(self.y, self.x, self.char, curses.A_REVERSE)
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def status(self):
        """
        Draw `Status` frame and `Hosts File` frame in the TUI window.
        """
        screen = self._stdscr.subwin(11, 25, 10, 0)
        screen.bkgd(' ', curses.color_pair(4))
        # Set local variable
        normal = curses.A_NORMAL
        green = curses.color_pair(7)
        red = curses.color_pair(9)
        # Status info
        for i, stat in enumerate(self.statusinfo):
            screen.addstr(2 + i, 2, stat[0], normal)
            stat_str = ''.join(['[', stat[1], ']']).ljust(9)
            screen.addstr(2 + i, 15, stat_str,
                          green if stat[2] == "GREEN" else red)
        # Hosts file info
        i = 0
        for key, info in self.hostsinfo.items():
            screen.addstr(7 + i, 2, key, normal)
            screen.addstr(7 + i, 15, info, normal)
            i += 1
        screen.refresh()
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def sub_selection_dialog_items(self, pos, i_pos, screen):
        """
        Draw items in `Selection Dialog`.

        :param pos: Index of selected item in `Configure Setting` frame.
        :type pos: int
        :param i_pos: Index of selected item in `Selection Dialog`.
        :type i_pos: int
        :param screen: A **WindowObject** which represents the selection
            dialog.
        :type screen: WindowObject
        """
        # Set local variable
        normal = curses.A_NORMAL
        select = normal + curses.A_BOLD
        for p, item in enumerate(self.settings[pos][2]):
            item_str = item if pos else item["tag"]
            screen.addstr(1 + p, 2, item_str,
                          select if p == i_pos else normal)
        screen.refresh()
项目:copycat    作者:LSaldyt    | 项目源码 | 文件源码
def depict_fps(self):
        w = self.fpsWindow
        now = time.time()
        elapsed = now - self.fpsSince
        fps = self.fpsTicks / elapsed
        if self.fpsGoal is not None:
            seconds_of_work_per_frame = (elapsed / self.fpsTicks) - self.fpsDelay
            desired_time_working_per_second = self.fpsGoal * seconds_of_work_per_frame
            if desired_time_working_per_second < 1.0:
                self.fpsDelay = (1.0 - desired_time_working_per_second) / fps
            else:
                self.fpsDelay = 0
        w.addstr(1, 1, 'FPS:%3d' % fps, curses.A_NORMAL)
        w.refresh()
        self.fpsSince = now
        self.fpsTicks = 0
        self.fpsMeasured = fps
项目:copycat    作者:LSaldyt    | 项目源码 | 文件源码
def depict_workspace_object(self, w, row, column, o, maxImportance, description_structures):
        if maxImportance != 0.0 and o.relativeImportance == maxImportance:
            attr = curses.A_BOLD
        else:
            attr = curses.A_NORMAL
        w.addstr(row, column, str(o), attr)
        column += len(str(o))
        if o.descriptions:
            w.addstr(row, column, ' (', curses.A_NORMAL)
            column += 2
            for i, d in enumerate(o.descriptions):
                if i != 0:
                    w.addstr(row, column, ', ', curses.A_NORMAL)
                    column += 2
                s, attr = self.slipnode_name_and_attr(d.descriptor)
                if d not in description_structures:
                    s = '[%s]' % s
                w.addstr(row, column, s, attr)
                column += len(s)
            w.addstr(row, column, ')', curses.A_NORMAL)
            column += 1
        return column
项目:matrixgram    作者:samsiegart    | 项目源码 | 文件源码
def tick(self, scr, steps, padding_rows, padding_cols, output_rows, output_cols):
        height, width = scr.getmaxyx()
        in_picture_frame = self.y >= padding_rows and self.y <= padding_rows + output_rows and self.x >= padding_cols and self.x <= padding_cols + output_cols
        if self.advances(steps):
            # if window was resized and char is out of bounds, reset
            self.out_of_bounds_reset(width, height)
            # make previous char curses.A_NORMAL
            if not in_picture_frame:
                if USE_COLORS:
                    scr.addstr(self.y, self.x, self.char, curses.color_pair(COLOR_CHAR_NORMAL))
                else:
                    scr.addstr(self.y, self.x, self.char, curses.A_NORMAL)
            # choose new char and draw it A_REVERSE if not out of bounds
            self.char = random.choice(FallingChar.matrixchr).encode(encoding)
            self.y += 1
            in_picture_frame = self.y >= padding_rows and self.y <= padding_rows + output_rows and self.x >= padding_cols and self.x <= padding_cols + output_cols
            if not self.out_of_bounds_reset(width, height) and not in_picture_frame:
                if USE_COLORS:
                    scr.addstr(self.y, self.x, self.char, curses.color_pair(COLOR_CHAR_HIGHLIGHT))
                else:
                    scr.addstr(self.y, self.x, self.char, curses.A_REVERSE)
项目:zmq-chat    作者:jnthnwn    | 项目源码 | 文件源码
def start_bottom_window(window, chat_sender):
    window.bkgd(curses.A_NORMAL, curses.color_pair(2))
    window.clear()
    window.box()
    window.refresh()
    while True:
        window.clear()
        window.box()
        window.refresh()
        s = window.getstr(1, 1).decode('utf-8')
        if s is not None and s != "":
            chat_sender.send_string(s)
        # need to do sleep here...
        # if bottom window gets down to `window.getstr...` while top window is setting up,
        # it registers a bunch of control characters as the user's input
        time.sleep(0.005)
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def deselect(self):
        self.borderbox.bkgd(' ', curses.A_NORMAL)
        self.textinpt.bkgd(' ', colors.get_colorpair(self.default_color))
        self.refresh()
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def deselect(self):
        '''
        Deselects this Textbox and turns off cursor visiblity.
        '''
        self.borderbox.bkgd(' ', curses.A_NORMAL)
        self.textinpt.bkgd(' ', colors.get_colorpair(self.default_color))
        curses.curs_set(0)
        self.refresh()
项目:defuse_division    作者:lelandbatey    | 项目源码 | 文件源码
def draw_state(stdscr, state, me):
    """
    draw_state draws the state of a MineField onto a curses window.
    """
    startx, starty = 1, 1
    stdscr.erase()

    xoffset = 0
    players = state['players']
    for idx, pname in enumerate(sorted(players.keys())):
        player = players[pname]
        field = player['minefield']

        width, height = board_termsize(field['width'], field['height'])
        namey = starty + height
        middlefmt = "{{: ^{}}}"
        disp_name = middlefmt.format(width).format(pname)[:width]
        if pname == me:
            attr = curses_colors.get_colorpair('green-black')
        else:
            attr = curses.A_NORMAL

        for cell in field['cells']:
            glyphs = display.assemble_glyphs(cell, player)
            for g in glyphs:
                stdscr.addstr(g.y + starty, g.x + startx + xoffset, g.strng,
                              g.attr)
        # If a user has died, draw a big 'you're dead' message in the middle of
        # their board
        if not state['players'][pname]['living']:
            dead = middlefmt.format(width).format('WASTED')
            h = height // 2
            stdscr.addstr(h, startx+xoffset, dead, curses_colors.get_colorpair('yellow-red'))
        stdscr.addstr(namey, startx + xoffset, disp_name, attr)
        xoffset += width
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def __init__(self, this_plant, this_data):
        '''Initialization'''
        self.initialized = False
        self.screen = curses.initscr()
        curses.noecho()
        curses.raw()
        curses.start_color()
        try:
            curses.curs_set(0)
        except curses.error:
            # Not all terminals support this functionality.
            # When the error is ignored the screen will look a little uglier, but that's not terrible
            # So in order to keep botany as accesible as possible to everyone, it should be safe to ignore the error.
            pass
        self.screen.keypad(1)
        self.plant = this_plant
        self.user_data = this_data
        self.plant_string = self.plant.parse_plant()
        self.plant_ticks = str(self.plant.ticks)
        self.exit = False
        self.infotoggle = 0
        self.maxy, self.maxx = self.screen.getmaxyx()
        # Highlighted and Normal line definitions
        self.define_colors()
        self.highlighted = curses.color_pair(1)
        self.normal = curses.A_NORMAL
        # Threaded screen update for live changes
        screen_thread = threading.Thread(target=self.update_plant_live, args=())
        screen_thread.daemon = True
        screen_thread.start()
        self.screen.clear()
        self.show(["water","look","garden","instructions"], title=' botany ', subtitle='options')
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def draw(self):
        # Draw the menu and lines
        self.screen.refresh()
        try:
            self.draw_default()
            self.screen.refresh()
        except Exception as exception:
            # Makes sure data is saved in event of a crash due to window resizing
            self.screen.clear()
            self.screen.addstr(0, 0, "Enlarge terminal!", curses.A_NORMAL)
            self.screen.refresh()
            self.__exit__()
            traceback.print_exc()
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def ascii_render(self, filename, ypos, xpos):
        # Prints ASCII art from file at given coordinates
        this_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),"art")
        this_filename = os.path.join(this_dir,filename)
        this_file = open(this_filename,"r")
        this_string = this_file.readlines()
        this_file.close()
        for y, line in enumerate(this_string, 2):
            self.screen.addstr(ypos+y, xpos, line, curses.A_NORMAL)
        # self.screen.refresh()
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def draw_default(self):
        # draws default menu
        clear_bar = " " * (int(self.maxx*2/3))
        self.screen.addstr(2, 2, self.title, curses.A_STANDOUT) # Title for this menu
        self.screen.addstr(4, 2, self.subtitle, curses.A_BOLD) #Subtitle for this menu
        # clear menu on screen
        for index in range(len(self.options)+1):
            self.screen.addstr(5+index, 4, clear_bar, curses.A_NORMAL)
        # display all the menu items, showing the 'pos' item highlighted
        for index in range(len(self.options)):
            textstyle = self.normal
            if index == self.selected:
                textstyle = self.highlighted
            self.screen.addstr(5+index ,4, clear_bar, curses.A_NORMAL)
            self.screen.addstr(5+index ,4, "%d - %s" % (index+1, self.options[index]), textstyle)

        self.screen.addstr(11, 2, clear_bar, curses.A_NORMAL)
        self.screen.addstr(12, 2, clear_bar, curses.A_NORMAL)
        self.screen.addstr(11, 2, "plant: ", curses.A_DIM)
        self.screen.addstr(11, 9, self.plant_string, curses.A_NORMAL)
        self.screen.addstr(12, 2, "score: ", curses.A_DIM)
        self.screen.addstr(12, 9, self.plant_ticks, curses.A_NORMAL)

        # display fancy water gauge
        if not self.plant.dead:
            water_gauge_str = self.water_gauge()
            self.screen.addstr(5,14, water_gauge_str, curses.A_NORMAL)
        else:
            self.screen.addstr(5,13, clear_bar, curses.A_NORMAL)
            self.screen.addstr(5,13, " (   RIP   )", curses.A_NORMAL)

        # draw cute ascii from files
        self.draw_plant_ascii(self.plant)
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def clear_info_pane(self):
        # Clears bottom part of screen
        clear_bar = " " * (self.maxx-2) + "\n"
        clear_block = clear_bar * (self.maxy - 15)
        for y, line in enumerate(clear_block.splitlines(), 2):
            self.screen.addstr(y+12, 2, line, curses.A_NORMAL)
        self.screen.refresh()
项目:botany    作者:jifunks    | 项目源码 | 文件源码
def draw_info_text(self, info_text):
        # print lines of text to info pane at bottom of screen
        if type(info_text) is str:
            info_text = info_text.splitlines()

        for y, line in enumerate(info_text, 2):
            self.screen.addstr(y+12, 2, line, curses.A_NORMAL)
        self.screen.refresh()
项目:bittyband    作者:yam655    | 项目源码 | 文件源码
def move(self, x = None):
        if x is not None:
            if x < self.x1 or x >= self.x2:
                return
            self.stdscr.chgat(self.y, self.cursor, 1, curses.A_NORMAL)
            self.cursor = x
        self.stdscr.chgat(self.y, self.cursor, 1, curses.A_REVERSE)
项目:lgsm-python    作者:jaredballou    | 项目源码 | 文件源码
def display(self):
        self.panel.top()
        self.panel.show()
        self.window.clear()

        while True:
            self.window.refresh()
            curses.doupdate()
            for index, item in enumerate(self.items):
                if index == self.position:
                    mode = curses.A_REVERSE
                else:
                    mode = curses.A_NORMAL

                msg = '%d. %s' % (index, item[0])
                self.window.addstr(1+index, 1, msg, mode)

            key = self.window.getch()

            if key in [curses.KEY_ENTER, ord('\n')]:
                # Handle exit from menu
                if self.position == len(self.items)-1 or str(self.items[self.position][1]) == "exit":
                    break
                else:
                    if self.rootmenu.set_selection(self.items[self.position][1]):
                        break

            elif key == curses.KEY_UP:
                self.navigate(-1)

            elif key == curses.KEY_DOWN:
                self.navigate(1)

        self.window.clear()
        self.panel.hide()
        panel.update_panels()
        curses.doupdate()
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def tick(self, scr, steps):
        if self.step > WINDOW_SIZE:
            #stop window animation after some steps
            self.draw_frame(scr, self.x - self.step, self.y - self.step,
                            self.x + self.step, self.y + self.step,
                            curses.A_NORMAL)
            return False

        # clear all characters covered by the window frame
        for i in range(WINDOW_ANIMATION_SPEED):
            anistep = self.step + i
            self.draw_frame(scr, self.x - anistep, self.y - anistep,
                            self.x + anistep, self.y + anistep,
                            curses.A_NORMAL, ' ')
        #cancel last animation
        self.draw_frame(scr, self.x - self.step, self.y - self.step,
                        self.x + self.step, self.y + self.step,
                        curses.A_NORMAL)
        #next step
        self.step += WINDOW_ANIMATION_SPEED

        #draw outer frame
        self.draw_frame(scr, self.x - self.step, self.y - self.step,
                        self.x + self.step, self.y + self.step,
                        curses.A_REVERSE)
        return True
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def banner(self):
        """
        Draw the banner in the TUI window.
        """
        screen = self._stdscr.subwin(2, 80, 0, 0)
        screen.bkgd(' ', curses.color_pair(1))
        # Set local variable
        title = curses.A_NORMAL
        title += curses.A_BOLD
        normal = curses.color_pair(4)
        # Print title
        screen.addstr(0, 0, self.__title.center(79), title)
        screen.addstr(1, 0, "Setup".center(10), normal)
        screen.refresh()
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def footer(self):
        """
        Draw the footer in the TUI window.
        """
        screen = self._stdscr.subwin(1, 80, 23, 0)
        screen.bkgd(' ', curses.color_pair(1))
        # Set local variable
        normal = curses.A_NORMAL
        # Copyright info
        copyleft = self.__copyleft
        screen.addstr(0, 0, copyleft.center(79), normal)
        screen.refresh()
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def configure_settings_frame(self, pos=None):
        """
        Draw `Configure Setting` frame with a index number (`pos`) of the item
        selected.

        :param pos: Index of selected item in `Configure Setting` frame. The
            default value of `pos` is `None`.
        :type pos: int or None

        .. note:: None of the items in `Configure Setting` frame would be
            selected if pos is `None`.
        """
        self._stdscr.keypad(1)
        screen = self._stdscr.subwin(8, 25, 2, 0)
        screen.bkgd(' ', curses.color_pair(4))
        # Set local variable
        normal = curses.A_NORMAL
        select = curses.color_pair(5)
        select += curses.A_BOLD

        for p, item in enumerate(self.settings):
            item_str = item[0].ljust(12)
            screen.addstr(3 + p, 2, item_str, select if p == pos else normal)
            if p:
                choice = "[%s]" % item[2][item[1]]
            else:
                choice = "[%s]" % item[2][item[1]]["label"]
            screen.addstr(3 + p, 15, ''.ljust(10), normal)
            screen.addstr(3 + p, 15, choice, select if p == pos else normal)
        screen.refresh()
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def sub_selection_dialog(self, pos):
        """
        Draw a `Selection Dialog` on screen used to make configurations.

        :param pos: Index of selected item in `Configure Setting` frame.
        :type pos: int

        .. warning:: The value of `pos` MUST NOT be `None`.

        :return: A **WindowObject** which represents the selection dialog.
        :rtype: WindowObject
        """
        i_len = len(self.settings[pos][2])
        # Draw Shadow
        shadow = curses.newwin(i_len + 2, 18, 13 - i_len / 2, 31)
        shadow.bkgd(' ', curses.color_pair(8))
        shadow.refresh()
        # Draw Subwindow
        screen = curses.newwin(i_len + 2, 18, 12 - i_len / 2, 30)
        screen.box()
        screen.bkgd(' ', curses.color_pair(1))
        screen.keypad(1)
        # Set local variable
        normal = curses.A_NORMAL
        # Title of Subwindow
        screen.addstr(0, 3, self.settings[pos][0].center(12), normal)
        return screen
项目:sawtooth-validator    作者:hyperledger-archives    | 项目源码 | 文件源码
def cpprint(self, print_string, finish=False, reverse=False):
        if self.use_curses:
            try:
                attr = curses.A_NORMAL
                if reverse:
                    attr = curses.A_REVERSE
                if self.start:
                    self.scrn.erase()
                    self.start = False
                hw = self.scrn.getmaxyx()
                pos = self.scrn.getyx()
                if pos[0] < hw[0] and pos[1] == 0:
                    print_string = print_string[:hw[1] - 1]
                    self.scrn.addstr(print_string, attr)
                    if pos[0] + 1 < hw[0]:
                        self.scrn.move(pos[0] + 1, 0)
                if finish:
                    self.scrn.refresh()
                    self.start = True
            except curses.CursesError as e:
                # show curses errors at top of screen for easier debugging
                self.scrn.move(0, 0)
                self.scrn.addstr("{} {} {} {}\n".format(type(e), e, pos, hw),
                                 attr)
                self.scrn.addstr(print_string + "\n", attr)
        else:
            print print_string
项目:copycat    作者:LSaldyt    | 项目源码 | 文件源码
def addstr(self, y, x, s, attr=curses.A_NORMAL):
        try:
            self.w.addstr(y, x, s, attr)
        except Exception as e:
            if str(e) != 'addstr() returned ERR':
                raise
项目:copycat    作者:LSaldyt    | 项目源码 | 文件源码
def slipnode_name_and_attr(self, slipnode):
        if slipnode.activation == 100:
            return (slipnode.name.upper(), curses.A_STANDOUT)
        if slipnode.activation > 50:
            return (slipnode.name.upper(), curses.A_BOLD)
        else:
            return (slipnode.name.lower(), curses.A_NORMAL)
项目:copycat    作者:LSaldyt    | 项目源码 | 文件源码
def depict_bond(self, w, row, column, bond):
        slipnet = bond.ctx.slipnet
        if bond.directionCategory == slipnet.right:
            s = '-- %s -->' % bond.category.name
        elif bond.directionCategory == slipnet.left:
            s = '<-- %s --' % bond.category.name
        elif bond.directionCategory is None:
            s = '<-- %s -->' % bond.category.name
        if isinstance(bond.leftObject, Group):
            s = 'G' + s
        if isinstance(bond.rightObject, Group):
            s = s + 'G'
        w.addstr(row, column, s, curses.A_NORMAL)
        return column + len(s)
项目:keras_npi    作者:mokemokechicken    | 项目源码 | 文件源码
def ignore_error_add_str(win, y, x, s, attr=curses.A_NORMAL):
        """???????????????????????????????????????"""
        try:
            win.addstr(y, x, s, attr)
        except curses.error:
            pass
项目:Minesweeper    作者:M-Mueller    | 项目源码 | 文件源码
def open_menu(stdscr, items):
    """Opens a menu containing items and returns the selected item.
    Blocks until the user selected an item.
    """
    width = max(map(len, items)) + 20
    height = len(items*2)-1 + 4 # +2 for frame, +2 for padding
    curses.curs_set(False)
    selected = 0

    while True:
        center = (curses.COLS//2, curses.LINES//2)
        menu_rect = Rect(center[0]-width//2, center[1]-height//2, width, height)
        menu_rect = draw_frame(stdscr, menu_rect, thick_border=True)
        for i, item in enumerate(items):
            attr = curses.A_NORMAL
            if i == selected:
                attr = curses.A_STANDOUT
            stdscr.addstr(menu_rect.y + 1 + i*2, center[0] - len(item)//2, item, attr)

        c = stdscr.getch()
        if c == curses.KEY_UP:
            selected -= 1
        if c == curses.KEY_DOWN:
            selected += 1
        if c == curses.KEY_ENTER or c == 10:
            break
        selected = clamp(selected, 0, len(items)-1)
    curses.curs_set(True)
    return items[selected]
项目:Music-Scraper    作者:srivatsan-ramesh    | 项目源码 | 文件源码
def init_display():
        """
        Inits the display GUI
        """
        if not GUI.gui_stopped:
            curses.noecho()
            curses.cbreak()
            curses.start_color()
            GUI.screen.keypad(1)
            curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
            GUI.high_light_text = curses.color_pair(1)
            GUI.normal_text = curses.A_NORMAL
            curses.curs_set(0)
            GUI.refresh_values()
            GUI.position = 1
            GUI.page = 1
            GUI.box = curses.newwin(GUI.max_row + 3, curses.COLS, 0, 0)
            GUI.box.addstr(1, 1, GUI.status, GUI.high_light_text)
            GUI.add_bottom_menus()
            GUI.screen.refresh()
            GUI.box.refresh()
项目:pygram    作者:RedXBeard    | 项目源码 | 文件源码
def draw_form(self):
        super().draw_form()
        menu_advert = " " + self.__class__.MENU_KEY + ": Menu "
        x, y = self.display_menu_advert_at()
        if isinstance(menu_advert, bytes):
            menu_advert = menu_advert.decode('utf-8', 'replace')
        self.add_line(
            y, x,
            menu_advert,
            self.make_attributes_list(menu_advert, curses.A_NORMAL),
            self.columns - x
        )
项目:Otop    作者:fcbarclo    | 项目源码 | 文件源码
def WinCprint(self,y,x,msg,color=curses.A_NORMAL):
        self.lockvideo.acquire()
        try:
            #self.VWscreen.addstr(y,x,msg[:msg.find('\n')],color)
            self.VWscreen.addstr(y,x,msg,color)
            self.VWscreen.refresh()
        except:
            pass
                self.lockvideo.release()
项目:zmq-chat    作者:jnthnwn    | 项目源码 | 文件源码
def start_top_window(window, display):
    window_lines, window_cols = window.getmaxyx()
    bottom_line = window_lines - 1
    window.bkgd(curses.A_NORMAL, curses.color_pair(2))
    window.scrollok(1)
    while True:
        # alternate color pair used to visually check how frequently this loop runs
        # to tell when user input is blocking
        window.addstr(bottom_line, 1, display.recv_string())
        window.move(bottom_line, 1)
        window.scroll(1)
        window.refresh()
项目:cgroup_py    作者:rperigo    | 项目源码 | 文件源码
def runCheck(initType, scrn):
    if initType == "systemd":
        try:
            getStatus = subprocess.Popen(['systemctl', 'status', 'cgroup_py'], stdout=subprocess.PIPE)
        except subprocess.CalledProcessError as e:
            eMsg = "Unable to get status of cgroup_py daemon. Exiting!"
            scrn.addstr(1,1,eMsg)
            time.sleep(2)
            sys.exit(2)
        statlines = getStatus.communicate()[0].splitlines()
        for l in statlines:
            if "Active:" in l:
                status = l.split(':')[1]
                if 'active' in status and not 'inactive' in status:
                    pass
                else:
                    eMsg = "Cgroup_py daemon does not appear to be active. Exiting."
                    scrn.erase()
                    scrn.addstr(1,1,eMsg)
                    scrn.refresh()
                    time.sleep(2)
                    sys.exit(2)
    elif initType == "sysV":
        try:
            getStatus = subprocess.Popen(['/etc/init.d/cgroup_py', 'status'], stdout=subprocess.PIPE)
        except subprocess.CalledProcessError as e:
            eMsg = "Unable to get status of cgroup_py daemon. Exiting!"
            scrn.addstr(1,1, eMsg)
            time.sleep(2)
            sys.exit(2)
        if not "running" in getStatus.communicate()[0]:
            eMsg = "Cgroup_py daemon doesn't appear to be running. Exiting."
            scrn.addstr(1,1, eMsg, curses.A_NORMAL)
            scrn.refresh()
            time.sleep(2)
            sys.exit(2)
        else:
            print "Cgroup_py daemon found."
项目:satori-rtm-sdk-python    作者:satori-com    | 项目源码 | 文件源码
def render_chat(users, history, screen, x, y, w, h):
    for (i, a) in enumerate(history[-h:]):
        buffer = []
        if 'user' in a:
            if a['user'] in users:
                user_attr = curses.A_BOLD
            else:
                user_attr = curses.A_NORMAL
            if a['message'].startswith('/me '):
                text = '* {0} {1}'.format(a['user'], a['message'][4:])
                buffer = [
                    ('* ', curses.A_NORMAL),
                    (a['user'], user_attr),
                    (u' {0}'.format(a['message'][4:]), curses.A_NORMAL)]
            else:
                buffer = [
                    (a['user'], user_attr),
                    (u'> {0}'.format(a['message']), curses.A_NORMAL)]
        else:
            buffer = [(u'* {0}'.format(a), curses.A_NORMAL)]
        x_ = x + 1
        for (text, attr) in buffer:
            if not isinstance(text, six.binary_type):
                text = text.encode('utf8')
            screen.addstr(y + 1 + i, x_, text, attr)
            x_ += len(text.decode('utf8'))
项目:soyouhaveanidea    作者:yigitbey    | 项目源码 | 文件源码
def select_mode(self, index):
        if self.has_focus:
            if self.first_item_index == 0 and index == self.position:
                mode = curses.A_REVERSE
            elif (self.position - self.first_item_index) == index:
                mode = curses.A_REVERSE
            elif (self.position + 1 == self.last_item_index) and (index == len(self.employees) - 1):
                mode = curses.A_REVERSE
            else:
                mode = curses.A_NORMAL
        else:
            mode = curses.A_NORMAL

        return mode
项目:soyouhaveanidea    作者:yigitbey    | 项目源码 | 文件源码
def display(self):
        self.window.clear()
        while True:
            self.window.refresh()
            curses.doupdate()
            for index, item in enumerate(self.items):
                if index == self.position:
                    mode = curses.A_REVERSE
                else:
                    mode = curses.A_NORMAL

                msg = '- %s\n   (Features: %s, Design: %s)' % (item, item.features, item.design_need)
                self.window.addstr(1+index*2, 2, msg, mode)

            key = self.window.getch()

            if key in [curses.KEY_ENTER, ord('\n')]:
               if self.position == len(self.items)-1:
                   return None
               else:
                   return self.position

            if key == curses.KEY_UP:
                self.navigate(-1)

            elif key == curses.KEY_DOWN:
                self.navigate(1)
项目:new    作者:atlj    | 项目源码 | 文件源码
def create(liste):
    screen = curses.initscr()
    curses.start_color()
    curses.init_pair(1,curses.COLOR_RED, curses.COLOR_WHITE)
    s = curses.color_pair(1)
    h = curses.A_NORMAL
    pos = 0

    while 1:
        curses.noecho()
        screen.clear()
        screen.border(0)
        screen.keypad(True)
        screen.addstr(1,2,"(w)Yukari/Up (s)Asagi/Down (e)Sec", curses.A_BOLD)
        a = 0
        b = 4
        c = 3
        for oge in liste:
            if int(a/15)<1:
                if pos == a:
                    screen.addstr(b, 4, "".join(liste[a]), s)
                else:
                    screen.addstr(b, 4, "".join(liste[a]), h)
            else:
                c = c + 1
                if pos == a:
                    screen.addstr(c, 23, "".join(liste[a]), s)
                else:
                    screen.addstr(c, 23, "".join(liste[a]), h)


            a = a + 1
            b = b + 1
        screen.refresh()
        try:
            inp = screen.getkey(1,1)

            if inp == 'e':
                screen.refresh()
                curses.echo()
                screen.keypad(False)
                curses.endwin()
                break
            if inp == 'w':
                if pos > 0:
                    pos = pos - 1
                else:
                    pos = len(liste)-1
            if inp== 's':
                if pos < len(liste)-1:
                    pos = pos + 1
                else:
                    pos=0
        except Exception as e:
            pass
    return pos
项目:ssha    作者:claranet    | 项目源码 | 文件源码
def addline(self, y, string, attr):
        """
        Displays a string on the screen. Handles truncation and borders.

        """

        if y >= self.max_y:
            return

        # Display the left blank border.
        self.addstr(
            y=y,
            x=0,
            string=' ' * self.offset_x,
            attr=curses.A_NORMAL,
        )

        # Remove trailing spaces so the truncate logic works correctly.
        string = string.rstrip()

        # Truncate the string if it is too long.
        if self.offset_x + len(string) + self.offset_x > self.max_x:
            string = string[:self.max_x - self.offset_x - self.offset_x - 2] + '..'

        # Add whitespace between the end of the string and the edge of the
        # screen. This is required when scrolling, to blank out characters
        # from other lines that had been displayed here previously.
        string += ' ' * (self.max_x - self.offset_x - len(string) - self.offset_x)

        # Display the string.
        self.addstr(
            y=y,
            x=self.offset_x,
            string=string,
            attr=attr,
        )

        # Display the right blank border.
        self.addstr(
            y=y,
            x=self.max_x - self.offset_x,
            string=' ' * self.offset_x,
            attr=curses.A_NORMAL,
        )
项目: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
项目:huhamhire-hosts    作者:jiangsile    | 项目源码 | 文件源码
def process_bar(self, done, block, total, mode=1):
        """
        Draw `Process Bar` at the bottom which is used to indicate progress of
        downloading operation.

        .. note:: This method is a callback function responses to
            :meth:`urllib.urlretrieve` method while fetching hosts data
            file.

        :param done: Block count of packaged retrieved.
        :type done: int
        :param block: Block size of the data pack retrieved.
        :type block: int
        :param total: Total size of the hosts data file.
        :type total: int
        :param mode: A flag indicating the status of `Process Bar`.
            The default value of `mode` is `1`.

            ====  ====================================
            mode  `Process Bar` status
            ====  ====================================
            1     Downloading operation is processing.
            0     Not downloading.
            ====  ====================================
        :type mode: int
        """
        screen = self._stdscr.subwin(2, 80, 20, 0)
        screen.bkgd(' ', curses.color_pair(4))
        normal = curses.A_NORMAL
        line_width = 76
        prog_len = line_width - 20
        # Progress Bar
        if mode:
            done *= block
            prog = 1.0 * prog_len * done / total
            progress = ''.join(['=' * int(prog), '-' * int(2 * prog % 2)])
            progress = progress.ljust(prog_len)
            total = CommonUtil.convert_size(total).ljust(7)
            done = CommonUtil.convert_size(done).rjust(7)
        else:
            progress = ' ' * prog_len
            done = total = 'N/A'.center(7)
        # Show Progress
        prog_bar = "[%s] %s | %s" % (progress, done, total)
        screen.addstr(1, 2, prog_bar, normal)
        screen.refresh()
项目:Music-Scraper    作者:srivatsan-ramesh    | 项目源码 | 文件源码
def main():
    """
    The entry point for the app. Called when music-scraper is typed in terminal.
    Starts the GUI and starts the scraping process after the input is given
    """
    curses.initscr()
    if curses.COLS < 80 or curses.LINES < 5:
        curses.endwin()
        print('Terminal\'s dimensions are too small')
        return

    process = CrawlerProcess({'LOG_ENABLED': False})

    def gui_input(screen):
        GUI.screen = screen
        curses.start_color()
        GUI.screen.keypad(1)
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
        GUI.high_light_text = curses.color_pair(1)
        GUI.normal_text = curses.A_NORMAL
        GUI.box = curses.newwin(curses.LINES, curses.COLS, 0, 0)
        GUI.message = GUI.get_input()

    curses.wrapper(gui_input)
    s = request.quote(GUI.message)

    MusicSpider.start_urls = [
        "http://www.google.com/search?q=" + s,
    ]
    process.crawl(MusicSpider)
    thread = GUIThread(process, start_gui)
    thread.start()
    process.start()
    if not GUI.gui_stopped:
        if len(GUI.strings) == 0:
            GUI.box.erase()
            GUI.box.addstr(1, 1, "No Results Found... Try with Some other keywords.", GUI.high_light_text)
            GUI.add_bottom_menus()
            GUI.screen.refresh()
            GUI.box.refresh()
        else:
            GUI.box.addstr(curses.LINES - 2, 1, "Completed Scraping !!", GUI.high_light_text)
            GUI.add_bottom_menus()
            GUI.screen.refresh()
            GUI.box.refresh()
项目:vpn-fetch    作者:Flynston    | 项目源码 | 文件源码
def set_list(self, node):
        self.win.erase()
        highlighted = node.highlighted

        if not node.item_list:
            no_data_str = "no VPN data"
            self.win.addstr(self.height//2,(self.width-len(no_data_str))//2,
                                no_data_str)
            self.win.refresh()
            return

        list_len = len(node.item_list)
        half_win_height = self.height//2

        if highlighted < half_win_height or list_len < self.height:
            left = 0
            right = min(list_len, self.height)
        elif highlighted + half_win_height < list_len:
            left = highlighted - half_win_height
            right = highlighted + half_win_height
        else:
            left = list_len - self.height
            right = min(highlighted + half_win_height, list_len)        

        for index in range(left, right):
            try:
                item = node.item_list[index]
            except IndexError:
                self.win.addstr("Index out of range!")
                break
            text_atr = curses.A_REVERSE if index == highlighted else curses.A_NORMAL
            left_str = str(item[0])
            if isinstance(item[1], int):
                right_str = str(item[1])
            else:
                right_str = "{:.2f}".format(item[1])

            left_str = left_str if len(left_str)+len(right_str) < self.width else left_str[:self.width-len(right_str)-3]+'~'
            left_str = left_str.ljust(self.width-len(right_str)-1)  
            item_str = "{}{}".format(left_str, right_str) 
            self.win.addstr(index-left, 0, item_str, text_atr)

        self.win.refresh()