PDA

View Full Version : Multiple windows


madtw
2004-04-15, 10:35
i have been trying to get a parent window to open a child window but for the life of me can't get it to work. either i get errors like "finally pops bad exception" or xbmc freezes. here is some stripped down code that causes xbmc to freeze (2004-04-13 build - didn't seem to include a new python dll though):


import xbmcgui

class mainwin( xbmcgui.window ):
def ( self ):
xbmcgui.window.( self, 9990 )
self.addcontrol( xbmcgui.controlimage( \
0, 0, self.getwidth(), self.getheight(), \
'background.png' ) )
self.addcontrol( xbmcgui.controllabel( \
50, 30, 200, 20, "parent", 'font16', '0xffffffff' ) )

def onaction( self, action ):
try:
if action == 10:
self.close()
elif action == 7:
child = childwin()
child.domodal()
del child

except exception, ex:
traceback.print_exc()
xbmcgui.dialog().ok( "error", str(ex) )

class childwin( xbmcgui.window ):
def ( self ):
xbmcgui.window.( self, 9991 )
self.addcontrol( xbmcgui.controlimage( \
0, 0, self.getwidth(), self.getheight(), \
'background.png' ) )
self.addcontrol( xbmcgui.controllabel( \
50, 30, 200, 20, "child", 'font16', '0xffffffff' ) )

def onaction( self, action ):
try:
if action == 10:
self.close()

except exception, ex:
traceback.print_exc()
xbmcgui.dialog().ok( "error", str(ex) )

parent = mainwin()
parent.domodal()
del parent



if this worked the way i wanted it to, you should be able to open the child by pressing the 'select' button. then you can close the child window by pressing the 'previous menu' button. any ideas?

also, my windows are a bit more complex than this example. i kept getting errors like "an integer is required" when i had additional parameters to the window constructor. i'm guessing that python is expecting the window id to be passed after the self parameter. this is not necessarily true for new window classes derived from xbmcgui.window.

my workaround for this was to not have any parameters for the constructor and then call a method to initialize the window object after it was constructed. the other way should've worked as well but for some reason it didn't.

i also tried using show() and close() with a loop at the end of my script instead of domodal() but it didn't seem to make a difference...

oh, i should add that if i use xbmcgui.dialog() from the parent, it seems to work fine. so xbmcgui.dialog() must be doing something different than xbmcgui.window().

ent
2004-04-15, 11:01
just out of curiosity madtw what are you exactly working on?

burriko
2004-04-15, 14:35
i found the same thing as you, madtw. what i did instead is to simply draw background.png over the top of everything so you get a fresh screen to draw on. once you've finished with it just removecontrol on everything you've drawn for the child window, including the new background.png to get back to the main window.

madtw
2004-04-15, 18:23
i'm working on the python mythtv frontend. the parent window currently shows you all your recorded shows. the child window will show you the details of the recorded show, plus a screenshot of the show, and give you the option to watch the show, delete it, and maybe edit some of the properties (e.g. auto expire, etc.). i have communication with the mythbackend all sorted out for generating pixmaps, deleting a show, retrieving show info, etc..

i want to use the same idea for browsing the tv schedule... a parent window to display the schedule stored in the myth database and a child window when you select a program. you'll be able to specify if you want to record the program once, everytime on this channel, etc. much like the mythtv web interface.

burriko: thanks for the idea... i guess that'll work. it messes up all my classes but it sounds like a work around.

b01
2004-04-15, 19:56
you have to be clever, i want to create a file manager like in ava for xbmc with a parent window and about four child windows, but it was not neccessary.

what i plan to do is use a main window. then use image labels to represent the child windows, and use list and text labels to display the directory contents. http://www.xboxmediaplayer.de/forums/non-cgi/emoticons/cool.gif

darkie
2004-04-18, 18:00
if this worked the way i wanted it to, you should be able to open the child by pressing the 'select' button. *then you can close the child window by pressing the 'previous menu' button. *any ideas?
i have an idea :).
it was a nasty bug in the python sources but it is fixed now
btw, this is the code i usedimport xbmcgui

action_select_item * * * * * *= 7
action_previous_menu * * * *= 10

class mainwin(xbmcgui.window):
*def (self):
* *self.addcontrol( xbmcgui.controlimage(0, 0, self.getwidth(), self.getheight(), 'background.png' ))
* *self.addcontrol( xbmcgui.controllabel(50, 200, 200, 20, "parent", 'font16', '0xffffffff'))

*def onaction(self, action):
* *if action == action_previous_menu:
* * *self.close()
* *elif action == action_select_item:
* * *child = childwin()
* * *child.domodal()
* * *del child

class childwin(xbmcgui.window):
*def (self):
* *self.addcontrol(xbmcgui.controlimage(0, 0, self.getwidth(), self.getheight(), 'background.png'))
* *self.addcontrol(xbmcgui.controllabel(50, 200, 200, 20, "child", 'font16', '0xffffffff'))

*def onaction(self, action):
* *if action == action_previous_menu:
* * *self.close()

parent = mainwin()
parent.domodal()
del parent


edit:
just noticed that this board changed my code
def (self): should be def --init-- (self):

madtw
2004-04-21, 06:40
i have an idea :).
it was a nasty bug in the python sources but it is fixed now
excellent... i was hoping it was just a bug.

guess i'm waiting for a new build of the python lib... :)