Implemented Invoke type callbacks

This commit is contained in:
Davide Andreoli 2015-01-24 10:51:14 +01:00
parent 14a070012d
commit ae2dec22da
3 changed files with 51 additions and 12 deletions

View File

@ -155,19 +155,24 @@ def _widget_generate(self, data, name):
# callbacks
if 'Callbacks' in w_data:
for cb_name, cb_data in w_data['Callbacks'].items():
for event_name, cb_data in w_data['Callbacks'].items():
if cb_data[0] == 'Modify':
target_name, target_prop, values = cb_data[1:4]
target_prop = target_prop.split('.')[-1]
self._print('callback %s (Modify) %s.%s => %s' % \
(cb_name, target_name, target_prop, values))
w._callback_add(str(cb_name), _property_modify_cb,
self._print('event %s (Modify) %s.%s => %s' % \
(event_name, target_name, target_prop, values))
w._callback_add(str(event_name), _property_modify_cb,
self, target_name, target_prop, values)
elif cb_data[0] == 'Create':
print("TODO")
elif cb_data[0] == 'Invoke':
cb_alias = cb_data[1]
cb_name = data['Resources']['Eo_Callbacks'][cb_alias]
self._print('event %s (Invoke) %s => %s' % \
(event_name, cb_alias, cb_name))
w._callback_add(str(event_name), getattr(self, cb_name))
elif cb_data[0] == 'Create':
print("TODO")
return w

View File

@ -11,6 +11,10 @@
"Images":
{
"logo":"/home/yakov/egui/examples/logo.png"
},
"Eo_Callbacks":
{
"btn5_clicked_cb_alias":"btn5_clicked_cb"
}
},
"Widgets":
@ -153,8 +157,9 @@
"Contains":
{
"elm_button2":[0, 0, 1, 1],
"elm_button3":[1, 1, 1, 1],
"elm_button4":[0, 1, 1, 1]
"elm_button3":[1, 0, 1, 1],
"elm_button4":[0, 1, 1, 1],
"elm_button5":[1, 1, 1, 1]
}
},
"elm_button2":
@ -227,6 +232,25 @@
{
"clicked":["Modify", "elm_button1", "Elm_Widget.part_text", [null, "Halo !"]]
}
},
"elm_button5":
{
"Desc":
{
"parent":"elm_table1",
"class":"Elm_Button"
},
"Properties":
{
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Evas.Object.size":[73, 30],
"Elm_Widget.part_text":[null, "user cb"]
},
"Callbacks":
{
"clicked":["Invoke", "btn5_clicked_cb_alias", null]
}
}
}
}

View File

@ -10,21 +10,31 @@ from efl.utils.erigo import ErigoGui
prj_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "erigo_prj")
json_file = os.path.join(prj_path, "test_gui.egui")
class MyGui(ErigoGui):
def __init__(self, *args, **kargs):
ErigoGui.__init__(self, *args, **kargs)
# Here you can put your init stuff, if needed
def btn5_clicked_cb(self, btn):
print('USER CB INVOKED', btn)
self.elm_label1.text = 'User cb invoked!'
def erigo_clicked(obj):
start_time = time.time()
# Test from file
egui = ErigoGui(json_file, verbose=True)
egui = MyGui(json_file, verbose=True)
# Test from json string
# json = open(json_file).read()
# egui = ErigoGui(json_string=json, verbose=True)
# egui = MyGui(json_string=json, verbose=True)
egui.elm_label1.text = 'GUI Generated in %.5f seconds' % \
(time.time() - start_time)
if __name__ == '__main__':
elementary.init()