Display a custom List container
#1
Hi
I'm working in my first Kodi add-on and I'm not able to figure out how to solve this problem (or maybe it's impossible)

This add-on creates a custom window with several data from a .json file.

Finally I've got a python list and I want to store every list item inside a property. This is my python script:

Code:
import xbmcgui

my_sample_list = ['item number 1', 'item number 2', 'item number 3' ]
lenght = len(my_sample_list)

for i in range(lenght):
    xbmcgui.window(15005).setProperty('NewProperty', my_sample_list)

And this is the label I've placed inside a list control container:

Code:
<label>$INFO[Window().Property(NewProperty)]</label>

I just see the last item of my python list. Any idea?
Reply
#2
Not sure, but try this:
python:

import xbmcgui

my_sample_list = ['item number 1', 'item number 2', 'item number 3' ]

for i in my_sample_list:
    xbmcgui.window(15005).setProperty('NewProperty', i)
Reply
#3
(2019-11-26, 16:36)Rick987 Wrote: Not sure, but try this:
python:

import xbmcgui

my_sample_list = ['item number 1', 'item number 2', 'item number 3' ]

for i in my_sample_list:
    xbmcgui.window(15005).setProperty('NewProperty', i)
The result is the same. It seems to me that setProperty() method can't store a full list.
Reply
#4
I don't think you can do it like that.  You need to add the items to the list container, then show that.

python:

self.container = self.getControl(6)
self.listitems = []
my_sample_list = ['item number 1', 'item number 2', 'item number 3' ]
for i in my_sample_list:
     self.listitems.append(i)
self.container.addItems(self.listitems)

Definition of the list container
xml:
<control type="list" id="6">
<viewtype label="list_1">list</viewtype>
<left>180</left>
<top>180</top>
<width>700</width>
<height>361</height>
<pagecontrol>17</pagecontrol>
<onleft>5</onleft>
<onright>5</onright>
<onup>6</onup>
<ondown>6</ondown>
<orientation>vertical</orientation>
<scrolltime tween="Quadratic" easing="Out">1000</scrolltime>
<autoscroll>false</autoscroll>
<preloaditems>2</preloaditems>
<animation effect="fade" start="100" end="50" time="200" >Conditional</animation>
<itemlayout height="30">
<control type="label">
<left>68</left>
<top>0</top>
<width>650</width>
<height>28</height>
<font>font10</font>
<aligny>center</aligny>
<label>$INFO[ListItem.Label]</label>
</control>
</itemlayout>
<focusedlayout height="30">
<control type="label">
<left>68</left>
<top>0</top>
<width>650</width>
<height>28</height>
<font>font10</font>
<aligny>center</aligny>
<label>$INFO[ListItem.Label]</label>
</control>
</focusedlayout>
</control>
Learning Linux the hard way !!
Reply
#5
(2019-11-26, 20:28)black_eagle Wrote: I don't think you can do it like that.  You need to add the items to the list container, then show that.

python:

self.container = self.getControl(6)
self.listitems = []
my_sample_list = ['item number 1', 'item number 2', 'item number 3' ]
for i in my_sample_list:
     self.listitems.append(i)
self.container.addItems(self.listitems)

Definition of the list container
xml:
<control type="list" id="6">
<viewtype label="list_1">list</viewtype>
<left>180</left>
<top>180</top>
<width>700</width>
<height>361</height>
<pagecontrol>17</pagecontrol>
<onleft>5</onleft>
<onright>5</onright>
<onup>6</onup>
<ondown>6</ondown>
<orientation>vertical</orientation>
<scrolltime tween="Quadratic" easing="Out">1000</scrolltime>
<autoscroll>false</autoscroll>
<preloaditems>2</preloaditems>
<animation effect="fade" start="100" end="50" time="200" >Conditional</animation>
<itemlayout height="30">
<control type="label">
<left>68</left>
<top>0</top>
<width>650</width>
<height>28</height>
<font>font10</font>
<aligny>center</aligny>
<label>$INFO[ListItem.Label]</label>
</control>
</itemlayout>
<focusedlayout height="30">
<control type="label">
<left>68</left>
<top>0</top>
<width>650</width>
<height>28</height>
<font>font10</font>
<aligny>center</aligny>
<label>$INFO[ListItem.Label]</label>
</control>
</focusedlayout>
</control>

Add items to List containers was my first approach. In fact, I found all the information in this tutorial: https://kodi.wiki/view/HOW-TO:Script_addon

I´ll try to explain clearly my real problem. Firstly I show you my python code:

python:

        # define temporary lists where we are going to add listitems
        foto_slider = []
        titular_slider = []
        description_slider = []
        foto_card = []
        titulo_card = []
        description_card = []

        # for loop python iterate through dictionary
        for items in json_response['level1_nodes']['featured']:
            foto_slider.append(items['icon'])
        for items in json_response['level1_nodes']['featured']:
            titular_slider.append(items['translatableName']['en_gb'])
        for items in json_response['level1_nodes']['featured']:
            description_slider.append(items['translatableDescription']['en_gb'])
        for items in json_response['level1_nodes']['children']:
            foto_card.append(items['icon'])
        for items in json_response['level1_nodes']['children']:
            titulo_card.append(items['translatableName']['en_gb'])
        for items in json_response['level1_nodes']['children']:
            description_card.append(items['translatableDescription']['en_gb'])

        # now define containers, the id's refer to the container id's you use in the xml file
        self.cont1 = self.getControl(100)
        self.cont2 = self.getControl(200)
        self.cont4 = self.getControl(400)
        self.cont3 = self.getControl(300)
        self.cont5 = self.getControl(500)
        self.cont6 = self.getControl(600)

        # adding items
        self.cont1.addItems(titular_slider)
        self.cont2.addItems(description_slider)
        self.cont4.addItems(foto_slider)
        self.cont3.addItems(foto_card)
        self.cont5.addItems(titulo_card)
        self.cont6.addItems(description_card)

And in the xml there are different containers as you can see in this snippet:

xml:
<control type="group" description="Pictures">
            <include>ContentFade</include>
            <posx>80</posx>
            <posy>526,2</posy>
            <width>436</width>
            <onright>63</onright>
            <onup>53</onup>
            <ondown>53</ondown>
            <preloaditems>12</preloaditems>
            <pagecontrol>63</pagecontrol>
            <control type="list" id="300" description="Grid">
                <orientation>vertical</orientation>
                <itemlayout height="246" width="436">
                    <control type="image">
                        <top>0</top>
                        <width>436</width>
                        <height>246</height>
                        <texture border="15,0,0,15" colordiffuse="Transparent">img/WhiteRoundedST.png</texture>
                    </control>
                    <control type="image">
                        <include>servicethumb</include>
                        <texture>$INFO[ListItem.Label]</texture>
                    </control>
                </itemlayout>
                <focusedlayout height="246" width="436">
                    <control type="image">
                        <top>0</top>
                        <width>436</width>
                        <height>246</height>
                        <texture border="15,0,0,15" colordiffuse="Highlight">img/WhiteRoundedST2.png</texture>
                    </control>
                    <control type="image">
                        <include>servicethumb</include>
                        <texture>$INFO[ListItem.Label]</texture>
                    </control>
                </focusedlayout>
            </control>
        </control>
<control type="group" description="single service">
            <include>ContentFade</include>
            <posy>530</posy>
            <posx>520</posx>
            <width>1287</width>
            <height>500</height>
            <control type="list" id="500">
                <posy>10</posy>
                <itemlayout>
                    <control type="label">
                        <posx>25</posx>
                        <font>font12_title</font>
                  <wrapmultiline>false</wrapmultiline>
                        <textcolor>White2</textcolor>
                        <scroll>false</scroll>
                        <label>$INFO[ListItem.Label]</label>
                    </control>
                </itemlayout>
                <focusedlayout>
                    <control type="label">
                        <posx>25</posx>
                        <font>font12_title</font>
                  <wrapmultiline>false</wrapmultiline>
                        <textcolor>White2</textcolor>
                        <scroll>false</scroll>
                        <label>$INFO[ListItem.Label]</label>
                    </control>
                </focusedlayout>
            </control>
            <control type="list" id="600">
                <posy>65</posy>
                <itemlayout>
                    <control type="textbox">
                        <posx>25</posx>
                        <width max="1200">auto</width>
                        <height>430</height>
                        <font>fontService</font>
                  <wrapmultiline>true</wrapmultiline>
                        <textcolor>White2</textcolor>
                        <scroll>false</scroll>
                        <label>$INFO[ListItem.Label]</label>
                    </control>
                </itemlayout>
                <focusedlayout>
                    <control type="textbox">
                        <posx>25</posx>
                        <width max="1200">auto</width>
                        <height>430</height>
                        <font>fontService</font>
                  <wrapmultiline>true</wrapmultiline>
                        <textcolor>White2</textcolor>
                        <scroll>false</scroll>
                        <label>$INFO[ListItem.Label]</label>
                    </control>
                </focusedlayout>
            </control>
        </control>

So what´s my problem if everything looks like ok? Well, I need that when a user selects (focus on) a picture from the first group list control, the same window shows the text information from the second group list control related to that picture.

I appreciate your help.
Reply
#6
that's not really possible in the way you try to do it...
if you scroll one list, the others won't scroll to the same position.
in kodi, each list scroll individually and it's no possible to get them to scroll in sync.

but you can display info about the focused listitem outside of the list container though.

perhaps something like this will work for your purposes:
python:
featureditems = []

for items in json_response['level1_nodes']['featured']:
    # create a listitem
    listitem = xbmcgui.ListItem()
    # add the icon, label and description to the listitem
    listitem.setArt({'icon': items['icon']})
    listitem.setLabel(items['translatableName']['en_gb'])
    listitem.setLabel2(items['translatableDescription']['en_gb'])

self.cont1 = self.getControl(100)
self.cont1.addItems(featureditems)

xml:
<!-- list of images -->
<control type="list" id="100" description="Grid">
    <orientation>vertical</orientation>
    <itemlayout height="246" width="436">
        <control type="image">
            <top>0</top>
            <width>436</width>
            <height>246</height>
            <texture border="15,0,0,15" colordiffuse="Transparent">img/WhiteRoundedST.png</texture>
        </control>
        <control type="image">
            <include>servicethumb</include>
            <texture>$INFO[ListItem.Icon]</texture>
        </control>
    </itemlayout>
    <focusedlayout height="246" width="436">
        <control type="image">
            <top>0</top>
            <width>436</width>
            <height>246</height>
            <texture border="15,0,0,15" colordiffuse="Highlight">img/WhiteRoundedST2.png</texture>
        </control>
        <control type="image">
            <include>servicethumb</include>
            <texture>$INFO[ListItem.Icon]</texture>
        </control>
    </focusedlayout>
</control>

<!-- title of the focused image -->
<control type="label">
    <posx>545</posx>
    <posy>0</posy>
    <width>1287</width>
    <height>500</height>
    <font>font12_title</font>
    <wrapmultiline>false</wrapmultiline>
    <textcolor>White2</textcolor>
    <scroll>false</scroll>
    <label>$INFO[Container(100).ListItem.Label]</label>
</control>

<!-- description of the focused image -->
<control type="textbox">
    <posx>545</posx>
    <posy>65</posy>
    <width max="1200">auto</width>
    <height>430</height>
    <font>fontService</font>
    <wrapmultiline>true</wrapmultiline>
    <textcolor>White2</textcolor>
    <scroll>false</scroll>
    <label>$INFO[Container(100).ListItem.Label2]</label>
</control>
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
#7
(2019-12-02, 13:00)ronie Wrote: that's not really possible in the way you try to do it...
if you scroll one list, the others won't scroll to the same position.
in kodi, each list scroll individually and it's no possible to get them to scroll in sync.

but you can display info about the focused listitem outside of the list container though.

perhaps something like this will work for your purposes:
python:
featureditems = []

for items in json_response['level1_nodes']['featured']:
    # create a listitem
    listitem = xbmcgui.ListItem()
    # add the icon, label and description to the listitem
    listitem.setArt({'icon': items['icon']})
    listitem.setLabel(items['translatableName']['en_gb'])
    listitem.setLabel2(items['translatableDescription']['en_gb'])

self.cont1 = self.getControl(100)
self.cont1.addItems(featureditems)
xml:
<!-- list of images -->
<control type="list" id="100" description="Grid">
    <orientation>vertical</orientation>
    <itemlayout height="246" width="436">
        <control type="image">
            <top>0</top>
            <width>436</width>
            <height>246</height>
            <texture border="15,0,0,15" colordiffuse="Transparent">img/WhiteRoundedST.png</texture>
        </control>
        <control type="image">
            <include>servicethumb</include>
            <texture>$INFO[ListItem.Icon]</texture>
        </control>
    </itemlayout>
    <focusedlayout height="246" width="436">
        <control type="image">
            <top>0</top>
            <width>436</width>
            <height>246</height>
            <texture border="15,0,0,15" colordiffuse="Highlight">img/WhiteRoundedST2.png</texture>
        </control>
        <control type="image">
            <include>servicethumb</include>
            <texture>$INFO[ListItem.Icon]</texture>
        </control>
    </focusedlayout>
</control>

<!-- title of the focused image -->
<control type="label">
    <posx>545</posx>
    <posy>0</posy>
    <width>1287</width>
    <height>500</height>
    <font>font12_title</font>
    <wrapmultiline>false</wrapmultiline>
    <textcolor>White2</textcolor>
    <scroll>false</scroll>
    <label>$INFO[Container(100).ListItem.Label]</label>
</control>

<!-- description of the focused image -->
<control type="textbox">
    <posx>545</posx>
    <posy>65</posy>
    <width max="1200">auto</width>
    <height>430</height>
    <font>fontService</font>
    <wrapmultiline>true</wrapmultiline>
    <textcolor>White2</textcolor>
    <scroll>false</scroll>
    <label>$INFO[Container(100).ListItem.Label2]</label>
</control>
It works!
Thank you so much
Reply

Logout Mark Read Team Forum Stats Members Help
Display a custom List container0