Ejemplo n.º 1
0
def main():
  ## Curses normal init sequence
  stdscr = curses.initscr()
  curses.noecho() # no echo, but we still see the cursor
  curses.curs_set(False) #turns off the cursor drawing
  stdscr.keypad(True) # allows special keys and arrow keys
  
  try:
    curses.start_color()

    window = curses.newwin(2, 25, 3, 5)
    window.addstr(0,0,"Hello, World!")

    # this window will now be displayed. Since we are doing getch
    # on window, that one is brought to front, window 2 isn't.
    # We can tackle this with panels. Or, explicitly call window2.refresh()
    window2 = curses.newwin(2, 25, 3, 50)
    window2.addstr(0,0,"Hello, World again!")
    
    while True:
      key = window.getch()
      if key == 27:
        break

  except Exception as e:
    stdscr.addstr(0,0,str(e))
    stdscr.getch()
  finally:
    
    curses.endwin()
  
  return 0
Ejemplo n.º 2
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        window = curses.newwin(10, 25, 3, 3)
        window.addstr(1, 1, "Hey there!")

        window.box()

        while True:
            key = window.getch()
            if key == 27:
                break

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
 def _curs_set(self,x):
     if self.cursor_state== "fixed" or x == self.cursor_state:
         return
     try:
         curses.curs_set(x)
         self.cursor_state = x
     except _curses.error:
         self.cursor_state = "fixed"
Ejemplo n.º 7
0
def terminateCursesTerminal(stdscr):
    """Terminate the curses terminal."""

    unicurses.nocbreak()
    unicurses.keypad(stdscr, False)
    unicurses.curs_set(True)
    unicurses.timeout(True)
    unicurses.echo()

    unicurses.endwin()
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def show_search_screen(stdscr):
    curses.curs_set(1)
    stdscr.addstr(1, 2, 'Artist name: (Enter to search)')

    editwin = curses.newwin(1, 40, 3, 3)
    rectangle(stdscr, 2, 2, 4, 44)
    stdscr.refresh()

    box = Textbox(editwin)
    box.edit()

    criteria = box.gather()
    return criteria
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
    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")
Ejemplo n.º 12
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        window = curses.newwin(3, 20, 5, 5)
        window.addstr(1, 1, "Hey there!")
        window.box()

        window2 = curses.newwin(3, 20, 4, 4)
        window2.addstr(1, 1, "Hey there, again!")
        window2.box()

        panel = curses.new_panel(window)
        panel2 = curses.new_panel(window2)

        #curses.move_panel(panel, 10, 30)

        curses.update_panels()
        curses.doupdate()

        top_p = None

        while True:
            key = curses.getch()
            if key == 27:
                break

            top_p = panel if top_p is panel2 else panel2
            curses.top_panel(top_p)

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 13
0
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))
Ejemplo n.º 14
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN)

        dude = curses.newwin(1, 1, 10, 30)
        curses.waddstr(dude, "@", curses.color_pair(2) + curses.A_BOLD)
        dude_panel = curses.new_panel(dude)

        grass = curses.newwin(10, 50, 5, 5)
        grass.bkgd(" ", curses.color_pair(1))
        grass_panel = curses.new_panel(grass)

        curses.top_panel(dude_panel)

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 15
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK,
                        curses.A_BOLD)

        curses.attron(curses.color_pair(1))
        curses.vline("|", 10)
        curses.hline("-", 10)
        curses.attroff(curses.color_pair(1))

        while True:
            key = curses.getch()

            avatar.move(key)

            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
Ejemplo n.º 16
0
    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()
Ejemplo n.º 17
0
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()
Ejemplo n.º 18
0
 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 = []
Ejemplo n.º 19
0

message_refresh_thread = threading.Thread(target=get_messages)

err = []
sock = socket.socket()
while True:
    try:
        sock.connect((HOST, PORT))
    except WindowsError:
        print("Can't connect: " + HOST + ':' + str(PORT))
        continue
    break
sock.sendall(bytes(channel + chr(0) + chr(3) + chr(0) + args.user, "utf-8"))
stdscr = u.initscr()
u.curs_set(0)
chat_win = u.newwin(25, 90, 0, 0)
input_win = u.newwin(5, 90, 25, 0)
people_win = u.newwin(30, 30, 0, 90)
message_refresh_thread.start()
while True:
    sock = socket.socket()
    u.wclear(input_win)
    u.mvwaddstr(input_win, 1, 1, '> ')
    refresh()
    u.flushinp()
    data = u.mvwgetstr(input_win, 1, 3)
    send = True
    # if len(data.split()) > 1:
    #     if data.split()[0] == ":send":
    #         file = data.split()[1]
Ejemplo n.º 20
0
 def show(self):
     self._win.clear()
     self._win.box()
     self._set_title()
     curses.curs_set(0)
     self._panel.show()
Ejemplo n.º 21
0
        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)
Ejemplo n.º 22
0
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
    'djprofessork': 'DJ Professor K',
Ejemplo n.º 23
0
    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)
    init_pair(11, COLOR_RED, COLOR_CYAN)
Ejemplo n.º 24
0
 def __init__(self):
     self.screen = unicurses.initscr()
     unicurses.noecho()
     unicurses.cbreak()
     unicurses.curs_set(0)
     self.screen.refresh()
Ejemplo n.º 25
0
 def cursor_set(self, yes: bool = True):
     """Sets wether or not to display the blinking cursor at cursor position."""
     unicurses.curs_set(False)
Ejemplo n.º 26
0
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:
    c = uni.wgetch(menu_win)
Ejemplo n.º 27
0
def initCurses():
    stdscr = uc.initscr()
    uc.noecho()
    uc.curs_set(False)
    uc.keypad(stdscr, True)
    uc.start_color()
Ejemplo n.º 28
0
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()
Ejemplo n.º 29
0
import random
import unicurses

s = unicurses.initscr()
unicurses.curs_set(0)
sh, sw = s.getmaxyx()
w = unicurses.newwin(sh, sw, 0, 0)
w.keypad(1)
w.timeout(100)

snk_x = sw/4
snk_y = sh/2
snake = [
    [snk_y, snk_x],
    [snk_y, snk_x-1],
    [snk_y, snk_x-2]
]

food = [sh//2, sw//2]
w.addch(food[0], food[1], unicurses.ACS_PI)

key = unicurses.KEY_RIGHT

while True:
    next_key = w.getch()
    key = key if next_key == -1 else next_key

    if snake[0][0] in [0, sh] or snake[0][1]  in [0, sw] or snake[0] in snake[1:]:
        unicurses.endwin()
        quit()
Ejemplo n.º 30
0
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():
    '''
Ejemplo n.º 31
0
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