def __init__(self, y, x, h, w):
self.y = y
self.x = x
self.h = h
self.w = w
# Prevent rendering
self.hidden = False
# Clip children
self.clipped = False
# One row higher so last character is writable
self.pad = curses.newpad(h + 1, w + 1)
self.children = []
python类newpad()的实例源码
def _start_ui(self, stdscr):
"""TODO docs"""
rogue_height = 26
rogue_width = 84
# using a pad instead of the default win, it's safer
self.stdscr = curses.newpad(rogue_height, rogue_width)
self.stdscr.nodelay(True)
curses.curs_set(False)
self.draw_from_rogue()
minlogsize = 4
if curses.LINES - 1 >= rogue_height + minlogsize:
# there's enough space to show the logs
self.logpad = curses.newpad(curses.LINES - 1, curses.COLS - 1)
while True:
if self.timer_callback:
self.timer_callback()
time.sleep(self.sleep_time)
if self.keypress_callback:
try:
key = self.stdscr.getkey()
event = Event()
event.char = key
self.keypress_callback(event)
except curses.error:
pass
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...")
def _wrapped_run(self, stdscr):
self.left_width = 60
self.right_width = curses.COLS - self.left_width
# Setup windows
self.top = curses.newwin(2, curses.COLS, 0, 0)
self.left = curses.newpad(curses.LINES * 2, self.left_width)
self.right = curses.newwin(curses.LINES - 4, self.right_width, 2, self.left_width)
self.bottom = curses.newwin(2, curses.COLS, curses.LINES - 2, 0)
Color.setup_palette()
# Load some data and redraw
self.fetch_next()
self.selected = 0
self.full_redraw()
self.loop()
def __init__(self, stdscr):
self.stdscr = stdscr
self.par_height, self.par_width = stdscr.getmaxyx()
self.pad = curses.newpad(self.par_height + 200, self.par_width + 200)
self.pad.keypad(1)
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)
def _cw_setup_run(cls, app, window):
cls.RUNNING = True
cls.APP = app
height, width = window.getmaxyx()
if width < cls.WIDTH:
raise CursedSizeError('terminal width is %d and window width is '
'%d' % (width, cls.WIDTH))
if height < cls.HEIGHT:
raise CursedSizeError('terminal height is %d and window height '
'is %d' % (height, cls.HEIGHT))
if cls.PAD:
cls.WINDOW = curses.newpad(cls.PAD_HEIGHT, cls.PAD_WIDTH)
else:
cls.WINDOW = window.subwin(cls.HEIGHT, cls.WIDTH, cls.Y, cls.X)
if cls.SCROLL:
cls.WINDOW.scrollok(True)
cls.WINDOW.idlok(1)
if cls.BORDERED:
cls.WINDOW.border()
for attr in cls._CW_WINDOW_FUNCS:
cls._cw_set_window_func(attr)
for attr in cls._CW_SCREEN_FUNCS:
cls._cw_set_screen_func(attr)
for attr in cls._CW_WINDOW_SWAP_FUNCS:
cls._cw_swap_window_func(attr)
for attr in cls._CW_SCREEN_SWAP_FUNCS:
cls._cw_swap_screen_func(attr)
def __init__(self, ticks, silent, debug, compat_debug, debug_lines, autostep_debug, head):
super().__init__()
self.ticks = ticks
self.silent = silent
self.debug = debug
self.compat_debug = compat_debug
self.debug_lines = debug_lines
self.autostep_debug = autostep_debug
self.head = head
self.tick_number = 0
self.output_count = 0
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()
curses.curs_set(False)
self.win_program = curses.newwin(self.debug_lines, curses.COLS - 1, 0, 0)
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)
def resize(self, h, w):
"""Resize the drawable and create a new pad."""
self.h = h
self.w = w
self.pad = curses.newpad(h + 1, w + 1)
def WinConnInfo(self):
y = self.WinOtopData[self.ID_PAD_CI][1]
x = self.WinOtopData[self.ID_PAD_CI][2]
nlines = self.WinOtopData[self.ID_PAD_CI][3]
hsize = len(self.Vconndata_head)
Ltmp=(self.ID_PAD_CI,y,x,nlines,hsize)
self.padrefreshcoord.append(Ltmp)
try:
self.connIpad = curses.newpad(y+nlines+3,x+hsize+2)
self.connIwinbox = curses.newwin( y+nlines+2, hsize+3, y, x)
except Exception as err:
self.connIpad = -1
self.WinPrintError("WinConnInfo curses Error:"+str(err) )
finally:
try:
if not self.WinCheckThreadAlive(self.idthconn):
self.idthconn = threading.Thread(target=self._WinconninfoshowTH,name='conninfoshowTH')
self.idthconn.setDaemon(True)
self.thConfig.append((self.ID_PAD_CI,1))
else:
self.lockvideo.acquire()
self.connIpad.addstr(1,1,self.Vconndata_head,self.CYANONBLACK)
self.connIpad.addstr(2,2,"waiting refresh... ",self.GREENONBLACK)
self.connIpad.refresh(1,0,y+1,x+1,y+nlines+1,x+hsize)
self.lockvideo.release()
except Exception as err:
self.connIpad = -10
self.WinPrintError("WinConnInfo thrd Error:"+str(err) )
def Windb(self):
y = self.WinOtopData[self.ID_PAD_DB][1]
x = self.WinOtopData[self.ID_PAD_DB][2]
nlines = self.WinOtopData[self.ID_PAD_DB][3]
hsize = len(self.Vdbdata_head)
Ltmp=(self.ID_PAD_DB,y,x,nlines,hsize)
self.padrefreshcoord.append(Ltmp)
try:
self.dbpad = curses.newpad(y+nlines+3,x+hsize+2)
self.dbwinbox = curses.newwin( y+nlines+2, hsize+3, y, x)
except Exception as err:
self.dbpad =-1
self.WinPrintError("Windb curses Error:"+str(err) )
finally:
try:
if not self.WinCheckThreadAlive(self.idthdb):
self.idthdb = threading.Thread(target=self._WindbshowTH,name='dbshowTH')
self.idthdb.setDaemon(True)
self.thConfig.append((self.ID_PAD_DB,1))
else:
self.lockvideo.acquire()
self.dbpad.addstr(1,1,self.Vdbdata_head,self.CYANONBLACK)
self.dbpad.addstr(2,2,"waiting refresh... ",self.GREENONBLACK)
self.dbpad.refresh(1,0,y+1,x+1,y+nlines+1,x+hsize)
self.lockvideo.release()
except Exception as err:
self.dbpad =-10
self.WinPrintError("Windb thrd Error:"+str(err) )
def Wininst(self):
y = self.WinOtopData[self.ID_PAD_INST][1]
x = self.WinOtopData[self.ID_PAD_INST][2]
nlines = self.WinOtopData[self.ID_PAD_INST][3]
hsize = len(self.Vinstdata_head)
self.instdata_head = 'Instance info'
Ltmp=(self.ID_PAD_INST,y,x,nlines,hsize)
self.padrefreshcoord.append(Ltmp)
try:
self.instpad = curses.newpad(y+nlines+3,x+hsize+2)
self.instwinbox = curses.newwin( nlines+3, hsize+3, y, x)
except Exception as err:
self.instpad =-1
self.WinPrintError("Wininst curses Error:"+str(err) )
finally:
try:
if not self.WinCheckThreadAlive(self.idthinst):
self.idthinst = threading.Thread(target=self._WininstshowTH,name='instshowTH')
self.idthinst.setDaemon(True)
self.thConfig.append((self.ID_PAD_INST,1))
else:
self.lockvideo.acquire()
self.instpad.addstr(1,1,self.Vinstdata_head,self.CYANONBLACK)
self.instpad.addstr(2,2,"waiting refresh... ",self.GREENONBLACK)
self.instpad.refresh(1,0,y+1,x+1,y+nlines+1,x+hsize)
self.lockvideo.release()
except Exception as err:
self.instpad =-10
self.WinPrintError("Wininst thrd Error:"+str(err) )
def Wintbs(self):
y = self.WinOtopData[self.ID_PAD_TBS][1]
x = self.WinOtopData[self.ID_PAD_TBS][2]
nlines = self.WinOtopData[self.ID_PAD_TBS][3]
hsize = len(self.Vtbsdata_head)
self.tbs_head = 'Tablespace - max five used'
Ltmp=(self.ID_PAD_TBS,y,x,nlines,hsize)
self.padrefreshcoord.append(Ltmp)
try:
self.tbspad = curses.newpad(y+nlines+3,x+hsize+2)
self.tbswinbox = curses.newwin( nlines+3, hsize+3, y, x)
except Exception as err:
self.tbspad =-1
self.WinPrintError("Wintbs curses Error:"+str(err) )
finally:
try:
if not self.WinCheckThreadAlive(self.idthtbs):
self.idthtbs = threading.Thread(target=self._WintbsshowTH,name='tbsTH')
self.idthtbs.setDaemon(True)
self.thConfig.append((self.ID_PAD_TBS,1))
else:
self.lockvideo.acquire()
self.tbspad.addstr(1,1,self.Vtbsdata_head,self.CYANONBLACK)
self.tbspad.addstr(2,2,"waiting refresh..." ,self.GREENONBLACK)
self.tbspad.refresh(1,0,y+1,x+1,y+nlines+1,x+hsize)
self.lockvideo.release()
except Exception as err:
self.tbspad =-10
self.WinPrintError("Wintbs thrd Error:"+str(err) )
def Winsess(self):
y = self.WinOtopData[self.ID_PAD_SESS][1]
x = self.WinOtopData[self.ID_PAD_SESS][2]
nlines = self.WinOtopData[self.ID_PAD_SESS][3]
hsize = len(self.Vsessdata_head)
self.session_head = 'Active sessions (no sys/system)'
virtual_v_size = nlines*self.MAX_SESS_ROWS + y + 3
Ltmp=(self.ID_PAD_SESS,y,x,nlines,hsize)
self.padrefreshcoord.append(Ltmp)
try:
self.sesspad = curses.newpad(virtual_v_size,x+hsize+2)
self.sesswinbox = curses.newwin( nlines+3, hsize+3, y, x)
except Exception as err:
self.sesspad =-1
self.WinPrintError("Winsess curses Error:"+str(err) )
finally:
try:
if not self.WinCheckThreadAlive(self.idthsess):
self.idthsess = threading.Thread(target=self._WinsessshowTH,name='sessshowTH')
self.idthsess.setDaemon(True)
self.thConfig.append((self.ID_PAD_SESS,1))
else:
self.lockvideo.acquire()
self.sesspad.addstr(1,1,self.Vsessdata_head,self.CYANONBLACK)
self.sesspad.addstr(2,2,"waiting refresh... ",self.GREENONBLACK)
self.sesspad.refresh(1,0,y+1,x+1,y+nlines+1,x+hsize)
self.lockvideo.release()
except Exception as err:
self.sesspad =-10
self.WinPrintError("Winsess thrd Error:"+str(err) )
def update_pad_size(self, pad_y):
"""check pad size and update pad if neccesary"""
if self.pad_y != pad_y:
self.pad_y = pad_y
self.pad = curses.newpad(self.pad_y, self.max_x)
def term_resized(self, new_y, new_x):
"""handle terminal resize"""
self.pad = curses.newpad(new_y, new_x)
self.max_y = new_y
self.max_x = new_x
def term_resized(self, new_y, new_x):
"""handle terminal resize"""
self.pad = curses.newpad(self.row_count, new_x)
self.max_y = new_y
self.max_x = new_x
def enable():
# Initialize curses
global stdscr
global status_pad
global usage_win
global curses_sighandler
global map_track_num
global enabled
global pad_height, pad_width
global had_special
global extra_lines
if enabled:
return
had_special = 0
extra_lines = 2 # top + bottom status lines
if jack.display.discname:
extra_lines = extra_lines + 1
stdscr = initscr()
enabled = 1
jack.term.sig_winch_cache = signal.signal(signal.SIGWINCH, signal.SIG_IGN)
# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboard input
noecho()
cbreak()
# In keypad mode, escape sequences for special keys
# (like the cursor keys) will be interpreted and
# a special value like KEY_LEFT will be returned
stdscr.keypad(1)
stdscr.leaveok(0)
# build the pad
pad_height, pad_width = len(
jack.ripstuff.all_tracks_todo_sorted), jack.ripstuff.max_name_len + 72
status_pad = newpad(pad_height, pad_width)
usage_win = newwin(usage_win_height, usage_win_width, 0, 0)
map_track_num = {}
for i in range(len(jack.ripstuff.all_tracks_todo_sorted)):
map_track_num[jack.ripstuff.all_tracks_todo_sorted[i][NUM]] = i
sig_winch_handler(None, None)
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().__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)