| Issue 38: | on_load event for when a widget is fully initialized | |
| 1 person starred this issue and may be notified of changes. | Back to list |
an event that is triggered when the widget is done initializing (to do basic init stuff that doesnt need to be in constructor/you dont have to overwrite constructor) problem: cant add it at end of constructor in widget, since subcalsses will then trigger it before being done with their __init__ might need meta class thinsg to do this, im not sure how else? maybe use on_add event instead for when widget is added to a parent
Mar 16, 2009
Project Member
#1
txprog
Mar 16, 2009
In case the dpaste will disapear :
def decorate_onload(f):
def my_init(*args, **kwargs):
inst = args[0]
if hasattr(inst, '__decorate_onload__'):
return f(*args, **kwargs)
inst.__setattr__('__decorate_onload__', True)
f(*args, **kwargs)
print 'launch on_load!'
return my_init
class A(object):
@decorate_onload
def __init__(self):
print 'init A'
class B(A):
@decorate_onload
def __init__(self):
print 'init B'
super(B, self).__init__()
print 'fin init B'
class C(B):
@decorate_onload
def __init__(self):
print 'init C'
super(C, self).__init__()
print 'fin init C'
C()
# AND THE RESULT
# init C
# init B
# init A
# fin init B
# fin init C
# launch on_load!
Mar 16, 2009
my 2c, i've misunderstood the issue. Yeah, you cannot use the on_load event... because your widget are already loaded...
Mar 16, 2009
Let me explain, in my example above, imagine you want to define your own on_load: m = MTWidget() @m.event def on_load(self): print 'yoooooooo' It's impossible to get working, because the __init__ have already launched the on_load event!
Mar 16, 2009
(No comment was entered for this change.)
Labels:
Component-Core
Mar 16, 2009
Anyway, here is a patch for on_load ..
Mar 18, 2009
Can we close the issue ?
Mar 23, 2009
(No comment was entered for this change.)
Status:
Invalid
|