Kodi Community Forum

Full Version: Close window on empty list container
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The context is playlists. I restrict access to myplaylist.xml if no items are queued and boot the user if the list is cleared via the built-in function but this leaves individual deletions unaccounted for. Is it possible to somehow close/replace a window when numitems goes to zero?

I suspect not but no harm in asking.
There's a neat trick you can do with custom dialogs and visibility conditions that might achieve what you're looking for:

Create a new file called custom_windowClose.xml and populate as below:

xml:

<?xml version="1.0" encoding="UTF-8"?>
<window type="dialog" id="1100">
    <onload> [do something here like window.activate(home) ]</onload>
    <visible>Window.IsActive(MyPlaylist.xml) + Integer.IsEqual(container.numitems,0)</visible>
    <controls></controls>
</window>

The idea is pretty self evident. The dialog is loaded and sits quietly in the background waiting for the visibility condition to be satisfied.

Note that I haven't tested the above, but it should be enough to point you in the right direction. Hope it helps!
I'm pretty sure it wont work as the container isn't in the custom dialog and it can't get its value from another window.
Just add this to the button with the id="22" :
Code:
<onclick>close</onclick>

It's the clear button. Once it's triggered, the dialog is going to be closed.

You also can add this to the header of the myplaylist.xml
Code:
<onload condition="!Integer.IsGreater(Container(50).NumItems,0)">close</onload>

This will force close the window once is going to be openend (by the user, or automatically) if the list is empty.

To bypass animation glitches (depends on the used skin), you should also group all elements into a main group
Code:

        <control type="group">
            <visible>Integer.IsGreater(Container(50).NumItems,0)</visible>
.....
</control>

Example:
Code:

<?xml version="1.0" encoding="UTF-8"?>
<window>
    <defaultcontrol always="true">50</defaultcontrol>
    <onload condition="!Integer.IsGreater(Container(50).NumItems,0)">close</onload>
    <include>PropertyIncludes</include>
    <views>50</views>
    <controls>
        <control type="group">
            <visible>Integer.IsGreater(Container(50).NumItems,0)</visible>
            <!-- Content -->
            <include condition="Window.IsVisible(videoplaylist)">VideoPlaylistLayout</include>
            <include condition="Window.IsVisible(musicplaylist)">MusicPlaylistLayout</include>
        </control>
    </controls>
</window>
(2018-07-31, 08:02)sualfred Wrote: [ -> ]Just add this to the button with the id="22" :
Code:
<onclick>close</onclick>

Understood but the list can also be emptied with the delete key and dealing with that possibility is the crux of my question.
Not tested it, but as far as I remember one of the buttons is going to have the focus once the list is cleared, isn't it?

Try to add a onfocus command to it.

Code:

            <onfocus condition="Integer.IsLess(Container.NumItems,1)">close</onfocus>
(2018-07-31, 12:31)sualfred Wrote: [ -> ]Not tested it, but as far as I remember one of the buttons is going to have the focus once the list is cleared, isn't it?

Try to add a onfocus command to it.

Code:

            <onfocus condition="Integer.IsLess(Container.NumItems,1)">close</onfocus>

I'm oh so close. This approach in combination with a hidden button in the focused layout of the list works for tracks queued manually but I get ejected prematurely when using party mode.
Try to add "!MusicPartyMode.Enabled" to the condition.
This solved the race issue with party mode:

PHP Code:
<focusedlayout>
     <
control type="button" id="3000">
          <include>
HiddenButton</include>
          <
onfocus condition="Control.HasFocus(50) + 
              Integer.IsEqual(Container(50).NumItems,0)"
>Action(close)</onfocus>
     </
control>
</
focusedlayout

Thanks gentlemen for the thought-provoking suggestions!