Ejemplo n.º 1
0
def main():
    sections = defaultdict(int)

    for s in getValidSongs():
        with open(f"src/songs/{s}.txt", "r") as fp:
            contents = fp.readlines()
        for i in contents[1:]:
            sections[i.split(":")[0]] += 1

    for k, v in sorted(sections.items(), key=lambda kv: kv[1], reverse=True):
        print(k, v)
Ejemplo n.º 2
0
def checkSongGUI(songs, keys):
    if not any(songs):
        return popupError("You must select at least one song.")

    ignoreEmptyFile = False
    ignoreDanglingKey = False

    validSongs = getValidSongs()
    for song, key in zip(songs, keys):
        if song:
            if song not in validSongs:
                return popupError(
                    f"\"{song}\" not found in the songs directory.")
            elif not key:
                return popupError(f"No key specified for \"{song}\".")
            elif key not in validKeys:
                return popupError(f"\"{key}\" is not a valid key.")

            with Path(f"src/songs/{song}.txt").open() as fp:
                if len(fp.readlines()) == 1 and not ignoreEmptyFile:
                    button = popupWarn(
                        f"File for \"{song}\" has too few lines.")
                    if button == "Go Back":
                        return
                    elif button == "Ignore All":
                        ignoreEmptyFile = True
        else:
            if key and not ignoreDanglingKey:
                button = popupWarn(f"No song name entered for key \"{key}\".")
                if button == "Go Back":
                    return
                elif button == "Ignore All":
                    ignoreDanglingKey = True

    nonEmptySongs = [song for song in songs if song]
    if len(nonEmptySongs) != len(set(nonEmptySongs)):
        return popupError("Each song can only be selected once.")
    return True
Ejemplo n.º 3
0
def songGUI():
    numSongs = 4
    songs, keys = [""] * numSongs, [""] * numSongs
    makeNewWindow = True

    while True:
        if makeNewWindow:
            songsFromFile = getValidSongs()
            songColumnList = [sg.Text("Song")]
            keyColumnList = [sg.Text("Key")]

            def songCombo(i, input=""):
                if input and input not in songsFromFile:
                    prepend = [input, ""]
                else:
                    prepend = [""]
                return sg.Combo(prepend + songsFromFile, input, 37, key=f"-SONG{i}-")

            def keyInput(i, input=""):
                return sg.InputText(input, (5, None), key=f"-KEY{i}-")

            # TODO? Maybe Combo isn't the best implementation
            for i in range(numSongs):
                if i < len(songs):
                    songColumnList.append(songCombo(i, songs[i]))
                    keyColumnList.append(keyInput(i, keys[i]))
                else:
                    songColumnList.append(songCombo(i))
                    keyColumnList.append(keyInput(i))

            songDialogue = [
                [sg.Column([[s] for s in songColumnList]),
                 sg.Column([[k] for k in keyColumnList])],
                [buttonRow(["Change Number of Songs", "Add a New Song"], False),
                 [sg.HorizontalSeparator()],
                 [sg.Text("Enter a filename:")],
                 [sg.InputText("", key="-FILENAME-")],
                 buttonRow(["OK", "Use Next Sunday", "Quit"], False)
                 ]
            ]

            songWindow = sg.Window("WorshipList").Layout(songDialogue)

        button, values = songWindow.Read()
        makeNewWindow = True

        if button in {"Quit", None}:
            exit()
        else:
            songs, keys = [], []

            for i in range(numSongs):
                songs.append(values[f"-SONG{i}-"].strip())
                songWindow[f"-SONG{i}-"].update(songs[i])

                key = values[f"-KEY{i}-"].strip()
                if key:
                    key = key[0].upper() + key[1:].lower()
                keys.append(key)
                songWindow[f"-KEY{i}-"].update(key)

            if button == "Change Number of Songs":
                nonEmptyRows = [i for i in range(len(songs)) if songs[i] or keys[i]]
                newNS = numSongsGUI(nonEmptyRows)
                if newNS:
                    numSongs = newNS
                else:
                    makeNewWindow = False

            elif button == "Add a New Song":
                makeNewWindow = addSongGUI()

            else:
                if not checkSongGUI(songs, keys):
                    makeNewWindow = False
                    continue

                if button == "OK":
                    if checkFileName(values["-FILENAME-"]):
                        filename = values["-FILENAME-"]
                    else:
                        popupError("Invalid file name. Try again.")
                        continue
                elif button == "Use Next Sunday":
                    today = date.today()
                    nextSunday = today + timedelta(days=(6 - today.weekday()) % 7)
                    filename = f"LIFT Worship {nextSunday.strftime('%F')}"

                songWindow.close()
                toDelete = [i for i, s in enumerate(songs) if not s]

                def prune(xs):
                    return [x for i, x in enumerate(xs) if i not in toDelete]

                return prune(songs), prune(keys), filename

            if makeNewWindow:
                songWindow.close()