Example #1
0
    def setup(self):
        screen = self.screen
        height, width = self.height, self.width = self.screen.getmaxyx()

        # Instruction Pointer and Relative Base
        rectangle(screen, 0, OUTPUT_WIDTH + 3, 2, width - 2)
        self.pointer_win = curses.newwin(1, width - OUTPUT_WIDTH - 6, 1,
                                         OUTPUT_WIDTH + 4)

        # Output
        rectangle(screen, 0, 0, height - 1, OUTPUT_WIDTH + 2)
        self.output_win = curses.newwin(height - 2, OUTPUT_WIDTH, 1, 1)
        self.output = deque(maxlen=height - 2)

        # Array Vis
        rectangle(screen, 3, OUTPUT_WIDTH + 3, height - 4, width - 2)
        self.array_win = curses.newwin(height - 8, width - OUTPUT_WIDTH - 8, 4,
                                       OUTPUT_WIDTH + 5)
        self.array_win.attron(curses.color_pair(1))
        self.cells_per_row = (width - OUTPUT_WIDTH - 8) // CELL_WIDTH
        self.cells = self.cells_per_row * (height - 8)

        # Input
        rectangle(screen, height - 3, OUTPUT_WIDTH + 3, height - 1, width - 2)

        # Input line
        self.input_win = curses.newwin(1, width - OUTPUT_WIDTH - 6, height - 2,
                                       OUTPUT_WIDTH + 4)
        self.text_in = Textbox(self.input_win)

        self.screen.refresh()
        curses.doupdate()
    def create_textbox(self, color_code, default_value=None, validate=None):
        is_valid = False
        data = None
        while(not is_valid):
            self._window.hline(self.y + 1, self.x, "_", 16)
            self._window.refresh()

            new_win = curses.newwin(self.h, self.w,
                                    self.y + self.header_height, self.x)
            text = Textbox(new_win, insert_mode=False)

            if default_value:
                for i in default_value:
                    text.do_command(ord(i))

            data = text.edit()
            if not validate:
                is_valid = True
            elif getattr(Validation, validate)(data.strip()):
                is_valid = True
            else:
                col_code_attr = ColorCode().get_color_pair(3)
                self._obj.on_attr(col_code_attr)
                self._window.addstr(self.header_height - 1,
                                    3,
                                    f"Error: Invalid {validate}"
                                    f" {data.strip()} Please re-enter")
                self._obj.off_attr(col_code_attr)
                self._window.refresh()
        return data
Example #3
0
def init():
    global stdscr, chatlog_win, input_win, players_win, input_textbox

    stdscr = curses.initscr()
    curses.cbreak()
    curses.noecho()
    stdscr.keypad(1)

    h, w = stdscr.getmaxyx()
    PNW = 20  # player name width
    INH = 4   # input window height

    stdscr.vline(0, w - PNW - 1, curses.ACS_VLINE, h)
    stdscr.hline(h - INH - 1, 0, curses.ACS_HLINE, w - PNW - 1)

    chatlog_win = curses.newwin(h - INH - 1, w - PNW - 1, 0, 0)
    input_win = curses.newwin(INH, w - PNW - 1, h - INH, 0)
    players_win = curses.newwin(h, PNW, 0, w - PNW)

    chatlog_win.idlok(1)
    chatlog_win.scrollok(1)

    players_win.idlok(1)
    players_win.scrollok(1)

    input_textbox = Textbox(input_win)
    input_textbox.stripspaces = True

    stdscr.noutrefresh()
    input_win.noutrefresh()
    players_win.noutrefresh()
    chatlog_win.noutrefresh()

    curses.doupdate()
Example #4
0
def main() :
    choice = raw_input("Enter filename : ")
    screen = curses.initscr()
    curses.noecho()

    with open(choice, 'w+') as rf:
        filedata = rf.read()
        
    editwin = curses.newwin(20,70, 2,1)
    editwin.addstr(1,1,filedata)
    rectangle(screen, 1,0, 1+20+1, 1+70+1)
    screen.refresh()

    box = Textbox(editwin)

    # Let the user edit until Ctrl-G is struck.
    box.edit()

    # Get resulting contents
    message = box.gather()
        
    curses.endwin()

    with open(choice,'w+') as wf:
        wf.write(message)
Example #5
0
def user_submit(auth, assignment, stdscr, contents=''):
    stdscr.clear()
    stdscr.addstr(0, 0, "Which file to submit: (hit ctrl-g to finish)")

    editwin = curses.newwin(5, 30, 2, 1)
    rectangle(stdscr, 1, 0, 1 + 5 + 1, 1 + 30 + 1)
    stdscr.addstr(1 + 5 + 2, 0, contents)
    stdscr.refresh()

    box = Textbox(editwin)

    box.edit()
    message = box.gather().rstrip()
    if message.startswith("!ls"):
        try:
            contents = repr(os.listdir(message[4:]))
        except:
            contents = ''
    try:
        open(message, 'rb').close()
    except:
        return user_submit(auth, assignment, stdscr, contents)

    stdscr.clear()
    stdscr.addstr(
        0, 0, "What should the submission be titled? (hit ctrl-g to finish)")
    editwin = curses.newwin(5, 30, 2, 1)
    rectangle(stdscr, 1, 0, 1 + 5 + 1, 1 + 30 + 1)
    stdscr.refresh()

    box = Textbox(editwin)
    box.edit()

    submit(auth, assignment, message, box.gather().rstrip())
Example #6
0
 def editTextField(self, editwin):
     self.setCursorVisibility(1)
     self.textbox = Textbox(editwin, insert_mode=True)
     newname = self.textbox.edit(self.deleteKeyPressHandler).strip()
     self.textbox = ''
     self.setCursorVisibility(0)
     return newname
Example #7
0
def insertFile():
    global cursor, stdscr, theWorld


    title = "/\\\\ Set field name //\\"
    win = curses.newwin(3, theWorld.w - 10, theWorld.h / 2 - 1, 6)
    win.box()
    size = win.getmaxyx()
    win.addstr(0, size[1] / 2 - len(title) / 2, title)
    win.refresh()
    win = curses.newwin(1, theWorld.w - 12, theWorld.h / 2, 7)
    t = Textbox(win)
    filename = t.edit()
    f = file(filename[:-1])

    x, y = theWorld.player.pos

    for line in f.readlines():
        for letter in line:
            theWorld.player.gMap.setAscii(x, y, letter)
            theWorld.player.gMap.setFG(x, y, foreground)
            theWorld.player.gMap.setBG(x, y, background)
            theWorld.player.gMap.setWalkable(x, y, walkable)
            x += 1
        x = theWorld.player.pos[0]
        y += 1
Example #8
0
    def printSender(self,
                    pad: textpad.Textbox = None,
                    colour: int = None,
                    append: str = None) -> textpad.Textbox:
        """
		Add a Sender to the message.

		Args:
			pad (textpad.Textbox, optional): Defaults to self.pad. The pad to write to.
			colour (int, optional): Defaults to self.senderColour. The colour to write in.
			append (str, optional): Defaults to None. If supplied, appends the string to the pad in the same colour.

		Returns:
			textpad.Textbox: The pad written to.
		"""

        if colour is None: colour = self.senderColour
        if pad is None: pad = self.pad
        try:
            sender = getMember(self.room, self.event['sender']).displayname
        except Exception as e:
            message_logger.error('Exception in printSender: ' + str(e))
            sender = self.event['sender']
        if append is not None: sender += append
        pad.addstr(sender, colour)
        return (pad)
Example #9
0
def main_control(screen, event, inception_level):
    if event == ord("Q"):
        curses.endwin()
        exit(0)
    if event == ord("D"):
        window_for_done_task(screen)
    if event == ord("T"):
        window_for_undone_task(screen)
    if event == ord("F"):
        curses.flash()
    if event == ord("A"):
        editwin = curses.newwin(1,
                                screen.getmaxyx()[1]-6,
                                screen.getmaxyx()[0]-4,
                                1
                                )
        rectangle(screen,
                  screen.getmaxyx()[0]-5,
                  0, screen.getmaxyx()[0]-3,
                  screen.getmaxyx()[1]-5)
        screen.refresh()
        box = Textbox(editwin)
        # Let the user edit until Ctrl-G is struck.
        box.edit()
        # Get resulting contents
        message = box.gather()
        Tache().ajouter_tache(message, datetime.now())
        screen.clear()
        print_main_screen(screen)
        print_taches(screen, Tache().get_tache_undone(), "Taches a faire :")
        deal_with_selected(screen, 33, 45, Tache().get_tache_undone(),
                           window_for_undone_task)
Example #10
0
class MiniWindow:
    def __init__(self):
        self.__mini_window = curses.newwin(1, curses.COLS, curses.LINES - 1, 0)
        self.__mini_window.keypad(True)
        self.__mini_window_tb = Textbox(self.__mini_window)

    def display_message_in_mini_buffer(self, msg):
        self.__mini_window.erase()
        self.__mini_window.addstr(msg)
        self.__mini_window.refresh()

    def get_file_name(self):
        self.display_message_in_mini_buffer('file to save in: ')

        filename = ""
        while True:
            mini_buffer_ch = self.__mini_window.getch()
            if mini_buffer_ch == 24:
                self.__mini_window.erase()
                self.__mini_window.refresh()
                return None

            elif mini_buffer_ch == 10:
                return filename

            else:
                self.__mini_window_tb.do_command(mini_buffer_ch)
                filename += chr(mini_buffer_ch)
Example #11
0
def main(screen):
    while True:
        screen.clear()

        # command help
        screen.addstr(padding + 14, padding + 0, '* Commands')
        screen.addstr(padding + 15, padding + 0,
                      'Ctrl-G or Enter : send request / Ctrl-C : exit')

        # current resource usage
        screen.addstr(padding + 0, padding + 0, '* Current Usage of Entries')
        printResourceBar(screen)

        # input request
        screen.addstr(padding + 9, padding + 0, '* Enter the request ')
        edit_win = curses.newwin(1, BAR_SIZE, 11 + padding, 1 + padding)
        rectangle(screen, padding + 10, padding + 0, padding + 1 + 10 + 1,
                  padding + 1 + BAR_SIZE + 1)
        screen.refresh()
        box = Textbox(edit_win)
        box.edit()
        input_text = box.gather()

        if input_text != '':
            translateRules(input_text)
            populateRulesetToDP()  # if translation succeed
Example #12
0
def main(stdscr):
        
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(1)

    rT = threading.Thread(target=receiving, args=("RecvThread", s))
    rT.start()

    put = curses.newwin(4, 66, 20, 0)
    put.border(0)
    put.addstr(1, 1, nick+' >> ')
    put.addstr(3, 1, 'Enter to send------------------------------------------q to exit')
    put.refresh()

    boxbox = curses.newwin(1, 51, 21, 14)
    boxbox.refresh()
    box = Textbox(boxbox)
    message = ''
    while message != 'q ':
        box.edit()
        message = str(box.gather())
        if message != '':
            s.sendto(nick + " >> " + message, server)
            boxbox.clear()
        time.sleep(0.2)
    s.sendto('3 '+nick, server)
def input():
    editwin = curses.newwin(1, 60, 7, 3)
    rectangle(screen, 6, 2, 6 + 1 + 1, 2 + 60 + 1)
    screen.refresh()
    box = Textbox(editwin)
    box.edit()
    return box.gather()
Example #14
0
def loadPrintScreen(data): #Screen and actions for loading external files
  data.stdscr.clear()
  data.stdscr.addstr(0, 0, "Enter board file name (including '.txt')" +\
    " and press 'enter'")
  boxH,boxW = 1,30
  startY, startX = 3,1
  editwin = curses.newwin(boxH,boxW, startY,startX)
  rectULY, rectULX = 2, 0
  rectangle(data.stdscr, rectULY, rectULX, rectULY+boxH+1, rectULX+boxW+1)
  data.stdscr.addstr(rectULY+boxH+2,0, "Max size is %d x %d." % data.boardMax \
   + "If loaded board "+\
    "is smaller, rows and columns will be added. If too large, rows and"+\
    " columns will be removed until max dimensions acheived. If more space is"+\
    " needed, quit and resize the console window/reduce font size.")
  data.stdscr.refresh()

  box = Textbox(editwin)

  # Let the user edit until Ctrl-G is struck.
  box.edit()

  # Get resulting contents
  userInput = box.gather()
  try:#attempt to load user generated board
    data.lifeBoard = loadBoardState(userInput)
    data.loadedBoardTitle = userInput
    data.boardLoaded = True
    checkBoardSize(data) #fit to size
  except: #Something went wrong...
    data.stdscr.addstr(1,0, "Entered board state not found. "\
      +"Returning to main menu.", curses.color_pair(1) | curses.A_STANDOUT)
    curses.beep()
    data.stdscr.refresh()
    curses.napms(2000)
  data.loadScreen = False
Example #15
0
def init():
    global stdscr, chatlog_win, input_win, players_win, input_textbox

    stdscr = curses.initscr()
    curses.cbreak()
    curses.noecho()
    stdscr.keypad(1)

    h, w = stdscr.getmaxyx()
    PNW = 20  # player name width
    INH = 4  # input window height

    stdscr.vline(0, w - PNW - 1, curses.ACS_VLINE, h)
    stdscr.hline(h - INH - 1, 0, curses.ACS_HLINE, w - PNW - 1)

    chatlog_win = curses.newwin(h - INH - 1, w - PNW - 1, 0, 0)
    input_win = curses.newwin(INH, w - PNW - 1, h - INH, 0)
    players_win = curses.newwin(h, PNW, 0, w - PNW)

    chatlog_win.idlok(1)
    chatlog_win.scrollok(1)

    players_win.idlok(1)
    players_win.scrollok(1)

    input_textbox = Textbox(input_win)
    input_textbox.stripspaces = True

    stdscr.noutrefresh()
    input_win.noutrefresh()
    players_win.noutrefresh()
    chatlog_win.noutrefresh()

    curses.doupdate()
Example #16
0
File: cli.py Project: kondziu/6p
    def _display(self, text=None, edit=True):
        self._window.refresh()
        self._window.border()

        text_width = self._width - 2
        text_height = self._height - 2

        self._window.addstr(0, 1, "[%s]" % "Your answer"[0:text_width - 2])
        self._window.addstr(self._height - 1, text_width - 8, "[Ctrl+G]")
        #self._window.move(1,1)
        self._window.refresh()

        if edit:
            temporary_edit_window = curses.newwin(text_height, text_width,
                                                  self._y + 1, self._x + 1)
            curses.curs_set(True)

            edit_box = Textbox(temporary_edit_window)
            edit_box.edit()
            curses.curs_set(False)
            content = edit_box.gather().strip()
            del temporary_edit_window

            return content

        else:
            return None
Example #17
0
def draw_edit_box(menu_man, win_man, build_opts):
    ## BUGGY (resize + too small windows not handled properly)
    win_man.resize_wins("edit_mode")
    win_man.refresh_all()
    curses.curs_set(1)
    # Add title of the box
    win_man._field_win.bkgd(" ", curses.color_pair(5))
    win_man._field_win.addstr(0, 0, menu_man.get_verbose_cur_field(), curses.color_pair(5))
    win_man._field_win.chgat(0, 0, -1, curses.color_pair(1))
    # Create the window that will holds the text
    (YMAX, XMAX) = win_man._field_win.getmaxyx()
    (YBEG, XBEG) = win_man._field_win.getparyx()
    text_win = curses.newwin(YMAX, XMAX, YBEG + 6, XBEG + 5)
    text_win.bkgd(" ", curses.color_pair(5))
    text_win.addstr(0, 0, build_opts[menu_man._cur_field], curses.color_pair(5))
    # Refresh both windows
    win_man._field_win.noutrefresh()
    text_win.noutrefresh()
    curses.doupdate()
    # Create a textbox
    box = Textbox(text_win)
    box.edit()
    build_opts[menu_man._cur_field] = box.gather()[:-2]
    del text_win
    curses.curs_set(0)
    menu_man._cur_field = ""
    win_man.resize_wins("menu_mode")
Example #18
0
def draw_menu(stdscr):
    k = 0
    # Clear and refresh the screen for a blank canvas
    stdscr.clear()
    stdscr.refresh()
    height, width = stdscr.getmaxyx()

    # Start colors in curses
    curses.start_color()
    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)

    summoner_name_str = 'Summoner name:'
    start_x_title = int((width // 2) - (len(summoner_name_str)))
    stdscr.addstr(0, start_x_title, summoner_name_str, curses.color_pair(3))
    stdscr.refresh()

    editwin = curses.newwin(1, 17, 0, int((width // 2) + 1))
    box = Textbox(editwin)
    # Let the user edit until Ctrl-G is struck.
    box.edit()
    # Get resulting contents
    message = box.gather()

    while k != ord('q'):
        stdscr.clear()
        stdscr.refresh()
        stdscr.addstr(0, 0, message)
        # Refresh the screen

        # Wait for next input
        k = stdscr.getch()
Example #19
0
    def modify_subtask(self):
        current_subtask = self.controller.get_selected_subtask()
        curs_set(2)
        try:
            from math import ceil
            max_rows = ceil(
                len(current_subtask.description) /
                (self.window.getmaxyx()[1] - 2))

            # Display hint
            self.view.command_window.display_text("Ctrl+G - Save Result")

            edit_win = self.window.subwin(
                max_rows,
                self.window.getmaxyx()[1] - 2, current_subtask.sequence + 3,
                self.view.tasks_window.window.getmaxyx()[1] + 2)
            edit_win.clear()
            edit_win.addstr(0, 0,
                            self.controller.get_selected_subtask().description)
            edit_win.move(0, 0)
            e = Textbox(edit_win, insert_mode=True)
            text = self.controller.sanitize_input(e.edit())
            self.controller.modify_subtask(
                self.controller.get_selected_task().description,
                self.controller.get_selected_subtask().description,
                description=text)
        finally:
            curs_set(0)
            self.render(self.controller.get_subtasks())
            self.notify()
Example #20
0
def feditwin(editwin_loc):
    """
    Create a window to write message in.

    Parameters
    ----------
    editwin_loc: list
        the edit window localisation.

    Returns
    -------
    :class:curses._CursesWindow
        The edit window.
    :class:curses.Textbox
        The textbox to write text in.
    """
    n_line = editwin_loc[2] - editwin_loc[0] or 1
    n_col = editwin_loc[3] - editwin_loc[1]
    y = editwin_loc[0]
    x = editwin_loc[1]

    editwin = newwin(n_line, n_col, y, x)
    editwin.keypad(True)
    box = Textbox(editwin)
    box.edit()
    return editwin, box
Example #21
0
    def _main(self, stdscr):
        try:
            #   stdscr = curses.initscr()
            # Clear screen
            stdscr.clear()
            # remove the cursor
            curses.curs_set(True)
            # remove echo from touched keys
            # curses.noecho()
            self._initPanels(stdscr)

            box = Textbox(self.commandInput)
            #     stdscr.refresh()
            th = Thread(target = self.refreshProbes, name = "Probe-Refresh", daemon = True)
            th.start()
            stdscr.refresh()

            while self.isRunning:
                stdscr.refresh()
                box.edit()
                self.doCommand(box.gather())
                #         commandInput.refresh()

                # listen without entering enter
                # curses.cbreak())
        finally:
            self.isRunning = False
            th.join()
            # let curses handle special keys
            stdscr.keypad(True)
            stdscr.refresh()
            stdscr.getkey()
Example #22
0
def main_control(screen, event, inception_level):
    if event == ord("Q"):
        curses.endwin()
        exit(0)
    if event == ord("D"):
        window_for_done_task(screen)
    if event == ord("T"):
        window_for_undone_task(screen)
    if event == ord("F"):
        curses.flash()
    if event == ord("A"):
        editwin = curses.newwin(1,
                                screen.getmaxyx()[1] - 6,
                                screen.getmaxyx()[0] - 4, 1)
        rectangle(screen,
                  screen.getmaxyx()[0] - 5, 0,
                  screen.getmaxyx()[0] - 3,
                  screen.getmaxyx()[1] - 5)
        screen.refresh()
        box = Textbox(editwin)
        # Let the user edit until Ctrl-G is struck.
        box.edit()
        # Get resulting contents
        message = box.gather()
        Tache().ajouter_tache(message, datetime.now())
        screen.clear()
        print_main_screen(screen)
        print_taches(screen, Tache().get_tache_undone(), "Taches a faire :")
        deal_with_selected(screen, 33, 45,
                           Tache().get_tache_undone(), window_for_undone_task)
Example #23
0
def add_key_value_pair_below():
    global global_stdscr, last_key_pressed, post_request_body_boxes, PLUS_POS_Y, selected_box, chosen_move_index
    if len(post_request_body_boxes) == 0 or selected_box == len(
            post_request_body_boxes):
        global_stdscr.chgat(TOP + POST_REQUEST_NUM_LINES - 1 + PLUS_POS_Y,
                            LEFT + POST_REQUEST_NUM_COLS + 2 * PADDING, 1,
                            curses.A_REVERSE)

    update_key_value_table()

    if selected_box != -1 and selected_box != len(post_request_body_boxes):
        curses.curs_set(True)
        post_request_body_boxes[selected_box][
            key_or_val_selector + "_box"]["box"].edit(post_navigator)
    elif selected_box == -1 or len(post_request_body_boxes) == selected_box:
        last_key_pressed = global_stdscr.getch()

    if last_key_pressed == ENTER:
        key_editwin = curses.newwin(
            NUM_LINES, NUM_COLS // 2 - 2, TOP + POST_REQUEST_NUM_LINES +
            len(post_request_body_boxes) * 2 * PADDING + 1, LEFT + PADDING + 1)
        key_box = Textbox(key_editwin)
        value_editwin = curses.newwin(
            NUM_LINES, NUM_COLS // 2 - 2, TOP + POST_REQUEST_NUM_LINES +
            len(post_request_body_boxes) * 2 * PADDING + 1,
            LEFT + 3 * PADDING + NUM_COLS // 2 + 1)
        value_box = Textbox(value_editwin)
        selected_box = len(post_request_body_boxes)
        post_request_body_boxes.append({
            "key": "",
            "value": "",
            "key_box": {
                "box":
                key_box,
                "x":
                LEFT + PADDING + 1,
                "y":
                TOP + POST_REQUEST_NUM_LINES +
                len(post_request_body_boxes) * 2 * PADDING + 1,
                "cursor":
                0
            },
            "value_box": {
                "box":
                value_box,
                "x":
                LEFT + PADDING + NUM_COLS // 2 + 1 + 2 * PADDING,
                "y":
                TOP + POST_REQUEST_NUM_LINES +
                len(post_request_body_boxes) * 2 * PADDING + 1,
                "cursor":
                0
            }
        })
        PLUS_POS_Y += 4
    elif last_key_pressed == curses.KEY_UP:
        if selected_box == -1:
            chosen_move_index = move_indexes["edit_message_box"]
        else:
            selected_box = selected_box - 1 if selected_box > 0 else 0
Example #24
0
    def __edit_box(self,
                   title,
                   input_msg,
                   placeholder="",
                   size=5,
                   is_attachment=False):
        '''Function to show edit text box on screen'''

        curses.curs_set(1)
        self.__set_default_screen(title)
        # self.__stdscr.addstr(0, 0, input_msg)
        _, w = self.__stdscr.getmaxyx()

        number_of_lines = size
        number_of_columns = w - 3

        # create a new window
        editwin = curses.newwin(number_of_lines, number_of_columns, 2, 1)
        rectangle(self.__stdscr, 1, 0, 2 + number_of_lines,
                  2 + number_of_columns)
        if is_attachment:
            self.__stdscr.addstr(number_of_lines + 3, 1,
                                 "* Use ; to separate multiple filepaths")
        self.__stdscr.refresh()

        editwin.insstr(placeholder)

        # Make this new window a textbox to edit
        box = Textbox(editwin)
        # box.stripspaces = True
        box.edit()

        self.__set_default_screen(self.__title, isMain=True)
        curses.curs_set(0)
        return box.gather()
    def get_user_input(self, text):
        """
        Prints and centers text on screen.
        Creates a new text input where the user enters the player name and returns it.

        Keyword arguments:
        self.screen             -- the curses self.screen.
        text               -- Text that appears before the input.

        Example:
        text = "Insert player 1's name" => Insert player 1's name: (user types here)

        Returns:
        The name of the player that the user entered.
        """

        # Centers the text
        num_rows, num_cols = self.screen.getmaxyx()

        x = int(num_cols / 2) - int(len(text) / 2)
        y = int(num_rows / 2)

        self.screen.addstr(y, x, text)
        self.screen.refresh()

        # We must create a new window becuase the edit function will return
        # everything that has been printed on the self.screen and not just the entered name
        win = curses.newwin(5, 10, y, x + len(text))
        textbox = Textbox(win)
        user_input = textbox.edit(self.validate_key_input)

        return user_input
Example #26
0
    def main(self, stdscr):
        terminal_size = shutil.get_terminal_size()
        self.terminal_width = terminal_size[0]
        self.terminal_height = terminal_size[1]

        # Clear screen
        stdscr.clear()

        #Create the timeline window
        self.timeline_win = self.create_timeline_win()

        #Create the Prompt
        credentials = self.api.VerifyCredentials()
        prompt_win, prompt_width = self.create_prompt_win(
            credentials.screen_name)
        prompt_win.refresh()

        #Create Input window
        edit_line_win = self.create_edit_line_win(prompt_width)
        box = Textbox(edit_line_win, self)
        box.stripspaces = 1

        #Refresh tweets and start loop
        self.do_refresh()
        while True:
            message = box.edit(validate=self.validate_input)
            edit_line_win.clear()
            self.handle_command(message)
Example #27
0
def send(stdscr, contactId, contactName):
    draw_window(stdscr, "Briar Linux Client",
                "Type your message and press Ctrl+G to send")
    # Centering calculations
    height, width = stdscr.getmaxyx()
    z = 18
    x, y = int((width // 2) - (z // 2) - z % 2), 3
    stdscr.addstr(y - 1, x, "New message for: " + contactName,
                  curses.color_pair(2))

    ncols, nlines = 40, 5
    uly, ulx = 5, 2
    editwin = curses.newwin(nlines, ncols, uly, ulx)
    rectangle(stdscr, uly - 1, ulx - 1, uly + nlines, ulx + ncols)
    stdscr.refresh()

    box = Textbox(editwin)
    # Let the user edit until Ctrl-G is struck.
    box.edit()
    # Get resulting contents
    message = box.gather()

    if message != "":
        url_format = apiURL + "/v1/messages/" + contactId
        response = requests.post(url_format,
                                 headers=auth,
                                 json={"text": message})
        stdscr.addstr(20, 10, "Message sent")
    else:
        stdscr.addstr(20, 10, "Message empty", curses.color_pair(4))
    stdscr.refresh()
    stdscr.getch()

    messages(stdscr, contactId, contactName)
Example #28
0
File: cli.py Project: kondziu/6p
    def _display(self, text=None, edit=True):
        self._window.refresh()
        self._window.border()

        text_width = self._width - 2
        text_height = self._height - 2

        self._window.addstr(0, 1, "[%s]" % "Your answer"[0:text_width - 2])
        self._window.addstr(self._height - 1, text_width - 8, "[Ctrl+G]")
        #self._window.move(1,1)
        self._window.refresh()

        if edit:
            temporary_edit_window = curses.newwin(text_height, text_width, self._y + 1, self._x + 1)
            curses.curs_set(True)

            edit_box = Textbox(temporary_edit_window)
            edit_box.edit()
            curses.curs_set(False)
            content = edit_box.gather().strip()
            del temporary_edit_window

            return content

        else:
            return None
Example #29
0
 def run_curses(self, win):
     self.setup_win(win)
     self.editwin = win.subwin(1, curses.COLS - 1, curses.LINES - 1, 0)
     editpad = Textbox(self.editwin)
     while not self.closed:
         line = editpad.edit()
         self.editwin.erase()
         if line: self.send_admin(line)
Example #30
0
def testbox():
    myscreen.clear()
    myscreen.border(0)
    editwin = curses.newwin(5, 30, 2, 1)
    rectangle(myscreen, 1, 0, 1 + 5 + 1, 1 + 30 + 1)
    myscreen.refresh()
    box = Textbox(editwin)
    box.edit()
Example #31
0
 def run_curses(self, win):
     self.setup_win(win)
     self.editwin = win.subwin(1, curses.COLS - 1, curses.LINES - 1, 0)
     editpad = Textbox(self.editwin)
     while not self.closed:
         line = editpad.edit()
         self.editwin.erase()
         if line: self.send_admin(line)
Example #32
0
def command(stdscr, repl_y, repl_x):
    stdscr.addstr(repl_y, 0, ":")
    editwin = curses.newwin(1, repl_x - 1, repl_y, repl_x + 2)
    editwin.refresh()
    stdscr.refresh()
    box = Textbox(editwin)
    box.edit()
    return box.gather()
Example #33
0
def main() :
	
	screen = curses.initscr()
	height, width = screen.getmaxyx()
	
	curses.noecho()
	
	boardwin = curses.newwin(height-2, width-10, 0, 0)
	stashwin = curses.newwin((height-2)/2, 10, 0, width-10)
	playerwin = curses.newwin((height-2)/2, 10, (height-2)/2, width-10)
	msgwin = curses.newwin(1, width, height-2, 0)
	cmdwin = curses.newwin(1, width-5, height-1, 5)
	cmdline = Textbox(cmdwin)
	
	
	screen.addstr(height-1, 1, ">>>")
	screen.refresh()
	
	boardwin.box()
	boardwin.addstr(1, 1, "Board")
	boardwin.refresh()
	
	stashwin.box()
	stashwin.addstr(1, 1, "Stash")
	stashwin.refresh()
	
	playerwin.box()
	playerwin.addstr(1, 1, "Players")
	playerwin.refresh()
	
	msgwin.addstr(0, 1, "Enter 'START [Star1] [Star2] [Ship]' to start the game.")
	msgwin.refresh()
	
	players = ["Alpha", "Beta"]
	run = True
	
	while run :
		
		cmd = cmdline.edit().split(" ")
		
		try :
			error = eval(cmd[0].lower())(player, cmd[1:])
		
		except Exception :
			error = "ERROR: Unknown command or invalid arguments"
		
		if not "ERROR:" in error :
			cmdwin.clear()
			updateBoard(game.getBoard())
			updateStash(game.getStash())
			updateMsg(error)
			player = players[players.index(player)-1]
		
		else :
			updateMsg(error)
	
	curses.echo()
	curses.endwin()
Example #34
0
def textbox(nrow, ncol, x, y):
	editwin = curses.newwin(nrow,ncol,x,y)
	# upleft point x, upleft point y, downright x, downright y
	rectangle(scr, x-1, y-1, x + nrow, y + ncol)
	scr.refresh()
	box = Textbox(editwin)
	box.edit()
	message = box.gather()
	return message
Example #35
0
 def do_command(self, ch):
     if ch == 127:  # backspace
         Textbox.do_command(self, curses.KEY_BACKSPACE)
         self.win.refresh()
         return 1
     if ch == 27:
         Textbox.gather(self)
         return -1
     return Textbox.do_command(self, ch)
Example #36
0
def main(stdscr):

  curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
  curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLUE )

  #curses.noecho()
  #curses.curs_set(0)
  #stdscr.clear()
  #stdscr.resize(50, 50)
  #stdscr.border(0)
  #x=input("...waiting..")
  #curses.endwin()

  stdscr.border(0)
  stdscr.refresh()

  stdscr_y = curses.LINES - 1
  stdscr_x = curses.COLS - 1

  drawCoor(stdscr)

  pad = curses.newpad(20, 20)
  pad2 = curses.newpad(20, 20)


  for y in range(0, 19):
    for x in range(0, 19):
      pad.addch(y,x, ord('a') + (x*x+y*y) % 26)

  for y in range(0, 19):
    for x in range(0, 19):
      pad2.addch(y,x, ord('-'))

  pad.border(0)
  pad2.border(0)

  pad2.refresh(0,0, 15,5, 65,30)
  pad.refresh(0,0, 5,15, 30,40)
  stdscr.refresh()

  stdscr.addstr(15, 50,"Pretty text", curses.color_pair(2))
  stdscr.addstr(10, 50, "Current mode: Typing mode", curses.A_REVERSE)
  stdscr.addstr(10, 50, "HELLO")
  stdscr.refresh()


  stdscr.addstr(50, 50, "Enter IM message: (hit Ctrl-G to send)")


  rectangle(stdscr, 40,80, 60, 100)
  stdscr.refresh()

  ## Let the user edit until Ctrl-G is struck.
  editwin = curses.newwin(10,10, 50,90) # height, width, begin_y, begin_x
  stdscr.refresh()
  box = Textbox(editwin)
  box.edit()
Example #37
0
def textbox(screen):
    screen.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)", curses.A_REVERSE)
    editwin = curses.newwin(5, 30, 2, 1)
    rectangle(screen, 1, 0, 1+5+1, 1+30+1)
    screen.refresh()

    box = Textbox(editwin)
    box.edit()

    message = box.gather()
Example #38
0
File: GUI.py Project: W4ld3n/b-CD
    def inputCommand(self):
        box = Textbox(self.commandWin)

        # Let the user edit until Ctrl-G is struck.
        box.edit()

        # Get resulting contents
        message = box.gather()
        self.commandWin.clear()
        return message
Example #39
0
 def switch_buffer(self):
     """
     prompts to a buffer, opens it
     """
     prompt = curses.subwin(1, curses.COLS-1, curses.LINES -1, 0)
     prompt.addstr("BUFFER NAME:")
     inputbox = Textbox(prompt)
     inputbox.edit()
     dest = gather(inputbox)
     self.open_buffer(dest.split(":")[1])
Example #40
0
def main(stdscr):
    stdscr.addstr(0, 0, "Introduzca mensaje: (Ctrl-G para terminar)")

    editwin = curses.newwin(5, 30, 2,1)
    rectangle(stdscr, 1,0, 1 + 5 + 1, 1 + 30 +1)
    stdscr.refresh()

    box = Textbox(editwin)
    box.edit()  # Let the user edit until Ctrl-G is struck
    message = box.gather()  # Get resulting contents
Example #41
0
def main(output):
    ouput = curses.initscr()
    field = curses.newwin(2, curses.COLS, curses.LINES - 3, 0)
    curses.start_color()
    curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW)
    output.bkgd(curses.color_pair(1))
    field.bkgd(curses.color_pair(2))
    box = Textbox(field)
    box.edit()
Example #42
0
def drawLoginInput(screen, height, width):
    dramaticOutput(screen, height//2, width//2, 'Enter your handle:', 0.05)
    handleWindow = curses.newwin(1, 30, height//2+1, width//2 - 16) 
    handleBox = Textbox(handleWindow)
    handleBox.edit()
    handle = handleBox.gather()
    screen.clear()
    dramaticOutput(screen, height//2, width//2, 'Logging you in as ' + handle + '...', 0.05)
    time.sleep(1)
    return handle
Example #43
0
	def getText(self, dflt=""):
		offset = 40
		width  = 30
		self.showGetRectangle()
		self.textWin.addstr(0,0,dflt)
		box = Textbox(self.textWin)
		box.edit()
		message = box.gather()
		self.textWin.clear()
		return message.strip()
Example #44
0
def show_search_screen(stdscr):
     curses.curs_set(1)
     stdscr.addstr(1, 2, "Artist name: (Ctrl-G to search)")
     editwin = curses.newwin(1, 40, 3, 3)
     rectangle(stdscr, 2, 2, 4, 44)
     stdscr.refresh()
     box = Textbox(editwin)
     box.edit()
     criteria = box.gather()
     return criteria
Example #45
0
    def get_filename(self):
        editwin = curses.newwin(1, 30, 10, 1)
        rectangle(stdscr, 9, 0, 11, 42)
        stdscr.refresh()

        box = Textbox(editwin)

        # Let the user edit until Ctrl-G is struck.
        box.edit()
        return box.gather()
Example #46
0
def lineEdit(theWorld, title, text=""):
    title = "/\\\\ %s //\\" % title

    win = curses.newwin(3, theWorld.w - 10, theWorld.h / 2 - 1, 6)
    win.box()
    size = win.getmaxyx()
    win.addstr(0, size[1] / 2 - len(title) / 2, title)
    win.refresh()
    win = curses.newwin(1, theWorld.w - 12, theWorld.h / 2, 7)
    t = Textbox(win)
    return t.edit()
Example #47
0
def textEdit(theWorld, title, text=""):
    title = "/\\\\ %s //\\" % title

    win = curses.newwin(theWorld.h - 6, theWorld.w - 10, 3, 5)
    win.box()
    size = win.getmaxyx()
    win.addstr(0, size[1] / 2 - len(title) / 2, title)
    win.refresh()
    win = curses.newwin(theWorld.h - 8, theWorld.w - 12, 4, 6)
    win.addstr(text)
    t = Textbox(win)
    return t.edit()
Example #48
0
def main(stdscr):
	stdscr = curses.initscr()
	stdscr.clear()
	stdscr.addstr(0, 0, "JukeBox - v.0.1 'dancing Saci'")
	editwin = curses.newwin(5,30, 2,1)
	rectangle(stdscr, 1,0,1+5+1, 1+30+1)
	stdscr.refresh()
	
	box = Textbox(editwin)

	box.edit()
	message = box.gather()
Example #49
0
def main(stdscr):
    stdscr.clear()
    columns = split_into_columns(stdscr,3)
    shouldExit = False

    box = Textbox(columns[0])
    rect = rectangle(columns[0],5,5,0,0)

    while not shouldExit:
        box.edit()
        k = stdscr.getkey()

        if k == "q":
            shouldExit = True
Example #50
0
def main(stdscr):
    stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)")

    editwin = curses.newwin(30,30, 30, 30)
    rectangle(stdscr, 20, 20, 1+5+1, 1+30+1)
    stdscr.refresh()

    box = Textbox(editwin)

    # Let the user edit until Ctrl-G is struck.
    box.edit()

    # Get resulting contents
    message = box.gather()
Example #51
0
def main():
    stdscr = curses.initscr()
    begin_x =  2
    begin_y = 2
    height = 8
    width = 54

    window = curses.newwin(height, width, begin_y, begin_x)
    window.addstr(0, 0, "Please type what you heard:")
    rectangle(window, 1, 0, 7, 50)
    text_box = Textbox(window)

    text_box.edit(on_key)
    message = text_box.gather()
    window.addstr(0, 40, message)
Example #52
0
 def editTextField(self, editwin):
     self.setCursorVisibility(1)
     self.textbox = Textbox(editwin, insert_mode = True)
     newname = self.textbox.edit(self.deleteKeyPressHandler).strip()
     self.textbox = ''
     self.setCursorVisibility(0)
     return newname
Example #53
0
File: wax.py Project: wlaub/pybld
def getString(inwin, title, init = None, default = None):
    namewin, cy, cx = centerWin(inwin, 3, 25)
    namewin.border()
    namewin.addstr(0,12-len(title)/2, title)
    editwin = namewin.subwin(1,23,cy+1,cx+1) 
    if init != None:
        editwin.addstr(0,0,init)
    namewin.refresh()
    tbox = Textbox(editwin)
    validator = waxutil.Validator()
    result = tbox.edit(validator.validate).strip()
    namewin.clear()
    namewin.refresh()
    if len(result) == 0 or validator.abort:
        return default
    return result
Example #54
0
def main(stdscr):
	lines, cols = curses.getmaxyx()
	stdscr.addstr(1, 1, "Enter IM message: (hit Ctrl-G to send)")
	stdscr.border()

	editwin = curses.newwin(5,30, 3,2)
	rectangle(stdscr, 2,1, 1+5+1, 1+30+1)
	stdscr.refresh()

	box = Textbox(editwin)

	# Let the user edit until Ctrl-G is struck.
	box.edit()

	# Get resulting contents
	message = box.gather()
def client(address, send_win):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(address)
    payload = (sock,)
    Thread(target=listen_for_updates, args=payload).start()
    title_buffer_win.addstr(0, 0, STATUS_CONSTANTS[1] + address[0], curses.A_STANDOUT)
    while True:
        box = Textbox(send_win)
        box.edit()
        message = box.gather()
        message = bytes(message.encode('utf-8'))
        sock.sendall(message)
        send_win = curses.newwin(1, TERMINAL_SIZE.columns, TERMINAL_SIZE.lines - 1, 0)

    update_status(STATUS_CONSTANTS[0])
    sock.shutdown(socket.SHUT_RD)
    sock.close()
Example #56
0
 def search(self, stdscr):
     y, x = stdscr.getmaxyx()
     y0 = int(y / 2)
     swin = curses.newwin(4, x, y0, 0)
     swin.border()
     swin.addstr(1, 1, 'Search')
     y1 = y0 + 2
     ewin = curses.newwin(1, x - 2, y1, 1)
     swin.refresh()
     tb = Textbox(ewin)
     curses.curs_set(1)
     s = tb.edit()
     curses.curs_set(0)
     terms = []
     filters = {}
     util.parseSearchString(s, terms, filters)
     self.withCore(lambda c: c.search('', *terms, **filters))
Example #57
0
 def print_ajouter_tache(self):
     self.screen.addstr(self.max["y"]-6, 1, "Ajouter une tache :")
     editwin = curses.newwin(1,
                             self.max["x"]-6,
                             self.max["y"]-4,
                             1
                             )
     rectangle(self.screen,
               self.screen.getmaxyx()[0]-5,
               0, self.max["y"]-3,
               self.max["x"]-5)
     self.screen.refresh()
     box = Textbox(editwin)
     # Let the user edit until Ctrl-G is struck.
     box.edit()
     # Get resulting contents
     message = box.gather()
     return(message)
Example #58
0
def text_edit(text_to_display):
   stdscr = curses.initscr()
   curses.noecho()
   stdscr.addstr(0, 0, "%s: (hit Ctrl-G when finished)" % text_to_display)

   editwin = curses.newwin(20, 100, 2,1)
   rectangle(stdscr, 1,0, 1+20+1, 1+100+1)
   stdscr.refresh()

   box = Textbox(editwin)

   # Let the user edit until Ctrl-G is struck.
   box.edit()

   # Get resulting contents
   data =  box.gather()
   curses.endwin()
   return data   
def foo(stdscr):
    stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)")

    editwin = curses.newwin(5, 30, 2, 1)
    rectangle(stdscr, 1,0, 1+5+1, 1+30+1)
    stdscr.refresh()

    box = Textbox(editwin)

    #pad = curses.newpad(100, 100)
    height = 7; width = 33

    begin_y = 1; begin_x = 33
    win0 = curses.newwin(height, width, begin_y, begin_x)
    win0.border()
    win0.refresh()

    begin_y = 8; begin_x = 0
    win1 = curses.newwin(height, width, begin_y, begin_x)
    win1.border()
    win1.refresh()

    begin_y = 8; begin_x = 33
    win2 = curses.newwin(height, width, begin_y, begin_x)
    win2.border()
    win2.refresh()

    # Let the user edit until Ctrl-G is struck.
    box.edit()

    # Get resulting contents
    message = box.gather()


    win0.addstr(1,1,message)
    win1.addstr(1,1,message)
    win2.addstr(1,1,message)

    win0.refresh()
    win1.refresh()
    win2.refresh()
    
    stdscr.refresh()
    stdscr.getkey()