from win10toast import ToastNotifier
import regex as re
from time import sleep

import graph_gen

announced = False
notification = ""
search_pat = re.compile(r"#\sLowShelf")

toast = ToastNotifier()


with open("C:/Program Files/EqualizerAPO/config/config.txt", "r+") as conf:

    conf_text = conf.read().splitlines()

    for i, line in enumerate(conf_text):

        if announced:
            if line[0] == "#":
                conf_text[i] = line[1:].strip()
                notification = "Enabled Bass-Boost ¯¯¯¯\_______"

            else:
                conf_text[i] = "# " + line.strip()
                notification = "Disabled Bass-Boost ----------------"

            announced = False

            break

        if search_pat.match(line):
            announced = True

    if notification != "":
        conf.seek(0)
        conf.truncate(0)
        conf.write("\n".join(conf_text))
    else:
        notification = "Filter not found!"


toast.show_toast(
    "Equalizer",
    notification,
    duration=3,
    icon_path="C:/Users/Leo/AppData/Roaming/midi-mixer-app/eq.ico",
    threaded=True)


graph_gen.main()


while toast.notification_active():
    sleep(0.1)
