Win [solved] Bug with getSelectedPosition() in ListControl
#1
Hello!

I was detected some bug with embedded function of ListControl - getSelectedPosition().
In some situations this function can to return invalid selected position.
For example, ListControl is filling by some values in total count of 20 items. I select item with number 20 and then I call reset(). Then I fill ListControl with new items, call:
self.listControl.selectItem(0)
self.listControl.getListItem(0).select(True)

and even after that getSelectedPosition() return 20.
Reply
#2
(2017-09-06, 13:10)Rameron Wrote: Hello!

I was detected some bug with embedded function of ListControl - getSelectedPosition().
In some situations this function can to return invalid selected position.
For example, ListControl is filling by some values in total count of 20 items. I select item with number 20 and then I call reset(). Then I fill ListControl with new items, call:
self.listControl.selectItem(0)
self.listControl.getListItem(0).select(True)

and even after that getSelectedPosition() return 20.

Can you post your example code?

Tested... and I'm seeing proper returns.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#3
(2017-09-06, 17:32)Lunatixz Wrote: Can you post your example code?
Of course!

My example:

PHP Code:
import xbmcaddon
import xbmcgui
import os

ADDON_PATH 
xbmcaddon.Addon().getAddonInfo("path")

ACTION_MOVE_UP 3
ACTION_MOVE_DOWN 
4
ACTION_SELECT_ITEM 
7

class TestWindow(xbmcgui.Window):
    
def __init__(self):
        
self.lstContent xbmcgui.ControlList(1010630710,                                     #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)
        
        for 
index in range(020):
            
self.lstContent.addItem("Position %d"%(index))
        
        
self.setFocus(self.lstContent)
        
self.lstContent.selectItem(0)
        
self.lstContent.getListItem(0).select(True)
    
    
def onAction(selfaction):
        if 
action == ACTION_MOVE_UP:
            
self.selectFocusedItem()
        
elif action == ACTION_MOVE_DOWN:
            
self.selectFocusedItem()
        
elif action == ACTION_SELECT_ITEM:
            
xbmc.log("PRERESET SELECTED POSITION: " str(self.lstContent.getSelectedPosition()))
            
self.lstContent.reset()
            for 
index in range(010):
                
self.lstContent.addItem("Position %d"%(index))
            
xbmc.log("BEFORE SELECTED POSITION: " str(self.lstContent.getSelectedPosition()))
            
self.lstContent.selectItem(0)
            
self.lstContent.getListItem(0).select(True)
            
xbmc.log("AFTER SELECTED POSITION: " str(self.lstContent.getSelectedPosition()))
            
    
def selectFocusedItem(self):
        for 
index in range(0self.lstContent.size()):
            
self.lstContent.getListItem(index).select(False)
        
self.lstContent.getSelectedItem().select(True)
    
if 
__name__ == "__main__":        
    
testWindow TestWindow()
    
testWindow.doModal() 

I just select, for example, 19 item and in log:
19:11:08.418 T:252 DEBUG: PRERESET SELECTED POSITION: 19
19:11:08.418 T:252 DEBUG: BEFORE SELECTED POSITION: 19
19:11:08.418 T:252 DEBUG: AFTER SELECTED POSITION: 19
Reply
#4
Have you tried adding a short sleep after reset and before filling new items?

Also out of curiosity have you tried
Code:
.removeItem(idx)

Or have you verified before adding new items that the contents of the listitem are empty?

Just trying to debug systematically, just looking at the code nothing stands out as an issue.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#5
(2017-09-06, 18:57)Lunatixz Wrote: Have you tried adding a short sleep after reset and before filling new items?

No. But it's working. Anyway, it is absolute not obvious.

Thank you.
Reply
#6
(2017-09-06, 18:57)Lunatixz Wrote: Also out of curiosity have you tried
Code:
.removeItem(idx)
I don't think that this is good idea. Especially for ControlList with 50+ items.
Reply
#7
(2017-09-06, 19:05)Rameron Wrote:
(2017-09-06, 18:57)Lunatixz Wrote: Also out of curiosity have you tried
Code:
.removeItem(idx)
I don't think that this is good idea. Especially for ControlList with 50+ items.

I agree, I just wanted to test to see what function was causing you issues...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#8
(2017-09-06, 19:04)Rameron Wrote:
(2017-09-06, 18:57)Lunatixz Wrote: Have you tried adding a short sleep after reset and before filling new items?

No. But it's working. Anyway, it is absolute not obvious.

Thank you.

So the short sleep worked for you? If so can you mark the thread solved = )
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#9
(2017-09-06, 19:07)Lunatixz Wrote: I agree, I just wanted to test to see what function was causing you issues...
You propose for test instead of reset() just remove all items?
Reply
#10
(2017-09-06, 19:09)Rameron Wrote:
(2017-09-06, 19:07)Lunatixz Wrote: I agree, I just wanted to test to see what function was causing you issues...
You propose for test instead of reset() just remove all items?

Well your issue was positioning.. I would have inevitably tried removing the listitems and rebuilding in order to check if it was getselecteditemposition function causing your issues. The only way to be sure would be to control the indexing as manually as you could...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#11
(2017-09-06, 18:57)Lunatixz Wrote: Or have you verified before adding new items that the contents of the listitem are empty?
For what? Does the function reset() not clear the listitems?

(2017-09-06, 19:12)Lunatixz Wrote: Well your issue was positioning.. I would have inevitably tried removing the listitems and rebuilding in order to check if it was getselecteditemposition function causing your issues. The only way to be sure would be to control the indexing as manually as you could...
But problem is with function reset() at the end. It do not have time to work out so I need to create artificial delay after it.
Reply
#12
(2017-09-06, 19:16)Rameron Wrote: But problem is with function reset() at the end. It do not have time to work out so I need to create artificial delay after it.

It does, but remember you raised the issue of a possible "Bug"... to debug I have to assume predefined functions may not be behaving correctly. Which is why I gave you alternative options.

(2017-09-06, 19:16)Rameron Wrote:
(2017-09-06, 19:12)Lunatixz Wrote: Well your issue was positioning.. I would have inevitably tried removing the listitems and rebuilding in order to check if it was getselecteditemposition function causing your issues. The only way to be sure would be to control the indexing as manually as you could...
But problem is with function reset() at the end. It do not have time to work out so I need to create artificial delay after it.

Short answer is yes... when you are dealing with xbmcgui... Its good practice to add a short delay on anything that you assume might take a few msecs to complete.

Please mark as solved =)
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#13
How much delay value better to use?

And GREAT THANKS for help Smile
Reply
#14
(2017-09-06, 19:27)Rameron Wrote: How much delay value better to use?

And GREAT THANKS for help Smile

I use xbmc.sleep(10), from my experience this works for me no matter what i'm doing.

However this really depends on how LARGE your list is... something you can play around with. You don't want to go nuts though this could create stall spots in your script.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply

Logout Mark Read Team Forum Stats Members Help
[solved] Bug with getSelectedPosition() in ListControl0