[Help]Handling actions
#1
Question 
Hello everybody.

I'm trying to develop a script that starts automatically and handles all "ACTION_TOGGLE_WATCHED" actions, to move the watched item into a separate folder on the filesystem.

I looked up the codes in the Key.h sourcefile. However so far I've been unsuccessful in handling any actions at all.

The following code is from two examples in docu.
Code:
# import the XBMC libraries so we can use the controls and functions of XBMC
import xbmc, xbmcgui

# name and create our window
class BlahMainWindow(xbmcgui.Window):
    # and define it as self
    def __init__(self):
        # add picture control to our window (self) with a hardcoded path name to picture
        self.addControl(xbmcgui.ControlImage(0,0,720,480, '/tmp/Piracy.jpg'))

def onAction(self,action):
    xbmcgui.Dialog().ok("Message",str(action))
        
# store our window as a short variable for easy of use
W = BlahMainWindow()
# run our window we created with our background jpeg image
W.doModal()
# after the window is closed, Destroy it.
del W
I tried putting the onAction function into the class, but then the script wouldn't run at all. If I moved the onAction function into the class and removed the __init__ method, then the modal window would be nonresponsive to any input.

What am I doing wrong ? Am I going about this all wrong ?

Cheers
Reply
#2
Question 
Is this too trivial or is this just not possible ?
Reply
#3
Several things:

1. Actions only get sent to your window, and only those actions which are keymapped for that window. You'll find ACTION_TOGGLE_WATCHED is only set in the video window?

2. Given that your window is onscreen, the user does not have access to their video window, so what you're doing is not possible in that regard.

3. Instead, you could perhaps look into JSON-RPC - there are announcements sent whenever a video's playcount changes.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
jmarshall Wrote:Several things:

1. Actions only get sent to your window, and only those actions which are keymapped for that window. You'll find ACTION_TOGGLE_WATCHED is only set in the video window?

2. Given that your window is onscreen, the user does not have access to their video window, so what you're doing is not possible in that regard.

3. Instead, you could perhaps look into JSON-RPC - there are announcements sent whenever a video's playcount changes.

Concerning the actions approach:

So far from what I've read about keymap.xml's structure the action can be sent so custom windows in the form of <window#>.Python windows have id's from 3000-3099.

I successfully made a window that did receive the ACTION_TOGGLE_WATCHED action by adding
Code:
<window13000>
    <keyboard>
        <w>ToggleWatched</w>
    </keyboard>
</window13000>
to my keymap file.However I'm having a problem with #2. Is there a way to create a background window ?

I've tried using threads - create background waiting thread - to no avail. The code below should just create a window and act like the doModal(), but the window just shows and doesn't accept input of any kind.

Code:
# import the XBMC libraries so we can use the controls and functions of XBMC
import xbmc, xbmcgui, time, threading

ACTION_PREVIOUS_MENU = 10
ACTION_TOGGLE_WATCHED = 200


# name and create our window
class MyMainWindow(xbmcgui.Window):

    #handle actions
    def onAction(self,action):
        xbmcgui.Dialog().ok('Window ' + str(xbmcgui.getCurrentWindowId()), str(action.getId())  )
        
        if action == ACTION_PREVIOUS_MENU:
            xbmcgui.Dialog().ok("Message","10")
            self.bg.loop=0
            self.close()
        if action == ACTION_TOGGLE_WATCHED:
            self.bg.loop=0
            xbmcgui.Dialog().ok("Message","Watched(200)")
            self.close()

class backgroundTask(threading.Thread):
    
    loop=1
    
    def run(self):
        xbmcgui.Dialog().ok("Message","Waiting")
        while self.loop:
            time.sleep(1)
            
        self.window.close()
        # after the window is closed, Destroy it.
        del self.window
        xbmcgui.Dialog().ok('Done','Script ended')


# store our window as a short variable for easy of use
window = MyMainWindow()
window.show()


window.bg = backgroundTask()
#Give waiter window to close when done
window.bg.window=window

#start waiting
window.bg.start()


Concerning JSON
Where are the descriptions about the announcements ? I canno find any information in the main JSON RPC article.

Thank you for your help so far :-)
Reply

Logout Mark Read Team Forum Stats Members Help
[Help]Handling actions0