Пример #1
0
def main(screen):
    """screen is a curses screen passed from the wrapper"""

    while True:
        event = screen.getch()
        if event:
            textpad.Textbox(curses.newwin(1, 13, 4, 0),
                            insert_mode=True).edit()
            textpad.Textbox(curses.newwin(1, 13, 4, 16),
                            insert_mode=True).edit()
            screen.refresh()
Пример #2
0
    def display_textpad(self, upper_left_y, nblines, nbcols):
        """

            Display a textpad enclosed in a rectangle, so it is visible.

            Arguments:

            upper_left_y: vertical coordinate of keypad upper left corner.

            nb_lines: number of lines of the keypad

            nb_cols: number of max of authorized characters + 1 for Curses

            Returns:

            content: values on ASCII format typed by the user.

            """
        self.win = self.inner_left_window.derwin(nblines, nbcols, upper_left_y,
                                                 1)
        self.win.clear()
        textpad.rectangle(self.inner_left_window, upper_left_y - 1, 0,
                          upper_left_y + nblines, nbcols + 1)
        curses.curs_set(1)
        self.win.refresh()
        box = textpad.Textbox(self.win, insert_mode=True)
        self.inner_left_window.refresh()
        content = box.edit()
        curses.curs_set(0)
        return content
Пример #3
0
def input_n(cursor, scr_bottom, max_stock_range, stock_list, scr_dim):

    stock_input = None
    curses.start_color()
    curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLUE)
    stock_win = curses.newwin(1, 10, scr_dim[0] - 1, 0)
    stock_win.bkgd(curses.color_pair(5))
    stock_box = textpad.Textbox(stock_win)
    stock_win.refresh()
    scr_bottom.addstr(0, curses.COLS - 20, "   [Enter]Save/Exit")
    scr_bottom.refresh()
    stock_input = stock_box.edit()
    stock_input = stock_input.upper()

    if str(stock_input) != "" and str(stock_input) not in stock_list:
        stocks.add_stock_code(str(stock_input))
        total_stocks = len(stock_list) + 1
        if total_stocks > scr_dim[0] - 6:
            cursor[1] = total_stocks
            cursor[2] = max_stock_range
        else:
            cursor[1] = max_stock_range + 1
            cursor[2] = cursor[1]
    elif str(stock_input) or (
        (str(stock_input)[0:(len(str(stock_input)) - 2)]
         and str(stock_input)[len(str(stock_input))])) in stock_list:
        total_stocks = len(stock_list)
        stock_pos = stock_list.index(str(stock_input)) + 1
        cursor[1] = stock_pos
        if total_stocks > max_stock_range:
            cursor[2] = 1
        else:
            cursor[2] = cursor[1]

    return cursor
Пример #4
0
def text_input(window):
    """
    Transform a window into a text box that will accept user input and loop
    until an escape sequence is entered.

    If enter is pressed, return the input text as a string.
    If escape is pressed, return None.
    """

    window.clear()
    curses.curs_set(2)
    textbox = textpad.Textbox(window, insert_mode=True)

    def validate(ch):
        "Filters characters for special key sequences"
        if ch == ESCAPE:
            raise EscapePressed
        return ch

    # Wrapping in an exception block so that we can distinguish when the user
    # hits the return character from when the user tries to back out of the
    # input.
    try:
        out = textbox.edit(validate=validate)
        out = out.strip()
    except EscapePressed:
        out = None

    curses.curs_set(0)
    return out
Пример #5
0
    def login_screen(self):
        """
        This method will render the screen used that will ask the user username/id
        and then login if everything asked is correct
        """
        login_title = "Please login using your Spotify username/id:\n"
        login_screen = newwin(0, 0)
        login_screen.box()
        v_dim, h_dim = login_screen.getmaxyx()

        login_screen.addstr(round(v_dim / 2),
                            round((h_dim - len(login_title)) / 2), login_title)

        username_input = login_screen.subwin(1, 44, round(v_dim / 2 + 1),
                                             round((h_dim - 44) / 2))
        username_text_input = textpad.Textbox(username_input)
        username_input.refresh()

        login_screen.addstr(v_dim - 1, h_dim - 20, "[Enter]Submit")
        login_screen.refresh()

        username = username_text_input.edit()

        if str(username) != '':
            oauth_win = newwin(0, 0)
            oauth_win.box()
            oauth_win.addstr(v_dim - 1, h_dim - 20, "[Enter]Submit")
            oauth_win.refresh()

            self.player.get_new_token(username)

        endwin()
Пример #6
0
 def __init__(self, screen, y, x):
     self.screen = screen
     self.y = y
     self.x = x
     self.height, self.width = screen.getmaxyx()
     #self.textpad = curses.newpad(16, self.width)
     self.textbox = textpad.Textbox(self.screen, insert_mode=True)
def test_textpad(stdscr, insert_mode=False):
    ncols, nlines = 8, 3
    uly, ulx = 3, 2
    if insert_mode:
        mode = 'insert mode'
    else:
        mode = 'overwrite mode'

    stdscr.addstr(uly-3, ulx, "Use Ctrl-G to end editing (%s)." % mode)
    stdscr.addstr(uly-2, ulx, "Be sure to try typing in the lower-right corner.")
    win = curses.newwin(nlines, ncols, uly, ulx)
    textpad.rectangle(stdscr, uly-1, ulx-1, uly + nlines, ulx + ncols)
    stdscr.refresh()

    box = textpad.Textbox(win, insert_mode)
    contents = box.edit()
    stdscr.addstr(uly+ncols+2, 0, "Text entered in the box\n")
    stdscr.addstr(repr(contents))
    stdscr.addstr('\n')
    stdscr.addstr('Press any key')
    stdscr.getch()

    for i in range(3):
        stdscr.move(uly+ncols+2 + i, 0)
        stdscr.clrtoeol()
Пример #8
0
 def init_editor(self):
     self.input_window = Window([x + 1 for x in self._pos],
                                [x - 2 for x in self._size],
                                title=None,
                                border=False)
     self.input_window._win.keypad(1)
     self.editor = textpad.Textbox(self.input_window._win)
Пример #9
0
def main(screen):
    global width, height, index
    height, width = screen.getmaxyx()

    win = curses.newwin(1, width, height - 1, 0)
    header = curses.newwin(1, width, 0, 0)
    content = curses.newwin(height - 2, width, 1, 0)

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
    curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)

    _header(header, 'robin [0737557200]', 'connected=true')

    field = textpad.Textbox(win)

    while (True):
        win.erase()
        win.addstr(0, 1, "$ ", curses.color_pair(3))
        win.refresh()

        field.edit(exit_on_enter)
        text = field.gather().replace('$ ', '', 1).strip()

        _parse(content, text)

        if index > height - 6:
            index = 2
Пример #10
0
 def clear_box(self):
     self.screen.move(self.window_height - 2, 2)
     self.screen.clrtoeol()
     textpad.rectangle(self.screen, self.window_height - 3, 0,
                       self.window_height - 1, self.window_width - 2)
     win = curses.newwin(1, self.window_width - 4, self.window_height - 2,
                         2)
     self.box = textpad.Textbox(win, True)
Пример #11
0
def new_query_input(scr_dim, scr_query_main):

    new_query_window = curses.newwin(scr_dim[0] - 10, scr_dim[1] - 6, 6, 3)
    new_query_box = textpad.Textbox(new_query_window)
    new_query_window.refresh()
    new_user_query = new_query_box.edit()

    return new_user_query
Пример #12
0
def new_execution_input(scr_dim):

    new_execution_window = curses.newwin(1, scr_dim[1] - 28, 5, 40)
    new_execution_box = textpad.Textbox(new_execution_window)
    new_execution_window.refresh()
    new_execution_input = new_execution_box.edit()

    return new_execution_input
Пример #13
0
def save_database_name(scr_dim, scr_bottom):

    new_save_window = curses.newwin(1, scr_dim[1] - 10, scr_dim[0] - 3, 8)
    new_save_box = textpad.Textbox(new_save_window)
    new_save_window.refresh()
    scr_bottom.addstr(0, 1, "Save:", curses.A_REVERSE)
    scr_bottom.refresh()
    new_save_input = new_save_box.edit()

    return new_save_input
Пример #14
0
def textBox(stdscr, text_y: int, text_x: int) -> str:
    ncols, nlines = 18, 1  #العرض، والطول
    box_y, box_x = text_y, text_x + 1  # الاحداثيات

    win = curses.newwin(nlines, ncols, box_y, box_x)  #انشاء النافذة
    textpad.rectangle(stdscr, box_y - 1, box_x - 1, box_y + nlines,
                      box_x + ncols)  #السماح بالكتابة عليها
    box = textpad.Textbox(win)
    stdscr.refresh()
    return box.edit()
Пример #15
0
def find_column_input(scr_bottom, scr_dim):

    new_find_column_window = curses.newwin(1, scr_dim[1] - 16, scr_dim[0] - 3,
                                           14)
    new_find_column_box = textpad.Textbox(new_find_column_window)
    scr_bottom.addstr(0, 1, "Column:", curses.A_REVERSE)
    scr_bottom.refresh()
    new_find_column_window.refresh()
    new_column_input = new_find_column_box.edit()

    return new_column_input
Пример #16
0
def find_value_input(scr_bottom, scr_dim):

    new_find_value_window = curses.newwin(1, scr_dim[1] - 16, scr_dim[0] - 2,
                                          14)
    new_find_value_box = textpad.Textbox(new_find_value_window)
    scr_bottom.addstr(1, 1, "Input:", curses.A_REVERSE)
    scr_bottom.refresh()
    new_find_value_window.refresh()
    new_value_input = new_find_value_box.edit()

    return new_value_input
Пример #17
0
 def __init__(self, stdscr):    
     self.screen = stdscr
     self.screen.nodelay(True)
     self.header_lines = 1
     self.win_x = 2
     self.win_y = self.header_lines+1
     self.head_y = 0
     self.foot_y = self.win_y+2
     self.win = curses.newwin(1, 16, self.win_y, self.win_x)
     textpad.rectangle(self.screen, self.win_y-1, self.win_x-1, self.win_y+1, self.win_x+16)
     self.box = textpad.Textbox(self.win, 'insert mode')
Пример #18
0
    def inputCommand(self):
        self.cmdTextbox.move(0, 0)

        tb = textpad.Textbox(self.cmdTextbox)
        text = tb.edit(self.cmdValidate)

        if not self.cancelCommand:
            self.rcon.sendCommand(text.strip())

        self.cancelCommand = False

        return self.getMainMenu()
Пример #19
0
def update_cell(scr_dim, original):

    #curses.start_color()
    #curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    new_entry_window = curses.newwin(1, scr_dim[1] - 2, scr_dim[0] - 3, 1)
    #new_entry_window.bkgd(curses.color_pair(1))
    new_entry_box = textpad.Textbox(new_entry_window)
    new_entry_window.addstr(0, 0, str(original), curses.A_REVERSE)
    new_entry_window.refresh()
    new_entry = new_entry_box.edit()

    return new_entry
Пример #20
0
 def __init__(self, screen):
     self.mode = 'move'
     self.screen = screen
     self.textwin = curses.newwin(1, 78, 21, 1)
     #		self.outputwin = curses.newwin(3,80,23,0)
     textpad.rectangle(self.screen, 0, 0, 20, 80)
     textpad.rectangle(self.screen, 20, 0, 22, 80)
     self.pad = curses.newpad(20, 80)
     self.textpad = textpad.Textbox(self.textwin)
     self.game = Game()
     self.output = ''
     self.redraw()
Пример #21
0
def add_new_row(column, scr_dim, scr_bottom):

    new_row_window = curses.newwin(1, scr_dim[1] - 16, scr_dim[0] - 3, 14)
    new_row_box = textpad.Textbox(new_row_window)
    new_row_window.refresh()
    scr_bottom.clear()
    scr_bottom.addstr(0, 1, str(column[1]), curses.A_REVERSE)
    scr_bottom.addstr(1, 1, "Type: " + str(column[2]))
    scr_bottom.refresh()
    new_row_input = new_row_box.edit()

    return new_row_input
Пример #22
0
def open_new_database(scr_top, scr_dim):

    curses.start_color()
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
    new_database_window = curses.newwin(1, scr_dim[1], 1, 0)
    new_database_window.bkgd(curses.color_pair(1))
    new_database_box = textpad.Textbox(new_database_window)
    new_database_window.refresh()
    scr_top.addstr(2, 1,
                   "Open new database. Leave blank and hit enter to close")
    new_database = new_database_box.edit()

    return new_database
Пример #23
0
 def render(self, status=None):
     win = curses.newwin(2, self.available_space - 2, self.starty,
                         self.startx)
     box = textpad.Textbox(win, insert_mode=True)
     curses.echo()
     curses.nocbreak()
     self.stdscr.refresh()
     contents = box.edit(self.__enter_is_terminate)
     win.clrtoeol()
     del win
     self.handle_submit(contents)
     curses.noecho()
     curses.cbreak()
def main(stdscr):
    win = curses.newwin(6, 23, 4, 1)
    pad = textpad.rectangle(stdscr, 3, 0, 10, 24)
    stdscr.refresh()
    win.addstr("Pre-Inputted Data")
    box = textpad.Textbox(win, insert_mode=False)

    box.edit()
    contents = box.gather().strip()

    stdscr.clear()

    stdscr.addstr(repr(contents))
    stdscr.getch()
Пример #25
0
 def render(self, status=None):
     curses.echo()
     curses.nocbreak()
     if self.win:
         del self.win
     self.win = curses.newwin(2, self.available_space - 2, self.starty,
                              self.startx)
     self.box = textpad.Textbox(self.win, insert_mode=True)
     self.stdscr.refresh()
     self.contents = self.box.edit(self.__enter_is_terminate)
     del self.win
     self.win = None
     self.handle_submit(self.contents)
     curses.noecho()
     curses.cbreak()
Пример #26
0
 def values_textpad(self, stdscr, key, text, insert_mode=False, validator= None, confermValue='' ):
     cord_x,cord_y = self.screen.getmaxyx()
     ncols, nlines = cord_y - 4, 1
     uly, ulx = cord_x - 3, 2
     if validator is None:
         validator =  self.enter_validator
     text_info = "{} {} :".format(text, key)
     stdscr.addstr(uly, ulx, confermValue, curses.color_pair(8))
     stdscr.addstr(uly-1, ulx, text_info, curses.color_pair(3))
     win = curses.newwin(nlines, ncols-len(text_info), uly-1, ulx+len(text_info))
     textpad.rectangle(stdscr, uly-3, ulx-1, uly + nlines, ulx + ncols)
     stdscr.refresh()
     box = textpad.Textbox(win, insert_mode)
     contents = box.edit(validator).strip()
     return str(contents)
    def text_input(
        self,
        prompt: str,
        x_pos: int,
        y_pos: int,
        length: int,
        color_pair_progress: int = curses.A_UNDERLINE | curses.A_BOLD,
        color_pair_done: int = curses.A_BOLD,
    ) -> str:
        """
        Get some input from the user, and return it. Similar to built-in input(), but for curses

        :param color_pair_progress: A curses color pair to show while the user can enter text.
        Default is underlined and bold.
        :param color_pair_done: A curses color pair to show when the user is done entering text.
        Default is bold
        :param prompt: A short text inviting the user to input something.
        :param x_pos: The x position where the prompt should be displayed
        :param y_pos: The y position where the prompt should be displayed
        :param length: The length of prompt. This will also limit the length of returned text.
        length - 1 characters can be returned.
        :return: The text imputed by the user, terminated by a carriage return.
        """
        logger.info("Getting text input at (%s, %s) of max length %s", x_pos,
                    y_pos, length)
        curses.curs_set(2)

        self.addtext(x_pos, y_pos, prompt)
        self.refresh()

        correct_x_pos = x_pos + len(prompt)

        win = curses.newwin(1, length, y_pos, correct_x_pos)
        win.bkgd(" ", color_pair_progress)

        pad = textpad.Textbox(win, insert_mode=True)
        text = pad.edit()
        text = text.strip()

        win.bkgd(" ", curses.A_NORMAL)
        win.refresh()
        win = curses.newwin(1, len(text) + 1, y_pos, correct_x_pos)
        win.addstr(0, 0, text, color_pair_done)
        win.refresh()

        curses.curs_set(0)
        logger.info("The user entered: %s", text)
        return text
Пример #28
0
    def show(self, mainscreen):
        # Control flow:
        #   alphanum and enter are reserved for task entry
        #   entering "q" causes the program to save and quit
        #   entering "done" causes the program to go back to main menu

        ENTER = ord('\n')
        ### USE TEXTPAD

        textentry = textpad.Textbox(mainscreen)
        userinput = textentry.edit()

        return userinput

        if functionality['save_each']:  # TODO
            pass
        if functionality['show_old']:  # TODO
            pass
Пример #29
0
    def text_input(self, window, allow_resize=False):
        """
        Transform a window into a text box that will accept user input and loop
        until an escape sequence is entered.

        If the escape key (27) is pressed, cancel the textbox and return None.
        Otherwise, the textbox will wait until it is full (^j, or a new line is
        entered on the bottom line) or the BEL key (^g) is pressed.
        """

        window.clear()

        # Set cursor mode to 1 because 2 doesn't display on some terminals
        self.curs_set(1)

        # Keep insert_mode off to avoid the recursion error described here
        # http://bugs.python.org/issue13051
        textbox = textpad.Textbox(window)
        textbox.stripspaces = 0

        def validate(ch):
            "Filters characters for special key sequences"
            if ch == self.ESCAPE:
                raise exceptions.EscapeInterrupt()
            if (not allow_resize) and (ch == curses.KEY_RESIZE):
                raise exceptions.EscapeInterrupt()
            # Fix backspace for iterm
            if ch == curses.ascii.DEL:
                ch = curses.KEY_BACKSPACE
            return ch

        # Wrapping in an exception block so that we can distinguish when the
        # user hits the return character from when the user tries to back out
        # of the input.
        try:
            out = textbox.edit(validate=validate)
            if isinstance(out, six.binary_type):
                out = out.decode('utf-8')
        except exceptions.EscapeInterrupt:
            out = None

        self.curs_set(0)
        return self.strip_textpad(out)
Пример #30
0
    def _initialize(self):
        if not self.screen:
            # if wrapper has been used, we don't need this
            self.screen = curses.initscr()
            curses.noecho()
            curses.cbreak()

        # get the current size of screen
        (y, x) = self.screen.getmaxyx()

        # leave last lines for prompt
        self.output_window = self.screen.subwin(y - 2, x, 0, 0)
        self.prompt_window = self.screen.subwin(1, x, y - 2, 0)
        self.edit = textpad.Textbox(self.prompt_window, insert_mode=True)

        # let output_window scroll by itself when number of lines are more than window size
        self.output_window.scrollok(True)
        self.prompt_window.scrollok(
            True)  #FIX: not working with textpad.Textbox