xbmc.executebuiltin('Notification(...)') only once?
#1
I have written a little service add-on which practically just sends notification to Kodi when certain conditions are 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?

python:
    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()

Reply
#2
if the code you've posted is the actual code your using (i don't think so), then those two functions will never be executed.
when you run your script it will enter the while loop, but since you're calling those functions outside of the loop, nothing will happen.

only once you exit kodi, it will break out of the loop and then call those two functions.


as for notifications: by default, kodi will display a notification for 5 seconds, but you can specify the time (in ms) as well:
xbmc.executebuiltin( 'Notification(Info, Some text, 2000)' )
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
(2022-02-15, 12:47)ronie Wrote: if the code you've posted is the actual code your using (i don't think so), then those two functions will never be executed.
when you run your script it will enter the while loop, but since you're calling those functions outside of the loop, nothing will happen.

only once you exit kodi, it will break out of the loop and then call those two functions.


as for notifications: by default, kodi will display a notification for 5 seconds, but you can specify the time (in ms) as well:
xbmc.executebuiltin( 'Notification(Info, Some text, 2000)' )

You're correct! Smile I have made some copy/paste error. They are 4 spaces more inward.

Regarding specifying the time. That's the thing. It doesn't matter what I specify because the line KEEPS executing again and again. I can't break out of it. If, for instance I add another Notification, they just alternate - forever.

What am I missingHuh
Reply
#4
You have nested for loops with a single break.  The breaks will only break the inner for loop.  Something like this should work for both:

            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_out_flag = True
                            break

                    if break_out_flag == True:
                        break


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#5
(2022-02-15, 11:56)Persona2022 Wrote: I have written a little service add-on which practically just sends notification to Kodi when certain conditions are 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).
...

Linking your Reddit post: https://www.reddit.com/r/kodi/comments/s...w_to_make/

As I mentioned in that post... I think you are better off playing around with "OnNotification". See if that can catch your resolution changes and use that as a trigger.

Since it appears you are new to python, split your project into smaller code blocks. Don't try and lump all your code together (yet). Smile

My first suggestion is to set up a monitor class that prints "OnNotification" debugging logs.

If you need help with more concrete code feel free to post...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#6
(2022-02-15, 18:06)Lunatixz Wrote: My first suggestion is to set up a monitor class that prints "OnNotification" debugging logs.

If you need help with more concrete code feel free to post...

hi, thank you for the suggestion of setting up a monitor class. I have tried to research this but I couldn't figure out how to do it. I'd appreciate any help.
Thank you.
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.executebuiltin('Notification(...)') only once?0