Context menu - get listitem data
#1
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.
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#2
(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
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#3
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
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#4
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.
Reply
#5
(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).

windowID = xbmcgui.window.getCurrentWindowId()
controlID  = xbmcgui.window.getFocus() or xbmcgui.window.getFocusId()
control     = windowID.getControl(controlID) 
listitem    = controlID.getSelectedItem()
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#6
@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
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#7
(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?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#8
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
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#9
*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.
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#10
(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).
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#11
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..
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#12
(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.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#13
Thanks.

The window ID was correct. I was testing it with a widget on the home screen.
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
#14
(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?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Twitter | Help?
Reply
#15
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
Embuary | Skin | Helper | Info | Repo | GitHub
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Context menu - get listitem data00