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 __init__(self, screen, args): self.log = logging.getLogger(__name__) self.log.debug("Initializing screen.") self.args = args self.interactive = not args.non_interactive if self.interactive: res, ret = unicurses.KEY_RESIZE, unicurses.KEY_ENTER self.ctrlchars = (res, ret, ord('\n'), ord('\x1b')) self.msg = None self.screen = screen self.h, self.w = 22, 78 self.wrap = textwrap.TextWrapper(width=self.w - 1) self.initattrs() self.frame = unicurses.newwin(self.h + 2, self.w + 2, 0, 0) unicurses.wborder(self.frame) self.win = unicurses.newwin(self.h, self.w, 0, 0) unicurses.keypad(self.win, 1) self.sslnoverify = sys.version_info >= (2, 7, 9) and args.ssl_no_verify self.loadst, self.savest = True, True self.state = DataTree(self, {}) self.oldstate = DataTree(self, {}) self.validate = Validate(self) self.format = Format(self) self.nexus = Nexus(self) self.artifactory = Artifactory(self) self.initstate(args.load_file) self.log.debug("Screen initialized.")
def showLineEdit(self, sel, quiet): maxwidth = 4096 fw, hw = self.scr.w - 2, (self.scr.w - 2) / 2 unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ") unicurses.noutrefresh(self.scr.win) (yn, xn) = unicurses.getyx(self.scr.win) buf = unicurses.newpad(1, maxwidth + 1) unicurses.keypad(buf, 1) offs, length, submit = 0, 0, False if not quiet and sel['val'] != None and sel['val'] != (None, ): length = len(sel['val']) unicurses.waddstr(buf, sel['val']) offs = max(0, length / hw - 1) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() while True: if quiet: ch = self.scr.getch(buf, redact=True) else: etc = (buf, 0, offs * hw, yn, xn, yn, xn + fw - 1) ch = self.scr.getch(buf, etc) (y, x) = unicurses.getyx(buf) if ch in (ord('\n'), unicurses.KEY_ENTER): sel['val'] = unicurses.mvwinstr(buf, 0, 0, length) if sel['val'] != None and len(sel['val']) == 0: sel['val'] = None submit = True break elif ch == ord('\x1b'): break elif ch == unicurses.KEY_HOME and x > 0: unicurses.wmove(buf, y, 0) elif ch == unicurses.KEY_END and x < length: unicurses.wmove(buf, y, length) elif ch == unicurses.KEY_LEFT and x > 0: unicurses.wmove(buf, y, x - 1) elif ch == unicurses.KEY_RIGHT and x < length: unicurses.wmove(buf, y, x + 1) elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE, unicurses.KEY_DC) and x > 0: unicurses.wmove(buf, y, x - 1) unicurses.wdelch(buf) length -= 1 elif ord(' ') <= ch <= ord('~') and length < maxwidth: unicurses.winsstr(buf, chr(ch)) length += 1 unicurses.wmove(buf, y, x + 1) else: continue if quiet: continue oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1] / hw - 1) if oldoffs < offs and maxwidth - offs * hw < fw: unicurses.wclrtoeol(self.scr.win) unicurses.noutrefresh(self.scr.win) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs * hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() return submit
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 showLineEdit(self, sel, quiet): maxwidth = 4096 fw, hw = self.scr.w - 2, (self.scr.w - 2)/2 unicurses.waddstr(self.scr.win, "Edit " + sel['text'] + ":\n> ") unicurses.noutrefresh(self.scr.win) (yn, xn) = unicurses.getyx(self.scr.win) buf = unicurses.newpad(1, maxwidth + 1) unicurses.keypad(buf, 1) offs, length, submit = 0, 0, False if not quiet and sel['val'] != None: length = len(sel['val']) unicurses.waddstr(buf, sel['val']) offs = max(0, length/hw - 1) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() while True: if quiet: ch = self.scr.getch(buf) else: etc = (buf, 0, offs*hw, yn, xn, yn, xn + fw - 1) ch = self.scr.getch(buf, etc) (y, x) = unicurses.getyx(buf) if ch in (ord('\n'), unicurses.KEY_ENTER): sel['val'] = unicurses.mvwinstr(buf, 0, 0, length) if sel['val'] != None and len(sel['val']) == 0: sel['val'] = None submit = True break elif ch == ord('\x1b'): break elif ch == unicurses.KEY_HOME and x > 0: unicurses.wmove(buf, y, 0) elif ch == unicurses.KEY_END and x < length: unicurses.wmove(buf, y, length) elif ch == unicurses.KEY_LEFT and x > 0: unicurses.wmove(buf, y, x - 1) elif ch == unicurses.KEY_RIGHT and x < length: unicurses.wmove(buf, y, x + 1) elif ch in (ord('\b'), ord('\x7f'), unicurses.KEY_BACKSPACE, unicurses.KEY_DC) and x > 0: unicurses.wmove(buf, y, x - 1) unicurses.wdelch(buf) length -= 1 elif ord(' ') <= ch <= ord('~') and length < maxwidth: unicurses.winsstr(buf, chr(ch)) length += 1 unicurses.wmove(buf, y, x + 1) else: continue if quiet: continue oldoffs, offs = offs, max(0, unicurses.getyx(buf)[1]/hw - 1) if oldoffs < offs and maxwidth - offs*hw < fw: unicurses.wclrtoeol(self.scr.win) unicurses.noutrefresh(self.scr.win) (yb, xb) = unicurses.getbegyx(self.scr.win) (yp, xp) = (yn + yb, xn + xb) unicurses.prefresh(buf, 0, offs*hw, yp, xp, yp, xp + fw - 1) unicurses.doupdate() return submit
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 __init__(self, screen): self.msg = None self.screen = screen self.modified = False self.h, self.w = 22, 78 self.nexus = Nexus() self.artifactory = Artifactory(self) self.wrap = textwrap.TextWrapper(width=self.w) self.initattrs() self.frame = unicurses.newwin(self.h + 2, self.w + 2, 0, 0) unicurses.wborder(self.frame) self.win = unicurses.newwin(self.h, self.w, 0, 0) unicurses.keypad(self.win, 1)
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 __init__(self, screen): self.msg = None self.screen = screen self.mainmenu = None self.oldstate = None self.h, self.w = 22, 78 self.nexus = Nexus() self.artifactory = Artifactory(self) self.wrap = textwrap.TextWrapper(width=self.w - 1) self.initattrs() self.frame = unicurses.newwin(self.h + 2, self.w + 2, 0, 0) unicurses.wborder(self.frame) self.win = unicurses.newwin(self.h, self.w, 0, 0) unicurses.keypad(self.win, 1)
def _init_curses(self): """Initialize the curses environment and windows.""" for win in self.get_windows(): # Make getch and getstr non-blocking. uc.nodelay(win, True) # Allow non-ascii keys. uc.keypad(win, True) # Don't echo text. uc.noecho() # Don't show the cursor. uc.curs_set(False) logger.debug("Curses display initialized")
def __init__(self, screen): self.log = logging.getLogger(__name__) self.log.debug("Initializing curses screen.") self.msg = None self.screen = screen self.mainmenu = None self.oldstate = None self.h, self.w = 22, 78 self.nexus = Nexus() self.artifactory = Artifactory(self) self.wrap = textwrap.TextWrapper(width=self.w - 1) self.initattrs() self.frame = unicurses.newwin(self.h + 2, self.w + 2, 0, 0) unicurses.wborder(self.frame) self.win = unicurses.newwin(self.h, self.w, 0, 0) unicurses.keypad(self.win, 1) self.log.debug("Curses screen initialized.")
def __init__(self, items, stdscreen): self.width = 30 self.height = 10 self.startx = int((80 - self.width) / 2) self.starty = int((24 - self.height) / 2) self.window = uni.newwin(self.height, self.width, self.starty, self.startx) #stdscreen.subwin(0,0) #self.window.keypad(1) uni.keypad(self.window, True) self.panel = uni.new_panel(self.window) #.panel.new_panel(self.window) #self.panel.hide() #uni.hide_panel(self.panel) uni.update_panels() #uni.panel.update_panels() self.position = 0 self.items = items self.items.append(('exit', 'exit'))
def main(): stdscr = curses.initscr() curses.keypad(stdscr, True) curses.curs_set(False) curses.noecho() curses.start_color() select = mainmenu() curses.erase() if (select == 3): pass elif (select == 2): curses.mvaddstr(1, 1, "Lataa peli") elif (select == 1): newgame() create_game() game_main_loop() curses.endwin()
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 = []
27, # Esc 'q', 113, 'Q', 81 ] # Window NLINES = 10 NCOLS = 40 #my_wins = [0] * 3 stdscr = uni.initscr() uni.cbreak() uni.noecho() uni.keypad(stdscr, True) uni.curs_set(0) uni.start_color() # Sub window # Max coords of parent window maxy, maxx = uni.getmaxyx(stdscr) menu_height = 3 menu = uni.newwin(menu_height, maxx, 0, 0) starty, startx = uni.getbegyx(menu) height, width = uni.getmaxyx(menu) # Box line uni.box(menu, 0, 0) #uni.bkgd(uni.COLOR_PAIR(1))
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) init_pair(11, COLOR_RED, COLOR_CYAN)
def __init__(self): stdscr = uni.initscr() uni.start_color() uni.cbreak() uni.noecho() uni.keypad(stdscr, True)
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) init_pair(11, COLOR_RED, COLOR_CYAN)
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(): '''
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: c = uni.wgetch(menu_win) if c == uni.KEY_MOUSE: id, x, y, z, bstate = uni.getmouse() if bstate & uni.BUTTON1_PRESSED: chosen = report_choice(x + 1, y + 1) if chosen is not None:
def initCurses(): stdscr = uc.initscr() uc.noecho() uc.curs_set(False) uc.keypad(stdscr, True) uc.start_color()
import unicurses import numpy as np import math import wave import struct import time stdscr = unicurses.initscr() unicurses.cbreak() unicurses.noecho() unicurses.curs_set(0) unicurses.keypad(stdscr, True) LINES, COLS = unicurses.getmaxyx(stdscr) height = 16 def drawData(data, x, y): for i in range(len(data)): v = data[i] for j in range(height): c = ' ' if (j <= v - 1): c = '#' unicurses.mvaddstr(y + height - 1 - j, x + i, c) # Initialize matrix matrix = [0, 0, 0, 0, 0, 0, 0, 0] power = [] weighting = [2, 2, 8, 8, 16, 32, 64, 64] # Change these according to taste # Set up audio