Kodi Community Forum
WindowXML tutorial does not work on my machine - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: WindowXML tutorial does not work on my machine (/showthread.php?tid=327686)

Pages: 1 2


WindowXML tutorial does not work on my machine - necbot - 2018-01-27

I'm trying to follow the Kodi development example posted here...

http://kodi.wiki/view/HOW-TO:Script_addon


I created the files and created the directory structure the way the tutorial indicated and I keep getting the following error when I try to start the program....

Code:
: -->Python callback/script returned the following error<--
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.TypeError'>
                                            Error Contents: function takes at most 4 arguments (5 given)
                                            Traceback (most recent call last):
                                              File "/home/necbot/.kodi/addons/script.testwindow/main.py", line 51, in <module>
                                                ui = GUI('script-testwindow.xml', CWD, 'default', '1080p', True, optional1='some data')
                                            TypeError: function takes at most 4 arguments (5 given)
                                            -->End of Python script error report<--


I copied and pasted exactly as the wiki showed and I still get this error. I'm new to kodi development. What exactly am I doing wrong? My Kodi version is 17.6 and I'm running it on Ubuntu 16.04.3.

I can see that the problem is that the GUI constructor (which is a xbmcgui.WindowXML object) is getting more arguments than it needs. If I try to remove the optional arguments like this....

ui = GUI('script-testwindow.xml', CWD, 'default', '1080p')

I get...

Code:
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.RuntimeError'>
Error Contents: XML File for Window is missing
Traceback (most recent call last):
File "/home/necbot/.kodi/addons/script.testwindow/main.py", line 51, in <module>
ui = GUI('script-testwindow.xml', CWD, 'default', '1080p')
RuntimeError: XML File for Window is missing
-->End of Python script error report<--


So now it cannot find the script-testwindow.xml file.  Am I missing a config setting in my Kodi setup or does that tutorial have a typo somehwere?


RE: WindowXML tutorial does not work on my machine - ronie - 2018-01-27

thx, the tutorial was written for kodi 18, but i forgot to mention that in the article :-)

could you try with 1080i instead of 1080p:
python:
ui = GUI('script-testwindow.xml', CWD, 'default', '1080i')



RE: WindowXML tutorial does not work on my machine - ronie - 2018-01-27

i've adopted the wiki article a bit. instructions for both kodi 17 and kodi 18 are in place now.

please let me know if the code in my post above fixes your issue.


RE: WindowXML tutorial does not work on my machine - necbot - 2018-01-28

Hello ronie,

Thanks for your help I changed the python call from 1080p to 1080i like you suggested and it did not work.  However, I did finally get it working.  I changed my function call to this...
Quote:ui = GUI('script-testwindow.xml', CWD, 'default')

And renamed the 1080i folder to 720p.  After I did that the tutorial worked just fine on 17.6.


RE: WindowXML tutorial does not work on my machine - ronie - 2018-01-28

ok, will have to check what's going on cause that ain't right ;-)


RE: WindowXML tutorial does not work on my machine - ronie - 2018-01-30

i'm afraid i couldn't reproduce the issue.
i've tested the code from the tutorial both on kodi 17 and kodi 18 and it works fine.


RE: WindowXML tutorial does not work on my machine - smitchell6879 - 2018-05-28

Quick question about https://kodi.wiki/view/HOW-TO:Script_addon.

just doing some testing and can create the window along with set the background image but when i try to show the list i get nothing. i am using kodi 18 alpha 1... so far i have copied exactly what is on the site nothing special.


RE: WindowXML tutorial does not work on my machine - smitchell6879 - 2018-05-28

So this works on Krypton but not in Leia. Can Someone else verify that it does not work for leia? or if does can you tell me the version of leia you are using?


RE: WindowXML tutorial does not work on my machine - ronie - 2018-05-28

i guess something has changed in kodi master since i wrote the tutorial... i'll look into it.


RE: WindowXML tutorial does not work on my machine - ronie - 2018-05-28

turns out you now need to set a viewmode, so add this line to onInit(self)
python:
xbmc.executebuiltin('Container.SetViewMode(50)')


..wiki tutorial updated


RE: WindowXML tutorial does not work on my machine - smitchell6879 - 2018-05-29

(2018-05-28, 23:28)ronie Wrote: turns out you now need to set a viewmode, so add this line to onInit(self)
python:
xbmc.executebuiltin('Container.SetViewMode(50)')


..wiki tutorial updated

Thank you for tracking down the issue. Now by setting a viewmode in my mind this is for displaying media, library style containers... what if I want to make a custom settings window that are just a bunch of buttons and text inputs? does the viewmode actually matter.

Also when playing around with this on kodi 17 I find that if I use getcontrol to set the container, I can add the list to the container but if I use a second getcontrol and add one item, a button, then the button will show but the list does not.

I my mind the windowxml should work similar to kodi in general.. I should be able to set a templete up per custom page I want, in theory I should be able to have predefined buttons ,list, panel, textbox etc. and then I can customize the look and placement within the xml. Is this correct or am I miss understanding the concept behind this?


RE: WindowXML tutorial does not work on my machine - ronie - 2018-05-29

(2018-05-29, 00:46)smitchell6879 Wrote: Now by setting a viewmode in my mind this is for displaying media, library style containers... what if I want to make a custom settings window that are just a bunch of buttons and text inputs? does the viewmode actually matter.

nope, not really. i such a case you'd be better off using this example:
https://kodi.wiki/view/HOW-TO:Script_addon#Other_options

(2018-05-29, 00:46)smitchell6879 Wrote: Also when playing around with this on kodi 17 I find that if I use getcontrol to set the container, I can add the list to the container but if I use a second getcontrol and add one item, a button, then the button will show but the list does not.

i would need to see the exact code you're using to be able to tell what's wrong.

(2018-05-29, 00:46)smitchell6879 Wrote: I my mind the windowxml should work similar to kodi in general.. I should be able to set a templete up per custom page I want, in theory I should be able to have predefined buttons ,list, panel, textbox etc. and then I can customize the look and placement within the xml. Is this correct or am I miss understanding the concept behind this? 

yup, that's correct.


RE: WindowXML tutorial does not work on my machine - smitchell6879 - 2018-05-29

@ronie

this is the python I have the buttons commented out.

python:
import xbmc
import xbmcgui
import xbmcaddon

ADDON = xbmcaddon.Addon()
CWD = ADDON.getAddonInfo('path').decode('utf-8')

class GUI(xbmcgui.WindowXML):
def __init__(self, *args, **kwargs):
self.data = kwargs['optional1']

def onInit(self):
xbmc.executebuiltin('Container.SetViewMode(50)')
listitems = []
listitem1 = xbmcgui.ListItem('my first item')
# test = xbmcgui.ControlButton('test')

listitems.append(listitem1)
listitem2 = xbmcgui.ListItem('my second item')
listitems.append(listitem2)
self.clearList()
self.cont1 = self.getControl(100)
# self.butn = self.getControl(200)
# self.butn.additem(test)
# self.addControl(test)
self.cont1.addItems(listitems)
xbmc.sleep(100)
self.setFocusId(self.getCurrentContainerId())

if (__name__ == '__main__'):
ui = GUI('script-testwindow.xml', CWD, 'default', '1080i', True, optional1='some data') # for kodi 18 and up..
# ui = GUI('script-testwindow.xml', CWD, 'default', '1080i', optional1='some data') # use this line instead for kodi 17 and earlier
ui.doModal()
del ui

This is the xml

xml:
<?xml version="1.0" encoding="UTF-8"?>
<window>
<views>50</views>
<controls>
<control type="image">
<posx>0</posx>
<posy>0</posy>
<width>1920</width>
<height>1080</height>
<texture>background-fallback.png</texture>
</control>
<control type="button" id="200">
<description>My first button control</description>
<left>80</left>
<top>60</top>
<width>250</width>
<height>200</height>
<visible>true</visible>
<wrapmultiline>true</wrapmultiline>
<font>font12</font>
<textcolor>FFFFFFFF</textcolor>
<focusedcolor>FFFFFFFF</focusedcolor>
<disabledcolor>80FFFFFF</disabledcolor>
<invalidcolor>FFFFFFFF</invalidcolor>
</control>
<control type="list" id="100">
<left>500</left>
<top>200</top>
<width>1000</width>
<height>500</height>
<itemlayout height="100" width="1000">
<control type="label">
<left>20</left>
<top>0</top>
<height>50</height>
<width>960</width>
<font>font13</font>
<label>$INFO[ListItem.Label]</label>
</control>
</itemlayout>
<focusedlayout height="100" width="1000">
<control type="image">
<left>0</left>
<top>0</top>
<width>1000</width>
<height>50</height>
<texture>background-fallback.png</texture>
</control>
<control type="label">
<left>20</left>
<top>0</top>
<height>50</height>
<width>960</width>
<font>font13</font>
<label>$INFO[ListItem.Label]</label>
<textcolor>orange</textcolor>
</control>
</focusedlayout>
</control>
</controls>
</window>



RE: WindowXML tutorial does not work on my machine - ronie - 2018-05-29

you're mixed up the python WindowXML and Window classes.

for xml based windows, all you need is something like:
python:
self.butn = self.getControl(200)
self.butn.setLabel('my first button')



RE: WindowXML tutorial does not work on my machine - smitchell6879 - 2018-05-29

(2018-05-29, 01:56)ronie Wrote: you're mixed up the python WindowXML and Window classes.

for xml based windows, all you need is something like:
python:
self.butn = self.getControl(200)
self.butn.setLabel('my first button')


This is awesome thank you. since I am mixing them up will I still get a call back on self.butn? so that I could add something like onclick do something?

NVM.. after playing around a little more I got it working... Thank you again for the help. now the fun begins maybe next year I will have another complete addon hahaha.