Added a method called on each public widget creation
We can now populate the genlist when needed
This commit is contained in:
parent
4d41e26f9b
commit
57481ac5fb
|
@ -107,6 +107,11 @@ class ErigoGui(object):
|
|||
for w_name in self._data['Settings']['start_points']:
|
||||
_widget_generate(self, w_name)
|
||||
|
||||
def widget_generated(self, name, widget):
|
||||
""" User can redefine this method to be informed when a public widget
|
||||
is created. """
|
||||
self._print('Widget generated: %s' % widget.__class__)
|
||||
|
||||
def _print(self, msg):
|
||||
if self._verbose:
|
||||
print(msg)
|
||||
|
@ -143,12 +148,6 @@ def _widget_generate(self, name, parent_name=None):
|
|||
self._widgets[name] = w
|
||||
|
||||
|
||||
# make the widget public if requested
|
||||
if w_data['Desc'].get('public', False) is True:
|
||||
self._print('Installing name: %s' % name)
|
||||
setattr(self, name, w)
|
||||
|
||||
|
||||
# apply widget properties
|
||||
if 'Properties' in w_data:
|
||||
for eo_name, p_vals in w_data['Properties'].items():
|
||||
|
@ -176,28 +175,6 @@ def _widget_generate(self, name, parent_name=None):
|
|||
_item_generate(self, w, None, item_name, item_data)
|
||||
|
||||
|
||||
# generate (and pack) children widgets
|
||||
if eo_klass_name == 'Elm_Win':
|
||||
for c_name in w_data.get('Contains', []):
|
||||
child = _widget_generate(self, c_name)
|
||||
w.resize_object_add(child)
|
||||
|
||||
elif eo_klass_name == 'Elm_Box':
|
||||
for c_name in w_data.get('Contains', []):
|
||||
child = _widget_generate(self, c_name)
|
||||
w.pack_end(child)
|
||||
|
||||
elif eo_klass_name == 'Elm_Table':
|
||||
for c_name, (x, y, cspan, rspan) in w_data.get('Contains', {}).items():
|
||||
child = _widget_generate(self, c_name)
|
||||
w.pack(child, x, y, cspan, rspan)
|
||||
|
||||
elif eo_klass_name == 'Elm_Flip':
|
||||
for c_name, (swallow,) in w_data.get('Contains', {}).items():
|
||||
child = _widget_generate(self, c_name)
|
||||
w.part_content_set(swallow, child)
|
||||
|
||||
|
||||
# callbacks
|
||||
if 'Callbacks' in w_data:
|
||||
for event_name, cb_data in w_data['Callbacks'].items():
|
||||
|
@ -223,6 +200,35 @@ def _widget_generate(self, name, parent_name=None):
|
|||
w._callback_add(str(event_name), _widget_create_cb,
|
||||
self, w_name, w_parent_name)
|
||||
|
||||
|
||||
# make the widget public if requested, and call the widget_generated method
|
||||
if w_data['Desc'].get('public', False) is True:
|
||||
self._print('Installing name: %s' % name)
|
||||
setattr(self, name, w)
|
||||
self.widget_generated(name, w)
|
||||
|
||||
|
||||
# generate (and pack) children widgets
|
||||
if eo_klass_name == 'Elm_Win':
|
||||
for c_name in w_data.get('Contains', []):
|
||||
child = _widget_generate(self, c_name)
|
||||
w.resize_object_add(child)
|
||||
|
||||
elif eo_klass_name == 'Elm_Box':
|
||||
for c_name in w_data.get('Contains', []):
|
||||
child = _widget_generate(self, c_name)
|
||||
w.pack_end(child)
|
||||
|
||||
elif eo_klass_name == 'Elm_Table':
|
||||
for c_name, (x, y, cspan, rspan) in w_data.get('Contains', {}).items():
|
||||
child = _widget_generate(self, c_name)
|
||||
w.pack(child, x, y, cspan, rspan)
|
||||
|
||||
elif eo_klass_name == 'Elm_Flip':
|
||||
for c_name, (swallow,) in w_data.get('Contains', {}).items():
|
||||
child = _widget_generate(self, c_name)
|
||||
w.part_content_set(swallow, child)
|
||||
|
||||
return w
|
||||
|
||||
|
||||
|
@ -241,6 +247,7 @@ def _item_generate(self, parent_widget, parent_item, item_name, item_data):
|
|||
_item_generate(self, parent_widget, it, item_name, item_data)
|
||||
|
||||
|
||||
|
||||
def _params_list_parse(mod, params):
|
||||
return [ _param_parse(mod, p) for p in params ]
|
||||
|
||||
|
|
|
@ -730,6 +730,10 @@
|
|||
"Elm_Toolbar.shrink_mode":["ELM_TOOLBAR_SHRINK_MENU"],
|
||||
"Evas.Object.size_hint_weight":[1, 0]
|
||||
},
|
||||
"Callbacks":
|
||||
{
|
||||
"selected":["Modify", "elm_flip1", "Elm_Flip.go", ["ELM_FLIP_CUBE_LEFT"]]
|
||||
},
|
||||
"Items":
|
||||
{
|
||||
"elm_toolbar1_it0":
|
||||
|
@ -786,7 +790,8 @@
|
|||
"Desc":
|
||||
{
|
||||
"parent":"elm_flip1",
|
||||
"class":"Elm_Genlist"
|
||||
"class":"Elm_Genlist",
|
||||
"public":true
|
||||
},
|
||||
"Properties":
|
||||
{
|
||||
|
@ -799,7 +804,8 @@
|
|||
"Desc":
|
||||
{
|
||||
"parent":"elm_flip1",
|
||||
"class":"Elm_Gengrid"
|
||||
"class":"Elm_Gengrid",
|
||||
"public":true
|
||||
},
|
||||
"Properties":
|
||||
{
|
||||
|
|
|
@ -6,15 +6,31 @@ import time
|
|||
|
||||
from efl import elementary
|
||||
from efl.utils.erigo import ErigoGui
|
||||
from efl.elementary.icon import Icon
|
||||
from efl.elementary.genlist import GenlistItemClass
|
||||
|
||||
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 MyGenlistItemClass(GenlistItemClass):
|
||||
def text_get(self, obj, part, data):
|
||||
return 'Item #%d' % data
|
||||
|
||||
def content_get(self, obj, part, data):
|
||||
if part == 'elm.swallow.icon':
|
||||
return Icon(obj, standard='home')
|
||||
|
||||
class MyGui(ErigoGui):
|
||||
def __init__(self, *args, **kargs):
|
||||
ErigoGui.__init__(self, *args, **kargs)
|
||||
# Here you can put your init stuff, if needed
|
||||
self.gl_itc = MyGenlistItemClass(item_style='default')
|
||||
|
||||
def widget_generated(self, name, widget):
|
||||
if name == 'elm_genlist1':
|
||||
for i in range(100):
|
||||
self.elm_genlist1.item_append(self.gl_itc, i)
|
||||
|
||||
|
||||
def btn5_clicked_cb(self, btn):
|
||||
print('USER CB INVOKED', btn)
|
||||
|
|
Loading…
Reference in New Issue