Example #1
0
    def _dump(self, why='', output=None):

        tout = out

        if output:
            tout = output
        if debug or output or out:
            lead = '-' * 20
            if why:
                why = '(' + why + ') '
            oprint(lead + ' Screen at %s %s' % (dtToReadable(dtNow()), why) +
                   lead)
            for i in range(0, len(self.rows)):
                if self.rows[i].strip():
                    oprint('  row[%2d] = %s' %
                           (i, repr(postEllipse(self.rows[i], 80))),
                           output=tout)
Example #2
0
def main(screen):

    global scr
    global maxx
    global maxy
    global curSelected
    global msgbot
    global msgtop
    global keys
    global out

    scr = screen
    if type(scr) != StrScreen:
        oprint('DEBUG: type(scr) = %s' % repr(type(scr)))
        scr = StrScreen(None if debug else screen,
                        output=out if not debug else sys.stdout)

    scr.timeout(2000)
    if screen and type(screen) != StrScreen:
        curses.curs_set(0)

    maxy, maxx = scr.getmaxyx()

    oprint('DEBUG: main(): maxy = %d, maxx = %d' % (maxy, maxx))

    # Create randomly shuffled decks...
    onedeck = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13]
    numdecks = 8
    allcards = []
    for i in range(0, numdecks):
        allcards.extend(onedeck)
    allcards = shuffle(allcards)
    decks = []
    while allcards:
        thesecards = allcards[0:13]
        allcards = allcards[13:]
        thisdec = Deck()
        for cardno in thesecards:
            thisdec.append(Card(cardno))
        decks.append(thisdec)

    # Deal stacks...
    numstacks = 10
    stacks = []
    for i in range(0, numstacks):
        stacks.append(Deck())

    cardno = 0
    for d in range(0, 6):
        while cardno < 54:
            dealOne(decks, stacks[cardno % len(stacks)])
            cardno += 1

    selected = False
    for s in range(0, len(stacks)):
        stack = stacks[s]
        print('DEBUG: len(stacks[%d]) = %d' % (s, len(stack)))
        print('DEBUG: type(stack) = %s' % repr(type(stack)))
        if stack and stack[-1].cardno < 0:
            stack[-1].cardno = -(stack[-1].cardno)

    # select first visible card in first stack...
    stack = stacks[0]
    for i in range(0, len(stack)):
        card = stack[i]
        if card.cardno >= 0 and not curSelected:
            card.selected = True
            curSelected = card
            break

    renderAll(decks, stacks)
    scr.addstr(maxy - 1, 0, 'Press \'q\' or \'x\' to exit...')

    #
    # Do it...
    #

    key = ''

    scr.refresh()

    while key not in ('q', 'Q', 'x', 'X', chr(0x03)):

        dt = dtToReadable(dtNow())
        scr.addstr(0, maxx - len(dt), dt)
        key = scr.getch()
        if key < 0:
            if debug:
                break
            continue

        okey = key
        key = chr(key)

        if debug:
            oprint('DEBUG: Key = 0x%x = %s' % (okey, repr(key)))

        msg = 'Continue on...'

        if key in ('d', 'D'):  # Deal...
            for s in range(0, len(stacks)):
                stack = stacks[s]
                dealOne(decks, stack)
                if stack and stack[-1].cardno < 0:
                    stack[-1].cardno = -(stack[-1].cardno)
            renderAll(decks, stacks, msg)
            scr.refresh()
            continue

        left = [0x104, ord(ld_larr)]
        right = [0x105, ord(ld_rarr)]
        if curSelected and (okey in left or okey in right):
            card = curSelected
            lr = card.getLeftRight()
            next = lr[0] if okey in left else lr[1]
            if next:
                curSelected = next
                next.selected = True
                card.selected = False
            elif type(scr) != StrScreen:
                curses.beep()

        up = [0x103, ord(ld_uarr)]
        down = [0x102, ord(ld_darr)]
        if curSelected and (okey in up or okey in down):
            card = curSelected
            ud = card.getUpDown()
            next = ud[0] if okey in up else ud[1]
            if next:
                curSelected = next
                next.selected = True
                card.selected = False

        if key in ('b', 'B'):
            obreak()

        if key in ('c', 'C'):
            scr.refresh()

        if key in ('p', 'P'):
            if screen:
                curses.beep()
            if debug:
                oprint('DEBUG: Calling _dump()...')
            scr._dump('Key press...')
Example #3
0
breaker = 0


def obreak(msg=None, end='\n'):

    global breaker

    breaker += 1
    if not debug: return
    if not msg:
        msg = ' Break %d ' % breaker
    oprint('=' * 30 + msg + '=' * 30)


oprint('----- BEGIN... %s -----' % dtToReadable(dtNow())[:-4])


def beep(duration=1):

    freq = 880 * 2
    res, sout, serr = execute('aplay -d {} {}'.format(duration, 'beep.wav'))
    if res and debug:
        oprint('DEBUG: beep: res = %s' % repr(res))
        oprint('       sout = %s' % repr(sout))
        oprint('       serr = %s' % repr(serr))


#---
#
# Various classes...
Example #4
0
Last line'''
        result = scr.putstr(string, rect)
        print('putstr test...')
        print('  result = %s' % repr(type(result)))

        rect = Rect(Point(0, 0), Point(len(scr.rows) - 1, 50))
        s = scr.getrect(rect)
        lines = s.split('\n')
        print('Lines at 0,0...')
        for i in range(0, len(lines)):
            print('  %2d: %s' % (i, repr(lines[i])))

    test += 1
    if 0:

        now1 = dtNow()
        numrows, numcols = os.popen('stty size', 'r').read().split()
        now2 = dtNow()
        now3 = dtNow()
        print('Get tty size took      %f seconds' % deltaSeconds(now2 - now1))
        print('Getting time diff took %f seconds' % deltaSeconds(now3 - now2))

    test += 1
    if 0:

        maxy, maxx = scr.getmaxyx()
        print('maxy,maxx = %s' % repr(scr.getmaxyx()))
        msg = 'Hi there Dude!!!'
        scr.addstr(0, maxx - 5, msg)
        scr.addstr(0, 0, msg)
Example #5
0
        if old_sigwinch:
            old_sigwinch(signum, frame)


def getmaxyx() -> tuple:

    rows, cols = os.popen('stty size', 'r').read().split()
    try:
        rows = int(rows)
        cols = int(cols)
    except:
        rows = cols = 0

    return (rows - 1, cols - 1)


if __name__ == '__main__':

    maxy, maxx = getmaxyx()
    print('maxy = %d, maxx = %d' % (maxy, maxx))
    old_sigwinch = signal.signal(signal.SIGWINCH, sighandler)

    then = dtNow()
    while elapsed(then, dtNow()) < 60:
        time.sleep(1)
        print('.', end='')
        sys.stdout.flush()
    print('\n')

    signal.signal(signal.SIGWINCH, original_sigwinch)
Example #6
0
        ch = stdin.read(1)
    finally:
        termios.tcsetattr(stdin, termios.TCSADRAIN, old_settings)
    return ch


if __name__ == '__main__':

    if 1:
        timeout = 1
        print('Press any keyi (Ctrl-C to break), timeout %s second%s...' % \
              (repr(timeout),'' if timeout == 1 else 's'))
        while 1:
            ch = getchar(timeout)
            if not ch and timeout:
                print(dtToReadable(dtNow())[-10:])
                continue
            if not ch: continue
            print('You pressed 0x%02x' % ord(ch))
            if ord(ch) == 0x03: break
            print('type(ch) = ' + repr(type(ch)))

    if 0:
        term = TerminalController()
        a = b'\x1b[H\x1b[2J'
        b = eval(term.CLEAR_SCREEN)
        print("DEBUG: a = %s" % repr(a))
        print("DEBUG: b = %s" % repr(b))
        print("DEBUG: type(b) = %s" % repr(type(b)))
        print("DEBUG: type(b'') = %s" % repr(type(b'')))
        sys.stdout.buffer.write(b)