Get and set viewmode from script
#1
Hi,

I am writing a script that uses a WindowXML with internal lists with ids 50-5x and a "change view" button with id 2. This works fine and I am able to show different views of my data. But everytime the script starts it shows the same initial view. If anybody wants to use another view it is annoying that you have to change the view everytime you start the script. I would like to save the last selected view and restore this state on startup. Is this possible?

I already searched through the wiki and the forum but I did not find any hint on this. If you have a link how to do this or maybe an idea how to implement a work around please help me with this.

Regards,
malte
Reply
#2
put a setting !
Reply
#3
Thanks for your quick response. But I will need some more input.

You mean skin settings? Are there predefined settings to toggle the view or do I have to store my own ones?

I have tried with writing a setting in python:
Code:
xbmc.executebuiltin( "Skin.SetBool(%s)" %'info_view')

and reading it in the xml:
Code:
<control type="wraplist" id="50">
    <visible>Skin.HasSetting(info_view)</visible>
...

This nearly works but the view won't refresh when I push the button. The new setting applies only when I move around my UI.

Is this the right direction or am I on the wrong path?
Reply
#4
Sorry, I have to ask again. I am trying to get this working several days now and I don't find a satisfying solution. If I am just too dumb to find the correct wiki article or thread please point me in a direction, I really don't find anything useful about this.

I have tried different scenarios with conditional includes, writing guisettings and other things but none of them really works. It seems that every change to the visibility of an internal list (via python or via skinning) disturbs XBMC with handling these views.

My best working solution is to save the last viewmode when the script exits:
Code:
xbmc.executebuiltin( "Skin.SetBool(%s)" %lastView)
xbmc.executebuiltin( "Skin.SetBool(%s)" %'rcb_OnLoad')

and to read this flag as a visibility condition in the xml file:
Code:
<visible>Skin.HasSetting(rcb_info2_view) | !Skin.HasSetting(rcb_OnLoad)</visible>
I have to use this onLoad-flag to make sure that all views are available for the change view button. Otherwise changing the view doesn't work anymore.

This nearly works now. It loads the correct view on startup and I can still change the views. The only problem is now that every time I have to reload my internal list the view is set back to the default view. This is the code to reload the list:
Code:
xbmcgui.lock()        
self.clearList()
        
for item in items:
    self.addItem(item, False)                
xbmcgui.unlock()

Maybe I am doing eveything wrong here, please tell me if you know it better.

I have seen that there is a viewmodes.db that is used when a skin changes the view of a page but I don't think this is available via scripting.

My last idea is now to implement all this on my own (using my own lists and buttons and control visibility in script logic) but this can't be the way how to do this.

If you have an idea how to get this solved or if you know a script that is able to save and restore its last viewmode please tell me. I really want to have this functionality, otherwise it doesn`t make any sense to provide different views in a script.

Regards,
malte
Reply
#5
look here

http://code.google.com/p/passion-xbmc/so...Gui.py#186

on close window get container id and save this

CONTROL_MAIN_LIST_START = 50
CONTROL_MAIN_LIST_END = 59

Code:
def get_view_mode( self ):
        view_mode = ""
        for id in range( self.CONTROL_MAIN_LIST_START, self.CONTROL_MAIN_LIST_END + 1 ):
            try:
                if xbmc.getCondVisibility( "Control.IsVisible(%i)" % id ):
                    view_mode = repr( id )
                    return view_mode
                    break
            except:
                pass
        return view_mode
and on open window after listing your controlist set container view
Code:
id = self.settings.get( "manager_view_mode", self.CONTROL_MAIN_LIST_START )
            xbmc.executebuiltin( "Container.SetViewMode(%i)" % id )
cheers
frost
For my bad English, sorry. I am French Canadian.
Admin @ Passion-XBMC.org
Reply
#6
Thank you very much. Works perfectly.

Now that I know the solution I can't imagine why I have not found this Container.SetViewMode method...

Regards,
malte
Reply
#7
Also here: http://forum.xbmc.org/showthread.php?tid=52106
Reply
#8
Sorry to bump this thread after 5 years! But I have the same question.

What is the best way to get the current viewmode ID, the following code still works, but is there currently a cleaner way then this?

Code:
def get_view_mode( self ):
        view_mode = ""
        for id in range( self.CONTROL_MAIN_LIST_START, self.CONTROL_MAIN_LIST_END + 1 ):
            try:
                if xbmc.getCondVisibility( "Control.IsVisible(%i)" % id ):
                    view_mode = repr( id )
                    return view_mode
                    break
            except:
                pass
        return view_mode
Reply
#9
Big Grin 
Resurrecting the dead Laugh
Reply
#10
(2015-07-07, 15:21)Dwaalspoor98 Wrote: Sorry to bump this thread after 5 years! But I have the same question.

What is the best way to get the current viewmode ID, the following code still works, but is there currently a cleaner way then this?

Code:
def get_view_mode( self ):
        view_mode = ""
        for id in range( self.CONTROL_MAIN_LIST_START, self.CONTROL_MAIN_LIST_END + 1 ):
            try:
                if xbmc.getCondVisibility( "Control.IsVisible(%i)" % id ):
                    view_mode = repr( id )
                    return view_mode
                    break
            except:
                pass
        return view_mode

Did you try WindowXML.getFocusId()?
Donate: https://kodi.tv/contribute/donate (foundation), 146Gr48FqHM7TPB9q33HHv6uWpgQqdz1yk (BTC personal)
Estuary: Kodis new default skin - ExtendedInfo Script - KodiDevKit
Reply
#11
(2015-07-09, 01:47)phil65 Wrote: Did you try WindowXML.getFocusId()?

Somehow I missed your reply, it works perfect, thanks a lot phil65!

Full example:
Code:
import xbmcgui
window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
window.getFocusId()
Reply

Logout Mark Read Team Forum Stats Members Help
Get and set viewmode from script0