Assign a function to yesno
#1
Can someone give me a clue as to how to assign functions to the yesno dialog window please

I want to assign

something.py to 'YES'

and

ActivateWindow(10000,return) to 'No'

Thanks in advance, its for my first addon Smile
Reply
#2
Code:
import xbmc
import xbmcgui
import subprocess

DIALOG = xbmcgui.Dialog()

if __name__ == "__main__":
    response = DIALOG.yesno('Heading', 'Text', yeslabel='youryeslabel', nolabel='yournolabel')

    if response:
        # why not just write your code here?

        # call the script outside of kodi
        subprocess.Popen(['sudo', 'python', ' your_script'])

        # call the script from with kodi
        xbmc.executebuiltin('RunScript(your_script)')

    else:
        xbmc.executebuiltin('ActivateWindow(10000,return)')

Here is a shell of an addon. The code above would go into default.py, and would be called when the user runs the addon.

https://github.com/KODeKarnage/script.skeleton
Reply
#3
(2015-05-16, 11:46)Karnagious Wrote:
Code:
import xbmc
import xbmcgui
import subprocess

DIALOG = xbmcgui.Dialog()

if __name__ == "__main__":
    response = DIALOG.yesno('Heading', 'Text', yeslabel='youryeslabel', nolabel='yournolabel')

    if response:
        # why not just write your code here?

        # call the script outside of kodi
        subprocess.Popen(['sudo', 'python', ' your_script'])

        # call the script from with kodi
        xbmc.executebuiltin('RunScript(your_script)')

    else:
        xbmc.executebuiltin('ActivateWindow(10000,return)')

Here is a shell of an addon. The code above would go into default.py, and would be called when the user runs the addon.

https://github.com/KODeKarnage/script.skeleton

Hi, Karnagious,

Im going to give that a go tonight and tomorrow, As Im not happy with the code I have come up with so far. Its almost there, but not working properly. Ive had to do some research into __name__ == "__main__": and how to use it, At the end of the day I want to learn, not just copy code. If you dont give up on me Im gonna give it give it the beans, But if help dries out its going to be almost impossible.
For the sake of it ill post the code I have so far. BIG Thanks to all that have helped me so far.
Code:
import xbmcgui
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')
yesnowindow = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")
NOOPTION = xbmc.executebuiltin("ActivateWindow(10000,return)")


if yesnowindow:
    os.path.exists(TARGETFOLDER)
    if os.path.exists(TARGETFOLDER):
        shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted, All done,()"), xbmc.executebuiltin("ActivateWindow(10000,return)")
    else:
        NOOPTION

The ONLY problem with this is that if file doesn't exist there is no confirmation that file is already removed and all is good. apart from that, It works perfect.

Once again Thank you all who have helped so far. Smile
Reply
#4
Sorry, was there another question there? If so, then I think I missed it.
Reply
#5
(2015-05-17, 12:19)Karnagious Wrote: Sorry, was there another question there? If so, then I think I missed it.

Yeah, There is, I'm getting in a pickle with this a bit I think. Ill try to break it down.

i) The code I have works there is just 1 more thing i need to do to it

ii) I have had a play about with your help code, but alas i think its too advanced for me as this would be my first addon. Late night last night and all this morning. Not happening for me at all saying that, I don't know how, But I think I can see that

if response:
yes label - then do something
no label - then do something else
else ActivateWindow(10000,return)

So I guess the final question is this, using the code I have done with help from yourself, enen92 and curti,

iii) If yes is pressed (if yesnowindow), and (TARGETFOLDER) is not present, then
xbmc.executebuiltin("Notification(Folder already deleted, All done,()"), xbmc.executebuiltin("ActivateWindow(10000,return)")

Thanks for replying. I cant believe I use to write basic code as a kid on the commadre64, zx80 etc. Its a whole new ball game now.
Reply
#6
You should just be able to put the function you want to execute in the else block.

Code:
import xbmcgui
import xbmc
import os
import shutil

TARGETFOLDER = xbmc.translatePath('special://home/userdata/addon_data/01')
yesnowindow = xbmcgui.Dialog().yesno("This Will Delete a folder","Click yes to delete","Click No to exit")
NOOPTION = xbmc.executebuiltin("ActivateWindow(10000,return)")


if yesnowindow:
    os.path.exists(TARGETFOLDER)
    if os.path.exists(TARGETFOLDER):
        shutil.rmtree(TARGETFOLDER), xbmc.executebuiltin("Notification(Folder has been deleted, All done,()"), xbmc.executebuiltin("ActivateWindow(10000,return)")
    else:
        xbmc.executebuiltin("Notification(Folder has been deleted, All done,()")
        NOOPTION
Reply

Logout Mark Read Team Forum Stats Members Help
Assign a function to yesno0