Exemplo n.º 1
0
 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
Exemplo n.º 2
0
def display_menu(menu, prompt='>>>', header='', info=''):
    if len(menu) > Y_SIZE - 5:
        raise ValueError("Too many menu options")

    # print the header
    t.wipe()
    display_header(header)

    # print the menu items
    for k, v in menu.items():
        print("{}) {}".format(k, v))

    # print prompt and info
    print(prompt, end=' ')
    x, y = t.get_pos()
    print('\n\n' + info)
    t.set_pos(x, y)

    # get user's choice
    k = None
    while k not in menu:
        k = input('')
        t.set_pos(x, y)
        print(' ' * (X_SIZE - x), end='')
        t.set_pos(x, y)

    return k
Exemplo n.º 3
0
def display_menu(menu, prompt='>>>', header='', info=''):
    if len(menu) > Y_SIZE - 5:
        raise ValueError("Too many menu options")
    
    # print the header
    t.wipe()
    display_header(header)
    
    # print the menu items
    for k, v in menu.items():
        print("{}) {}".format(k, v))
        
    # print prompt and info
    print(prompt, end=' ')
    x, y = t.get_pos()
    print('\n\n' + info)
    t.set_pos(x, y)
    
    # get user's choice
    k = None
    while k not in menu:
        k = input('')
        t.set_pos(x, y)
        print(' ' * (X_SIZE - x), end='')
        t.set_pos(x, y)
    
    return k
Exemplo n.º 4
0
    def _draw_ftr(self, idx):
        termutils.set_pos(1, self.ui.rows - 3)
        termutils.set_color(self.ui.ps1_fg, self.ui.ps1_bg)
        print(self.ui.prompt, end='')
        termutils.set_color(self.ui.fg, self.ui.bg)
        print(' ' * (self.ui.cols - len(self.ui.prompt)), end='')

        if idx < len(self._pages) - 1:
            termutils.set_pos(self.ui.cols - 1, self.ui.rows - 4)
            termutils.set_color(self.ui.hdr_fg, self.ui.hdr_bg)
            print('+', end='')
        if idx > 0:
            termutils.set_pos(self.ui.cols - 3, self.ui.rows - 4)
            termutils.set_color(self.ui.hdr_fg, self.ui.hdr_bg)
            print('-', end='')
        termutils.set_pos(len(self.ui.prompt) + 1, self.ui.rows - 3)
        termutils.set_color(self.ui.fg, self.ui.bg)
Exemplo n.º 5
0
def denom_settings():
    global CONFIG

    t.wipe()
    display_header("Denomination enable/inhibit settings")

    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.denom_inhibit'].keys()):
        if id003.DENOM_MAP[k] in id003.ESCROW_USA:
            denom = id003.ESCROW_USA[id003.DENOM_MAP[k]]
        else:
            denom = None

        denom_enabled = CONFIG['bv.denom_inhibit'].getboolean(k)
        opts[i] = k  # index into this config section
        set_opts[k] = denom_enabled  # cache settings before writing to config

        if denom is not None:
            line = k + ' (' + denom + '):\t\t'
        else:
            line = k + ':\t\t\t'

        if denom_enabled:
            line += 'X'
        else:
            line += '_'

        print(line)

    print(
        "\n\nIf a denom is inhibited through these settings that's not inhibited by the\n"
        "appropriate DIP switch on the BV, the BV will go into INHIBIT status."
    )
    print(
        "\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(25, 3)

    max_opt = len(CONFIG['bv.denom_inhibit']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()

        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y - 1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.denom_inhibit'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 6
0
def security_settings():
    global CONFIG

    t.wipe()
    display_header("Denomination security settings")

    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.security'].keys()):
        if id003.DENOM_MAP[k] in id003.ESCROW_USA:
            denom = id003.ESCROW_USA[id003.DENOM_MAP[k]]
        else:
            denom = None

        denom_enabled = CONFIG['bv.security'].getboolean(k)
        opts[i] = k
        set_opts[k] = denom_enabled

        if denom is not None:
            line = k + ' (' + denom + '):\t\t'
        else:
            line = k + ':\t\t\t'

        if denom_enabled:
            line += 'X'
        else:
            line += '_'

        print(line)

    print("\n\nX = high security, _ = low security")
    print(
        "\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(25, 3)

    max_opt = len(CONFIG['bv.security']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()

        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y - 1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.security'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 7
0
def direction_settings():
    global CONFIG

    t.wipe()
    display_header("Direction ihibit settings")

    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.direction'].keys()):
        dir_enabled = CONFIG['bv.direction'].getboolean(k)
        opts[i] = k
        set_opts[k] = dir_enabled

        if k == 'fa':
            print("Front side up, left side in:\t\t", end='')
        elif k == 'fb':
            print("Front side up, right side in:\t\t", end='')
        elif k == 'bb':
            print("Back side up, left side in:\t\t", end='')
        elif k == 'ba':
            print("Back side up, right side in:\t\t", end='')

        start_x, start_y = t.get_pos()
        if dir_enabled:
            print('X')
        else:
            print('_')

    print("\n\n_ = enabled, X = inhibited")
    print(
        "\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(start_x, 3)

    max_opt = len(CONFIG['bv.direction']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()

        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y - 1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.direction'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 8
0
def opt_settings():
    global CONFIG

    t.wipe()
    display_header("Optional function settings")

    opts = dict()
    set_opts = OrderedDict()
    opt_txt = {
        'power_recovery': "Power recovery:\t\t\t\t",
        'auto_retry': "Auto-retry operaton:\t\t\t",
        '24_char_barcode': "Accept 24-character barcodes:\t\t",
        'near_full': "Stacker nearly full event:\t\t",
        'entrance_event': "Entrance sensor event:\t\t\t",
        'encryption': "Encryption:\t\t\t\t",
    }

    for i, k in enumerate(CONFIG['bv.optional'].keys()):
        opt_enabled = CONFIG['bv.optional'].getboolean(k)
        opts[i] = k
        set_opts[k] = opt_enabled

        print(opt_txt[k], end='')
        start_x, start_y = t.get_pos()
        if opt_enabled:
            print('X')
        else:
            print('_')

    print("\n\n_ = disabled, X = enabled")
    print(
        "\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(start_x, 3)

    max_opt = len(CONFIG['bv.optional']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()

        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y - 1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y + 1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y + 1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.optional'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 9
0
def display_header(text):
    t.set_pos(0, 0)
    print(text.center(X_SIZE), end='')
    print('=' * X_SIZE, end='')
Exemplo n.º 10
0
def denom_settings():
    global CONFIG
    
    t.wipe()
    display_header("Denomination enable/inhibit settings")
    
    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.denom_inhibit'].keys()):
        if id003.DENOM_MAP[k] in id003.ESCROW_USA:
            denom = id003.ESCROW_USA[id003.DENOM_MAP[k]]
        else:
            denom = None
            
        denom_enabled = CONFIG['bv.denom_inhibit'].getboolean(k)
        opts[i] = k     # index into this config section
        set_opts[k] = denom_enabled     # cache settings before writing to config
        
        if denom is not None:
            line = k + ' (' + denom + '):\t\t'
        else:
            line = k + ':\t\t\t'
        
        if denom_enabled:
            line += 'X'
        else:
            line += '_'
            
        print(line)
    
    print("\n\nIf a denom is inhibited through these settings that's not inhibited by the\n"
          "appropriate DIP switch on the BV, the BV will go into INHIBIT status.")
    print("\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(25, 3)
    
    max_opt = len(CONFIG['bv.denom_inhibit']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()
        
        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y-1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.denom_inhibit'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 11
0
def security_settings():
    global CONFIG
    
    t.wipe()
    display_header("Denomination security settings")
    
    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.security'].keys()):
        if id003.DENOM_MAP[k] in id003.ESCROW_USA:
            denom = id003.ESCROW_USA[id003.DENOM_MAP[k]]
        else:
            denom = None
            
        denom_enabled = CONFIG['bv.security'].getboolean(k)
        opts[i] = k
        set_opts[k] = denom_enabled
        
        if denom is not None:
            line = k + ' (' + denom + '):\t\t'
        else:
            line = k + ':\t\t\t'
        
        if denom_enabled:
            line += 'X'
        else:
            line += '_'
            
        print(line)
    
    print("\n\nX = high security, _ = low security")
    print("\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(25, 3)
    
    max_opt = len(CONFIG['bv.security']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()
        
        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y-1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.security'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 12
0
def direction_settings():
    global CONFIG
    
    t.wipe()
    display_header("Direction ihibit settings")
    
    opts = dict()
    set_opts = OrderedDict()
    for i, k in enumerate(CONFIG['bv.direction'].keys()):
        dir_enabled = CONFIG['bv.direction'].getboolean(k)
        opts[i] = k
        set_opts[k] = dir_enabled
        
        if k == 'fa':
            print("Front side up, left side in:\t\t", end='')
        elif k == 'fb':
            print("Front side up, right side in:\t\t", end='')
        elif k == 'bb':
            print("Back side up, left side in:\t\t", end='')
        elif k == 'ba':
            print("Back side up, right side in:\t\t", end='')
            
        start_x, start_y = t.get_pos()
        if dir_enabled:
            print('X')
        else:
            print('_')
            
    print("\n\n_ = enabled, X = inhibited")
    print("\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(start_x, 3)
    
    max_opt = len(CONFIG['bv.direction']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()
        
        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y-1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.direction'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 13
0
def opt_settings():
    global CONFIG
    
    t.wipe()
    display_header("Optional function settings")
    
    opts = dict()
    set_opts = OrderedDict()
    opt_txt = {
        'power_recovery': "Power recovery:\t\t\t\t",
        'auto_retry': "Auto-retry operaton:\t\t\t",
        '24_char_barcode': "Accept 24-character barcodes:\t\t",
        'near_full': "Stacker nearly full event:\t\t",
        'entrance_event': "Entrance sensor event:\t\t\t",
        'encryption': "Encryption:\t\t\t\t",
    }
    
    for i, k in enumerate(CONFIG['bv.optional'].keys()):
        opt_enabled = CONFIG['bv.optional'].getboolean(k)
        opts[i] = k
        set_opts[k] = opt_enabled
        
        print(opt_txt[k], end='')
        start_x, start_y = t.get_pos()
        if opt_enabled:
            print('X')
        else:
            print('_')
            
    print("\n\n_ = disabled, X = enabled")
    print("\nPress Enter to save and go back, or Esc to go back without saving")
    t.set_pos(start_x, 3)
    
    max_opt = len(CONFIG['bv.optional']) - 1
    cur_opt = 0
    while True:
        x, y = t.get_pos()
        c = t.getch()
        
        if c == b'\xe0H' and cur_opt > 0:
            # up
            t.set_pos(x, y-1)
            cur_opt -= 1
        elif c == b'\xe0P' and cur_opt < max_opt:
            # down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'\t' and cur_opt == max_opt:
            # wrap around to first option
            t.set_pos(x, 3)
            cur_opt = 0
        elif c == b'\t':
            # next option, same as down
            t.set_pos(x, y+1)
            cur_opt += 1
        elif c == b'X' or c == b'x':
            set_opts[opts[cur_opt]] = True
            print('X', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b' ':
            set_opts[opts[cur_opt]] = False
            print('_', end='')
            if cur_opt < max_opt:
                t.set_pos(x, y+1)
                cur_opt += 1
            else:
                t.set_pos(x, y)
        elif c == b'\r':
            # save and go back
            CONFIG['bv.optional'] = set_opts
            return
        elif c == b'\x1b':
            # escape, go back without saving
            return
Exemplo n.º 14
0
def display_header(text):
    t.set_pos(0, 0)
    print(text.center(X_SIZE), end='')
    print('=' * X_SIZE, end='')