Python curses.textpad() Examples

The following are 7 code examples of curses.textpad(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module curses , or try the search function .
Example #1
Source File: tabview.py    From OpenTrader with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _search_validator(self, ch):
        """Fix Enter and backspace for textbox.

        Used as an aux function for the textpad.edit method

        """
        if ch == curses.ascii.NL:  # Enter
            return curses.ascii.BEL
        elif ch == 127:  # Backspace
            self.search_str = self.textpad.gather().strip().lower()[:-1]
            return 8
        else:
            if 0 < ch < 256:
                c = chr(ch)
                if c in string.printable:
                    res = self.textpad.gather().strip().lower()
                    self.search_str = res + chr(ch)
                    self.search_results(look_in_cur=True)
                    self.display()
            return ch 
Example #2
Source File: tabview.py    From OpenTrader with GNU Lesser General Public License v3.0 5 votes vote down vote up
def search(self):
        """Open search window, get input and set the search string."""
        if self.init_search is not None:
            return
        scr2 = curses.newwin(3, self.max_x, self.max_y - 3, 0)
        scr3 = scr2.derwin(1, self.max_x - 12, 1, 9)
        scr2.box()
        scr2.move(1, 1)
        addstr(scr2, "Search: ")
        scr2.refresh()
        curses.curs_set(1)
        self._search_win_open = 3
        self.textpad = Textbox(scr3, insert_mode=True)
        self.search_str = self.textpad.edit(self._search_validator)
        self.search_str = self.search_str.lower().strip()
        try:
            curses.curs_set(0)
        except _curses.error:
            pass
        if self.search_str:
            self.init_search = None
        self._search_win_open = 0 
Example #3
Source File: misc.py    From py-nltools with Apache License 2.0 5 votes vote down vote up
def edit_popup (stdscr, title, s):

    my, mx = stdscr.getmaxyx()

    ww = mx * 9 / 10
    wh = 3

    wox = mx / 2 - ww/2
    woy = my / 2 - wh/2

    win = curses.newwin(wh, ww, woy, wox)
    win.box()
    win.addstr(0, 3, title)

    win.refresh()

    swin = win.derwin (1, ww-4, 1, 2)

    tb = curses.textpad.Textbox(swin, insert_mode=True)

    swin.insstr (0, 0, tex_encode(s))

    swin.refresh()

    s = tex_decode(tb.edit())

    return s.rstrip() 
Example #4
Source File: pytrader.py    From pytrader with MIT License 5 votes vote down vote up
def __init__(self, dlg, posy, posx, length):
        self.dlg = dlg
        self.win = dlg.win.derwin(1, length, posy, posx)
        self.win.keypad(1)
        self.box = curses.textpad.Textbox(self.win, insert_mode=True)
        self.value = ""
        self.result = None
        self.editing = False 
Example #5
Source File: ncurses.py    From collection with MIT License 5 votes vote down vote up
def test2():
		def main(stdscr):
			begin_x = 20
			begin_y = 7
			height = 5
			width = 40
			win = curses.newwin(height, width, begin_y, begin_x)
			tb = curses.textpad.Textbox(win)
			text = tb.edit()
			curses.addstr(4,1,text.encode('utf_8'))
			time.sleep(10)
		nc.wrapper(main) 
Example #6
Source File: infinite_jukebox.py    From Remixatron with Apache License 2.0 5 votes vote down vote up
def get_window_contents():
    """Dump the contents of the current curses window."""

    tbox = curses.textpad.Textbox(window)
    tbox.stripspaces = False

    w_str = tbox.gather()

    return w_str 
Example #7
Source File: cli.py    From wifibroadcast with GNU General Public License v3.0 4 votes vote down vote up
def init(stdscr, profile):
    cfg_video = getattr(settings, '%s_video' % (profile,))
    cfg_telem = getattr(settings, '%s_mavlink' % (profile,))
    cfg_tunnel = getattr(settings, '%s_tunnel' % (profile,))

    height, width = stdscr.getmaxyx()
    height -= 1
    w1h = height // 3
    w1w = width
    w2h = height // 3
    w2w = width
    w3h = height - w1h - w2h
    w3w = width
    status_win1 = stdscr.subpad(w1h - 2, w1w - 2, 1, 1)
    status_win2 = stdscr.subpad(w2h - 2, w2w - 2, w1h + 1, 1)
    status_win3 = stdscr.subpad(w3h - 2, w3w - 2, w1h + w2h + 1, 1)

    curses.textpad.rectangle(stdscr, 0, 0, w1h - 1, w1w - 1)
    curses.textpad.rectangle(stdscr, w1h, 0, w1h + w2h - 1, w2w - 1)
    curses.textpad.rectangle(stdscr, w1h + w2h, 0, w1h + w2h + w3h - 1, w3w - 1)
    stdscr.addstr(0, 3, '[video]')
    stdscr.addstr(w1h, 3, '[telem]')
    stdscr.addstr(w1h + w2h, 3, '[tunnel]')
    stdscr.refresh()

    for i in (status_win1, status_win2, status_win3):
        i.idlok(1)
        i.scrollok(1)

    if cfg_video.stats_port is not None:
        reactor.connectTCP('127.0.0.1', cfg_video.stats_port, AntennaStatClientFactory(status_win1, cfg_video.peer.startswith('listen:')))
    else:
        status_win1.addstr(0, 0, '[statistics disabled]', curses.A_REVERSE)
        status_win1.refresh()

    if cfg_telem.stats_port is not None:
        reactor.connectTCP('127.0.0.1', cfg_telem.stats_port, AntennaStatClientFactory(status_win2, True))
    else:
        status_win2.addstr(0, 0, '[statistics disabled]', curses.A_REVERSE)
        status_win2.refresh()

    if cfg_tunnel.stats_port is not None:
        reactor.connectTCP('127.0.0.1', cfg_tunnel.stats_port, AntennaStatClientFactory(status_win3, True))
    else:
        status_win3.addstr(0, 0, '[statistics disabled]', curses.A_REVERSE)
        status_win3.refresh()