예제 #1
0
파일: pyuim.py 프로젝트: Kopachris/PyUIM
 def show(self):
     # pgup = \xe0 I
     # pgdwn = \xe0 Q
     # bkspc = \x08
     self._paginate()
     i = 0
     cur_page = self._pages[i]
     choice = b''
     self._draw_page(cur_page)
     self._draw_ftr(i)
     k = b''
     while True:
         k = termutils.get_key()
         if k == b'\r':
             try:
                 opt = int(choice)
                 if self._opts[opt] is not None:
                     v = self._opts[opt].func()
                 else:
                     choice = b''
                     self._draw_ftr(i)
                     continue
                 if v is not None:
                     self._draw_page(cur_page)
                     self._draw_ftr(i)
                     termutils.set_pos(1, self.ui.rows - 1)
                     print(v, end='')
                     termutils.set_pos(len(self.ui.prompt) + 1, self.ui.rows - 3)
                     choice = b''
                     continue
                 else:
                     return "Library list changed"
             except ValueError:
                 choice = b''
                 self._draw_ftr(i)
                 continue
         if k == b'\xe0' or k == b'\x00':
             k += termutils.get_key()
         if k == b'\xe0Q':
             if i < len(self._pages):
                 i += 1
                 cur_page = self._pages[i]
                 self._draw_page(cur_page)
                 self._draw_ftr(i)
         elif k == b'\xe0I':
             if i > 0:
                 i -= 1
                 cur_page = self._pages[i]
                 self._draw_page(cur_page)
                 self._draw_ftr(i)
         elif k == b'\xe0\x86':
             return "Library list changed"
         # todo
         # if k == b'\x00;': display help
         elif not k.startswith(b'\xe0') and not k.startswith(b'\x00'):
             print(k.decode(), end='')
             choice += k
예제 #2
0
def kb_loop(bv, stdout_lock, bv_lock):
    global CONFIG

    print("Press Q at any time to quit, or H for help")
    while True:
        with stdout_lock:
            opt = t.get_key(0.1)
        if opt is not None:
            opt = opt.lower()
        if opt == b'q':
            bv.bv_on = False
            with open(CONFIG_FILE, 'w') as f:
                CONFIG.write(f)
            return
        elif opt == b'h':
            print("Q - Quit\n"
                  "H - Help\n"
                  "S - Settings menu\n"
                  "R - Reset and initialize bill validator\n"
                  "P - Pause bill validator\n"
                  "M - Stop polling "
                  "and return to main menu")
        elif opt == b'm':
            return
        elif opt == b's':
            with stdout_lock:
                logging.debug("Entered settings menu from status poll")
                settings()
                logging.debug("Exited settings menu")
                bv.bv_status = None  # print current status after returning
                t.wipe()
        elif opt == b'r':
            with bv_lock:
                logging.debug("Sending reset command")
                status = None
                while status != id003.ACK:
                    bv.send_command(id003.RESET)
                    status, data = bv.read_response()
                    time.sleep(0.2)
                logging.debug("Received ACK")

                if bv.req_status()[0] == id003.INITIALIZE:
                    denom = get_denoms()
                    sec = get_security()
                    dir = get_directions()
                    opt = get_optional()
                    logging.info("Initializing bill validator")
                    bv.initialize(denom, sec, dir, opt)

                bv.bv_status = None
        elif opt == b'p':
            print("Not implemented yet")
예제 #3
0
def kb_loop(bv, stdout_lock, bv_lock):
    global CONFIG

    print("Press Q at any time to quit, or H for help")
    while True:
        with stdout_lock:
            opt = t.get_key(0.1)
        if opt is not None:
            opt = opt.lower()
        if opt == b'q':
            bv.bv_on = False
            with open(CONFIG_FILE, 'w') as f:
                CONFIG.write(f)
            return
        elif opt == b'h':
            print("Q - Quit\n" "H - Help\n" "S - Settings menu\n"
                  "R - Reset and initialize bill validator\n"
                  "P - Pause bill validator\n" "M - Stop polling "
                  "and return to main menu")
        elif opt == b'm':
            return
        elif opt == b's':
            with stdout_lock:
                logging.debug("Entered settings menu from status poll")
                settings()
                logging.debug("Exited settings menu")
                bv.bv_status = None  # print current status after returning
                t.wipe()
        elif opt == b'r':
            with bv_lock:
                logging.debug("Sending reset command")
                status = None
                while status != id003.ACK:
                    bv.send_command(id003.RESET)
                    status, data = bv.read_response()
                    time.sleep(0.2)
                logging.debug("Received ACK")
                
                if bv.req_status()[0] == id003.INITIALIZE:
                    denom = get_denoms()
                    sec = get_security()
                    dir = get_directions()
                    opt = get_optional()
                    logging.info("Initializing bill validator")
                    bv.initialize(denom, sec, dir, opt)
                    
                bv.bv_status = None
        elif opt == b'p':
            print("Not implemented yet")
예제 #4
0
sys.ps1 = ""
sys.ps2 = ""

# basic telnet client without keystroke buffering


def tn_loop(key_pipe):
    tn = Telnet(HOST, PORT)
    tn.write(b'\n')
    while True:
        if key_pipe.poll():
            tn.write(key_pipe.recv())
        data = tn.read_very_eager()
        print(data.decode(), end='')


if __name__ == '__main__':
    t.wipe()

    p_pipe, ch_pipe = Pipe()
    tn_conn = Process(target=tn_loop, args=(ch_pipe, ))
    tn_conn.start()

    while True:
        try:
            k = t.get_key()
        except:
            sys.exit()
        else:
            p_pipe.send(k)
예제 #5
0
sys.ps1 = ""
sys.ps2 = ""

# basic telnet client without keystroke buffering


def tn_loop(key_pipe):
    tn = Telnet(HOST, PORT)
    tn.write(b'\n')
    while True:
        if key_pipe.poll():
            tn.write(key_pipe.recv())
        data = tn.read_very_eager()
        print(data.decode(), end='')


if __name__ == '__main__':
    t.wipe()

    p_pipe, ch_pipe = Pipe()
    tn_conn = Process(target=tn_loop, args=(ch_pipe, ))
    tn_conn.start()

    while True:
        try:
            k = t.get_key()
        except:
            sys.exit()
        else:
            p_pipe.send(k)