def initInteractive(setup): logging.info("Initializing Nexus migration tool.") os.environ.setdefault('ESCDELAY', '25') try: stdscr = unicurses.initscr() unicurses.noecho() unicurses.cbreak() try: unicurses.start_color() except: pass scr = Screen(stdscr, setup.args) saf = Safety(scr) win = Main(scr) scr.render() while True: win.show() if not scr.modified() or saf.show(): break except: logging.exception("Error running Nexus migration tool:") raise finally: logging.info("Terminating Nexus migration tool.") logging.shutdown() if 'stdscr' in locals(): unicurses.echo() unicurses.nocbreak() unicurses.endwin()
def init(): """Initialize curses and start application.""" global stdscr stdscr = curses.initscr() # Display settings curses.cbreak() curses.noecho() # Key input settings curses.raw() curses.keypad(stdscr, 1) # No cursor curses.curs_set(0) global TERMNAME TERMNAME = curses.termname() info('Terminal name: ' + TERMNAME) global LONGNAME LONGNAME = curses.longname() info('Long terminal name: ' + LONGNAME) global TERMATTRS TERMATTRS = curses.termattrs() info('Terminal attributes: ' + str(TERMATTRS)) init_colors()
def __init__(self, player): self.player = player self.on_menu = True # Shifts the focus between menu and board, = show new ship self.menu_hi = 0 # Which ele is hightlighted in the menu self.menu_sel = -1 # Current item selected, relevant when board is active self.num_ships_set = 0 self.menu = self.player.left_to_set() self.new_ship_x = 0 self.new_ship_y = 0 self.new_ship_hor = True self.title = f'Set ships for player: {self.player.name}' self.max_y, self.max_x = uc.getmaxyx(stdscr) uc.noecho() # Disable typing on the screen uc.cbreak() # catching characters directly without waiting for [ENTER] uc.curs_set(0) # Disable blinking curser uc.keypad(stdscr, True) # for catching the arrow keys uc.start_color() self.init_wins()
def main(): try: stdscr = unicurses.initscr() unicurses.cbreak() # unicurses.noecho() unicurses.start_color() stdscr.keypad(1) # Determine if we need color if args.nocolor: unicurses.init_pair(1, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK) unicurses.init_pair(2, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK) else: unicurses.init_pair(1, unicurses.COLOR_BLUE, unicurses.COLOR_BLACK) unicurses.init_pair(2, unicurses.COLOR_RED, unicurses.COLOR_BLACK) unicurses.init_pair(3, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK) # Game loop after this point gameLoop(stdscr) except KeyboardInterrupt: pass # TODO: Use global variables to fix this #saveGame( playerName ) finally: stdscr.erase() stdscr.refresh() stdscr.keypad(0) unicurses.echo() unicurses.nocbreak() unicurses.endwin()
def _getch(self, wait_tenths): if wait_tenths==0: return self._getch_nodelay() if wait_tenths is None: curses.cbreak() else: curses.halfdelay(wait_tenths) self.stdscr.nodelay(0) return self.stdscr.getch()
def _getch_nodelay(self): self.stdscr.nodelay(1) while 1: # this call fails sometimes, but seems to work when I try again try: curses.cbreak() break except _curses.error: pass return self.stdscr.getch()
def initializeCursesTerminal(): """Initialize the curses terminal and return the window object.""" stdscr = unicurses.initscr() unicurses.start_color() unicurses.noecho() unicurses.cbreak() unicurses.keypad(stdscr, True) unicurses.timeout(False) unicurses.curs_set(False) return stdscr
def start(): global screen screen = curses.initscr() curses.noecho() curses.cbreak() curses.curs_set(0) screen.keypad(1) screen.nodelay(1) curses.nonl() screen.scrollok(False) curses.start_color() for i in range(0, 17): curses.init_pair(i+1, i, 0) #log.log("Pair : ({}, {}, 0)".format(i+1,i)) h, w = screen.getmaxyx() log.log("Screen size : {}x{}".format(h, w))
def __init__(self): #, stdscreen): self.screen = uni.initscr() #stdscreen uni.keypad(self.screen, True) uni.curs_set(0) uni.noecho() uni.cbreak() #menuwin = uni.subwin(self.screen, 23, 79, 0, 0) menuwin = uni.newwin(10, 40, 0, 0) #uni.box(menuwin, 0, 0) #uni.hline(2, 1)#, uni.ACS_HLINE, 77) #uni.mvwhline(menuwin, 2, 1, uni.ACS_HLINE, 40 - 2) uni.new_panel(menuwin) uni.refresh() submenu_items = [('beep', uni.beep), ('flash', uni.flash)] submenu = Menu(submenu_items, self.screen) main_menu_items = [('beep', uni.beep), ('flash', uni.flash), ('submenu', submenu.display)] main_menu = Menu(main_menu_items, self.screen) main_menu.display()
def __init__(self): # Initialize screen self.stdscr = uni.initscr() # Hide cursor uni.curs_set(0) # Characters available one-by-one uni.cbreak() # Prevent displying user input uni.noecho() # Allow user input uni.keypad(self.stdscr, True) # Enable colors uni.start_color() # Enable mouse uni.mouseinterval(0) uni.mousemask(uni.ALL_MOUSE_EVENTS) # Window dimensions y, x = uni.getmaxyx(self.stdscr) # Make maxx/maxy the last row/col visible self.maxy = y - 1 self.maxx = x - 1 # Drawing order of contained widgets self.widgets = []
def report_choice(mouse_x, mouse_y): i = startx + 2 j = starty + 3 for choice in range(0, n_choices): if (mouse_y == j + choice) and (mouse_x >= i) and (mouse_x <= i + len(choices[choice])): if choice == n_choices - 1: return -1 else: return choice + 1 break stdscr = uni.initscr() uni.clear() uni.noecho() uni.cbreak() uni.curs_set(0) startx = int((80 - WIDTH) / 2) starty = int((24 - HEIGHT) / 2) menu_win = uni.newwin(HEIGHT, WIDTH, starty, startx) uni.keypad(menu_win, True) uni.mvaddstr(0, 0, "Click on Exit to quit (works best in a virtual console)") uni.refresh() print_menu(menu_win, 1) uni.mouseinterval(0) uni.mousemask(uni.ALL_MOUSE_EVENTS) msg = "MOUSE: {0}, {1}, {2}, Choice made is: {3}, Chosen string is: {4}" while True:
def __init__(self): self.screen = unicurses.initscr() unicurses.noecho() unicurses.cbreak() unicurses.curs_set(0) self.screen.refresh()
def key_event(self, key): if not self.game_menu_interface.enabled and not self.game_field.enabled and not self.game_stat.enabled: self.main_menu.key_event(key) elif self.main_menu.enabled and self.game_menu_interface.blocked: self.main_menu.key_event(key) elif not self.main_menu.enabled and self.game_menu_interface.blocked: self.game_field.key_event(key) else: self.game_menu_interface.key_event(key) if __name__ == "__main__": stdscr = initscr() clear() noecho() cbreak() curs_set(0) keypad(stdscr, True) start_color() use_default_colors() nodelay(stdscr, True) init_pair(1, COLOR_BLACK, COLOR_WHITE) init_pair(2, COLOR_WHITE, COLOR_BLUE) init_pair(3, COLOR_BLACK, COLOR_BLUE) init_pair(4, COLOR_WHITE, COLOR_CYAN) init_pair(5, COLOR_YELLOW, COLOR_GREEN) init_pair(6, COLOR_GREEN, COLOR_BLACK) init_pair(7, COLOR_RED, COLOR_BLACK) init_pair(8, COLOR_BLUE, COLOR_YELLOW) init_pair(9, COLOR_RED, COLOR_YELLOW) init_pair(10, COLOR_WHITE, COLOR_RED)
def __init__(self): stdscr = uni.initscr() uni.start_color() uni.cbreak() uni.noecho() uni.keypad(stdscr, True)
def main(stdscr): curses.cbreak() curses.noecho() stdscr.keypad(True) height, width = stdscr.getmaxyx() suffix_text = ' (TAB to search by artist)' albums_panel = Menu('Album(s) for the selected artist' + suffix_text, (height, width, 0, 0)) tracks_panel = Menu('Track(s) for the selected album' + suffix_text, (height, width, 0, 0)) criteria = show_search_screen(stdscr) _data_manager = DataManager() artist = _data_manager._search_artist(criteria) albums = _data_manager.get_artist_albums(artist['id']) clear_screen(stdscr) albums_panel.items = albums albums_panel.init() albums_panel.update() albums_panel.show() current_panel = albums_panel is_running = True while is_running: curses.doupdate() current_panel.update() key = stdscr.getch() action = current_panel.handle_events(key) if action is not None: action_result = action() if current_panel == albums_panel and action_result is not None: _id, uri = action_result tracks = _data_manager.get_album_tracklist(_id) current_panel.hide() current_panel = tracks_panel current_panel.items = tracks current_panel.init() current_panel.show() elif current_panel == tracks_panel and action_result is not None: _id, uri = action_result _data_manager.play(uri) if key == TAB: current_panel.hide() criteria = show_search_screen(stdscr) artist = _data_manager._search_artist(criteria) albums = _data_manager.get_artist_albums(artist['id']) clear_screen(stdscr) current_panel = albums_panel current_panel.items = albums current_panel.init() current_panel.show() if key == ord('q') or key == ord('Q'): is_running = False current_panel.update()
kw['ssl_version'] = ssl.PROTOCOL_TLSv1 return func(*args, **kw) return bar ssl.wrap_socket = sslwrap(ssl.wrap_socket) # Start the tool by initializing unicurses and creating a new Screen object. # Before doing so, set the ESCDELAY environment variable to 25, in an attempt to # mitigate the delay following the pressing of the escape key during line # editing. if __name__ == '__main__': os.environ.setdefault('ESCDELAY', '25') fixssl() try: stdscr = unicurses.initscr() unicurses.noecho() unicurses.cbreak() try: unicurses.start_color() except: pass scr = Screen(stdscr) saf = Safety(scr) win = Main(scr) scr.render() while True: win.show() if not scr.modified() or saf.show(): break finally: if 'stdscr' in locals(): unicurses.echo() unicurses.nocbreak() unicurses.endwin()
import unicurses from nex2art.menu import Safety, Main from nex2art.core import Setup, Screen # Start the tool by initializing unicurses and creating a new Screen object. # Before doing so, set the ESCDELAY environment variable to 25, in an attempt to # mitigate the delay following the pressing of the escape key during line # editing. if __name__ == '__main__': setup = Setup() logging.info("Initializing Nexus migration tool.") os.environ.setdefault('ESCDELAY', '25') try: stdscr = unicurses.initscr() unicurses.noecho() unicurses.cbreak() try: unicurses.start_color() except: pass scr = Screen(stdscr) saf = Safety(scr) win = Main(scr) scr.render() while True: win.show() if not scr.modified() or saf.show(): break except: logging.exception("Error running Nexus migration tool:") raise finally:
import unicurses as curses import time import os from random import randint, choice os.environ['ESCDELAY'] = '25' stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.keypad(stdscr, 1) curses.wborder(stdscr) curses.curs_set(0) middley, middlex = map(lambda x: x // 2, curses.getmaxyx( stdscr)) # get middle coordinates depending on the size of the terminal UP = 259 # ascii key codes DOWN = 258 LEFT = 261 RIGHT = 260 asci = ''' _____ _ _ _ ________ / ____| \ | | /\ | |/ / ____| | (___ | \| | / \ | ' /| |__ \___ \| . ` | / /\ \ | < | __| ____) | |\ |/ ____ \| . \| |____ |_____/|_| \_/_/ \_\_|\_\______|''' def reset_game(): '''
import sys import threading import time import unicurses import wave os.chdir(os.path.dirname(os.path.realpath(__file__))) # Changes working directory to the script's parent directory # Screen config stdscr = unicurses.initscr() # initiates the unicurses module & returns a writable screen obj unicurses.noecho() # disables echoing of user input unicurses.cbreak() # characters are read one-by-one unicurses.curs_set(0) # Hide the cursor from view by the user unicurses.start_color() # enables color in terminal stdscr.keypad(True) # returns special keys like PAGE_UP, etc. stdscr.nodelay(False) # enables input blocking to keep CPU down locale.setlocale(locale.LC_ALL, '') encoding = locale.getpreferredencoding() # get the preferred system encoding for unicode support if sys.platform == 'win32': # Windows: set codepage to 65001 for unicode support os.system('chcp 65001') # Settings broadcaster_names = { # Broadcaster names for the 'BCST' bar