Implement erigo json V3

NOTE: this is only compatible with erigo develop branch
This commit is contained in:
Davide Andreoli 2015-02-02 20:18:08 +01:00
parent 57481ac5fb
commit f4445f05e7
2 changed files with 49 additions and 18 deletions

View File

@ -21,7 +21,7 @@ TODO
====
* mainmenu ??
* test more widget items (only menu tested atm)
* test more widget items (only menu/toolbar tested atm)
* add all the supported widget to KLASSES
* documentation for this module
* fix (in erigo) the label with markup
@ -30,7 +30,7 @@ TODO
* scrollable interface, widgets must be changed to always inherit from Scroller
* how to manage translations??
* what when we create the same widget more than one time ?
* Radio.group_add is not a property !!
* Radio.group_add accept an obj, not a string !!!
* Widget that seems not usable in erigo itsef:
- Icon: how to set a standard icon?
@ -54,6 +54,7 @@ except NameError:
## From py-efl 1.14 we will need to rise py min version
###################################################################
JSON_Version = 3
KLASSES = {
'Elm_Actionslider': ('efl.elementary.actionslider', 'Actionslider'),
@ -86,6 +87,7 @@ class ErigoGui(object):
self._verbose = verbose
self._widgets = {} # key: widget_name data: widget_instance
self._data = None # parsed json data
if resources_path:
self._res_path = resources_path
elif json_file:
@ -104,6 +106,10 @@ class ErigoGui(object):
else:
raise RuntimeError('One of "file" or "json_string" is mandatory')
if int(self._data['JSON_Version']) != JSON_Version:
raise RuntimeError('Wrong json version. Found: %s, wanted: %s' % \
(self._data['JSON_Version'], JSON_Version))
for w_name in self._data['Settings']['start_points']:
_widget_generate(self, w_name)
@ -136,13 +142,13 @@ def _widget_generate(self, name, parent_name=None):
klass = getattr(mod, klass_name)
# class constructor
if eo_klass_name+'.constructor' in w_data.get('Properties', []):
# Custom CONSTRUCTOR
params = w_data['Properties'][eo_klass_name+'.constructor']
if 'Constructors' in w_data:
# Custom (TODO support multiple constructors)
params = w_data['Constructors'][eo_klass_name + '.constructor']
params = _params_list_parse(mod, params)
w = klass(*params, parent=self._widgets.get(parent_name))
else:
# Standard CONSTRUCTOR
# Standard
parent = self._widgets[parent_name or w_data['Desc']['parent']]
w = klass(parent)
self._widgets[name] = w
@ -160,15 +166,23 @@ def _widget_generate(self, name, parent_name=None):
p_vals = _params_list_parse(mod, p_vals)
if p_name == 'file':
p_vals = _resource_find(self, p_vals)
elif p_name == 'group_add':
w.group_add(self._widgets[p_vals[0]])
continue
if len(p_vals) == 1:
setattr(w, p_name, p_vals[0])
else:
setattr(w, p_name, p_vals)
# call widget methods
if 'Methods' in w_data:
for eo_name, params in w_data['Methods'].items():
meth_name = eo_name.split('.')[-1]
params = _params_list_parse(mod, params)
self._print('method %s %s' % (meth_name, params))
if meth_name == 'group_add': # ARGH !!!!!!
params = [ self._widgets[params[0]] ] # resolv widget by name
getattr(w, meth_name)(*params)
# generate widget items
if 'Items' in w_data:
for item_name, item_data in w_data['Items'].items():

View File

@ -1,9 +1,8 @@
{
"JSON_Version":"2",
"JSON_Version":"3",
"Settings":
{
"project":"pyefl_erigo_test",
"images_prefix":"",
"start_points":["elm_win1"]
},
"Resources":
@ -31,10 +30,13 @@
"class":"Elm_Win",
"public":true
},
"Constructors":
{
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"]
},
"Properties":
{
"Evas.Object.visibility":[true],
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"],
"Elm_Win.autodel":[true],
"Elm_Win.title":["Win1 Title"],
"Evas.Object.size":[381, 480]
@ -290,13 +292,16 @@
"class":"Elm_Win",
"public":true
},
"Constructors":
{
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"]
},
"Properties":
{
"Elm_Win.title":["elm_win2"],
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Evas.Object.size":[150, 100],
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"],
"Elm_Win.autodel":[true]
},
"Contains":["elm_bg2", "elm_box2"]
@ -415,13 +420,16 @@
"parent":null,
"class":"Elm_Win"
},
"Constructors":
{
"Elm_Win.constructor":["dia-win", "ELM_WIN_DIALOG_BASIC"]
},
"Properties":
{
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Evas.Object.size":[150, 100],
"Elm_Win.title":["A dialog win"],
"Elm_Win.constructor":["dia-win", "ELM_WIN_DIALOG_BASIC"],
"Elm_Win.autodel":[true]
},
"Contains":["elm_bg3", "elm_label3"]
@ -581,9 +589,12 @@
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Elm_Widget.part_text":[null, "Radio Two"],
"Elm_Radio.group_add":["elm_radio1"],
"Elm_Radio.state_value":[2]
},
"Methods":
{
"Elm_Radio.group_add":["elm_radio1"]
},
"Callbacks":
{
"changed":["Invoke", "win2_radio_changed_alias", null]
@ -601,9 +612,12 @@
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Elm_Widget.part_text":[null, "Radio Three"],
"Elm_Radio.group_add":["elm_radio1"],
"Elm_Radio.state_value":[3]
},
"Methods":
{
"Elm_Radio.group_add":["elm_radio1"]
},
"Callbacks":
{
"changed":["Invoke", "win2_radio_changed_alias", null]
@ -681,9 +695,12 @@
"parent":null,
"class":"Elm_Win"
},
"Constructors":
{
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"]
},
"Properties":
{
"Elm_Win.constructor":[null, "ELM_WIN_BASIC"],
"Elm_Win.title":["elm_win4"],
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
@ -814,4 +831,4 @@
}
}
}
}
}