2004-04-15, 09: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):
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().
Quote: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().