Kodi Community Forum

Full Version: How to get current GUI state informations? Possible improvements?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is continuation of my thread in skin forum. In post #10 (and some before) there is description of my goal and problems so I'll not repeat myself here again.

I'll continue with question:
Is there any hard reason why there isn't something like xbmc.getListItemVideoInfoTag()?
Method which return VideoInfoTag of currently selected item. I know we can get majority of these informations from xbmc.getInfoLabel(...) method, but there are some other which will probably never be made ListItem infolabels (like m_iDbId). I checked other addons (Trakt, Cinema experience) how they solve problem with absence of direct key to Movies/TVShows DB tables and found same workaround (lookup by name), so I guess it'll be useful for others too.

Basicaly I'm asking because I already did some code changes to my local repo to test possibilities and looks like it works fine, so I want to know if I can continue to polish it to some patch form or return to lookup by name workaround.
I don't have a problem with python accessing more of the listitem, but I'd personally prefer if you index it via properties rather than introducing yet another structure in python that won't be maintained. i.e. listitem.property('videotitle') etc. rather than listitem.getVideoInfoTag().videoTitle.
jmarshall Wrote:I don't have a problem with python accessing more of the listitem, but I'd personally prefer if you index it via properties rather than introducing yet another structure in python that won't be maintained. i.e. listitem.property('videotitle') etc. rather than listitem.getVideoInfoTag().videoTitle.
I choose to return VideoInfoTag because it already exist for Python (returned by Player class), but you are right it's bit overkill for my purposes and pain to maintain. So I followed your proposal and added following "properties":

ListItem.Property(MovieId)
ListItem.Property(TvShowId)
ListItem.Property(EpisodeId)
ListItem.Property(MusicVideoId)
ListItem.Property(MovieSetId)

But now I have question about implementation. Properties introduced above are all related to VideoInfoTag, so I fill them in case there is VideoInfoTag set to CFileItem, but what about other cases when CFileItem is created for example from String in CVideoDatabase? In these situations DB record Id is also known from selects, but setting it as property will be really big mess because it's all over CVideoDatabase. As far as I understand it, setting Id property only from VideoInfoTag should be enough because these other instances of CFileItem have different usage, but I'm not 100% sure.

You can see what I did in this patch.
What I meant was to wrap the pseudo-properties in the python wrapper. Don't alter the internals, as that has issues likeyou point out Smile

Cheers,
Jonathan
Looks like I got your proposal completely wrong :p. I tried to make it clean and allow access to these properties to all "clients".
So there is my second try. Property names are same like above, but implementation is now only on Python facade (xbmcmodule.cpp).
What's your opinion?
Heh - we're still talking past each other Smile

Change:

ListItem_GetProperty()

To take in your new property values. You'll notice there's already support for startoffset in there.

Cheers,
Jonathan
Ahh, finally I got what you mean, at least I hope Smile.
Because my inexperience with Python XBMC api I never expected it's possible to simply hook up existing window by id. So following code

PHP Code:
lisItem xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocus().getSelectedItem() 

should return currently selected ListItem from current Window. But it doesn't work at all. It's fine up to ControlList, I get correct Window, correct ControlList with correct Id, but this ControlList is empty (size=0, currentPosition=-1). From source code (controllist.cpp) it's obvious why it dosn't work, ControlList never touches original XBMC list (even in case it originates from one) and works only with ListItems created from Python.

Should I invest some time to make ControlList working as expected? I'm asking because it's not easy job for someone without overview about all use cases like me. I have idea what to do, but it'll still need complete review.
Or am I still missing some other way how to get current ListItem? Smile
(2011-08-07, 17:10)bambi73 Wrote: [ -> ]Ahh, finally I got what you mean, at least I hope Smile.
Because my inexperience with Python XBMC api I never expected it's possible to simply hook up existing window by id. So following code

PHP Code:
lisItem xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocus().getSelectedItem() 

should return currently selected ListItem from current Window. But it doesn't work at all. It's fine up to ControlList, I get correct Window, correct ControlList with correct Id, but this ControlList is empty (size=0, currentPosition=-1). From source code (controllist.cpp) it's obvious why it dosn't work, ControlList never touches original XBMC list (even in case it originates from one) and works only with ListItems created from Python.

Should I invest some time to make ControlList working as expected? I'm asking because it's not easy job for someone without overview about all use cases like me. I have idea what to do, but it'll still need complete review.
Or am I still missing some other way how to get current ListItem? Smile

Bump. I'm having the same issue and it's really hampering my ability to expand the SageTV addon I'm working on. Has anyone figured out a good way to get the currently selected list item in a list of directory items?
+1
(2011-08-07, 17:10)bambi73 Wrote: [ -> ]Ahh, finally I got what you mean, at least I hope Smile.
Because my inexperience with Python XBMC api I never expected it's possible to simply hook up existing window by id. So following code

PHP Code:
lisItem xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocus().getSelectedItem() 

should return currently selected ListItem from current Window. But it doesn't work at all. It's fine up to ControlList, I get correct Window, correct ControlList with correct Id, but this ControlList is empty (size=0, currentPosition=-1). From source code (controllist.cpp) it's obvious why it dosn't work, ControlList never touches original XBMC list (even in case it originates from one) and works only with ListItems created from Python.

Should I invest some time to make ControlList working as expected? I'm asking because it's not easy job for someone without overview about all use cases like me. I have idea what to do, but it'll still need complete review.
Or am I still missing some other way how to get current ListItem? Smile
+1

I have the same problem too.

What is the solution here?

Thanks.
i've no experience with getFocus(), but using getFocusId() always works fine for me.
perhaps you can give that a shot?
Code:
win = xbmcgui.Window(xbmcgui.getCurrentWindowId())
cid = win.getFocusId()
ctrl = win.getControl(cid)
listitem = ctrl.getSelectedItem()
I tried this also with getFocusID(). but I'm still getting ctrl.size() = 0, and listitem = None.
Having exactly the same issue. ctrl.size() is always 0, did anyone figure out a way around this yet?

I really only need to figure out the selected item position so I can neatly reset the list after deleting an item but even ctrl.getSelectedPosition() is always returning -1, oddly enough ctrl.selectItem( x ) works fine.