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 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 start(filenames): """Initialize curses and start application.""" terminal.init() try: from .textuserinterface import TextUserInterface from . import screen Document.create_userinterface = TextUserInterface # Create all interfaces if not filenames: filenames = [''] for filename in filenames: Document(filename) # Activate first document documentlist[0].ui.activate() #debug(str(document.document_list)) #debug(document.document_list[0].filename) #debug(screen.active_ui) screen.main() #while 1: #ui = next(s.ui for s in document.document_list if s.ui.active) except: curses.endwin() raise else: curses.endwin()
def stop(): global screen curses.nocbreak() screen.timeout(-1) curses.curs_set(1) screen.keypad(0) curses.nl() screen.scrollok(True) curses.echo() curses.endwin()
def terminateCursesTerminal(stdscr): """Terminate the curses terminal.""" unicurses.nocbreak() unicurses.keypad(stdscr, False) unicurses.curs_set(True) unicurses.timeout(True) unicurses.echo() unicurses.endwin()
def destroy(self, msg="", wait=2): """Clears and closes the window with optional message.""" # Reset cursor position if msg: self.reset() uni.addstr(msg) uni.refresh() time.sleep(wait) uni.endwin() sys.exit(0)
def _stop(self): """ Restore the screen. """ curses.echo() self._curs_set(1) try: curses.endwin() except _curses.error: pass # don't block original error with curses error if self._old_signal_keys: self.tty_signal_keys(*self._old_signal_keys) super(Screen, self)._stop()
def _selected(self): if self.topics_pointer == 0: if self.game_interface.game_initialized: self.game_interface.game_menu_interface.unblock() self.game_interface.game_field.unblock() self.locked_topics.append(1) self.game_interface.game_initialized = False self.start_new_game() elif self.topics_pointer == 1: self.locked_topics.append(1) self.game_interface.game_menu_interface.unblock() self.game_interface.game.pause() if self.game_interface.game_field.blocked: self.game_interface.game_field.unblock() self.disable() elif self.topics_pointer == 5: clear() endwin() exit(0)
def main(): determineOS() if glob.platform == Platform.UNDEFINED: print "Your operating system is not supported.\n" return -1 glob.orig_shell_x, glob.orig_shell_y = term_size.getTerminalSize() #atexit.register(clean_screen) resizeTerminal(True) initCurses() #Run the title screen title_screen = Title() #Get world parameters #Breaks when world is smaller than screen (min size: 34x34) world_size = title_screen.getWorldSize() if world_size == "Small": glob.N_HEX_ROWS = 34 glob.N_HEX_COLS = 34 elif world_size == "Average": glob.N_HEX_ROWS = 50 glob.N_HEX_COLS = 50 elif world_size == "Large": glob.N_HEX_ROWS = 120 glob.N_HEX_COLS = 100 else: print "Error getting world size." sys.exit() #Run the game. Game() #Close unicurses uc.endwin()
def parse_commands(msg): """ Parses commands sent by the user Args: msg (str): The command string to execute """ command = msg.split(' ')[0].lower() # Get the command command_args = msg.split(' ')[1:] # Get all the args along with the command name if command == 'exit': # Quit the app current_song = 'None' # Stop song stdscr.clear() # Clear screen before exit stdscr.refresh() # Refresh to load cleared screen time.sleep(0.2) # Give time for song to stop try: os.remove('./temp.wav') # Try to delete tempfile except OSError: pass unicurses.endwin() # Reset terminal back to original state sys.exit() # Exit the application elif command == 'setvolume': # Volume change command try: # Try and parse the argument as a volume and then set said volume global volume volume = max(0, min(9, int(command_args[0]))) # Clamp between 0 and 9 except (TypeError, IndexError): pass elif command == 'skipsong': # Skip the current song global current_song current_song = 'Loading...' # Since the playback code stops if the current_song's changed, this works
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 sys import time, random import unicurses as curses screen = curses.initscr() screen.nodelay(1) screen.border() curses.noecho() curses.curs_set(0) dims = screen.getmaxyx() height,width = dims[0]-1, dims[1]-1 curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) row,col= 0,0 for i in range(256): screen.addch(row,col,i,curses.color_pair(0) ) col +=1 if col>75: row +=1 col = 1 screen.refresh() time.sleep(0.051) curses.endwin()
bkgd(COLOR_PAIR(2)) game_interface = GameInterface() game_interface.refresh() game_interface.first_launch() def kbhit(): ch = getch() if ch != ERR: ungetch(ch) return True else: return False while True: if kbhit(): key = getch() game_interface.key_event(key) game_interface.refresh() else: game_interface.refresh() game_interface.draw_tick += 1 game_interface.draw_tick %= 1000 refresh() clear() endwin()
break except KeyboardInterrupt: # CTRL+C pass except SystemExit: # /exit pass except: # unexpected shutdown register_exception() if has_exception: # If an exception occurs, print how to get help debugging the client current_song = 'None' # Stop the current song logfile = open('./errorlog.txt', 'w') # Create errorlog.txt in the working directory to write the exception to logfile.write(error_msg) # Writes the exception traceback to the file... logfile.close() # ...and then closes it, saving it stdscr.clear() # Clear the screen to print the error message unicurses.beep() # Attempt to make a beep; may not be possible on Linux without the pcspkr driver loaded # Write a message stating how to get help with debugging for those who aren't programmers write('Fatal error occured: please send errorlog.txt to bb via [email protected]', 0, 0) write('Press any key to exit.', 0, 1) stdscr.refresh() get_key() # Wait for key os.remove('./temp.wav') # Remove the temporary song file unicurses.endwin() # Returns the terminal to it's original state
def main_loop(manga_list): global compc, compv for m in manga_list: req = _parsers.ParseRequest(m) sout, title, path = get_listing(req._name) if _g.conf._usecache and _g.conf._found_in_cache: sout = subdir_recurse(sout, path) else: sout = sout.splitlines() sout = rem_subdir_recurse(sout, path) compv, compc, allf, compfile = walk_thru_listing(req, title, sout) if req._vols and req._vols[-1] == req.ALL: del req._vols[-1] if req._chps and req._chps[-1] == req.ALL: del req._chps[-1] missv = str([v for v in req._vols if v not in compv]).strip('[]') missc = str([c for c in req._chps if c not in compc]).strip('[]') if missv: _out._("couldn't find vol(s): " + missv) if missc: _out._("couldn't find chp(s): " + missc) if any((compfile, compc, compv)): # XXX sigh... # need to append MLOC when we get a cache match. ppfx = ''.join(['https://', loc['DOMAIN']]) if _g.conf._found_in_cache: ppfx = ''.join([ppfx, loc['MLOC']]) try: stdscr = unicurses.initscr() _g.conf._stdscr = stdscr unicurses.noecho() if compfile: _out._('downloading complete archive... ', end='') _g.conf._stdscr.erase() _g.conf._stdscr.addstr(0, 0, compfile.name) _g.conf._stdscr.refresh() _curl.curl_to_file('/'.join([ppfx, _util.create_nwo_basename( compfile.basename), urllib .parse .quote(compfile.name)]), compfile.name, 'HTTP') elif compv or compc: _out._('downloading volume/chapters... ', end='') for f,v,c in allf: #_g.log.info('DL ' + f) _g.conf._stdscr.erase() _g.conf._stdscr.addstr(0, 0, 'title - {}' .format(title)) _g.conf._stdscr.addstr(1, 0, 'current - {}' .format(f.name)) _g.conf._stdscr.refresh() _curl.curl_to_file('/'.join([ppfx, _util .create_nwo_basename( f.basename), urllib .parse .quote(f.name)]), f.name, 'HTTP') except: raise finally: unicurses.nocbreak() _g.conf._stdscr.keypad(False) unicurses.echo() unicurses.endwin() print('done', file=sys.stderr) else: _out._('could not find any requested volume/chapters.') return 1 return 0