Python curses.newpad() Examples

The following are 21 code examples of curses.newpad(). 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: proto_fm_screen_area.py    From TelegramTUI with MIT License 6 votes vote down vote up
def _create_screen(self):
    
        try:
            if self.lines_were_auto_set: self.lines = None
            if self.cols_were_auto_set: self.columns = None
        except: pass

        
        if not self.lines: 
            self.lines = self._max_physical()[0]+1
            self.lines_were_auto_set = True
        if not self.columns: 
            self.columns = self._max_physical()[1]+1
            self.cols_were_auto_set = True

        if self.min_l > self.lines:
            self.lines = self.min_l

        if self.min_c > self.columns:
            self.columns = self.min_c

        #self.area = curses.newpad(self.lines, self.columns)
        self.curses_pad = curses.newpad(self.lines, self.columns)
        #self.max_y, self.max_x = self.lines, self.columns
        self.max_y, self.max_x = self.curses_pad.getmaxyx() 
Example #2
Source File: app.py    From toot with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, stdscr, height, width, top, left):
        # Dimensions and position of region in stdscr which will contain the pad
        self.region_height = height
        self.region_width = width
        self.region_top = top
        self.region_left = left

        # How many statuses fit on one page (excluding border, at 3 lines per status)
        self.page_size = (height - 2) // 3

        # Initially, size the pad to the dimensions of the region, will be
        # increased later to accomodate statuses
        self.pad = curses.newpad(10, width)
        self.pad.box()

        # Make curses interpret escape sequences for getch (why is this off by default?)
        self.pad.keypad(True)

        self.scroll_pos = 0 
Example #3
Source File: proto_fm_screen_area.py    From EDCOP with Apache License 2.0 6 votes vote down vote up
def _create_screen(self):
    
        try:
            if self.lines_were_auto_set: self.lines = None
            if self.cols_were_auto_set: self.columns = None
        except: pass

        
        if not self.lines: 
            self.lines = self._max_physical()[0]+1
            self.lines_were_auto_set = True
        if not self.columns: 
            self.columns = self._max_physical()[1]+1
            self.cols_were_auto_set = True

        if self.min_l > self.lines:
            self.lines = self.min_l

        if self.min_c > self.columns:
            self.columns = self.min_c

        #self.area = curses.newpad(self.lines, self.columns)
        self.curses_pad = curses.newpad(self.lines, self.columns)
        #self.max_y, self.max_x = self.lines, self.columns
        self.max_y, self.max_x = self.curses_pad.getmaxyx() 
Example #4
Source File: proto_fm_screen_area.py    From apple_bleee with GNU General Public License v3.0 6 votes vote down vote up
def _create_screen(self):
    
        try:
            if self.lines_were_auto_set: self.lines = None
            if self.cols_were_auto_set: self.columns = None
        except: pass

        
        if not self.lines: 
            self.lines = self._max_physical()[0]+1
            self.lines_were_auto_set = True
        if not self.columns: 
            self.columns = self._max_physical()[1]+1
            self.cols_were_auto_set = True

        if self.min_l > self.lines:
            self.lines = self.min_l

        if self.min_c > self.columns:
            self.columns = self.min_c

        #self.area = curses.newpad(self.lines, self.columns)
        self.curses_pad = curses.newpad(self.lines, self.columns)
        #self.max_y, self.max_x = self.lines, self.columns
        self.max_y, self.max_x = self.curses_pad.getmaxyx() 
Example #5
Source File: termpdf.py    From termpdf.py with MIT License 6 votes vote down vote up
def create_text_win(self, length, header):
        # calculate dimensions
        w = max(self.cols - 4, 60)
        h = self.rows - 2
        x = int(self.cols / 2 - w / 2)
        y = 1

        win = curses.newwin(h,w,y,x)
        win.box()
        win.addstr(1,2, '{:^{l}}'.format(header, l=(w-3)))
        
        self.stdscr.clear()
        self.stdscr.refresh()
        win.refresh()
        pad = curses.newpad(length,1000)
        pad.keypad(True)
        
        return win, pad 
Example #6
Source File: proto_fm_screen_area.py    From HomePWN with GNU General Public License v3.0 6 votes vote down vote up
def _create_screen(self):
    
        try:
            if self.lines_were_auto_set: self.lines = None
            if self.cols_were_auto_set: self.columns = None
        except: pass

        
        if not self.lines: 
            self.lines = self._max_physical()[0]+1
            self.lines_were_auto_set = True
        if not self.columns: 
            self.columns = self._max_physical()[1]+1
            self.cols_were_auto_set = True

        if self.min_l > self.lines:
            self.lines = self.min_l

        if self.min_c > self.columns:
            self.columns = self.min_c

        #self.area = curses.newpad(self.lines, self.columns)
        self.curses_pad = curses.newpad(self.lines, self.columns)
        #self.max_y, self.max_x = self.lines, self.columns
        self.max_y, self.max_x = self.curses_pad.getmaxyx() 
Example #7
Source File: gcore_box.py    From gaycore with MIT License 6 votes vote down vote up
def make_text_box(self, boxes):
        self.boxes = boxes
        self.pad = curses.newpad(self.PAD_WIDTH, self.PAD_HEIGHT)

        self.pad.box()
        height = 1
        for num, text in enumerate(boxes, 1):
            box = self.pad.derwin(
                self.BOX_HEIGHT, self.BOX_WIDTH, height, self.PAD_WIDTH//2 - self.BOX_WIDTH//2)
            box.box()
            if len(text) > 37:
                text = text[:36] + "..."
            box.addstr(1, 0, "{}. {}".format(num, text))
            yield box
            height += self.BOX_HEIGHT
        self.max_height = height 
Example #8
Source File: curses_ui.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def _screen_new_output_pad(self, rows, cols):
    """Generate a new pad on the screen.

    Args:
      rows: (int) Number of rows the pad will have: not limited to screen size.
      cols: (int) Number of columns the pad will have: not limited to screen
        size.

    Returns:
      A curses textpad object.
    """

    return curses.newpad(rows, cols) 
Example #9
Source File: curses_ui.py    From keras-lambda with MIT License 5 votes vote down vote up
def _screen_new_output_pad(self, rows, cols):
    """Generate a new pad on the screen.

    Args:
      rows: (int) Number of rows the pad will have: not limited to screen size.
      cols: (int) Number of columns the pad will have: not limited to screen
        size.

    Returns:
      A curses textpad object.
    """

    return curses.newpad(rows, cols) 
Example #10
Source File: curses_menu.py    From GPIOnext with MIT License 5 votes vote down vote up
def _main_loop(self, scr):
		if scr is not None:
			CursesMenu.stdscr = scr
			
		height = 7
		screen_rows, screen_cols = CursesMenu.stdscr.getmaxyx()
		for index, item in enumerate( self.items ):
			end = -1
			indent = 0
			textLen = len( item.text )
			itemText = item.show( index )
			while end < textLen - 1:
				height += 1
				start = end + 1
				end = min(start + screen_cols - 15 - indent, textLen )
				if end < textLen:
					for x in range(15):
						if itemText[end] in '- ,;':
							break
						end = min( end + 1, textLen - 1 )
				indent = 16
		self.screen = curses.newpad(height, CursesMenu.stdscr.getmaxyx()[1])
		self._set_up_colors()
		curses.curs_set(0)
		CursesMenu.stdscr.refresh()
		self.draw()
		CursesMenu.currently_active_menu = self
		self._running.set()
		while self._running.wait() is not False and not self.should_exit:
			self.process_user_input() 
Example #11
Source File: curses_ui.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def _screen_new_output_pad(self, rows, cols):
    """Generate a new pad on the screen.

    Args:
      rows: (int) Number of rows the pad will have: not limited to screen size.
      cols: (int) Number of columns the pad will have: not limited to screen
        size.

    Returns:
      A curses textpad object.
    """

    return curses.newpad(rows, cols) 
Example #12
Source File: render.py    From ricedb with GNU General Public License v3.0 5 votes vote down vote up
def populate(self, results):
        if not self.results == None:
          del self.results
        self.results = curses.newpad(max(len(results), curses.LINES - 1), curses.COLS//2)
        self.results.clear()
        for i in range(curses.LINES - SEARCHBAR_OFFSET):
          self.results.insch(i, curses.COLS//2 - 2, curses.ACS_VLINE)
        i = 0
        for result in results:
          # print(result)
          self.results.addstr(i, 0, result.name)
          if (not result.images == None) and (self.w3m_enabled):
            try:
                images_array = ast.literal_eval(result.images) 
                temp_file = util.RDBDIR + 'tmp'
                #os.remove(temp_file)
                # print(result.images[0])
                request.urlretrieve(images_array[0], temp_file)
                self.draw_image(temp_file, curses.COLS - curses.COLS/2, SEARCHBAR_OFFSET, curses.COLS/2, curses.LINES - SEARCHBAR_OFFSET)
                if self.first_pic:
                  self.first_pic = False
            except Exception as e:
                # Who cares? it's just a picture.
                self.end()
                print(str(e))
                pass
          i += 1

        self.results.noutrefresh(0, 0, SEARCHBAR_OFFSET, 0, curses.LINES-1, curses.COLS-1) 
Example #13
Source File: cyberbot.py    From cyberbot with MIT License 5 votes vote down vote up
def init_scr(self):
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.curs_set(0)

        self.stdscr_size = self.stdscr.getmaxyx()
        self.task_total = count_file_linenum(self.config.seedfile)

        self.pgsscr_size = (self.config.proc_num + 2, 40)
        self.pgsscr = curses.newpad(*self.pgsscr_size)
        self.cntscr_size = (4, 40)
        self.cntscr = curses.newpad(*self.cntscr_size)
        self.optscr_size = (18, 80)
        self.optscr = curses.newpad(*self.optscr_size) 
Example #14
Source File: curses_menu.py    From curses-menu with MIT License 5 votes vote down vote up
def _main_loop(self, scr):
        if scr is not None:
            CursesMenu.stdscr = scr
        self.screen = curses.newpad(len(self.items) + 6, CursesMenu.stdscr.getmaxyx()[1])
        self._set_up_colors()
        curses.curs_set(0)
        CursesMenu.stdscr.refresh()
        self.draw()
        CursesMenu.currently_active_menu = self
        self._running.set()
        while self._running.wait() is not False and not self.should_exit:
            self.process_user_input() 
Example #15
Source File: cursesDisplay.py    From cbpro-trader with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, enable=True):
        self.enable = enable
        if not self.enable:
            return
        self.logger = logging.getLogger('trader-logger')
        self.stdscr = curses.initscr()
        self.pad = curses.newpad(23, 120)
        self.order_pad = curses.newpad(10, 120)
        self.timestamp = ""
        self.last_order_update = 0
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
        self.stdscr.keypad(1)
        self.pad.addstr(1, 0, "Waiting for a trade...") 
Example #16
Source File: curses_ui.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def _screen_new_output_pad(self, rows, cols):
    """Generate a new pad on the screen.

    Args:
      rows: (int) Number of rows the pad will have: not limited to screen size.
      cols: (int) Number of columns the pad will have: not limited to screen
        size.

    Returns:
      A curses textpad object.
    """

    return curses.newpad(rows, cols) 
Example #17
Source File: curses_ui.py    From lambda-packs with MIT License 5 votes vote down vote up
def _screen_new_output_pad(self, rows, cols):
    """Generate a new pad on the screen.

    Args:
      rows: (int) Number of rows the pad will have: not limited to screen size.
      cols: (int) Number of columns the pad will have: not limited to screen
        size.

    Returns:
      A curses textpad object.
    """

    return curses.newpad(rows, cols) 
Example #18
Source File: window.py    From lyrics-in-terminal with MIT License 5 votes vote down vote up
def __init__(self, stdscr, player, timeout):
		self.stdscr = stdscr
		self.height, self.width = stdscr.getmaxyx()
		self.player = player
		self.scroll_pad = curses.newpad(self.player.track.length + 2,
					self.player.track.width + 2)
		self.current_pos = 0
		self.pad_offset = 1
		self.text_padding = 5
		self.keys = Key()

		curses.use_default_colors()
		self.stdscr.timeout(timeout)
		self.set_up() 
Example #19
Source File: epr.py    From epr with MIT License 4 votes vote down vote up
def meta(stdscr, ebook):
    rows, cols = stdscr.getmaxyx()
    hi, wi = rows - 4, cols - 4
    Y, X = 2, 2
    meta = curses.newwin(hi, wi, Y, X)
    if COLORSUPPORT:
        meta.bkgd(stdscr.getbkgd())

    meta.box()
    meta.keypad(True)
    meta.addstr(1,2, "Metadata")
    meta.addstr(2,2, "--------")
    key_meta = 0

    mdata = []
    for i in ebook.get_meta():
        data = re.sub("<[^>]*>", "", i[1])
        data = re.sub("\t", "", data)
        mdata += textwrap.wrap(i[0].upper() + ": " + data, wi - 6)
    src_lines = mdata
    totlines = len(src_lines)

    pad = curses.newpad(totlines, wi - 2 )
    if COLORSUPPORT:
        pad.bkgd(stdscr.getbkgd())

    pad.keypad(True)
    for n, i in enumerate(src_lines):
        pad.addstr(n, 0, i)
    y = 0
    meta.refresh()
    pad.refresh(y,0, Y+4,X+4, rows - 5, cols - 6)

    padhi = rows - 5 - Y - 4 + 1

    while key_meta not in META|QUIT:
        if key_meta in SCROLL_UP and y > 0:
            y -= 1
        elif key_meta in SCROLL_DOWN and y < totlines - hi + 6:
            y += 1
        elif key_meta in PAGE_UP:
            y = pgup(y, padhi)
        elif key_meta in PAGE_DOWN:
            y = pgdn(y, totlines, padhi)
        elif key_meta in CH_HOME:
            y = 0
        elif key_meta in CH_END:
            y = pgend(totlines, padhi)
        elif key_meta in {curses.KEY_RESIZE}|HELP|TOC:
            return key_meta
        pad.refresh(y,0, 6,5, rows - 5, cols - 5)
        key_meta = meta.getch()

    meta.clear()
    meta.refresh()
    return 
Example #20
Source File: __main__.py    From asciidots with GNU Affero General Public License v3.0 4 votes vote down vote up
def __init__(self, env, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, output_limit):
        """

        :param dots.environment.Env env: The env of the interpreter
        :param int ticks: The max number of ticks for the program
        :param bool silent: True to turn off all outputs
        :param bool debug: True to show the execution of the program
        :param bool compat_debug: True to show the debug with only builtin functions
        :param int debug_lines: The number of lines to show the debug
        :param float autostep_debug: The timebetween automatic ticks. 0 disables the auto ticks.
        :param int output_limit: The max number of outputs for the program
        """
        super(DefaultIOCallbacks, self).__init__(env)

        # if it is zero or false, we don't want to stop
        self.ticks_left = ticks or float('inf')
        self.outputs_left = output_limit or float('inf')

        self.silent = silent
        self.debug = debug
        self.compat_debug = compat_debug
        self.debug_lines = debug_lines
        self.debug_cols = terminalsize.get_terminal_size()[0] - 1
        self.autostep_debug = autostep_debug

        self.compat_logging_buffer = ''
        self.compat_logging_buffer_lines = terminal_lines - debug_lines - 1

        self.first_tick = True

        if self.debug and not self.compat_debug:
            self.logging_loc = 0
            self.logging_x = 1

            self.stdscr = curses.initscr()

            curses.start_color()

            curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
            curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
            curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
            curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK)

            curses.noecho()

            # hides the cursor
            curses.curs_set(False)

            # defining the two main parts of the screen: the view of the program
            self.win_program = curses.newwin(self.debug_lines, curses.COLS, 0, 0)
            # and pad for the output of the prog
            self.logging_pad = curses.newpad(1000, curses.COLS - 1)

            def signal_handler(signal, frame):
                self.on_finish()
                sys.exit(0)

            signal.signal(signal.SIGINT, signal_handler) 
Example #21
Source File: epr.py    From epr with MIT License 4 votes vote down vote up
def help(stdscr):
    rows, cols = stdscr.getmaxyx()
    hi, wi = rows - 4, cols - 4
    Y, X = 2, 2
    help = curses.newwin(hi, wi, Y, X)
    if COLORSUPPORT:
        help.bkgd(stdscr.getbkgd())

    help.box()
    help.keypad(True)
    help.addstr(1,2, "Help")
    help.addstr(2,2, "----")
    key_help = 0

    src = re.search("Key Bind(\n|.)*", __doc__).group()
    src_lines = src.splitlines()
    totlines = len(src_lines)

    pad = curses.newpad(totlines, wi - 2 )
    if COLORSUPPORT:
        pad.bkgd(stdscr.getbkgd())

    pad.keypad(True)
    for n, i in enumerate(src_lines):
        pad.addstr(n, 0, i)
    y = 0
    help.refresh()
    pad.refresh(y,0, Y+4,X+4, rows - 5, cols - 6)

    padhi = rows - 5 - Y - 4 + 1

    while key_help not in HELP|QUIT:
        if key_help in SCROLL_UP and y > 0:
            y -= 1
        elif key_help in SCROLL_DOWN and y < totlines - hi + 6:
            y += 1
        elif key_help in PAGE_UP:
            y = pgup(y, padhi)
        elif key_help in PAGE_DOWN:
            y = pgdn(y, totlines, padhi)
        elif key_help in CH_HOME:
            y = 0
        elif key_help in CH_END:
            y = pgend(totlines, padhi)
        elif key_help in {curses.KEY_RESIZE}|META|TOC:
            return key_help
        pad.refresh(y,0, 6,5, rows - 5, cols - 5)
        key_help = help.getch()

    help.clear()
    help.refresh()
    return