0

I have written this code which sends a notification to Kodi when a certain condition is met. (When I start a movie/tv show or play music I want the language, resolution, refresh rate and sound mode to appear on the screen).

I have grouped my media in different folders.

The code is working fine but I can't fix one issue:

The line in bold where I actually send the notification xbmc.executebuiltin( 'Notification(Info, Some text)' ) stays on the screen - forever, unless I change the window or to a file which is in a different folder (then a different notification stays on the screen). Not what I want.

What is missing so the line only executes once and the notification disappears after a few seconds?

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not monitor.abortRequested():

        def my_function_one():
            for root, dirs, files in os.walk(path_1):
                for x in dirs:
                    if condition_1 and condition_2:
                        **xbmc.executebuiltin( 'Notification(Info, Some text)' )**
                        break


        def my_function_two():
            for root, dirs, files in os.walk(path_2):
                for y in dirs:
                    if condition_3 and condition_4:
                        **xbmc.executebuiltin( 'Notification(Info, Some other text)' )**
                        break


        if monitor.waitForAbort(5):
            break

    my_function_one()
    my_function_two()

update: I have tried adding True/False statements to my code but the notification is still not disappearing after a few seconds - as it should:

displayed = False
def my_function_one():
    for root, dirs, files in os.walk(path_1):
        for x in dirs:
            if condition_1 and condition_2:
                if not displayed:
                    displayed = True
                    xbmc.executebuiltin( 'Notification(Info, Some text)' )
                    break
  • maybe use some variable with value `True/False` to control if it was already displayed. At start `displayed = False` and later `if not displayed: displayed = True ; xbmc.executebuiltin(...)` – furas Feb 14 '22 at 22:17
  • hi, thank you for the reply. I did that but nothing changed. Maybe I did it wrong? def my_function_one(): displayed = False for root, dirs, files in os.walk(path_1): for x in dirs: if condition_1 and condition_2: if not displayed: displayed = True xbmc.executebuiltin( 'Notification(Info, Some text)' ) break – Identidad Persona Feb 15 '22 at 09:23
  • you have to define `displayed = False` as global variable outside `my_function_one` to keep value after exiting functions – furas Feb 15 '22 at 13:20
  • I did that too. Still the same.... I have added the exact code above - including your proposed change. – Identidad Persona Feb 15 '22 at 13:45
  • Is it correct now? Or did I do something wrong? – Identidad Persona Feb 15 '22 at 13:46
  • inside function you need `global displayed` to inform function that it has to assign new value to external/global variable instead of local varaible. – furas Feb 15 '22 at 17:37
  • Ah great! Now it stops. HOWEVER: how do I make it run the second for loop? It's not continuing. – Identidad Persona Feb 15 '22 at 20:00
  • use two variables - in first function uses `displayed1` and in second function use `displayed2`. – furas Feb 15 '22 at 20:46
  • Thank you! I had already tried that but somehow it didn't continue with my second function. I added two while True loops with breaks when I call the functions. Now it's working! BUT I don't know if while True is the way to go? Should I look for another way? What do you think? – Identidad Persona Feb 16 '22 at 16:16

0 Answers0