v16 Why is the window black?
#1
I followed this tutorial:
http://kodi.wiki/view/HOW-TO:Write%20python%20scripts

but one thing confuses me. The window background is black. How can I make my window use the current skin, as well as the labels and everything else so that things are consistent?
Reply
#2
there are various ways to accomplish things. which method will suit you best depends on what you're exactly trying to accomplish.
please provide some details on what kind of addon you want to create.
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
#3
I'd like to do it entirely in Python if possible. I basically want to make a table like any other table with rows, columns, etc. For now, that is the only thing I want to display.
Reply
#4
(2016-06-22, 08:50)Kochab Wrote: I followed this tutorial:
http://kodi.wiki/view/HOW-TO:Write%20python%20scripts

but one thing confuses me. The window background is black.

A new instance of xbmcgui.Window class have a black background (it covers Kodi UI completely) and no visual elements on its own. You need to add xbmcgui.ControlXXX elements to the Window instance to create your own UI elements. Also note that there is also xbmcgui.WindowDialog class that has a transparent background, that is, it does not cover Kodi UI, but it is modal, unlike xbmcgui.Window.

Quote:How can I make my window use the current skin, as well as the labels and everything else so that things are consistent?

In a general case it is not possible, unless you include texture images from all skins that you are going to support into your addon and switch those textures based on the current skin. However, there is xbmcgui.Dialog class that can be used as a "poor man's GUI". xbmcgui.Dialog elements use textures from the current skin automatically, so you don't need to bother yourself with this.

Also you can take look at my PyXBMCt micro-framework: https://github.com/romanvm/script.module.pyxbmct . I created it a while ago (when Kodi was XBMC) but it still works with current Kodi versions.
Reply
#5
Thanks for the info. I took a look at PyXBMCt, but I was unable to run the demo. Kodi log says, "No module named pyxbmct." I checked dependencies in Kodi and don't see anything about PyXBMCt, so there must be something I'm missing. I saw in your thread that it was included in Gotham, but I can't find it in Jarvis.

For now, I have decided to not worry about the skin and simply make a background image. Now, my problem is with the path to the image.

Code:
self.addControl(xbmcgui.ControlImage(0,0,800,600, 'background.png'))

background.png resides in my addon folder (the same folder with addon.py, addon.xml, LICENSE.txt, etc), however the above code doesn't work. Do I need to use the "special protocol"? I already tried "special://addons/my.custom.addon/background.png", but unfortunately that did not work. I'm not sure what path Kodi is looking for that would be system agnostic. If you could help me solve this, I'd be grateful.
Reply
#6
this will provide the path to the root folder of your addon:

Code:
path = xbmcaddon.Addon().getAddonInfo('path').decode('utf-8')
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
(2016-06-22, 21:10)Kochab Wrote: Thanks for the info. I took a look at PyXBMCt, but I was unable to run the demo. Kodi log says, "No module named pyxbmct." I checked dependencies in Kodi and don't see anything about PyXBMCt, so there must be something I'm missing. I saw in your thread that it was included in Gotham, but I can't find it in Jarvis.

PyXBMCt is automatically installed when it is present in addon's dependencies. You need to install the demo addon from an installable ZIP (not the one that is auto-generated by Github) via Kodi addon manager.

Quote:Now, my problem is with the path to the image.

Code:
self.addControl(xbmcgui.ControlImage(0,0,800,600, 'background.png'))

background.png resides in my addon folder (the same folder with addon.py, addon.xml, LICENSE.txt, etc), however the above code doesn't work.

Filenames for images without a full path work only if this image is included in the current skin's resources. Otherwise you must provide a full path.

(2016-06-22, 21:34)ronie Wrote: this will provide the path to the root folder of your addon:

Code:
path = xbmcaddon.Addon().getAddonInfo('path').decode('utf-8')

Correction, you shouldn't decode path in this case. Yes, this is needed for Python import, but for images decoded paths won't work if you have non-ASCII characters in your path.
Reply
#8
It works! Thank you both.

But I have run into another problem. The image is bloated because the resolution seems to be off. My screen is 1920x1080. The image is 1920x1080. I am setting the aspectRatio parameter in ControlImage to 0 (stretch/default). When I set the coordinate resolution to 0:

Code:
self.setCoordinateResolution(0)

The image looks as expected and everything is fine. However, this code will not work:

Code:
res = self.getResolution(self)
self.setCoordinateResolution(res)

When I logged the res variable, I expected to find an int between 0-9 as per the docs:
http://mirrors.kodi.tv/docs/python-docs/...tml#Window

However, it is giving me 16. So, of course, I get a "RuntimeError: Invalid resolution" in the log file. Any ideas?
Reply
#9
looks like the docs are outdated :-)
the current resolution list can be found here:
https://github.com/xbmc/xbmc/blob/master....h#L33-L52

the reason for your error:
https://github.com/xbmc/xbmc/blob/master...#L609-L610

i'm afraid i have no idea whether or it's a bug or if there's a specific reason why resolutions above 14 can't be used.
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
#10
Thanks for the links. It's not perfect, but my workaround is this:
Code:
windowWidth = self.getWidth(self)
resfinder = {
    1920: 0,
    720: 5,
    480: 6,
}
self.setCoordinateResolution(resfinder[windowWidth])

I'm not displaying any video, so hopefully that will be fine.
Reply
#11
Just FYI: new Window and WindowDialog instances use 1280x720 pixels coordinate grid by default, regardless of your actual skin resolution and display resolution (those are not the same).
Reply

Logout Mark Read Team Forum Stats Members Help
Why is the window black?0