Question about Control.SetFocus(id, position)
#1
Hi, I'm a little confused about description of this builtin function:
Code:
Control.SetFocus(id,position)     Will make a list with the "id" specified in the command gain focus at "postion" number in its list. Alias SetFocus(id,position)
I gave it a try (my goal was to have list that when is focused it have selected always default item and not the last remembered one) and I noticed it doesn't really do what description say so I've looked into sources and found out that it applies only to list container (fixedlist, wraplist and panel aren't touched) and it doesn't do what I thought it does (it select item from visible part of list, so if You see items from 10th to 20th, SetFocus(id, 3) would select 3rd visible item - in this case 12th item).

My questions:
  • Is there any workaround to force XBMC to forget what item was selected in list and select default item of my choose (let's say that everytime I enter Home window I would like to have Videos item selected instead of item that was selected when I left Home window)
  • Does any1 use SetFocus with that additional parameter to select item in list? And if You do, what You do with it?
  • To Devs: If there isn't any workaround to achieve my goal, would You be willing to accept patch that adds new builtin function: 'Container(id).Select(item)', where item would be absolute position in list? Basicly it would just require to pass GUI_MSG_ITEM_SELECT with 'item' as parameter.

    Sidenote: Currently each container have separate handling of GUI_MSG_ITEM_SELECT message and all are the same:
    Code:
    if (message.GetMessage() == GUI_MSG_ITEM_SELECT)
        {
          SelectItem(message.GetParam1());
          return true;
        }
    It could be moved to BaseContainer to clean up code a little bit, right?
Reply
#2
The trick is to make another hidden list with the same id as that one so XBMC forgets where it's focused.
Reply
#3
Hitcher Wrote:The trick is to make another hidden list with the same id as that one so XBMC forgets where it's focused.
Hidden as <visible>false</visible> or Hidden as <width>1</width>, <height>1</height>?

Do You know maybe where I can find this trick that is working?

To give a little more context: I'm trying to do PS3-style menu navigation for Home Window (for Alaska to be more detailed ;P) - Here's quick preview of what I have now: http://www.youtube.com/watch?v=wLvyyqAU_YU

The problem is that It's not simple list but rather list of lists: For each item in Home menu (videos, movies, music, etc) I have sublist: (for tvshows in order: genres, years, actors, studios, titles (this one I want to be selected as default), LatestEpisode.1, LatestEpisode.2, ...)

Any suggestions? Smile
Reply
#4
So you're trying to override XBMC default behavior of remembering the position you last left off, correct?

Actually many of us get this but by mistake. Usually we made this error by having 2 Lists with different <visibles>:

<control type="fixedlist" id="50">
<visible>Container.Content(tvshows)</visible>

<control type="fixedlist" id="50">
<visible>Container.Content(movies)</visible>

I guess this screws up XBMC having two id's with two different <visibles> and causes it to default on the 1st position not the last....
Image

Check out The Carmichael - A Skin For XBMC

Check out Night - A Skin For XBMC

Check out Unfinished - A Skin For XBMC
Reply
#5
grajen3 Wrote:
Code:
Control.SetFocus(id,position)     Will make a list with the "id" specified in the command gain focus at "postion" number in its list. Alias SetFocus(id,position)
I gave it a try (my goal was to have list that when is focused it have selected always default item and not the last remembered one) and I noticed it doesn't really do what description say so I've looked into sources and found out that it applies only to list container (fixedlist, wraplist and panel aren't touched) and it doesn't do what I thought it does (it select item from visible part of list, so if You see items from 10th to 20th, SetFocus(id, 3) would select 3rd visible item - in this case 12th item).

i noticed exactly the same and would consider this being a bug.

grajen3 Wrote:[*]To Devs: If there isn't any workaround to achieve my goal, would You be willing to accept patch that adds new builtin function: 'Container(id).Select(item)', where item would be absolute position in list? Basicly it would just require to pass GUI_MSG_ITEM_SELECT with 'item' as parameter.

a built-in solution would be great, but to use Container(id).Select(item), you would need another hidden button to pass the command to the list control.

so why not make it a list property?
something along these lines:
Code:
<control type="list">
          <focuseditem>0</focuseditem>

Hitcher Wrote:The trick is to make another hidden list with the same id as that one so XBMC forgets where it's focused.
if you or anybody else has an easy to follow code example i would be very interested.
i have tried it more than a few times but never got it to work.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
grajen3 Wrote:Hidden as <visible>false</visible> or Hidden as <width>1</width>, <height>1</height>?

Do You know maybe where I can find this trick that is working?

To give a little more context: I'm trying to do PS3-style menu navigation for Home Window (for Alaska to be more detailed ;P) - Here's quick preview of what I have now: http://www.youtube.com/watch?v=wLvyyqAU_YU

The problem is that It's not simple list but rather list of lists: For each item in Home menu (videos, movies, music, etc) I have sublist: (for tvshows in order: genres, years, actors, studios, titles (this one I want to be selected as default), LatestEpisode.1, LatestEpisode.2, ...)

Any suggestions? Smile
Check out Alaska Revisited's Includes_HomeDefault XML because I have it working in that.
Reply
#7
ronie Wrote:if you or anybody else has an easy to follow code example i would be very interested.
i have tried it more than a few times but never got it to work.

All I did to get it working in this test was copy the original list control and remove most of it -

PHP Code:
<control type="fixedlist" id="51">
    <
viewtype>list</viewtype>
    <
visible>false</visible>
    <
itemlayout>
    </
itemlayout>
    <
focusedlayout>
    </
focusedlayout>
</
control
Reply
#8
Im propably stupid or I'm missing something ... :
Code:
        <control type="fixedlist" id="440">
            <posx>580</posx>
            <include>CustomList</include>
            <posy>-100</posy>
            <focusposition>4</focusposition>
            <visible>Container(300).HasFocus(4)</visible>
            <content>
                <include>VideoItems</include>
            </content>
        </control>
        <control type="fixedlist" id="440">
            <include>emptyList</include>
        </control>

emptyList is copied from Your post, VideoItems are irrelevant I think, CustomList contains visual related stuff (animations, layouts). This isn't working - it remembers position ...

putting lists the other way around doesn't work too ... I begin to believe in conspiracy theory ...
Reply
#9
1. SetFocus(id,position) sets the position (i.e. which "slot" has focus) not the item. It's primarily useful for being able to navigate to the right onto a list and ensuring you end up in the left most "slot".

2. You showed the code for SELECTED_ITEM not for SELECT_ITEM Wink

3. IMO this is only useful for "home screen" lists for the most part. It's not really something that should be done on other screens as it can often defeat what the user would expect. However, I do see that in some scenarios where you're linking lists together it can be useful.

If it's just a matter of having a list "always" forget where it was, then we can look to add it as a property (similar to control groups' <defaultcontrol always="true">). A patch for that would be great - however it may well be quite tricky to get it right, as the window remembers the focused item, so we might have to differentiate between the SELECT_ITEM on start of the window and SELECT_ITEM during navigation...

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#10
jmarshall Wrote:3. IMO this is only useful for "home screen" lists for the most part. It's not really something that should be done on other screens as it can often defeat what the user would expect.

i'd say any list (home screen or not) with static content.
i agree we shouldn't mess with lists that are filled with content by xbmc.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#11
Static content lists would be easy to do in the same way as grouplists are done, yup.

It's only the media lists that present trickiness (as the focused item is saved at multiple levels)
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#12
I can't understand why it's suddenly not working for grajen3 if he's using the original Alaska Revisited code because it works fine for the submenu lists I have now.
Reply
#13
jmarshall Wrote:1. SetFocus(id,position) sets the position (i.e. which "slot" has focus) not the item. It's primarily useful for being able to navigate to the right onto a list and ensuring you end up in the left most "slot".

2. You showed the code for SELECTED_ITEM not for SELECT_ITEM Wink

3. IMO this is only useful for "home screen" lists for the most part. It's not really something that should be done on other screens as it can often defeat what the user would expect. However, I do see that in some scenarios where you're linking lists together it can be useful.

If it's just a matter of having a list "always" forget where it was, then we can look to add it as a property (similar to control groups' <defaultcontrol always="true">). A patch for that would be great - however it may well be quite tricky to get it right, as the window remembers the focused item, so we might have to differentiate between the SELECT_ITEM on start of the window and SELECT_ITEM during navigation...

Cheers,
Jonathan
Ad. 1, Yes, I got that - I just wanted to know if this is actually used by someone anywhere.

Ad. 2, You're right, code in first post edited - hope You got my point (same code is replicated in all subclasses of CGUIBaseContainer)

Ad. 3, Well, ronie did good point - it could be applied to static content (maybe in <content defaultitem="X"> ?), usable in home menu, scripts

Hitcher Wrote:I can't understand why it's suddenly not working for grajen3 if he's using the original Alaska Revisited code because it works fine for the submenu lists I have now.
After several tries I dropped this idea (to be honest I never liked it cause it's more like causing xbmc to do error) and made util script to select item in container:

Code:
import xbmcgui

try:
    wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
    
    c = len(sys.argv)
    
    id = -1
    item = -1
    
    if ile == 2:
        id = wnd.getFocusId()
    elif ile == 3:
        id = int(sys.argv[1])
    
    if ile > 1:
        item = int(sys.argv[ile - 1])
    
    if id > 0 and item > 0:
        wnd.getControl(id).selectItem(item)
except:
    pass
usage: RunScript(script_path,container_id,new_item) or if we want to use currently focused container RunScript(script_path,new_item)

Thanks for all replies anyway!
Reply
#14
Hitcher Wrote:All I did to get it working in this test was copy the original list control and remove most of it -

PHP Code:
<control type="fixedlist" id="51">
    <
viewtype>list</viewtype>
    <
visible>false</visible>
    <
itemlayout>
    </
itemlayout>
    <
focusedlayout>
    </
focusedlayout>
</
control

thanx Hitcher!
that sure did the trick.

in case anyone else is having issues, the fake list needs to be below the real one.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#15
It was Jezz who reminded me of this trick recently.
Reply

Logout Mark Read Team Forum Stats Members Help
Question about Control.SetFocus(id, position)0