Is it possible to use custom windows for video add-ons?
#1
Hi there,

I've been googling this all along, but the XBMC add-on development docs are so bad, even after hours I wasn't a bit smarter about my problem. :-(

I want to write a video add-on which scrapes a few RSS feeds and plays videos from there. Normally I would simply go with xbmcgui.ListItem() and xbmcplugin.addDirectoryItem() to display a listing for all entries. This time, though, I'd like to create a completely new window so I have a little more control over the appearance.
I started with creating a simple class:

PHP Code:
ACTION_PREVIOUS_MENU 10

class Plugin_Video_Test(xbmcgui.Window):
    
def onAction(selfaction):
        if 
action == ACTION_PREVIOUS_MENU:
            print 
"Hello world"
            
self.close()

test Plugin_Video_Test()
test.doModal()
del test 
The problem that I have is that I only get a loading spinner when I start the add-on. The only thing I can do is to cancel this by hitting ESC twice. When I do that, it takes a while and then the add-on exits and the log shows the following:

Code:
19:10:50 T:140407241447360   ERROR: GetDirectory - Error getting plugin://plugin.video.test/
19:10:50 T:140407241447360   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.test/) failed
19:10:50 T:140406875166464  NOTICE: Thread Background Loader start, auto delete: false
19:10:56 T:140406883559168   ERROR: XBPyThread::stop - script /home/janek/.xbmc/addons/plugin.video.test/default.py didn't stop in 5 seconds - let's kill it
19:10:56 T:140405278496512  NOTICE: Hello world
19:10:56 T:140406875166464  NOTICE: Thread Background Loader start, auto delete: false
19:10:56 T:140406875166464  NOTICE: Thread XBPyThread start, auto delete: false

I have searched this error message for hours and I found a lot of forum threads and bug reports, but never did I find a solution other than "developer has provided a new version". Not one of those threads had something to do with windows and video add-ons.

The only thing that seems to get rid of this is to change this part in my addon.xml
Code:
<extension point="xbmc.python.pluginsource" library="default.py">
    <provides>video</provides>
</extension>
to
Code:
<extension point="xbmc.python.script" library="default.py">
    <provides>video</provides>
</extension>
But the problem with that solution is that XBMC always shows a popup whether I want to "play" the item when I open the add-on (i.e. it shows my default play action that should only show up when I open a video file). When I remove the <provides> tag, that popup is gone, but it causes the add-on to be moved from the video add-ons section to "Programs".

Is there any way to solve this issue? Are custom windows for video add-ons even supported?

Thanks!

EDIT:
I also tried adding an empty directory using xbmcplugin.addDirectoryItem() but that doesn't work either. Shortly before the window opens an empty directory entry blinks up and the application breaks horribly when I exit the window.
Reply
#2
Hmm, I found out, it's working when I explicitly call xbmcplugin.endOfDirectory(int(sys.argv[1])) prior to opening a window.
But the problem I now have is that XBMC freezes when I close the window and reopen it.

Slightly different but related question: is there any way to show an input dialog besides using xbmcgui.Dialog()? I want a window with two input fields. I thought I could maybe get this with either xbmcgui.Window or xbmcgui.WindowDialog, but the first isn't working well and the second doesn't seem to open any window at all. For the latter I also can't find any documentation except the API doc which doesn't provide much information to be honest.
Reply
#3
(2013-09-11, 23:35)Manko10 Wrote: Slightly different but related question: is there any way to show an input dialog besides using xbmcgui.Dialog()? I want a window with two input fields. I thought I could maybe get this with either xbmcgui.Window or xbmcgui.WindowDialog, but the first isn't working well and the second doesn't seem to open any window at all. For the latter I also can't find any documentation except the API doc which doesn't provide much information to be honest.

I've been experimenting with xbmcgui.Window and xbmcgui.WindowDialog, and they worked well for me. Though, for that purpose I created a simple program addon rather than video one.
The difference between xbmcgui.Window and xbmcgui.WindowDialog is that the former has black background and the latter has transparent background, and it's completely up to you how to decorate your interface. Both classes serve as top-level containers and provide you a coordinate grid (1280x720 by default, starting from the top-left corner of the screen) on which your place necessary widgets or, in terms of XBMC, controls. All elements - xbmcgui.Window , xbmcgui.WindowDialog and controls - are more like skeletons than complete widgets and require some graphics (images/textures) to decorate them (though some controls can use graphics from the current skin). You can create the images yourself or take them from skin sources to make your interface consistent with the skin appearance.
As for xbmcgui.WindowDialog, the basic algorithm is the following:
- Place an image on the screen which will act as a background, using xbmc.ControlImage()
- Place other controls over the background using coordinate grid.
Reply
#4
Okay, thanks for your dedicated answer.
As I said, for program add-ons it works, but for video add-ons it somehow doesn't. Either I get the loading spinner and the first error message that plugin://plugin.video.test/ could not be resolved or (if I add an empty root folder) it behaves very weird when closing the window and freezes XBMC when reopening it.

Is there any other way to display an input dialog with two input controls? xbmcgui.Dialog() works fine, but that doesn't provide the required widgets.
Reply
#5
a plugin is not a script!

a plugin is a* VFS* entry. it shall only implement the analogues of listing a directory and opening a file.

a script is a full blown window with a gui. you cannot put a GUI on a plugin it WILL deadlock/crash/give errors.
Reply
#6
That's what I suspected. :-(
So I guess it's not possible, what a bummer. Anyway, thanks for clarifying things.
Reply
#7
hmm, what's not possible?
you implement a script with content type video. it shows up together with the plugins. the user clicks it, we toss off your script.

you can implement a full blown gui through e.g. the windowxml framework or you can code the controls by hand using Window. the only thing not possible here is trying to make a plugin behave like a script.
Reply
#8
(2013-09-12, 16:18)Manko10 Wrote: That's what I suspected. :-(
So I guess it's not possible, what a bummer. Anyway, thanks for clarifying things.

IMO you need to be more specific about what you're trying to accomplish. No, you cannot use plugin:// syntax to create virtual directories in a script, but I don't see what prevents you from creating you own content lists using xbmcgui.ControlList() class, for example, and passing your media content to the player via xbmc.Player().
Reply
#9
Quote:the only thing not possible here is trying to make a plugin behave like a script.
Well, ya, that's basically what I tried. I wanted a video plugin but with a custom GUI, not a program add-on/script.
But I just canceled that plan and went back to a simple plugin which I try to customize as much as possible. The only thing that's still a little sad is that there is no xbmcgui.Dialog() which provides text input fields.

Quote:No, you cannot use plugin:// syntax to create virtual directories in a script, but I don't see what prevents you from creating you own content lists using xbmcgui.ControlList() class
I never tried that. It's the other way round. I have a video plugin which by design needs to have a virtual directory and wanted to build a GUI upon it.
Reply
#10
(2013-09-12, 18:34)Manko10 Wrote: Well, ya, that's basically what I tried. I wanted a video plugin but with a custom GUI, not a program add-on/script.

Yes, you can create such plug-in, but you need to create your own GUI from scratch, including content list, etc. If you need to play video, use xbmcgui.Window class container, because it hides under video when playback started.
I've tried xbmcgui.WindowDialog - its controls are always on top of video, so, I guess, this class is more suited for program addons where you don't need to play anything.

Quote:
Quote:No, you cannot use plugin:// syntax to create virtual directories in a script, but I don't see what prevents you from creating you own content lists using xbmcgui.ControlList() class
I never tried that. It's the other way round. I have a video plugin which by design needs to have a virtual directory and wanted to build a GUI upon it.

You contradict yourself. Above you wrote:
Quote:Either I get the loading spinner and the first error message that plugin://plugin.video.test/ could not be resolved...
So you did try plugin://plugin.video.test. Why to be so confusing?
Reply
#11
No, I did not. All the code I had was to create a simple window using xbmcgui.Window, nothing more. But obviously it is expected from a video plugin to create a folder which I didn't do, therefore that error.

Quote:Yes, you can create such plug-in, but you need to create your own GUI from scratch, including content list, etc.
As I said, I tried that but it gives me deadlocks at best.

This is what spiff told me then (see above):
Quote:a script is a full blown window with a gui. you cannot put a GUI on a plugin it WILL deadlock/crash/give errors.
and that's exactly what I've been experiencing.
When I write the plugin as a script, it works, but that's not what I want to do.
Reply
#12
I need to do exactly the same as you

I've a video plugin that must show a custom window.

So: is it absolutely NOT possible ?

Did you found a way to workaround this ?
Reply
#13
It is definitely possible. You can launch a custom window based on xbmcgui.WindowDialog from your plugin with no problem. xbmcgui.Window is indeed buggy, so you'd better not to try it.
Reply
#14
Can you address me with a link or an example ?

I'm using WindowDialog in this plugin:

https://github.com/realtebo/plugin.video...jw_exec.py

But probably I'm doing something wrong because
- in my HDTV with Xbian on RPi the self.getWidth() is 1920, but if I set the width of a control box to getWidth() value, the content is a lot larger than screen, and I cannot see it fully
- same tv, same raspberry, at HD Ready it's all ok
- in my desktop pc, with a 4:3 ratio and windows, it's okay at full screen but has width and height wrong when windowed...

Please give a moment of your attention to my script and tell me the full list of my errors

note: this is a snapshot of my dev branch, to make it run you need to set addon to 'italian' ...
Reply
#15
(2013-09-26, 21:24)realtebo Wrote: Can you address me with a link or an example ?

Try this in Confluence skin (the background is taken from skin resources):
PHP Code:
import sys
import xbmcgui
xbmcplugin


class TestWindow(xbmcgui.WindowDialog):
    
def __init__(self):
        
background xbmcgui.ControlImage(450200400300'ContentPanel.png')
        
self.addControl(background)
        
label xbmcgui.ControlLabel(60030015050'This is test!')
        
self.addControl(label)   


addon_url sys.argv[0]
addon_id int(sys.argv[1])
paramstring sys.argv[2]
if 
paramstring == '?test=true':
    
window TestWindow()
    
window.doModal()
else:
    
tester xbmcgui.ListItem('Window test')
    
url addon_url '?test=true'
    
xbmcplugin.addDirectoryItem(addon_idurltesterisFolder=False)
    
xbmcplugin.endOfDirectory(addon_id

You should get this:

Image

(2013-09-26, 21:24)realtebo Wrote: But probably I'm doing something wrong because
- in my HDTV with Xbian on RPi the self.getWidth() is 1920, but if I set the width of a control box to getWidth() value, the content is a lot larger than screen, and I cannot see it fully
- same tv, same raspberry, at HD Ready it's all ok
- in my desktop pc, with a 4:3 ratio and windows, it's okay at full screen but has width and height wrong when windowed...

You have probably confused actual display resolution and the resolution of the coordinate grid on which controls are placed on the screen. The latter is 1280x720 by default regardless of your actual display resolution. This way your addon UI items have the same visible size no matter what resolution of your display is.

BTW, soon I'm going to release a preview of a UI framework for XBMC addons which should make building addon UI much easier. The framework is inspired by PyQt and use similar principles (a parent container window with a grid layout manager, a set of ready-to-use widgets and signal-slot connections). Those who are familiar with PyQt or PySide should feel right at home.Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Is it possible to use custom windows for video add-ons?0