Kodi Community Forum

Full Version: How to detect window activation?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello.

I want to detect a moment when the user fired actions ACTION_NAV_BACK or ACTION_PREVIOUS_MENU in Player. After these keys pressing, it is activating last active window. But I cannot to detect this.

Thanks.
(2017-09-15, 16:32)Rameron Wrote: [ -> ]Hello.

I want to detect a moment when the user fired actions ACTION_NAV_BACK or ACTION_PREVIOUS_MENU in Player. After these keys pressing, it is activating last active window. But I cannot to detect this.

Thanks.
The only way to retrieve actions is through a custom window.

https://codedocs.xyz/xbmc/xbmc/class_x_b...10f5a3db21

Sent from my SM-G935T
(2017-09-15, 16:36)Lunatixz Wrote: [ -> ]The only way to retrieve actions is through a custom window.

https://codedocs.xyz/xbmc/xbmc/class_x_b...10f5a3db21

Sent from my SM-G935T (typie typie)

No, I'm already use custom window. But I cannot to detect the moment, when this window activating after pressing by user ACTION_NAV_BACK or ACTION_PREVIOUS_MENU in xbmc.Player. There aren't any action, only when I start navigating in my window or something press.
(2017-09-15, 18:25)Rameron Wrote: [ -> ]
(2017-09-15, 16:36)Lunatixz Wrote: [ -> ]The only way to retrieve actions is through a custom window.

https://codedocs.xyz/xbmc/xbmc/class_x_b...10f5a3db21

Sent from my SM-G935T (typie typie)

No, I'm already use custom window. But I cannot to detect the moment, when this window activating after pressing by user ACTION_NAV_BACK or ACTION_PREVIOUS_MENU in xbmc.Player. There aren't any action, only when I start navigating in my window or something press.
Sorry I'm having difficulty following... You should still be able to capture keypresses after play as long as you don't close your custom window.

It might be easier if you post your code.

Sent from my SM-G935T
(2017-09-15, 19:29)Lunatixz Wrote: [ -> ]Sorry I'm having difficulty following... You should still be able to capture keypresses after play as long as you don't close your custom window.

It might be easier if you post your code.

Sent from my SM-G935T (typie typie)
But xbmc.Player (). Play (...) is activating Player and any keypresses is processed by Player. My window just is in the background and onAction function do not receive anything.
(2017-09-15, 19:56)Rameron Wrote: [ -> ]
(2017-09-15, 19:29)Lunatixz Wrote: [ -> ]Sorry I'm having difficulty following... You should still be able to capture keypresses after play as long as you don't close your custom window.

It might be easier if you post your code.

Sent from my SM-G935T (typie typie)
But xbmc.Player (). Play (...) is activating Player and any keypresses is processed by Player. My window just is in the background and onAction function do not receive anything.

Code please, I can easily point out your issues looking at the code.
(2017-09-15, 19:58)Lunatixz Wrote: [ -> ]Code please, I can easily point out your issues looking at the code.

There is my function to play video:

Code:
def videoLaunch(self):
    videoURL = ""
    videoID = 0
    episodeNumber = 0
    
    if self.currentShowMode == 1:
        videoID = self.currentVideosList[self.lstContent.getSelectedPosition()]["id"]
        videoURL = VideoAPI.getSingleVideoLink(videoID)
    elif self.currentShowMode == 2:
        videoID = self.currentVideosList[self.selectedVideo]["id"]
        episodeNumber = self.currentVideosList[self.selectedVideo]["series"][self.lstContent.getSelectedPosition()]
        videoURL = VideoAPI.getSeriesLink(videoID, episodeNumber)
    
    lstInfo = self.createInfoListItem()
    xbmc.Player().play(videoURL, lstInfo, False)

This function is called from onControl, when I choose item in ControlList.
(2017-09-15, 20:04)Rameron Wrote: [ -> ]
(2017-09-15, 19:58)Lunatixz Wrote: [ -> ]Code please, I can easily point out your issues looking at the code.

There is my function to play video:

Code:
def videoLaunch(self):
    videoURL = ""
    videoID = 0
    episodeNumber = 0
    
    if self.currentShowMode == 1:
        videoID = self.currentVideosList[self.lstContent.getSelectedPosition()]["id"]
        videoURL = VideoAPI.getSingleVideoLink(videoID)
    elif self.currentShowMode == 2:
        videoID = self.currentVideosList[self.selectedVideo]["id"]
        episodeNumber = self.currentVideosList[self.selectedVideo]["series"][self.lstContent.getSelectedPosition()]
        videoURL = VideoAPI.getSeriesLink(videoID, episodeNumber)
    
    lstInfo = self.createInfoListItem()
    xbmc.Player().play(videoURL, lstInfo, False)

This function is called from onControl, when I choose item in ControlList.

Where is your window controls, onaction? I can only resolve your issue if you are willing to provide me relevant information...

I can only guess that perhaps you are using windowxml and maybe you should use windowxmldialog... but again without code i'm only guessing since both should still capture onaction commands).

Below you will find a link to Kodis doc's maybe this will help you further.

https://codedocs.xyz/xbmc/xbmc
(2017-09-15, 20:28)Lunatixz Wrote: [ -> ]Where is your window controls, onaction? I can only resolve your issue if you are willing to provide me relevant information...

I can only guess that perhaps you are using windowxml and maybe you should use windowxmldialog... but again without code i'm only guessing since both should still capture onaction commands).

Below you will find a link to Kodis doc's maybe this will help you further.

https://codedocs.xyz/xbmc/xbmc

Code:
import os
import xbmcaddon
import xbmcgui

ADDON_ID = xbmcaddon.Addon().getAddonInfo("id")
ADDON_PATH = xbmcaddon.Addon().getAddonInfo("path")
ADDON_DATA_PATH = os.path.join(xbmc.translatePath("special://profile/addon_data/"), ADDON_ID)

ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4
ACTION_PREVIOUS_MENU = 10
ACTION_NAV_BACK = 92
ACTION_MOUSE_RIGHT_CLICK = 101

class MainWindowClass(xbmcgui.Window):
    videoURLs = []

    def __init__(self):
        self.initGUI()
        self.initVideoURLs()
        self.loadVideoURLs()
    def initGUI(self):
        self.lstContent = xbmcgui.ControlList(10, 10, 1270, 710,                                     #position
                                            "font14",                                                 #font Name
                                            "0xFFFFFFFF",                                             #text Color
                                            os.path.join(ADDON_PATH, "images\\unselected.png"),        #button Texture
                                            os.path.join(ADDON_PATH, "images\\selected.png"),        #button Focus Texture
                                            "0xFF000000",                                             #selected Color
                                            120,                                                    #image Width
                                            90,                                                        #image Height
                                            0,                                                        #item Text X Offset
                                            0,                                                        #item Text Y Offset
                                            95,                                                        #item Height
                                            2)                                                        #space
        self.addControl(self.lstContent)
        self.setFocus(self.lstContent)
    def initVideoURLs(self):
        self.videoURLs.append("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        self.videoURLs.append("https://cinelerra-cv.org/footage/byger-20030708-liten.avi")
        self.videoURLs.append("https://cinelerra-cv.org/footage/lys-20031106.avi")
    def loadVideoURLs(self):
        for url in self.videoURLs:
            self.lstContent.addItem(url)
    def onAction(self, action):
        if action == ACTION_NAV_BACK or action == ACTION_MOUSE_RIGHT_CLICK:
            xbmc.log("# Backspace pressed")        
        elif action == ACTION_PREVIOUS_MENU:
            self.close()
        elif action == ACTION_MOVE_UP:
            self.selectItem()
        elif action == ACTION_MOVE_DOWN:
            self.selectItem()    
    def onControl(self, control):
        if control == self.lstContent:
            self.playVideo(self.lstContent.getSelectedPosition())
    def playVideo(self, index):
        xbmc.Player().play(item=self.videoURLs[index], windowed=False)
    
    def selectItem(self):
        for index in range(0, lstContent.size()):
            lstContent.getListItem(index).select(False)
        lstContent.getSelectedItem().select(True)
        
if __name__ == "__main__":        
    mainWindow = MainWindowClass()
    mainWindow.doModal()

Here. When I'm pressing backspace in player and main window is activated, there isn't any action.
(2017-09-16, 09:38)Rameron Wrote: [ -> ]
(2017-09-15, 20:28)Lunatixz Wrote: [ -> ]Where is your window controls, onaction? I can only resolve your issue if you are willing to provide me relevant information...

I can only guess that perhaps you are using windowxml and maybe you should use windowxmldialog... but again without code i'm only guessing since both should still capture onaction commands).

Below you will find a link to Kodis doc's maybe this will help you further.

https://codedocs.xyz/xbmc/xbmc

Here. When I'm pressing backspace in player and main window is activated, there isn't any action.

Code looks okay, I ran it, and backspace returned me to your menu.
There are a few structure issues with your code and how it was written, for example you should use def onInit(self):
(2017-09-17, 03:15)Lunatixz Wrote: [ -> ]Code looks okay, I ran it, and backspace returned me to your menu.
There are a few structure issues with your code and how it was written, for example you should use def onInit(self):

Yes, backspace returned to main menu, but how to handle moment of returning? There aren't any action or something.
I don't think that onInit instead __init__ changed the situation. But I tryed and nothing happened.
(2017-09-17, 20:15)Rameron Wrote: [ -> ]
(2017-09-17, 03:15)Lunatixz Wrote: [ -> ]Code looks okay, I ran it, and backspace returned me to your menu.
There are a few structure issues with your code and how it was written, for example you should use def onInit(self):

Yes, backspace returned to main menu, but how to handle moment of returning? There aren't any action or something.
I don't think that onInit instead __init__ changed the situation. But I tryed and nothing happened.

init is the window initialization. ie called once when you open the window.

oninit is called everytime the window is in focus.... so YES fundamentally you should be using it!

I didn't say that was the root of your issue but it is one of them, you also have list focus issues.

Handle moment of returning? that would be oninit...
(2017-09-17, 20:34)Lunatixz Wrote: [ -> ]init is the window initialization. ie called once when you open the window.

oninit is called everytime the window is in focus.... so YES fundamentally you should be using it!

I didn't say that was the root of your issue but it is one of them, you also have list focus issues.

Handle moment of returning? that would be oninit...

When I'm using onInit instead __init__ there is only black screen, nothing happened and any actions aren't present.
(2017-09-20, 10:16)Rameron Wrote: [ -> ]
(2017-09-17, 20:34)Lunatixz Wrote: [ -> ]init is the window initialization. ie called once when you open the window.

oninit is called everytime the window is in focus.... so YES fundamentally you should be using it!

I didn't say that was the root of your issue but it is one of them, you also have list focus issues.

Handle moment of returning? that would be oninit...

When I'm using onInit instead __init__ there is only black screen, nothing happened and any actions aren't present.
I never mentioned to replace init with oninit... I was explaining the fundamentals of both functions.

This will help you get started.

http://kodi.wiki/view/Python_development...evelopment



Sent from my SM-G935T
(2017-09-20, 14:45)Lunatixz Wrote: [ -> ]I never mentioned to replace init with oninit... I was explaining the fundamentals of both functions.

This will help you get started.

http://kodi.wiki/view/Python_development...evelopment



Sent from my SM-G935T (typie typie)

I modify the code and add this function with OnFocus for test. So, onInit never called.
I just launch video, player focused and then I press backspace for returning on my window.

Code:
import os
import xbmcaddon
import xbmcgui

ADDON_ID = xbmcaddon.Addon().getAddonInfo("id")
ADDON_PATH = xbmcaddon.Addon().getAddonInfo("path")
ADDON_DATA_PATH = os.path.join(xbmc.translatePath("special://profile/addon_data/"), ADDON_ID)

ACTION_MOVE_UP = 3
ACTION_MOVE_DOWN = 4
ACTION_PREVIOUS_MENU = 10
ACTION_NAV_BACK = 92
ACTION_MOUSE_RIGHT_CLICK = 101

class MainWindowClass(xbmcgui.Window):
    videoURLs = []

    def __init__(self):
        self.initGUI()
        self.initVideoURLs()
        self.loadVideoURLs()
    def initGUI(self):
        self.lstContent = xbmcgui.ControlList(10, 10, 1270, 710,                                     #position
                                            "font14",                                                 #font Name
                                            "0xFFFFFFFF",                                             #text Color
                                            os.path.join(ADDON_PATH, "images\\unselected.png"),        #button Texture
                                            os.path.join(ADDON_PATH, "images\\selected.png"),        #button Focus Texture
                                            "0xFF000000",                                             #selected Color
                                            120,                                                    #image Width
                                            90,                                                        #image Height
                                            0,                                                        #item Text X Offset
                                            0,                                                        #item Text Y Offset
                                            95,                                                        #item Height
                                            2)                                                        #space
        self.addControl(self.lstContent)        
    def initVideoURLs(self):
        self.videoURLs.append("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        self.videoURLs.append("https://cinelerra-cv.org/footage/byger-20030708-liten.avi")
        self.videoURLs.append("https://cinelerra-cv.org/footage/lys-20031106.avi")        
    def loadVideoURLs(self):
        for url in self.videoURLs:
            self.lstContent.addItem(url)
        self.setFocus(self.lstContent)
        self.selectItem()
    def onAction(self, action):
        if action == ACTION_NAV_BACK or action == ACTION_MOUSE_RIGHT_CLICK:
            xbmc.log("# Backspace pressed or right clicke pressed")        
        elif action == ACTION_PREVIOUS_MENU:
            self.close()
        elif action == ACTION_MOVE_UP:
            self.selectItem()
        elif action == ACTION_MOVE_DOWN:
            self.selectItem()    
    def onControl(self, control):
        if control == self.lstContent:
            self.playVideo(self.lstContent.getSelectedPosition())
    def onInit(self):
        xbmc.log("============================ Window is init")    
    def onFocus(self, controlId):
        xbmc.log("============================ %d is focused"%(controlId))
    def playVideo(self, index):
        xbmc.Player().play(item=self.videoURLs[index], windowed=False)
    def selectItem(self):
        for index in range(0, self.lstContent.size()):
            self.lstContent.getListItem(index).select(False)
        self.lstContent.getSelectedItem().select(True)
        
if __name__ == "__main__":        
    mainWindow = MainWindowClass()
    mainWindow.doModal()
Pages: 1 2