Kodi Community Forum

Full Version: Context menu - get listitem data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is there any way to get the listitem informations of the item where the context menu was opened?
In library views listitem.foo is returning everything as it should, but outside of library views - like for widgets - these values are empty and cleared/not available anymore as soon as I'm opening the context menu.

Edit:
I've also tried to get the values via sys.listitem, which should be a copy of xbmcgui.ListItem, but this leads to an exception: AttributeError: 'module' object has no attribute 'listitem'. I guess this is caused by a different instance.

Edit2:
Just to be sure: I do not want to add a context menu item. I just want the values of the listitems.
(2019-08-20, 09:50)sualfred Wrote: [ -> ]Is there any way to get the listitem informations of the item where the context menu was opened?
In library views listitem.foo is returning everything as it should, but outside of library views - like for widgets - these values are empty and cleared/not available anymore as soon as I'm opening the context menu.

Edit:
I've also tried to get the values via sys.listitem, which should be a copy of xbmcgui.ListItem, but this leads to an exception: AttributeError: 'module' object has no attribute 'listitem'. I guess this is caused by a different instance.

Edit2:
Just to be sure: I do not want to add a context menu item. I just want the values of the listitems.

Have you tried using the windows control Id and getSelectedItem?

https://codedocs.xyz/xbmc/xbmc/group__py...03c0d91c06
Can you give me an example?
The context menu is a grouplist control and  the window control ID would return the ID of each single button

Edit
If you mean
Code:

xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocus().getSelectedItem()

-> Force close of Kodi
Maybe possible to use the <defaultcontrol></defaultcontrol> tag in skin and use it together with the grouplist id?

EDIT: 
Sorry I misunderstood your question this won't remember your last position.
(2019-08-20, 14:13)sualfred Wrote: [ -> ]Can you give me an example?
The context menu is a grouplist control and  the window control ID would return the ID of each single button

Edit
If you mean
Code:

xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocus().getSelectedItem()

-> Force close of Kodi


Try below example (untested).
python:

windowID = xbmcgui.window.getCurrentWindowId()
controlID  = xbmcgui.window.getFocus() or xbmcgui.window.getFocusId()
control     = windowID.getControl(controlID) 
listitem    = controlID.getSelectedItem()
@Lunatixz 

Thanks, but isn't this the same? Corrected the syntax of your example to:
Code:


    windowID = xbmcgui.getCurrentWindowId()
    log('windowID ' + str(windowID))
    controlID = xbmcgui.Window(windowID).getFocusId()
    log('controlID ' + str(controlID))
    control = xbmcgui.Window(windowID).getControl(controlID)
    log('control ' + str(control))
    listitem = control.getSelectedItem()
    log('listitem ' + listitem)

And it still force closes.

Log output:
Code:

2019-08-21 23:26:57.860 T:13504  NOTICE: [ script.embuary.helper ] windowID 10025
2019-08-21 23:26:57.861 T:13504  NOTICE: [ script.embuary.helper ] controlID 56
2019-08-21 23:26:57.861 T:13504  NOTICE: [ script.embuary.helper ] control <xbmcgui.ControlList object at 0x000002231F1BD3C8>

So it basically gets the cList, but all functions like .getSelectedItem() or .getListItem etc are going to force close Kodi
(2019-08-21, 23:30)sualfred Wrote: [ -> ]@Lunatixz 

Thanks, but isn't this the same? Corrected the syntax of your example to:
Code:


    windowID = xbmcgui.getCurrentWindowId()
    log('windowID ' + str(windowID))
    controlID = xbmcgui.Window(windowID).getFocusId()
    log('controlID ' + str(controlID))
    control = xbmcgui.Window(windowID).getControl(controlID)
    log('control ' + str(control))
    listitem = control.getSelectedItem()
    log('listitem ' + listitem)

And it still force closes.

Log output:
Code:

2019-08-21 23:26:57.860 T:13504  NOTICE: [ script.embuary.helper ] windowID 10025
2019-08-21 23:26:57.861 T:13504  NOTICE: [ script.embuary.helper ] controlID 56
2019-08-21 23:26:57.861 T:13504  NOTICE: [ script.embuary.helper ] control <xbmcgui.ControlList object at 0x000002231F1BD3C8>

So it basically gets the cList, but all functions like .getSelectedItem() or .getListItem etc are going to force close Kodi

Yes and no, Sometimes methods do not return in a timely manner or with a valid return. Which might have explained the crashes... Breaking things down would narrow down issues.

Odd it's crashing; I can look into it in detail over the weekend.

Did you verify the windowID and controlID? I believe the context window id is 10106 not 10025

Maybe try hardcoding the window ID?
If I use this:
Code:


    windowID = xbmcgui.getCurrentWindowId()
    log('windowID ' + str(windowID))
    win = xbmcgui.Window(windowID)
    log('win ' + str(win))
    cid = win.getFocusId()
    log('cid ' + str(cid))
    ctrl = win.getControl(cid)
    log('ctrl ' + str(ctrl))
    listitem = ctrl.getSelectedItem()
    log(listitem)

It does not crash, but returns "None"

Output:
Code:

2019-08-21 23:45:42.988 T:26796  NOTICE: [ script.embuary.helper ] windowID 10000
2019-08-21 23:45:42.988 T:26796  NOTICE: [ script.embuary.helper ] win <xbmcgui.Window object at 0x000001E5C0705530>
2019-08-21 23:45:42.988 T:26796  NOTICE: [ script.embuary.helper ] cid 205
2019-08-21 23:45:42.988 T:26796  NOTICE: [ script.embuary.helper ] ctrl <xbmcgui.ControlList object at 0x000001E5C0087E40>
2019-08-21 23:45:42.998 T:26796  NOTICE: [ script.embuary.helper ] None
*sigh*
Crawled the board history a bit. And it really seems that you cannot get Kodi listitems by Python. I'm not the first one with that problem. I wish it would be possible to use xbmc.getInfoLabel() from the underlaying window of an active dialog.
(2019-08-21, 23:55)sualfred Wrote: [ -> ]*sigh*
Crawled the board history a bit. And it really seems that you cannot get Kodi listitems by Python. I'm not the first one with that problem. I wish it would be possible to use xbmc.getInfoLabel() from the underlaying window of an active dialog.

I'm able to get listitems through Python, I do it all the time... unless its a bug in nightlies (which i'm not running).
I'm running Leia and tested the stable + latest nightly. I've just "quoted" what I read in the board. Feel free to correct me. That would solve my problem Smile

Just to prevent mistakes: I'm not trying to get the object from a Python window or control that I have filled with in by myself..
(2019-08-22, 00:15)sualfred Wrote: [ -> ]I'm running Leia and tested the stable + latest nightly. I've just "quoted" what I read in the board. Feel free to correct me. That would solve my problem Smile

Just to prevent mistakes: I'm not trying to get the object from a Python window or control that I have filled with in by myself..

I understand, you're trying to "capture" a listitem that's in focus. I'm not aware of any recent bugs, However a quick test does confirm widget items are not filling sys.listitem.

I still believe using manual control types works.

I can test over the weekend or you could rule out issues by manually entering the window and control IDs. I don't believe the window id posted early is correct as mentioned above.
Thanks.

The window ID was correct. I was testing it with a widget on the home screen.
(2019-08-22, 08:29)sualfred Wrote: [ -> ]Thanks.

The window ID was correct. I was testing it with a widget on the home screen.

Which skin and widget are you testing?
My embuary skin. Skins are mostly provided by my embuary helper script. All of them have the correct mediatype + dbid set

Edit:
But I also get "None" returned in libraries. The IDs are correct.

Code:

2019-08-25 18:11:06.848 T:27260  NOTICE: [ script.embuary.helper ] windowID 10025
2019-08-25 18:11:06.848 T:27260  NOTICE: [ script.embuary.helper ] win <xbmcgui.Window object at 0x0000015E70DC57D8>
2019-08-25 18:11:06.848 T:27260  NOTICE: [ script.embuary.helper ] cid 56
2019-08-25 18:11:06.848 T:27260  NOTICE: [ script.embuary.helper ] ctrl <xbmcgui.ControlList object at 0x0000015E70E97698>
2019-08-25 18:11:06.856 T:27260  NOTICE: [ script.embuary.helper ] None
Pages: 1 2