Example #1
0
File: ui.py Project: anmitsu/pyful
 def enable(cls, flag):
     if flag:
         attr = curses.BUTTON1_CLICKED | curses.BUTTON1_DOUBLE_CLICKED
         curses.mousemask(attr)
         curses.mouseinterval(200)
     else:
         curses.mousemask(0)
Example #2
0
def main(screen):
	#screen = curses.initscr() 
	#curses.noecho() 
	curses.curs_set(0) 
	screen.keypad(1) 
	curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)

	screen.addstr("This is a Sample Curses Script\n\n")
	# printf("\033[?1003h\n"); // Makes the terminal report mouse movement events
	print '\033[?1003h'


	it = 1;
	while True:
	    event = screen.getch()
	    screen.addstr(8, 10, "Iteration:" + str(it))
	    it += 1
	    screen.addstr(9, 10, "Event:" + str(event))
	    if event == curses.ERR: break
	    if event == ord("q"): break 
	    if event == curses.KEY_MOUSE:
	        # _, mx, my, _, _ = curses.getmouse()
	        # y, x = screen.getyx()
	        screen.addstr(10, 10, "pippo")
	        screen.addstr(11, 10, str(curses.getmouse()) + "                      ")
Example #3
0
    def __init__(self, evm):
        self.evm = evm
        evm.RegisterListener(self)
        # first we must create a window object; it will fill the whole screen
        self.scrn = curses.initscr()
        # turn off keystroke echo
        curses.noecho()
        # keystrokes are honored immediately, rather than waiting for the
        # user to hit Enter
        curses.cbreak()

        self.scrn.keypad(1)

        self.scrn.nodelay(1)
        # start color display (if it exists; could check with has_colors())
        curses.start_color()

        curses.mousemask(curses.BUTTON1_PRESSED)

        curses.curs_set(0)

        # clear screen
        self.scrn.clear()

        i = 1
        for color_background in self.list_of_colors:
            for color_foreground in self.list_of_colors:
                curses.init_pair(i, color_foreground, color_background)
                self.mapping[color_foreground, color_background] = i
                i += 1

        # implement the actions done so far (just the clear())
        self.scrn.refresh()
Example #4
0
    def __init__(self, evm):
        self.evm = evm
        evm.RegisterListener(self)
        # first we must create a window object; it will fill the whole screen
        self.scrn = curses.initscr()
        # turn off keystroke echo
        curses.noecho()
        # keystrokes are honored immediately, rather than waiting for the
        # user to hit Enter
        curses.cbreak()

        self.scrn.keypad(1)

        self.scrn.nodelay(1)
        # start color display (if it exists; could check with has_colors())
        curses.start_color()

        curses.mousemask(curses.BUTTON1_PRESSED)

        curses.curs_set(0)

        # clear screen
        self.scrn.clear()

        i = 1
        for color_background in self.list_of_colors:
            for color_foreground in self.list_of_colors:
                curses.init_pair(i, color_foreground, color_background)
                self.mapping[color_foreground, color_background] = i
                i += 1

        # implement the actions done so far (just the clear())
        self.scrn.refresh()
Example #5
0
def main(argv):
    global mines, board

    args = map(int, argv[1:])
    xw = int(args[0]) if args else 20
    yw = int(args[1]) if len(args) > 1 else xw / 2
    mines = int(args[2]) if len(args) > 2 else int(xw * yw / 20)

    board = [' ' * xw for i in range(yw)]
    mines = {(randint(0, xw), randint(0, yw)) : True for i in range(mines)}

    scr = curses.initscr()
    scr.keypad(1)
    curses.curs_set(0)
    curses.noecho()
    curses.mousemask(curses.ALL_MOUSE_EVENTS)

    while True:
        scr.clear()

        k = scr.getch()
        scr.addstr(yw + 2, 0, ': ' + str(k))
        if k == 27:
            break
        elif k == curses.KEY_MOUSE:
            _, x, y, z, bstate = curses.getmouse()
            scr.addstr(y, x, ' '.join(str(v) for v in (z, bstate)))
        elif k == curses.KEY_DC:
            boom(scr)

    scr.clear()
    curses.endwin()
Example #6
0
def main():
    os.environ["ESCDELAY"] = "0"

    stdscr = curses.initscr()
    curses.noecho()
    curses.raw()
    curses.curs_set(False)

    # Enable mouse actions.
    curses.mousemask(curses.BUTTON1_CLICKED | curses.BUTTON1_DOUBLE_CLICKED)

    stdscr.keypad(True)
    stdscr.nodelay(True)
    stdscr.notimeout(True)

    try:
        history = []
        while True:
            key, arg = get_key(stdscr)
            k = "{!r}, {!r}".format(key, arg)
            history.append(k)
            if len(history) > 10:
                history.pop(0)
            stdscr.clear()
            for i in range(len(history)):
                stdscr.addstr(i, 2, history[i])
            if key == "q" or key == 113:
                break
    finally:
        curses.curs_set(True)
        curses.noraw()
        stdscr.keypad(False)
        curses.echo()
        curses.endwin()
Example #7
0
def curses_destroy(stdscr):
    curses.echo()
    curses.nocbreak()
    stdscr.keypad(False)
    curses.endwin()
    curses.mousemask(0)
    curses.curs_set(1)
Example #8
0
def setup():
    """
     sets environment up and creates main window
     :returns: the main window object
    """
    # setup the console
    mmask = curses.ALL_MOUSE_EVENTS # for now accept all mouse events
    main = curses.initscr()         # get a window object
    y,x = main.getmaxyx()           # get size
    if y < 24 or x < 80:            # verify minimum size rqmts
        raise RuntimeError("Terminal must be at least 80 x 24")
    curses.noecho()                 # turn off key echoing
    curses.cbreak()                 # turn off key buffering
    curses.mousemask(mmask)         # accept mouse events
    initcolors()                    # turn on and set color pallet
    main.keypad(1)                  # let curses handle multibyte special keys
    main.clear()                    # erase everything
    banner(main)                    # write the banner
    mainmenu(main)                  # then the min and menu
    main.attron(CPS[RED])           # make the border red
    main.border(0)                  # place the border
    main.attroff(CPS[RED])          # turn off the red
    curses.curs_set(0)              # hide the cursor
    main.refresh()                  # and show everything
    return main
Example #9
0
def init_curses(escape_delay=None, use_mouse=False):
    """
    """
    #The ESCDELAY environment variable controls how long curses waits in getch
    #to see if the Esc Key is being used for an escape sequence. If ESCDELAY is
    #not set then it will wait 1s, this is commonly an annoyance.
    if escape_delay is None:
        if 'ESCDELAY' not in os.environ:
            os.environ['ESCDELAY'] = '10'  # A 10ms delay as default
    else:
        os.environ['ESCDELAY'] = str(escape_delay)

    #Initialize our curses environment
    #return_code = None
    locale.setlocale(locale.LC_ALL, '')
    stdscr = curses.initscr()
    try:
        curses.start_color()
    except:
        pass
    #These lines might be redundant after curses.initscr()?
    curses.noecho()
    curses.cbreak()
    stdscr.keypad(1)

    if use_mouse:
        curses.mousemask(curses.ALL_MOUSE_EVENTS)
        #curses.mousemask(curses.REPORT_MOUSE_POSITION)

    return stdscr
Example #10
0
def main(screen):
    curses.curs_set(0)
    curses.mousemask(curses.BUTTON1_PRESSED)

    x1, y1 = None, None

    while True:

        # Get key input
        key = screen.getch()
        # screen.clear()

        if key == curses.KEY_MOUSE:
            _, mouseX, mouseY, _, _ = curses.getmouse()

            screen.addstr(0, 0, '({}, {})'.format(mouseX, mouseY))
            screen.refresh()

            if not x1 and not y1:
                x1, y1 = mouseX, mouseY
            else:
                line(screen, x1, y1, mouseX, mouseY)
                x1, y1 = None, None

        elif key == ord('q'):
            break

        elif key == ord('c'):
            screen.clear()
Example #11
0
 def setup_mouse(self):
     # Mouse support
     curses.mouseinterval(10)
     if self.app.config["editor"]["use_mouse"]:
         curses.mousemask(-1)  # All events
     else:
         curses.mousemask(0)  # All events
Example #12
0
    def main():
        stdscr = curses.initscr()
        # curses.curs_set(0)
        curses.mousemask(1)
        stdscr.scrollok(1)
        stdscr.idlok(1)

        # Create a scrolling pad.
        pad = stdscr.subpad(0, 0)
        pad.scrollok(1)
        pad.idlok(1)
        pad.nodelay(1)

        # Get a callback dictionary with the ch as the keys
        # and the `callback` method as the values
        callback_dictionary = get_callback_dict('text_editor_callbacks',
                                                excludes=['common'],
                                                ch=True)

        # Instantiate the interface.
        interface = Interface(pad, callbacks=callback_dictionary)
        # A callback can be registered using the instance.
        # interface.set_callback(32, callback_dictionary[32])

        # Start the main function and make sure everything restarts.
        try:
            interface.main()
        finally:
            interface.curses.nocbreak()
            interface.stdscr.keypad(False)
            interface.curses.echo()
            interface.curses.endwin()
    def initcurse(self):
        
        # Check the terminal type.  If we fail, then assume that the
        # terminal has no capabilities.
        try: curses.setupterm()
        except: return
        
        #self.colors = cursescolors()
        
        self.cols = curses.tigetnum('cols')
        self.lines = curses.tigetnum('lines')
        self.wfilelines = self.lines-3

        self.w = curses.initscr()
        # fenetre                    hauteur          largeur    y             x
        self.wheader = curses.newwin(              1, self.cols,            0, 0)
        self.wfile   = curses.newwin(self.wfilelines, self.cols,            1, 0)
        self.wfooter = curses.newwin(              1, self.cols, self.lines-2, 0)
        self.wcmd    = curses.newwin(              1, self.cols, self.lines-1, 0)
        curses.noecho()
        curses.cbreak()
        curses.nonl() # permet d'activer la touche enter (code 13)
        curses.curs_set(0)
        curses.mousemask(0)
        curses.mouseinterval(0)
        self.w.keypad(1)
        self.w.nodelay(0)
        self.w.timeout(self.timeout)
        
        try:
            self.initcolors_1()
        except:
            self.initcolors_2()
Example #14
0
    def __init__(self, stdscr, state):
        self.state = state
        self.scr = stdscr
        curses.mousemask(curses.BUTTON1_CLICKED)
        curses.init_pair(1, WHITE_PIECES,
                         DARK_SQUARES)  # White piece on dark square
        curses.init_pair(2, WHITE_PIECES, LIGHT_SQUARES)  # White on bright
        curses.init_pair(3, BLACK_PIECES, DARK_SQUARES)  # Black on dark
        curses.init_pair(4, BLACK_PIECES, LIGHT_SQUARES)  # Black on bright
        curses.init_pair(5, 0, 12)  # Status bar
        curses.init_pair(6, 15, 9)  # [FAIL]
        curses.init_pair(7, 15, 2)  # [OK]
        curses.init_pair(8, 9, 0)  # Logo
        curses.init_pair(9, 14, 0)  # Bright white on black
        curses.init_pair(10, 10, 0)  # Past move from/to marker, move text
        curses.init_pair(11, 9, 4)  # Move selector from/to marker

        curses.halfdelay(1)
        self.scr.clear()

        self.widgets = [
            MoveReady(stdscr, state),
            Logo(stdscr, state),
            HelpPane(stdscr, state),
            Status(stdscr, state),
            ChessBoard(stdscr, state),
            StatusBar(stdscr, state),
            Engine(stdscr, state),
            Timer(stdscr, state),
            Info(stdscr, state),
            MoveList(stdscr, state),
            Promotions(stdscr, state),
            MoveInput(stdscr, state),
        ]
 def initwheel(self):
     if self.wheelon == False:
         curses.mousemask(0)
     else:
         curses.mousemask(curses.BUTTON1_CLICKED | curses.BUTTON2_CLICKED | curses.BUTTON3_CLICKED | curses.BUTTON4_CLICKED |
                         curses.BUTTON1_PRESSED | curses.BUTTON2_PRESSED | curses.BUTTON3_PRESSED | curses.BUTTON4_PRESSED |
                         curses.BUTTON1_RELEASED | curses.BUTTON2_RELEASED | curses.BUTTON3_RELEASED | curses.BUTTON4_RELEASED )
Example #16
0
    def main(self, stdscr):

        try:

            curses.start_color()
            curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_BLUE)
            curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_YELLOW)
            curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)

            curses.mousemask(1)

            height, width = stdscr.getmaxyx()
            field = curses.newwin(50, 100, 0, width / 2 - 50)
            field.border(0)
            field.addstr(1, 15, "Enter Text In here", curses.A_REVERSE)
            field.refresh()

            #Add the help and view options field
            options = curses.newwin(20, 100, 50, width / 2 - 50)
            options.border(0)
            options.bkgd(curses.color_pair(3))
            options.addstr(0, 35, "OPTIONS ARE TO BE INCLUDED", curses.A_BLINK)
            options.addstr(
                2, 2,
                "Control H = Backspace. Delete option will be in later version"
            )
            options.addstr(3, 2, "Arrows = line navigation")
            options.addstr(4, 2, "Control K = Delete a whole line")
            options.addstr(5, 2, "Control G = Save and Exit the file")
            options.addstr(10, 2, "Current version: 1.0.0 >Developed by James",
                           curses.A_BOLD)
            options.addstr(12, 2,
                           "Alot of the key features are not working yet",
                           curses.A_BOLD)
            options.refresh()

            current_win = curses.newwin(20, 52, 0, 0)
            current_win.border(0)
            current_win.bkgd(curses.color_pair(6))
            current_win.addstr(0, 18, self.fileName.upper(), curses.A_REVERSE)
            current_win.addstr(2, 2, "Current date is: " + str(date.today()))
            current_win.addstr(4, 2,
                               "Current Admin User: "******"You are currently in Edit Mode:::")
            current_win.refresh()

            #<!---- Text Field Beginning ---->

            tbWin = curses.newwin(48, 98, 1, width / 2 - 49)
            tbWin.bkgd(curses.color_pair(5))
            tb = curses.textpad.Textbox(tbWin, insert_mode=True)
            tb.edit()
            tbWin.refresh()
            tbWin.getch()
            self.file_content = tb.gather()
        finally:  #This is the end of the ui, This is where we begin to save the contents
            curses.endwin()
            self.saveState(self.fileName, self.file_content)
            print "File has been created!"
def main(win):

    curses.mousemask(1)
    
    while True:
        win.refresh()
                                             
        event = win.getch()
        y, x = win.getyx() # get current pos of cursor
        
        if event == ord("q"): break
        elif event == 9: # tab
                pass
        elif event == 263: # delete
                if x>0:
                        win.delch(y,x-1)
        elif event == curses.KEY_LEFT:
                if x>0:
                        win.move(y,x-1)
        elif event == curses.KEY_RIGHT:
                if x<curses.COLS-1:
                        win.move(y,x+1)
        elif event == curses.KEY_UP:
                pass
        elif event == curses.KEY_DOWN:
                pass
        elif event == 10:
                pass
        else:
                win.addstr(chr(event),1)
Example #18
0
def UI(stdscr, board):
    curses.echo()
    curses.mousemask(1)
    curses.init_pair(2, 255, 1)
    curses.init_pair(12, 232, 1)
    curses.init_pair(3, 255, 130)
    curses.init_pair(13, 232, 130)
    curses.init_pair(4, 255, 88)
    curses.init_pair(14, 232, 88)
    curses.init_pair(5, 255, 4)
    curses.init_pair(15, 232, 4)
    p1, p2 = side_select(stdscr)
    draw_board(stdscr, board)
    if not os.path.exists('logs'):
        os.makedirs('logs')
    with open(
            os.path.join(
                'logs',
                str(datetime.datetime.now()).replace(' ', '_').replace(
                    ':', '-') + '.log'), 'w', 1) as moves_file:
        while not board.is_game_over():
            current_player = p1 if board.turn else p2
            quit = current_player(board)
            moves_file.write('%s\n' % board.peek())
            if quit:
                break
            stdscr.clear()
            draw_board(stdscr, board)
            assert board.is_valid()
        stdscr.addstr(get_results(board.result()))
        _ = stdscr.getch()
Example #19
0
    def initialize(self):
        if Window.INSTANCE is not None:
            raise RuntimeError('Window already present.')

        Window.INSTANCE = self

        def init_color():
            for a in range(-1, 15):
                for b in range(-1, 15):
                    if a != -1 or b != -1:
                        _curses.init_pair(self._color(a, b), a, b)

        self._window = _curses.initscr()
        self._window.keypad(True)
        self._window.timeout(1000)
        _curses.noecho()
        _curses.cbreak()
        _curses.mouseinterval(1)
        _curses.mousemask(0 | _curses.BUTTON1_PRESSED
                          | _curses.BUTTON1_RELEASED)
        _curses.curs_set(0)

        try:
            _curses.start_color()
            _curses.use_default_colors()
            init_color()
        except _curses.error:
            pass
Example #20
0
def main(stdscr):
	curses.curs_set(0)
	curses.mousemask(1)
	curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_RED)
	curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_GREEN)

	stdscr.addstr(0, 0, "Hello!")
	stdscr.addstr(1, 0, "Red")
	stdscr.addstr(2, 0, "Green")

	while 1:
		stdscr.refresh()
		key = stdscr.getch()

		if key == curses.KEY_MOUSE:
			_, x, y, _, _ = curses.getmouse()
			if y == 1 and x in range(3):
				stdscr.attron(curses.color_pair(1))
				stdscr.addstr(0, 0, "Hello!")
				stdscr.attroff(curses.color_pair(1))
			elif y == 2 and x in range(5):
				stdscr.attron(curses.color_pair(2))
				stdscr.addstr(0, 0, "Hello!")
				stdscr.attroff(curses.color_pair(2))
		elif key == 27:
			break
Example #21
0
def UI(stdscr, board):
    curses.echo()
    curses.mousemask(1)
    curses.init_pair(2, 255, 1)
    curses.init_pair(12, 232, 1)
    curses.init_pair(3, 255, 130)
    curses.init_pair(13, 232, 130)
    curses.init_pair(4, 255, 88)
    curses.init_pair(14, 232, 88)
    curses.init_pair(5, 255, 4)
    curses.init_pair(15, 232, 4)
    p1, p2 = side_select(stdscr)
    draw_board(stdscr, board)
    if not os.path.exists('logs'):
        os.makedirs('logs')
    with open(os.path.join('logs', str(datetime.datetime.now()).replace(' ', '_').replace(':', '-') + '.log'), 'w', 1) as moves_file:
        while not board.is_game_over():
            current_player = p1 if board.turn else p2
            quit = current_player(board)
            moves_file.write('%s\n' % board.peek())
            if quit:
                break
            stdscr.clear()
            draw_board(stdscr, board)
            assert board.is_valid()
        stdscr.addstr(get_results(board.result()))
        _ = stdscr.getch()
Example #22
0
 def scrinit(self):
     pad = curses.newpad(self.height, self.width)  # 初始化显示区域
     curses.noecho()
     curses.cbreak()
     curses.mousemask(curses.ALL_MOUSE_EVENTS)
     pad.keypad(True)
     return pad
Example #23
0
    def set_mouse_tracking(self, enable=True):
        """
        Enable mouse tracking.

        After calling this function get_input will include mouse
        click events along with keystrokes.
        """
        enable = bool(enable)
        if enable == self._mouse_tracking_enabled:
            return

        if enable:
            curses.mousemask(0
                             | curses.BUTTON1_PRESSED | curses.BUTTON1_RELEASED
                             | curses.BUTTON2_PRESSED | curses.BUTTON2_RELEASED
                             | curses.BUTTON3_PRESSED | curses.BUTTON3_RELEASED
                             | curses.BUTTON4_PRESSED | curses.BUTTON4_RELEASED
                             | curses.BUTTON1_DOUBLE_CLICKED
                             | curses.BUTTON1_TRIPLE_CLICKED
                             | curses.BUTTON2_DOUBLE_CLICKED
                             | curses.BUTTON2_TRIPLE_CLICKED
                             | curses.BUTTON3_DOUBLE_CLICKED
                             | curses.BUTTON3_TRIPLE_CLICKED
                             | curses.BUTTON4_DOUBLE_CLICKED
                             | curses.BUTTON4_TRIPLE_CLICKED
                             | curses.BUTTON_SHIFT | curses.BUTTON_ALT
                             | curses.BUTTON_CTRL)
        else:
            raise NotImplementedError()

        self._mouse_tracking_enabled = enable
Example #24
0
def main(stdscr):
    curses.curs_set(0)
    curses.mousemask(1)
    curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)

    stdscr.addstr(0, 0, tittle)
    stdscr.addstr(15, 0, "Red")
    stdscr.addstr(16, 0, "Green")

    while 1:
        stdscr.refresh()
        key = stdscr.getch()

        if key == curses.KEY_MOUSE:
            _, x, y, _, _ = curses.getmouse()
            if y == 15 and x in range(3):
                stdscr.attron(curses.color_pair(1))
                stdscr.addstr(0, 0, tittle)
                stdscr.attroff(curses.color_pair(1))
            elif y == 16 and x in range(5):
                stdscr.attron(curses.color_pair(2))
                stdscr.addstr(0, 0, tittle)
                stdscr.attroff(curses.color_pair(2))
        elif key == 27:
            break
Example #25
0
 def __init__(self):
     self.scr = curses.initscr()
     self.scr.keypad(1)
     curses.mousemask(curses.ALL_MOUSE_EVENTS)
     curses.start_color()
     curses.init_pair(1, curses.COLOR_BLACK, 255)
     self.scr.bkgd(" ", curses.color_pair(0))
Example #26
0
    def set_mouse_tracking(self, enable=True):
        """
        Enable mouse tracking.

        After calling this function get_input will include mouse
        click events along with keystrokes.
        """
        enable = bool(enable)
        if enable == self._mouse_tracking_enabled:
            return

        if enable:
            curses.mousemask(0
                | curses.BUTTON1_PRESSED | curses.BUTTON1_RELEASED
                | curses.BUTTON2_PRESSED | curses.BUTTON2_RELEASED
                | curses.BUTTON3_PRESSED | curses.BUTTON3_RELEASED
                | curses.BUTTON4_PRESSED | curses.BUTTON4_RELEASED
                | curses.BUTTON1_DOUBLE_CLICKED | curses.BUTTON1_TRIPLE_CLICKED
                | curses.BUTTON2_DOUBLE_CLICKED | curses.BUTTON2_TRIPLE_CLICKED
                | curses.BUTTON3_DOUBLE_CLICKED | curses.BUTTON3_TRIPLE_CLICKED
                | curses.BUTTON4_DOUBLE_CLICKED | curses.BUTTON4_TRIPLE_CLICKED
                | curses.BUTTON_SHIFT | curses.BUTTON_ALT
                | curses.BUTTON_CTRL)
        else:
            raise NotImplementedError()

        self._mouse_tracking_enabled = enable
Example #27
0
File: t.py Project: int3l/explains
def c_main(stdscr: curses._CursesWindow) -> int:
    curses.mousemask(-1)
    curses.mouseinterval(0)

    pressed = False
    x, y = 0, 0

    stdscr.addstr('hello hello world')

    while True:
        stdscr.erase()
        stdscr.addstr('click anywhere!')
        if pressed:
            for y in range(y - 1, y + 2):
                stdscr.addstr(y, x - 1, 'XXX')

        c = stdscr.get_wch()
        if c == 'q':
            return 0
        elif c == curses.KEY_MOUSE:
            _, x, y, _, bstate = curses.getmouse()
            if bstate & curses.BUTTON1_PRESSED:
                pressed = True
            elif bstate & curses.BUTTON1_RELEASED:
                pressed = False
        else:
            raise AssertionError(c)
Example #28
0
def run():
    ch = -1
    count = 0
    event = None

    os.environ['TERM'] = "xterm-1003"

    screen = curses.initscr()
    curses.raw()
    screen.keypad(True)
    curses.noecho()

    screen.clear()
    curses.cbreak()

    curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)

    while ch != ord('q'):
        count += 1
        # screen.addstr(1, 1, "Has mouse {}".format(curses.has_mouse()))
        screen.addstr(
            2, 1, "Key code: {}; mouse code:{}".format(ch, curses.KEY_MOUSE))
        if ch == curses.KEY_MOUSE:
            event = curses.getmouse()
            screen.addstr(
                3, 3,
                "Mouse Event: x={}, y={}, z={}".format(event[1], event[2],
                                                       event[3]))
            screen.addstr(4, 3, "Mouse device id: {}".format(event[0]))
            screen.addstr(5, 3, "Mouse button mask: {}".format(event[4]))
        screen.addstr(6, 1, "Event number: {}".format(count))
        screen.refresh()
        ch = screen.getch()
    curses.endwin()
Example #29
0
    def __init__(self):
        self.vk_s = vk_api.interactive_log_in()
        self.vk = self.vk_s.get_api()

        self.screen = curses.initscr()

        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        self.screen.keypad(1)
        curses.mousemask(curses.ALL_MOUSE_EVENTS)

        curses.start_color()
        curses.init_pair(1, curses.COLOR_WHITE + 8, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_WHITE + 8, curses.COLOR_RED + 8)
        curses.init_pair(3, curses.COLOR_WHITE + 8, curses.COLOR_BLACK + 8)
        curses.init_color(0, 145, 145, 145)

        self.style_highlighted = curses.color_pair(1) | curses.A_REVERSE
        self.style_title = curses.color_pair(1)
        self.style_statusline = curses.color_pair(2)
        self.style_hovered = curses.color_pair(3)

        self.height, self.width = self.screen.getmaxyx()

        self.mx, self.my = -1, -1
        self.bstate = 0

        self.statusline_text = ''
        self.last_statusline_style = self.style_statusline

        self.conversations = conversations.Conversations(
            self.height, 50, self, 0, 0)
        self.activity = self.conversations
Example #30
0
def main(screen):


    screen.keypad(1)
    curses.mousemask(1)
    populate_list(screen, "./list.txt")


    while True:                                            
        event = screen.getch()
        y, x = screen.getyx() # get current pos of cursor
                
        if event == ord("q"): break
        elif event == curses.KEY_LEFT:
                if x>0:
                        screen.move(y,x-1)
        elif event == curses.KEY_RIGHT:
                if x<curses.COLS-1:
                        screen.move(y,x+1)
        elif event == curses.KEY_UP:
                if y>0:
                        set_row_attribute(screen,y,x,curses.A_NORMAL)
                        set_row_attribute(screen,y-1,x,curses.A_REVERSE)
        elif event == curses.KEY_DOWN:
                if y<curses.LINES-2:
                        set_row_attribute(screen,y,x,curses.A_NORMAL)
                        set_row_attribute(screen,y+1,x,curses.A_REVERSE)
        elif event == 10:
                text_at_row = screen.instr(y,0,curses.COLS) # get string at xy
                screen.addstr(curses.LINES-2,0,text_at_row,curses.A_BLINK)
                
                screen.move(y,x)
        else:
                screen.addstr(chr(event),1)
Example #31
0
    def __init__(self, *args, **keywords):
        super(CommandList, self).__init__(*args, **keywords)
        self.command_handlers = {}

        # Any non highlited command handlers
        self.add_handlers({
            "q": self.exit_app,
            ord("n"): self.h_cursor_line_down,
            ord("p"): self.h_cursor_line_up,
            curses.ascii.ESC: self.exit_app
        })

        # All handlers for when a command is highlighted
        self.add_command_handlers({
            ord("i"): self.go_to_command_details,
            curses.ascii.SP: self.go_to_command_details,
            curses.ascii.NL: self.select_command,
            curses.ascii.CR: self.select_command,
            curses.ascii.BS: self.delete_command,
            curses.ascii.DEL: self.delete_command,
            curses.KEY_BACKSPACE: self.delete_command,
            curses.KEY_DC: self.delete_command
        })

        # Disable handling of ALL mouse events right now. Without this we're
        # unable to select text when inside of interactive search. This is
        # convenient for access to the clipboard since on bash it'll
        # automatically execute the command. Eventually find a way to allow this.
        # It'd be nice to allow clicking to select a line.
        curses.mousemask(0)
Example #32
0
 def setup_mouse(self):
     # Mouse support
     curses.mouseinterval(10)
     if self.app.config["editor"]["use_mouse"]:
         curses.mousemask(-1) # All events
     else:
         curses.mousemask(0) # All events
Example #33
0
    def __init__(self, *args, **keywords):
        super(CommandList, self).__init__(*args, **keywords)
        self.command_handlers = {}

        # Any non highlited command handlers
        self.add_handlers({
            "q": self.exit_app,
            curses.ascii.ESC: self.exit_app
        })

        # All handlers for when a command is highlighted
        self.add_command_handlers({
            ord("i"): self.go_to_command_details,
            curses.ascii.SP: self.go_to_command_details,
            curses.ascii.NL: self.select_command,
            curses.ascii.CR: self.select_command,
            curses.ascii.BS: self.delete_command,
            curses.ascii.DEL: self.delete_command,
            curses.KEY_BACKSPACE: self.delete_command,
            curses.KEY_DC: self.delete_command
        })

        # Disable handling of ALL mouse events right now. Without this we're
        # unable to select text when inside of interactive search. This is
        # convenient for access to the clipboard since on bash it'll
        # automatically execute the command. Eventually find a way to allow this.
        # It'd be nice to allow clicking to select a line.
        curses.mousemask(0)
def main(stdscr):
    global DEPTH

    curses.curs_set(0)
    curses.mousemask(1)
    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_CYAN)  # tiles 1
    curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLUE)  # tiles 2
    curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLUE)  # pieces 1
    curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLUE)  # pieces 2
    curses.init_pair(5, curses.COLOR_GREEN, curses.COLOR_BLUE)  # moves
    curses.init_pair(6, curses.COLOR_WHITE,
                     curses.COLOR_BLUE)  # first action of the movement
    curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK)  # borders
    curses.init_pair(8, curses.COLOR_GREEN, curses.COLOR_BLACK)  # you won
    curses.init_pair(9, curses.COLOR_RED, curses.COLOR_BLACK)  # you lost

    board = new_board()
    capture = check_captures(board, 1)
    moves = []

    while 1:
        stdscr.refresh()
        moved = 0

        go = game_over(board)
        if bool(go):
            print_game_over(board, stdscr, go)
        else:
            print_board(board, stdscr)

        key = stdscr.getch()

        if key == curses.KEY_MOUSE:
            _, x, y, _, _ = curses.getmouse()

            clear_moves(board)

            if not go:

                if x < BOARD_LEN * 2 and y < BOARD_LEN and x % 2 == 0:
                    x = int(x / 2)

                    for move in moves:
                        if move[-1] == (y, x):
                            step(board, move)
                            moves.clear()
                            moved = 1

                    if not moved:
                        capture = check_captures(board, 1)
                        moves = possible_moves(board, (y, x), 1, capture)
                        add_moves(board, moves)

                    if moved:
                        minimax(board, DEPTH, float("-inf"), float("+inf"), 0)
                        step(board, MOVE_PC)

        elif key == 27:  # Esc
            break
Example #35
0
def deinit_screen(screen):
    curses.curs_set(1)
    curses.mousemask(0)
    curses.echo()
    curses.nocbreak()
    screen.keypad(False)

    curses.endwin()
Example #36
0
def init():
    mmask = curses.ALL_MOUSE_EVENTS
    screen = curses.initscr()
    curses.curs_set(0)
    screen.keypad(1)
    curses.mousemask(mmask)
    curses.noecho()
    return (curses, screen)
Example #37
0
 def init_curses(self):
     curses.noecho()
     curses.mousemask(1)
     curses.start_color()
     curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
     curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)
     curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_YELLOW)
     self.screen.keypad(True)
Example #38
0
def main(scr):
    curses.mousemask(curses.ALL_MOUSE_EVENTS)
    curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_RED)
    
    room = lightUtil.lights(50)
    all = lightUtil.group(room,range(50))
    colors = {'red':127, 'green':127, 'blue':127}
    color_range = range(256)

    win = lightPanel(scr,'room',8,20,10,10)
    fields = ['red', 'green', 'blue']
    win.add_field('red',colors['red'],1)
    win.add_field('green',colors['green'],2)
    win.add_field('blue',colors['blue'],3)

    current_field = 'red'
    win.focus_on(current_field)
    all.setColor((colors['red'], colors['green'], colors['blue']))

    while True:
        c = scr.getkey()
        #scr.addstr(0,0,c)
        if c == 'KEY_UP':
            current_field = cycle_list(fields,current_field,'up')
            win.focus_on(current_field)
        if c == 'KEY_DOWN':
            current_field = cycle_list(fields,current_field,'down')
            win.focus_on(current_field)
        if c == 'KEY_RIGHT':
            colors[current_field] = cycle_list(color_range,
                                               colors[current_field],
                                               'down')
        if c == 'KEY_LEFT':
            colors[current_field] = cycle_list(color_range,
                                               colors[current_field],
                                               'up')
        if c == 'KEY_MOUSE':
            #scr.addstr(0,0,str(curses.getmouse()))
            id, x, y, z, bstate = curses.getmouse()
            for f in win.fields:
                if win.fields[f][0].enclose(y, x):
                    win.focus_on(f)
        if c == '0':
            colors[current_field] = 0
        if c == 'w':
            win.move('up')
        if c == 's':
            win.move('down')
        if c == 'a':
            win.move('left')
        if c == 'd':
            win.move('right')
        if c == 'q':
            break
        all.setColor((colors['red'], colors['green'], colors['blue']))
        win.update_field('red',colors['red'],1)
        win.update_field('green',colors['green'],2)
        win.update_field('blue',colors['blue'],3)
Example #39
0
def main(window):
    curses.mousemask(curses.ALL_MOUSE_EVENTS)
    curses.mouseinterval(0)
    while True:
        char = window.getch()
        if char == curses.KEY_MOUSE:
            window.addstr(repr(curses.getmouse()) + SEPARATOR)
        else:
            window.addstr(str(char) + SEPARATOR)
Example #40
0
    def loadscreens(self):
        self.screen.erase()

        curses.mousemask(1)

        curses.start_color()

        curses.noecho()

        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
        curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_BLUE)
        curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_WHITE)

        self.screen.bkgd(curses.color_pair(1))
        self.screen.box()
        screenheight, screenwidth = self.screen.getmaxyx()
        screenheight -= 1
        self.cmdheight = screenheight - 1
        acctwinwidth = 42
        self.screen.addstr(1, acctwinwidth + 2 - len(self.month.name) / 2,
                           " " + self.month.name + " ", curses.A_REVERSE)
        self.screen.refresh()

        self.winheight = screenheight - 3
        self.acctwin = curses.newwin(self.winheight, acctwinwidth, 2, 2)

        self.acctwinstartline = 2
        self.printtoacctwin()

        catwinx = 2 + acctwinwidth + 1
        catwinwidth = min(70, screenwidth - catwinx - 2)
        self.catwin = curses.newwin(self.winheight, catwinwidth, 2, catwinx)

        self.catwinstartline = 2  #start at line 2 and go for it
        self.printtocatwin()

        editx = catwinx + 1 + catwinwidth
        if editx > screenwidth - 30:
            self.editpad = False
        else:
            editwidth = screenwidth - editx - 2
            self.editwin = curses.newwin(self.winheight, editwidth, 2, editx)
            self.editpad = curses.newwin(screenheight - 9, editwidth - 4, 4,
                                         editx + 2)

            self.editwin.clear()
            self.editwin.box()
            self.editwin.bkgd(curses.color_pair(3))
            self.editwin.addstr(0, 2, "Edit")
            self.editwin.refresh()

            self.editpad.clear()
            self.editpad.bkgd(curses.color_pair(3))
            self.editpad.refresh()
            self.editor = curses.textpad.Textbox(self.editpad)

        self.resetblinker()
Example #41
0
def main(window):
    curses.mousemask(curses.ALL_MOUSE_EVENTS)
    curses.mouseinterval(0)
    while True:
        char = window.getch()
        if char == curses.KEY_MOUSE:
            window.addstr(repr(curses.getmouse()) + SEPARATOR)
        else:
            window.addstr(str(char) + SEPARATOR)
Example #42
0
 def _stop_screen(self) -> None:
     self._clear_screen()
     self.window.timeout(-1)
     self.window.keypad(False)
     self.window.nodelay(False)
     self.window = None
     curses.echo()
     curses.mousemask(False)
     curses.endwin()
Example #43
0
 def quit(self):
     """ End curses application. """
     # if FLAG_TTY:
     self._cancel_render()
     curses.nocbreak()
     curses.echo()
     curses.curs_set(1)
     curses.mousemask(0)
     curses.endwin()
def configure(screen):
  title_foreground = random.choice([curses.COLOR_WHITE,curses.COLOR_CYAN,curses.COLOR_MAGENTA,curses.COLOR_YELLOW,curses.COLOR_GREEN,curses.COLOR_RED])
  curses.init_pair(title_colors, title_foreground, curses.COLOR_BLACK)
  curses.init_pair(border_colors, curses.COLOR_BLACK, curses.COLOR_WHITE)
  curses.init_pair(player_one_colors, curses.COLOR_BLACK, curses.COLOR_CYAN)
  curses.init_pair(player_two_colors, curses.COLOR_BLACK, curses.COLOR_MAGENTA)
  curses.curs_set(0) # hide cursor
  curses.mousemask(1) # enable mouse support
  curses.noecho()
Example #45
0
 def _wrap(self, main, window, bg_color):
   self._window = window
   self._window.bkgd(" ", curses.color_pair(bg_color))
   self.cursor_visible = False
   self.mouse_location = (0,0)
   curses.mousemask(1)
   try:
     main(self)
   except KeyboardInterrupt: pass # Exit cleanly on Ctrl-C
	def __init__(self, window):
		"""
		Initializes windows, some state machine information, and the color information
		used by the terminal emulator.
		"""	
		self.borderWin = curses.newwin(27, 83, 0, 0)
		self.borderWin.border()
		self.borderWin.refresh()

		self.window = curses.newwin(25, 81, 1, 1)
		self.window.nodelay(1)
		self.window.keypad(1)

		self.windows = 	{ 
				  -1 : (self.window , False), 
				   3 : (self.window, False), 
				}

		self.nethackWindowsCleared = []
	
	 	curses.mousemask(curses.ALL_MOUSE_EVENTS)

		self.bottomWindowBorder = curses.newwin(4, 83, 27, 0)
		self.bottomWindowBorder.border()
		self.bottomWindowBorder.refresh()

		self.bottomWindow = curses.newwin(2, 81, 28, 1)
		self.bottomWindow.refresh()

		self.window.move(0,0)
	
		self.debugLevel = 0
		self.debugFile = None
		self.debugFileName = 'debug'
		
		self.escapeBuffer = ''
		self.isEscape = False
		self.isEscapeSequence = False
		self.isShiftSequence = False
		self.shiftOut = False
	
		self.carriageReturn = False
	
		self.fgColor = 'White'
		self.bgColor = 'Black'
		self.colors = { '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}
		self.fgColors = { 30 : 'Black', 31 : 'Red', 32 : 'Green', 33 : 'Yellow', 34 : 'Blue', 35 : 'Magenta', 36 : 'Cyan', 37 : 'White' }
		self.bgColors = { 40 : 'Black', 41 : 'Red', 42 : 'Green', 43 : 'Yellow', 44 : 'Blue', 45 : 'Magenta', 46 : 'Cyan', 47 : 'White' }
		self.colorPairs = {}
		
		self.initColors()

		self.tileArray = [[-1 for x in range(0, 80)] for x in range(0, 24)]

		self.tileData = {}
		self.loadTiles()
Example #47
0
File: hex.py Project: quo/hex.py
			def wrapped(scr):
				curses.use_default_colors()
				curses.mousemask(curses.ALL_MOUSE_EVENTS)
				curses.mouseinterval(0)
				curses.curs_set(2) # solid block cursor
				scr.idlok(True)
				curses.def_prog_mode()
				i = HexInterface(scr)
				i.set_file(hf)
				i.main_loop()
 def __remove_argument_call_main(self, screen, enable_mouse=True):
     # screen disgarded.#if fork is None:
         #return safewrapper.wrapper(self.__remove_argument_call_main)
     #else:
         #return safewrapper.wrapper(self.__remove_argument_call_main,
                                    #fork=fork)
     if enable_mouse:
         curses.mousemask(curses.ALL_MOUSE_EVENTS)
     del screen
     return self.main()
Example #49
0
 def __init__(self, canvas, w, h):
     self.canvas = canvas
     self.width = w
     self.height = h
     self.canvas.keypad(True)
     self.server = None
     curses.mousemask(True)
     curses.noecho()
     curses.start_color()
     init_color_pairs()
 def __remove_argument_call_main(self, screen, enable_mouse=True):
     # screen disgarded.#if fork is None:
     #return safewrapper.wrapper(self.__remove_argument_call_main)
     #else:
     #return safewrapper.wrapper(self.__remove_argument_call_main,
     #fork=fork)
     if enable_mouse:
         curses.mousemask(curses.ALL_MOUSE_EVENTS)
     del screen
     return self.main()
Example #51
0
def initialize(screen):
	screen.leaveok(1)
	# screen.nodelay(11)
	curses.curs_set(0)
	curses.mousemask(curses.BUTTON1_CLICKED | curses.BUTTON1_DOUBLE_CLICKED)
	engine = Engine(screen)
	term = CursesTerminal(engine, screen)
	kbd = CursesInput(engine, screen)
	engine.add_display(term)
	engine.add_input(kbd)
	engine.loop()
Example #52
0
    def _run(self, screen):
        curses.curs_set(0)
        curses.mousemask(1)

        screen.nodelay(1)

        colors.init()

        page = WelcomePage()

        self._main_loop(screen, page)
Example #53
0
File: csb.py Project: rayleyva/csb
def main(args):
    parser = OptionParser(version=version)
    #parser.add_option("-w", "--width", dest="width", default=20,
    #        help="set the default column width to COLS", metavar="COLS")
    parser.add_option("-t", "--table", dest="table", default=None,
            help="start with table NAME open", metavar="NAME")
    parser.add_option("-f", "--file", dest="dbfile", default=None,
            help="read the DB URI from a file", metavar="FILE")
    parser.add_option("-d", "--debug",
            action="store_true", dest="debug", default=False,
            help="turn on debugging to csb.log")
    parser.add_option("-y", "--yes",
            action="store_true", dest="yes", default=False,
            help="Do things without confirming")
    (options, args) = parser.parse_args()

    if len(args) == 1:
        options.fname = args[0]
    elif options.dbfile:
        options.fname = file(options.dbfile).read().strip()
    elif os.path.exists("/etc/csb.conf"):
        options.fname = file("/etc/csb.conf").read().strip()
    else:
        options.fname = raw_input("Enter database uri: ")

    if options.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)-8s %(message)s',
            filename="csb.log"
            )
    else:
        logging.basicConfig(
            level=logging.CRITICAL,
            format='%(asctime)s %(levelname)-8s %(message)s'
            )

    try:
        with dbapi(options.fname) as api:
            tables = get_tables(api)
            if len(tables) == 0:
                print "No tables in database"
                return 1
            if not options.table or options.table not in tables:
                options.table = get_tables(api)[0]
            with screen() as stdscr:
                csui.curs_set(False)
                curses.mousemask(0xFFFFFFF)
                main_loop(api, stdscr, options)
    except KeyboardInterrupt:
        print "Exited without committing changes"
        return 2

    return 0
Example #54
0
	def __init__(self, border=False, cursor=True, keypad=1):
		scr = curses.initscr()
		curses.noecho()

		if border: scr.box()
		curses.curs_set(cursor)
		scr.keypad(keypad)
		scr.refresh()
		curses.mousemask(curses.ALL_MOUSE_EVENTS)
		self.msg = ""

		self.scr = scr
Example #55
0
def init():
    screen = curses.initscr()
    curses.curs_set(False)  # hide cursor
    screen.keypad(1)
    curses.mousemask(curses.ALL_MOUSE_EVENTS)
    curses.noecho()
    win = SubWindow(shape=(0, 0, 20, 40))
    screen.refresh()
    win.window.refresh()

    # textbox = Textbox(shape=(1, 15, 38, 17), parent_window=win.window)
    return screen, win
Example #56
0
 def setCurses(self):
     self.scr.refresh()
     curses.start_color()
     curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
     curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
     curses.init_pair(6, curses.COLOR_BLUE, curses.COLOR_BLACK)
     curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)
     curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_BLACK)
     curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
     curses.init_pair(7, curses.COLOR_RED, curses.COLOR_BLACK)
     curses.mousemask(-1)
     curses.mouseinterval(0)
     curses.curs_set(0)
Example #57
0
    def wrapped(self, stdscr):
        self.scr = stdscr
        self.scr.nodelay(True)
        self.original_cursor = curses.curs_set(0)

        curses.mousemask(curses.BUTTON1_CLICKED |
                         curses.BUTTON1_DOUBLE_CLICKED)
        init_colors()

        self.create_pads()
        self.resize()
        self.func()
        curses.curs_set(self.original_cursor)
Example #58
0
def init_screen():
    curses.start_color() # load colors
    curses.use_default_colors()
    curses.noecho()      # do not echo text
    curses.cbreak()      # do not wait for "enter"
    curses.mousemask(curses.ALL_MOUSE_EVENTS)

    # Hide cursor, if terminal AND curse supports it
    if hasattr(curses, 'curs_set'):
        try:
            curses.curs_set(0)
        except:
            pass
Example #59
0
def mainloop(scr):
	curses.mousemask(curses.ALL_MOUSE_EVENTS)#curses.BUTTON1_PRESSED)#curses.ALL_MOUSE_EVENTS)
	while 1:
		scr.keypad(1)
		curses.halfdelay(1)
		ch = scr.getch()
		if ch == "-1": scr.addstr(2, 0, '-1')
		scr.addstr(2, 0, str(ch))
		if ch == curses.KEY_MOUSE:
		    scr.addstr(4,0, "%s" % ' '.join(str(curses.getmouse())))
		    curses.beep()
		#return ch
		scr.refresh()
Example #60
0
 def start(self):
   locale.setlocale(locale.LC_ALL,'')
   
   self.stdscr = curses.initscr()
   self.stdscr.keypad(1)
   curses.cbreak()
   curses.noecho()
   curses.curs_set(0)
   curses.mousemask(curses.BUTTON1_CLICKED|curses.BUTTON1_DOUBLE_CLICKED)
   self.initColors()
   self.windows = []
   
   self.status = ''