def __init__(self, curses, curses_window):
curses.start_color()
curses.curs_set(0)
curses_window.nodelay(1)
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_BLUE, curses.COLOR_BLACK)
self._curses = curses
self._curses_window = curses_window
self._stack = list()
python类COLOR_CYAN的实例源码
def define_colors(self):
# set curses color pairs manually
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_BLUE, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(8, curses.COLOR_CYAN, curses.COLOR_BLACK)
def set_color_pairs():
# based on the colors of pyradio
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_GREEN)
curses.init_pair(8, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_GREEN)
def init_curses(self):
"""Setup the curses"""
self.window = curses.initscr()
self.window.keypad(True)
curses.noecho()
curses.cbreak()
curses.start_color()
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN)
self.current = curses.color_pair(2)
def init_colors(self):
curses.start_color()
curses.use_default_colors()
colors = [ curses.COLOR_BLUE,
curses.COLOR_CYAN,
curses.COLOR_GREEN,
curses.COLOR_MAGENTA,
curses.COLOR_RED,
curses.COLOR_WHITE,
curses.COLOR_YELLOW ]
curses.init_pair(0, curses.COLOR_WHITE, curses.COLOR_BLACK)
for i, c in enumerate(colors):
curses.init_pair(i + 1, c, curses.COLOR_BLACK)
def __init__(self, arena_size):
self.arena_size = arena_size
self.max_moves = int(25*(2*arena_size*COLORS)/(28*6))
self.screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
try:
curses.curs_set(False)
except curses.error:
pass
self.screen.nodelay(True)
self.window_size = self.screen.getmaxyx()
if self.window_size[0] < self.arena_size+4 or self.window_size[1] < self.arena_size*2:
print('Your screen is too short!')
exit()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_GREEN)
curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_CYAN)
curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_RED)
curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_YELLOW)
curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_WHITE)
self.offset_x = int((self.window_size[1]-2*self.arena_size)/2)
self.offset_y = int((self.window_size[0]-self.arena_size)/2)
self.moves_position=[ self.offset_y+self.arena_size+1, self.offset_x+self.arena_size-5 ]
self.arena_initialize()
self.screen.addstr( self.offset_y-2, self.offset_x, self.title, curses.color_pair(0))
self.screen.addstr( self.offset_y-2, self.offset_x+2*self.arena_size-17, "Press '?' to help", curses.color_pair(0))
def __init__(self):
self.screen = curses.initscr()
self.screen.timeout(100) # the screen refresh every 100ms
# charactor break buffer
curses.cbreak()
self.screen.keypad(1)
self.netease = NetEase()
curses.start_color()
if Config().get_item('curses_transparency'):
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_GREEN, -1)
curses.init_pair(2, curses.COLOR_CYAN, -1)
curses.init_pair(3, curses.COLOR_RED, -1)
curses.init_pair(4, curses.COLOR_YELLOW, -1)
else:
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
# term resize handling
size = terminalsize.get_terminal_size()
self.x = max(size[0], 10)
self.y = max(size[1], 25)
self.startcol = int(float(self.x) / 5)
self.indented_startcol = max(self.startcol - 3, 0)
self.update_space()
self.lyric = ''
self.now_lyric = ''
self.tlyric = ''
self.storage = Storage()
self.config = Config()
self.newversion = False
def setup_colors():
"""Setup the colors for each player. Entry 8 is reserved for
zero-strength unowned squares.
"""
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE)
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_GREEN)
curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_CYAN)
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW)
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK)
def init_colors():
"""
Init the colors for the screen
"""
curses.use_default_colors()
# Colors we use for messages, etc
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_WHITE)
colors['white'] = curses.color_pair(1)
colors['green'] = curses.color_pair(2)
colors['cyan'] = curses.color_pair(3)
colors['yellow'] = curses.color_pair(4)
colors['green-black'] = curses.color_pair(5)
colors['black-white'] = curses.color_pair(6)
colors['red'] = curses.color_pair(7)
colors['white-white'] = curses.color_pair(8)
# Allocate colour ranges here for the ma display.
maprange = 10
for i in range(curses.COLORS - maprange):
curses.init_pair(i + maprange, 0, i)
def screen_curses_init():
#
# number of milliseconds to wait after reading an escape character, to
# distinguish between an individual escape character entered on the
# keyboard from escape sequences sent by cursor and function keys (see
# curses(3X).
os.putenv("ESCDELAY", "0") # was 25
#
global STDSCR
STDSCR = curses.initscr()
curses.noecho()
curses.cbreak()
#
if not curses.has_colors():
raise Exception("Need colour support to run.")
curses.raw()
#
curses.start_color()
#
# This is what allows us to use -1 for default when we initialise
# the pairs
curses.use_default_colors()
#
curses.init_pair(PROFILE_GREY , curses.COLOR_WHITE , -1)
curses.init_pair(PROFILE_WHITE , curses.COLOR_WHITE , -1)
curses.init_pair(PROFILE_RED , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_VERMILION , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_ORANGE , curses.COLOR_RED , -1)
curses.init_pair(PROFILE_AMBER , curses.COLOR_YELLOW , -1)
curses.init_pair(PROFILE_YELLOW , curses.COLOR_YELLOW , -1)
curses.init_pair(PROFILE_CHARTREUSE , curses.COLOR_GREEN , -1)
curses.init_pair(PROFILE_GREEN , curses.COLOR_GREEN , -1)
curses.init_pair(PROFILE_TEAL , curses.COLOR_CYAN , -1)
curses.init_pair(PROFILE_BLUE , curses.COLOR_BLUE , -1)
curses.init_pair(PROFILE_VIOLET , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_PURPLE , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_MAGENTA , curses.COLOR_MAGENTA , -1)
curses.init_pair(PROFILE_BLACK_INFO , curses.COLOR_BLACK , curses.COLOR_WHITE)
curses.init_pair(PROFILE_ALARM, curses.COLOR_RED , curses.COLOR_WHITE)
def init_display():
"""
Inits the display GUI
"""
if not GUI.gui_stopped:
curses.noecho()
curses.cbreak()
curses.start_color()
GUI.screen.keypad(1)
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
GUI.high_light_text = curses.color_pair(1)
GUI.normal_text = curses.A_NORMAL
curses.curs_set(0)
GUI.refresh_values()
GUI.position = 1
GUI.page = 1
GUI.box = curses.newwin(GUI.max_row + 3, curses.COLS, 0, 0)
GUI.box.addstr(1, 1, GUI.status, GUI.high_light_text)
GUI.add_bottom_menus()
GUI.screen.refresh()
GUI.box.refresh()
def start_screen(self):
self.screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.curs_set(0)
self.screen.keypad(True)
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
curses.init_pair(2, curses.COLOR_GREEN, -1)
curses.init_pair(3, curses.COLOR_CYAN, -1)
curses.init_pair(4, curses.COLOR_YELLOW, -1)
return None
def __init__(self):
self.screen = curses.initscr()
self.screen.timeout(100) # the screen refresh every 100ms
# charactor break buffer
curses.cbreak()
self.screen.keypad(1)
self.netease = NetEase()
curses.start_color()
if Config().get_item('curses_transparency'):
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_GREEN, -1)
curses.init_pair(2, curses.COLOR_CYAN, -1)
curses.init_pair(3, curses.COLOR_RED, -1)
curses.init_pair(4, curses.COLOR_YELLOW, -1)
else:
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
# term resize handling
size = terminalsize.get_terminal_size()
self.x = max(size[0], 10)
self.y = max(size[1], 25)
self.startcol = int(float(self.x) / 5)
self.indented_startcol = max(self.startcol - 3, 0)
self.update_space()
self.lyric = ''
self.now_lyric = ''
self.tlyric = ''
self.storage = Storage()
self.config = Config()
self.newversion = False
def __init__(self):
self.screen = curses.initscr()
self.screen.timeout(100) # the screen refresh every 100ms
# charactor break buffer
curses.cbreak()
self.screen.keypad(1)
self.netease = NetEase()
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
# term resize handling
size = terminalsize.get_terminal_size()
self.x = max(size[0], 10)
self.y = max(size[1], 25)
self.startcol = int(float(self.x) / 5)
self.indented_startcol = max(self.startcol - 3, 0)
self.update_space()
self.lyric = ''
self.now_lyric = ''
self.tlyric = ''
self.storage = Storage()
self.config = Config()
self.newversion = False
def setup_colors():
"""Setup the colors for each player. Entry 8 is reserved for
zero-strength unowned squares.
"""
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_RED)
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE)
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_GREEN)
curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_CYAN)
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_YELLOW)
curses.init_pair(8, curses.COLOR_WHITE, curses.COLOR_BLACK)
def parse_args():
parser = argparse.ArgumentParser()
# parser.add_argument('-a', '--abs', action='store_true')
parser.add_argument('abs_rel', choices=['at', 'after'])
font_choices = [font.split('.')[0]
for font in os.listdir('/usr/share/figlet')
if font.split('.')[1] == 'tlf']
parser.add_argument('-f', '--font', default=DEFAULT_FONT,
choices=font_choices)
parser.add_argument('-m', '--msg', default=None)
# parser.add_argument('-z', '--snooze', type=float, default=2)
parser_volume = parser.add_mutually_exclusive_group()
parser_song = parser_volume.add_argument_group()
parser_song.add_argument('-d', '--dir', default=DEFAULT_MUSIC_DIR)
parser_song.add_argument('--song', default=DEFAULT_SONG)
parser_volume.add_argument('-ns', '--silent', action='store_true')
parser.add_argument('-fg', choices=['black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white'],
default='white')
parser.add_argument('-bg', choices=['black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white'],
default='black')
parser.add_argument('time', nargs='+')
args = parser.parse_args()
args.abs = False if args.abs_rel == 'after' else True
if not args.silent:
args.song = validate_song(args)
args.time = ' '.join(args.time)
color_mapping = {
'black': curses.COLOR_BLACK,
'red': curses.COLOR_RED,
'green': curses.COLOR_GREEN,
'yellow': curses.COLOR_YELLOW,
'blue': curses.COLOR_BLUE,
'magenta': curses.COLOR_MAGENTA,
'cyan': curses.COLOR_CYAN,
'white': curses.COLOR_WHITE,
}
args.fg = color_mapping[args.fg]
args.bg = color_mapping[args.bg]
return args
def setup_colours(self):
curses.start_color()
# 0 - NOT_WORKED
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_RED)
# 1 - WORKED_COUNTRY_AND_STATION
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
# 2 - WORKED_COUNTRY_NOT_STATION
curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
# 3 - WORKED_COUNTRY_DIFF_BAND
curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
def run(self):
"""
"""
self.setup()
# Clear screen
self.screen.clear()
#
curses.start_color()
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLACK)
while True:
#
session.expire_all()
# TODO: Add some standard header to the top? (like interval time etc)
#
self.render()
#
self.increment.reset()
#
self.screen.refresh()
#
time.sleep(self.interval)
self.running += self.interval
return
def main():
"""
The entry point for the app. Called when music-scraper is typed in terminal.
Starts the GUI and starts the scraping process after the input is given
"""
curses.initscr()
if curses.COLS < 80 or curses.LINES < 5:
curses.endwin()
print('Terminal\'s dimensions are too small')
return
process = CrawlerProcess({'LOG_ENABLED': False})
def gui_input(screen):
GUI.screen = screen
curses.start_color()
GUI.screen.keypad(1)
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
GUI.high_light_text = curses.color_pair(1)
GUI.normal_text = curses.A_NORMAL
GUI.box = curses.newwin(curses.LINES, curses.COLS, 0, 0)
GUI.message = GUI.get_input()
curses.wrapper(gui_input)
s = request.quote(GUI.message)
MusicSpider.start_urls = [
"http://www.google.com/search?q=" + s,
]
process.crawl(MusicSpider)
thread = GUIThread(process, start_gui)
thread.start()
process.start()
if not GUI.gui_stopped:
if len(GUI.strings) == 0:
GUI.box.erase()
GUI.box.addstr(1, 1, "No Results Found... Try with Some other keywords.", GUI.high_light_text)
GUI.add_bottom_menus()
GUI.screen.refresh()
GUI.box.refresh()
else:
GUI.box.addstr(curses.LINES - 2, 1, "Completed Scraping !!", GUI.high_light_text)
GUI.add_bottom_menus()
GUI.screen.refresh()
GUI.box.refresh()
def init_ui():
check_size()
begin_x = 1
begin_y = 1
height = 40
width = 160
left_win_width = 28
middle_win_width = 80
right_win_width = width - left_win_width - middle_win_width - 4
win = newwin(height, width, begin_y, begin_x)
win.border(0, 0, 0, 0, 0, 0, 0, 0)
win.addstr("So You Have an Idea")
win.refresh()
left_win = win.subwin(height-5, left_win_width, 2, 2)
left_win.border(0, 0, 0, 0, 0, 0, 0, 0)
left_win.refresh()
left_win = left_win.derwin(height-7, left_win_width-2, 1, 1)
middle_win = win.subwin(height-5, middle_win_width, 2, left_win_width+2)
middle_win.border(0, 0, 0, 0, 0, 0, 0, 0)
for x in range(6, 20, 2):
middle_win.addstr(x, middle_win_width-1, ">")
middle_win.refresh()
middle_win = middle_win.derwin(height-7, middle_win_width-2, 1, 1)
right_win = win.subwin(height-5, right_win_width, 2, left_win_width + middle_win_width + 2)
right_win.border(0, 0, 0, 0, 0, 0, 0, 0)
for x in range(7, 21, 2):
right_win.addstr(x, 0, "<")
right_win.refresh()
right_win = right_win.derwin(height-7, right_win_width-2, 1, 1)
bottom_win = win.subwin(3, width-4, height-3, 2)
bottom_win.border(0, 0, 0, 0, 0, 0, 0, 0)
bottom_win.refresh()
bottom_win = bottom_win.derwin(1, 114, 1, 1)
left_win.refresh()
middle_win.refresh()
right_win.refresh()
bottom_win.refresh()
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_BLUE, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
return left_win, middle_win, right_win, bottom_win, win