From ae2dec22da565beef09d97bbe6c0b38c2e61f12c Mon Sep 17 00:00:00 2001 From: Dave Andreoli Date: Sat, 24 Jan 2015 10:51:14 +0100 Subject: [PATCH] Implemented Invoke type callbacks --- efl/utils/erigo.py | 19 ++++++++------ examples/elementary/erigo_prj/test_gui.egui | 28 +++++++++++++++++++-- examples/elementary/test_erigo.py | 16 +++++++++--- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/efl/utils/erigo.py b/efl/utils/erigo.py index 291d8a5..d3db5e6 100644 --- a/efl/utils/erigo.py +++ b/efl/utils/erigo.py @@ -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 diff --git a/examples/elementary/erigo_prj/test_gui.egui b/examples/elementary/erigo_prj/test_gui.egui index cfbeb89..6e03307 100644 --- a/examples/elementary/erigo_prj/test_gui.egui +++ b/examples/elementary/erigo_prj/test_gui.egui @@ -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] + } } } } \ No newline at end of file diff --git a/examples/elementary/test_erigo.py b/examples/elementary/test_erigo.py index ea20b18..1aca679 100644 --- a/examples/elementary/test_erigo.py +++ b/examples/elementary/test_erigo.py @@ -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()