def refresh(self):
prior, (cursr_y, cursr_x) = curses.curs_set(0), curses.getsyx()
for idx, item in enumerate(self.items):
fmt = '{{: <{}}}'.format(self.width-1)
s = fmt.format(str(item))[:self.width-1]
# s = str(item)[:self.width-1] if len(str(item)) > self.width-1 else str(item)
color = colors.get_colorpair(self.default_color)
if self.current == idx:
if self.is_selected:
color = colors.get_colorpair('black-white')
else:
color = colors.get_colorpair(self.highlight_color)
self.textinpt.addstr(idx, 0, s, color)
if self.is_selected:
self.borderbox.bkgd(' ', curses.A_BOLD)
else:
self.borderbox.bkgd(' ', curses.A_DIM)
self.borderbox.border()
self.borderbox.refresh()
self.textinpt.refresh()
curses.curs_set(prior)
curses.setsyx(cursr_y, cursr_x)
curses.doupdate()
python类A_BOLD的实例源码
def box_init(self):
"""Clear the main screen and redraw the box and/or title
"""
# Touchwin seems to save the underlying screen and refreshes it (for
# example when the help popup is drawn and cleared again)
self.scr.touchwin()
self.scr.refresh()
self.stdscr.clear()
self.stdscr.refresh()
if self.box is True:
self.boxscr.clear()
self.boxscr.box()
if self.title:
addstr(self.boxscr, 1, 1, self.title, curses.A_BOLD)
addstr(self.boxscr, self.title_help, curses.A_STANDOUT)
self.boxscr.refresh()
elif self.title:
self.boxscr.clear()
addstr(self.boxscr, 0, 0, self.title, curses.A_BOLD)
addstr(self.boxscr, self.title_help, curses.A_STANDOUT)
self.boxscr.refresh()
def sub_selection_dialog_items(self, pos, i_pos, screen):
"""
Draw items in `Selection Dialog`.
:param pos: Index of selected item in `Configure Setting` frame.
:type pos: int
:param i_pos: Index of selected item in `Selection Dialog`.
:type i_pos: int
:param screen: A **WindowObject** which represents the selection
dialog.
:type screen: WindowObject
"""
# Set local variable
normal = curses.A_NORMAL
select = normal + curses.A_BOLD
for p, item in enumerate(self.settings[pos][2]):
item_str = item if pos else item["tag"]
screen.addstr(1 + p, 2, item_str,
select if p == i_pos else normal)
screen.refresh()
def setTitle( self, title ):
self.decoration.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
#-------------------------------------------------------------------------#
# class TitleWindow( Window ):
#-------------------------------------------------------------------------#
# """Title Window"""
# def __init__( self, x, y, width, height ):
# NCursesUI.Window.__init__( self, x, y, width, height )
# version = bb.__version__
# title = "BitBake %s" % version
# credit = "(C) 2003-2007 Team BitBake"
# #self.win.hline( 2, 1, curses.ACS_HLINE, width-2 )
# self.win.border()
# self.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
# self.setText( 1, 2, credit.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
#-------------------------------------------------------------------------#
def _draw_footer(self, footer_window):
"""
Given a footer window and a list of items, draw the items in the footer and highlight the selected item.
Parameters:
footer_window (WindowObject): the window the footer will be drawn in
"""
for item in self.footer_items:
if self.footer_items.index(item) == self.current_column:
# Highlight the item that is currently selected
footer_window.addstr(1,
self.footer_items.index(item) * 10 + 1,
item,
curses.color_pair(1) | curses.A_BOLD)
else:
footer_window.addstr(1,
self.footer_items.index(item) * 10 + 1,
item)
def depict_workspace_object(self, w, row, column, o, maxImportance, description_structures):
if maxImportance != 0.0 and o.relativeImportance == maxImportance:
attr = curses.A_BOLD
else:
attr = curses.A_NORMAL
w.addstr(row, column, str(o), attr)
column += len(str(o))
if o.descriptions:
w.addstr(row, column, ' (', curses.A_NORMAL)
column += 2
for i, d in enumerate(o.descriptions):
if i != 0:
w.addstr(row, column, ', ', curses.A_NORMAL)
column += 2
s, attr = self.slipnode_name_and_attr(d.descriptor)
if d not in description_structures:
s = '[%s]' % s
w.addstr(row, column, s, attr)
column += len(s)
w.addstr(row, column, ')', curses.A_NORMAL)
column += 1
return column
def strng2():
treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
set_color(treescrn2, curses.COLOR_WHITE)
treescrn2.addch(5, 14, ord('\''))
treescrn2.addch(5, 13, ord(':'))
treescrn2.addch(5, 12, ord('.'))
treescrn2.addch(5, 11, ord(','))
treescrn2.addch(6, 10, ord('\''))
treescrn2.addch(6, 9, ord(':'))
treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
unset_color(treescrn2)
treescrn2.refresh()
w_del_msg.refresh()
return
def strng3():
treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
set_color(treescrn2, curses.COLOR_WHITE)
treescrn2.addch(7, 16, ord('\''))
treescrn2.addch(7, 15, ord(':'))
treescrn2.addch(7, 14, ord('.'))
treescrn2.addch(7, 13, ord(','))
treescrn2.addch(8, 12, ord('\''))
treescrn2.addch(8, 11, ord(':'))
treescrn2.addch(8, 10, ord('.'))
treescrn2.addch(8, 9, ord(','))
treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
unset_color(treescrn2)
treescrn2.refresh()
w_del_msg.refresh()
return
def strng4():
treescrn2.attrset(curses.A_BOLD | curses.A_BLINK)
set_color(treescrn2, curses.COLOR_WHITE)
treescrn2.addch(9, 17, ord('\''))
treescrn2.addch(9, 16, ord(':'))
treescrn2.addch(9, 15, ord('.'))
treescrn2.addch(9, 14, ord(','))
treescrn2.addch(10, 13, ord('\''))
treescrn2.addch(10, 12, ord(':'))
treescrn2.addch(10, 11, ord('.'))
treescrn2.addch(10, 10, ord(','))
treescrn2.addch(11, 9, ord('\''))
treescrn2.addch(11, 8, ord(':'))
treescrn2.addch(11, 7, ord('.'))
treescrn2.addch(11, 6, ord(','))
treescrn2.addch(12, 5, ord('\''))
treescrn2.attroff(curses.A_BOLD | curses.A_BLINK)
unset_color(treescrn2)
treescrn2.refresh()
w_del_msg.refresh()
return
def display(self, title, content):
curses.curs_set(0)
self.infowin.clear()
y, x = self.infowin.getmaxyx()
self.infowin.bkgd(" ", curses.color_pair(6))
self.infowin.box()
self.infowin.addstr(0, 0, title + " - 'q' to close", curses.A_UNDERLINE | curses.A_BOLD)
for count, line in enumerate(content.split('\n'), start=1):
try:
self.infowin.addstr(count, 1, line)
except:
pass
self.infopanel.show()
curses.panel.update_panels()
curses.doupdate()
while self.infowin.getch() != ord('q'):
pass
curses.curs_set(1)
def get_curses_colour_enum_closest_to_cpair(cpair):
if cpair in MAP_CONST_COLOURS_TO_CPAIR:
return curses.color_pair(MAP_CONST_COLOURS_TO_CPAIR[cpair])|curses.A_BOLD
else:
choice_cpair = None
for (avail_cpair, curses_pair_id) in MAP_CONST_COLOURS_TO_CPAIR.items():
if choice_cpair == None:
choice_cpair = avail_cpair
continue
# Locate the closest to the desired cpair that is not larger than
# it
if avail_cpair > cpair:
continue
elif avail_cpair > choice_cpair:
choice_cpair = avail_cpair
return avail_cpair|curses.A_BOLD
def addString(y, x, string, string_color=color.BLACK, bold=False):
if x == position.CENTER:
x = width/2 - len(string)/2
options = 0
if curses.can_change_color():
# tokens special cases color
if string == 'X':
options = curses.color_pair(color.RED) if not bold else curses.color_pair(color.RED_H) | curses.A_BOLD
elif string == 'O':
options = curses.color_pair(color.YELLOW) if not bold else curses.color_pair(color.YELLOW_H) | curses.A_BOLD
else:
options = curses.color_pair(string_color)
if bold:
options |= curses.A_BOLD
stdscr.addstr(y, x, string, options)
stdscr.refresh()
# main display
def get(colorType, delta=0):
global cache__
if type(colorType) == type(0):
colorIndex = colorType
else:
colorIndex = app.prefs.color[colorType]
colorIndex = min(colors - 1, colorIndex + delta)
#colorIndex = colorIndex % colors
r = cache__.get(colorIndex)
if r is not None:
return r
color = curses.color_pair(colorIndex)
if colorType in ('error', 'misspelling'):
color |= curses.A_BOLD | curses.A_REVERSE
cache__[colorIndex] = color
return color
def set_title(self, args):
if len(args) > 2:
args[2] = args[2].ljust(15)
str_arg = ' -> '.join(args[:-1])+' -> '
color_arg = args[-1]
width_margin = int(0.3*self.width)
text_width = self.width - width_margin - 3
if len(str_arg+color_arg) > text_width:
left_width = text_width-len(color_arg)
str_arg = '~'+str_arg[-left_width:]
self.win.erase()
self.win.addstr(self.height//2, width_margin+1, str_arg)
self.win.addstr(self.height//2, width_margin+len(str_arg)+1,
color_arg, curses.A_BOLD)
self.win.refresh()
def update(self):
for index, item in enumerate(self.employees):
mode = self.select_mode(index)
try:
if item.unlocked_age < 2:
mode = mode | curses.A_BOLD | curses.A_UNDERLINE
except:
pass
if self.first_item_index > 0:
self.window.addstr(0, 20, self.arrow_up)
order = self.first_item_index + index + 1
msg = self.item_message.format(order, item)
self.window.addstr(1 + index, 1, msg, mode)
if self.last_item_index < len(self.items):
self.window.addstr(self.LIST_SIZE + 1, 20, self.arrow_down)
self.window.refresh()
curses.doupdate()
def select(self):
self.borderbox.bkgd(' ', curses.A_BOLD)
self.textinpt.bkgd(' ', colors.get_colorpair('black-white'))
self.refresh()
def select(self):
'''
Not only selects this textbox, but turns on the cursor and moves it to
the correct possition within this textbox.
'''
self.borderbox.bkgd(' ', curses.A_BOLD)
self.textinpt.bkgd(' ', colors.get_colorpair(self.default_color))
curses.curs_set(1)
self.textinpt.move(0, self.keypos)
self.refresh()
def display_header(scr):
write(scr, 3, 0, 'Slot', curses.A_BOLD)
write(scr, 3, 5, 'Host', curses.A_BOLD)
write(scr, 3, 25, 'State', curses.A_BOLD)
write(scr, 3, 45, 'Filename', curses.A_BOLD)
#'%-4s %-20s %-15s %-40s%s' % ('Slot', 'Remote Host', 'State', 'Filename', ' '*(maxX-83)), curses.A_BOLD)
def draw_default(self):
# draws default menu
clear_bar = " " * (int(self.maxx*2/3))
self.screen.addstr(2, 2, self.title, curses.A_STANDOUT) # Title for this menu
self.screen.addstr(4, 2, self.subtitle, curses.A_BOLD) #Subtitle for this menu
# clear menu on screen
for index in range(len(self.options)+1):
self.screen.addstr(5+index, 4, clear_bar, curses.A_NORMAL)
# display all the menu items, showing the 'pos' item highlighted
for index in range(len(self.options)):
textstyle = self.normal
if index == self.selected:
textstyle = self.highlighted
self.screen.addstr(5+index ,4, clear_bar, curses.A_NORMAL)
self.screen.addstr(5+index ,4, "%d - %s" % (index+1, self.options[index]), textstyle)
self.screen.addstr(11, 2, clear_bar, curses.A_NORMAL)
self.screen.addstr(12, 2, clear_bar, curses.A_NORMAL)
self.screen.addstr(11, 2, "plant: ", curses.A_DIM)
self.screen.addstr(11, 9, self.plant_string, curses.A_NORMAL)
self.screen.addstr(12, 2, "score: ", curses.A_DIM)
self.screen.addstr(12, 9, self.plant_ticks, curses.A_NORMAL)
# display fancy water gauge
if not self.plant.dead:
water_gauge_str = self.water_gauge()
self.screen.addstr(5,14, water_gauge_str, curses.A_NORMAL)
else:
self.screen.addstr(5,13, clear_bar, curses.A_NORMAL)
self.screen.addstr(5,13, " ( RIP )", curses.A_NORMAL)
# draw cute ascii from files
self.draw_plant_ascii(self.plant)
def refresh_status(self, *, no_refresh = False):
max_y, max_x = self.stdscr.getmaxyx()
self.stdscr.hline(max_y - 2, 0, "=", max_x)
self.display_time(no_refresh=True)
self.display_line(no_refresh=True)
self.stdscr.chgat(max_y - 2, 0, curses.A_BOLD)
if not no_refresh:
self.stdscr.refresh()
def display_time(self, text = None, *, no_refresh=False):
if text == self.time and not no_refresh:
return
max_y, max_x = self.stdscr.getmaxyx()
if text is not None:
self.time = "[{}]".format(text)
if self.time is not None:
self.stdscr.addstr(max_y - 2, max_x - len(self.time), self.time)
if not no_refresh:
self.stdscr.chgat(max_y - 2, max_x - len(self.time), curses.A_BOLD)
self.stdscr.refresh()
def display_line(self, text = None, *, no_refresh=False):
if text == self.line and not no_refresh:
return
max_y, max_x = self.stdscr.getmaxyx()
if text is not None:
self.line = "@{}".format(text)
if self.line is not None:
self.stdscr.addstr(max_y - 2, max_x - len(self.line) - len(self.time) - 1, self.line)
if not no_refresh:
self.stdscr.chgat(max_y - 2, max_x - len(self.line) - len(self.time) - 1, curses.A_BOLD)
self.stdscr.refresh()
def paint(self):
self.stdscr.erase()
self.stdscr.addstr(0, 0, time.ctime())
all_procs = []
for host in self.hosts:
all_procs.extend(host.procs.itervalues())
all_procs.sort(key=(lambda proc: -proc.pcpu))
self.stdscr.addstr(1, 0, self.format % {
'hostname': 'HOST',
'pid': 'PID',
'ppid': 'PPID',
'pcpu': '%CPU',
'rss': 'RSS',
'command': 'COMMAND',
})
for i, proc in enumerate(all_procs):
if (i+3) >= self.height:
break
if proc.new:
self.stdscr.attron(curses.A_BOLD)
else:
self.stdscr.attroff(curses.A_BOLD)
self.stdscr.addstr(2+i, 0, self.format % dict(
vars(proc),
command=proc.command[:self.width-36]
))
self.stdscr.refresh()
def main(screen):
screen.clear()
screen_y, screen_x = screen.getmaxyx()
screen.addstr(0, 0, str(screen.getmaxyx()))
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
global DIR
DIR = dir(screen)
while True:
c = screen.getch()
screen.addstr(2, 2, str(c) + ' ', curses.color_pair(1) |
curses.A_BLINK | curses.A_BOLD)
if c == 'q' or c == ord('q'):
break
def main(screen):
screen.clear()
screen_y, screen_x = screen.getmaxyx()
screen.move(1, 1)
screen.addstr(str(screen.getmaxyx()))
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
while True:
c = screen.getch()
screen.move(2, 2)
# screen.addstr(str(c), curses.A_BLINK | curses.A_BOLD)
# screen.addstr(str(c), curses.color_pair(1))
screen.addstr(str(c), curses.color_pair(1) | curses.A_BLINK)
if c == 'q' or c == ord('q'):
break
def banner(self):
"""
Draw the banner in the TUI window.
"""
screen = self._stdscr.subwin(2, 80, 0, 0)
screen.bkgd(' ', curses.color_pair(1))
# Set local variable
title = curses.A_NORMAL
title += curses.A_BOLD
normal = curses.color_pair(4)
# Print title
screen.addstr(0, 0, self.__title.center(79), title)
screen.addstr(1, 0, "Setup".center(10), normal)
screen.refresh()
def configure_settings_frame(self, pos=None):
"""
Draw `Configure Setting` frame with a index number (`pos`) of the item
selected.
:param pos: Index of selected item in `Configure Setting` frame. The
default value of `pos` is `None`.
:type pos: int or None
.. note:: None of the items in `Configure Setting` frame would be
selected if pos is `None`.
"""
self._stdscr.keypad(1)
screen = self._stdscr.subwin(8, 25, 2, 0)
screen.bkgd(' ', curses.color_pair(4))
# Set local variable
normal = curses.A_NORMAL
select = curses.color_pair(5)
select += curses.A_BOLD
for p, item in enumerate(self.settings):
item_str = item[0].ljust(12)
screen.addstr(3 + p, 2, item_str, select if p == pos else normal)
if p:
choice = "[%s]" % item[2][item[1]]
else:
choice = "[%s]" % item[2][item[1]]["label"]
screen.addstr(3 + p, 15, ''.ljust(10), normal)
screen.addstr(3 + p, 15, choice, select if p == pos else normal)
screen.refresh()
def _cw_menu_display(cls):
x = 0
# Because cls with MENU will add 1 to y in _fix_xy, we need true origin
y = -1
# Makes the menu standout
menu_attrs = curses.A_REVERSE | curses.A_BOLD
saved_pos = cls.getxy()
for menu in Menu.ALL:
# double check we're not going to write out of bounds
if x + len(menu.title) + 2 >= cls.WIDTH:
raise CursedSizeError('Menu %s exceeds width of window: x=%d' %
(menu.title, x))
y = -1
cls.addstr(menu.title + ' ', x, y, attr=menu_attrs)
mxlen = max([len(str(i)) for i in menu.items])
if menu is cls._OPENED_MENU:
for item in menu.items:
y += 1
itemstr = str(item)
wspace = (mxlen - len(itemstr)) * ' '
itemstr = itemstr + wspace
if item is menu.selected:
attr = curses.A_UNDERLINE
else:
attr = curses.A_REVERSE
cls.addstr(itemstr, x, y, attr=attr)
# For the empty space filler
x += len(menu.title) + 2
# color the rest of the top of the window
extra = 2 if cls.BORDERED else 0
cls.addstr(' ' * (cls.WIDTH - x - extra), x, -1, attr=menu_attrs)
cls.move(*saved_pos)
def __init__( self, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ):
self.win = curses.newwin( height, width, y, x )
self.dimensions = ( x, y, width, height )
"""
if curses.has_colors():
color = 1
curses.init_pair( color, fg, bg )
self.win.bkgdset( ord(' '), curses.color_pair(color) )
else:
self.win.bkgdset( ord(' '), curses.A_BOLD )
"""
self.erase()
self.setScrolling()
self.win.noutrefresh()
def setTitle( self, title ):
title = "BitBake %s" % bb.__version__
self.decoration.setText( 2, 1, title, curses.A_BOLD )
self.decoration.setText( self.StatusPosition - 8, 1, "Status:", curses.A_BOLD )