Beispiel #1
0
 def _validate(_resp):
     try:
         _ints = [_i for _i in parseIntList(_resp)
                     if _i in range(1, menu_num + 1)]
         return bool(_ints)
     except Exception:
         return False
Beispiel #2
0
 def _validate(_resp):
     try:
         _ints = [_i for _i in parseIntList(_resp)
                     if _i in range(1, menu_num + 1)]
         return bool(_ints)
     except Exception:
         return False
Beispiel #3
0
def selectArtist(heading, choices=None, multiselect=False, allow_create=True):
    color = Fg.green
    artist = None
    name = None

    if heading:
        print(heading)

    while artist is None:
        if choices:
            name = choices[0].name
            for menu_num, a in enumerate(choices):
                print(("   %d) %s" % (menu_num + 1, a.origin())))
            menu_num += 1

            if not multiselect:
                if allow_create:
                    menu_num += 1
                    print(("   %d) Enter a new artist" % menu_num))

                choice = prompt("Which artist",
                                type_=int,
                                choices=list(range(1, menu_num + 1)))
                choice -= 1
                if choice < len(choices):
                    artist = choices[choice]
                # Otherwise fall through to select artist below
            else:

                def _validate(_resp):
                    try:
                        _ints = [
                            _i for _i in parseIntList(_resp)
                            if _i in range(1, menu_num + 1)
                        ]
                        return bool(_ints)
                    except:
                        return False

                resp = prompt(color("Choose one or more artists"),
                              validate=_validate)
                artists = []
                for choice in [i - 1 for i in parseIntList(resp)]:
                    artists.append(choices[choice])
                # XXX: blech, returning a list here and a single value below
                return artists

        if artist is None:
            artist = promptArtist(None, name=name)
            if choices:
                if not Artist.checkUnique(choices + [artist]):
                    print(
                        (Fg.red("Artist entered is not unique, try again...")))
                    artist = None

    assert (artist)
    return artist
Beispiel #4
0
def selectArtist(heading, choices=None, multiselect=False, allow_create=True):
    color = Fg.green
    artist = None
    name = None
    menu_num = 0

    if heading:
        print(heading)

    while artist is None:
        if choices:
            name = choices[0].name
            for menu_num, a in enumerate(choices, start=1):
                print("   %d) %s" % (menu_num + 1, a.origin()))

            if not multiselect:
                if allow_create:
                    menu_num += 1
                    print("   %d) Enter a new artist" % menu_num)

                choice = prompt("Which artist", type_=int,
                                choices=range(1, menu_num + 1))
                choice -= 1
                if choice < len(choices):
                    artist = choices[choice]
                # Otherwise fall through to select artist below
            else:
                def _validate(_resp):
                    try:
                        _ints = [_i for _i in parseIntList(_resp)
                                    if _i in range(1, menu_num + 1)]
                        return bool(_ints)
                    except Exception:
                        return False

                resp = prompt(color("Choose one or more artists"),
                              validate=_validate)
                artists = []
                for choice in [i - 1 for i in parseIntList(resp)]:
                    artists.append(choices[choice])
                # XXX: blech, returning a list here and a single value below
                return artists

        if artist is None:
            artist = promptArtist(None, name=name)
            if choices:
                if not Artist.checkUnique(choices + [artist]):
                    print(Fg.red("Artist entered is not unique, try again..."))
                    artist = None

    assert(artist)
    return artist