Issue 38: on_load event for when a widget is fully initialized
Status:  Invalid
Owner:
Closed:  Mar 2009
Project Member Reported by thomas.h...@gmail.com, Mar 15, 2009
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
I've found a solution for this :

http://dpaste.com/14985/
Mar 16, 2009
Project Member #2 txprog
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
Project Member #3 txprog
my 2c, i've misunderstood the issue. Yeah, you cannot use the on_load event...
because your widget are already loaded...


Mar 16, 2009
Project Member #4 txprog
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
Project Member #5 txprog
(No comment was entered for this change.)
Labels: Component-Core
Mar 16, 2009
Project Member #6 txprog
Anyway, here is a patch for on_load ..
patch-onload-decoration.diff
25.3 KB   View   Download
Mar 18, 2009
Project Member #7 txprog
Can we close the issue ?
Mar 23, 2009
Project Member #8 txprog
(No comment was entered for this change.)
Status: Invalid