Implemented resource management

This commit is contained in:
Davide Andreoli 2015-01-24 18:48:29 +01:00
parent 64c58021ea
commit ce1101e317
5 changed files with 90 additions and 9 deletions

View File

@ -21,9 +21,10 @@ TODO
====
* mainmenu ??
* implement Resources ... but when? always in the file prop?
* test more widget items (only menu tested atm)
* add all the supported widget to KLASSES
* documentation for this module
* fix (in erigo) the label with markup
* properties that need to be fixed:
- visibility
@ -34,6 +35,7 @@ TODO
"""
import os
import importlib
import json
@ -64,10 +66,17 @@ KLASSES = {
class ErigoGui(object):
""" TODO: Class doc """
def __init__ (self, json_file=None, json_string=None, verbose=False):
def __init__ (self, json_file=None, json_string=None, resources_path=None,
verbose=False):
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:
self._res_path = os.path.dirname(json_file)
else:
self._res_path = os.getcwd() # :/
if json_file is not None:
self._print('\n### Generating gui from file: %s' % json_file)
@ -86,6 +95,14 @@ class ErigoGui(object):
print(msg)
def _resource_find(self, value):
name, group = value
if name in self._data['Resources']['Images']:
fname = os.path.join(self._res_path,
self._data['Resources']['Images'][name])
return (fname, group)
return value
def _widget_generate(self, name, parent_name=None):
self._print('\n### Generating widget: %s' % name)
@ -127,8 +144,9 @@ def _widget_generate(self, name, parent_name=None):
else:
self._print('property %s => %s' % (p_name, p_vals))
p_vals = _params_list_parse(mod, p_vals)
if p_name == 'file': # ARGHHHHHHHHHHH TODO FIXME
p_vals = (p_vals[0])
if p_name == 'file':
p_vals = _resource_find(self, p_vals)
p_vals = (p_vals[0]) # ARGHHHHHHHHHHH TODO FIX THE FILE PROP
if len(p_vals) == 1:
setattr(w, p_name, p_vals[0])
else:
@ -202,6 +220,7 @@ def _item_generate(self, parent_widget, parent_item, item_name, item_data):
def _params_list_parse(mod, params):
return [ _param_parse(mod, p) for p in params ]
def _param_parse(mod, p_value):
if isinstance(p_value, basestring):
if p_value.startswith('ELM_'):
@ -210,14 +229,17 @@ def _param_parse(mod, p_value):
return enum_val
return p_value
def _property_modify_cb(obj, self, widget_name, prop_name, values):
w = self._widgets[widget_name]
if prop_name == 'visibility': # TODO implement this property in Evas.Object
w.show() if values[0] is True else w.hide()
else:
if prop_name == 'file': # ARGHHHHHHHHHHH TODO FIXME
values = (values[0])
if prop_name == 'file':
values = _resource_find(self, values)
values = (values[0]) # ARGHHHHHHHHHHH TODO FIX THE FILE PROP
setattr(w, prop_name, values[0] if len(values) == 1 else values)
def _widget_create_cb(obj, self, widget_name, parent_name):
_widget_generate(self, widget_name, parent_name)

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 KiB

View File

@ -10,7 +10,8 @@
{
"Images":
{
"logo":"/home/yakov/egui/examples/logo.png"
"tux":"images/tux.png",
"pyefl_logo":"images/logo.png"
},
"Eo_Callbacks":
{
@ -164,7 +165,10 @@
"elm_button5":[1, 1, 1, 1],
"elm_button6":[0, 2, 1, 1],
"elm_button8":[1, 2, 1, 1],
"elm_button9":[0, 3, 2, 1]
"elm_button9":[0, 3, 2, 1],
"elm_image1":[0, 4, 1, 2],
"elm_button10":[1, 4, 1, 1],
"elm_button11":[1, 5, 1, 1]
}
},
"elm_button2":
@ -454,6 +458,61 @@
"Evas.Object.size":[60, 30],
"Elm_Widget.part_text":[null, "I'm a dialog window <br> I should move with my parent"]
}
},
"elm_image1":
{
"Desc":
{
"parent":"elm_table1",
"class":"Elm_Image"
},
"Properties":
{
"Evas.Object.size_hint_weight":[1, 1],
"Evas.Object.visibility":[true],
"Efl.File.file":["tux", null],
"Evas.Object.size_hint_align":[-1, -1],
"Evas.Object.size":[100, 100],
"Evas.Object.size_hint_min":[100, 100]
}
},
"elm_button10":
{
"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, "<- tux"]
},
"Callbacks":
{
"clicked":["Modify", "elm_image1", "Efl.File.file", ["tux", null]]
}
},
"elm_button11":
{
"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, "<- pyefl"]
},
"Callbacks":
{
"clicked":["Modify", "elm_image1", "Efl.File.file", ["pyefl_logo", null]]
}
}
}
}

View File

@ -35,7 +35,7 @@ def erigo_clicked(obj):
# Test from json string
# json = open(json_file).read()
# egui = MyGui(json_string=json, verbose=True)
# egui = MyGui(json_string=json, resources_path=prj_path, verbose=True)
egui.elm_label1.text = 'GUI Generated in %.5f seconds' % \
(time.time() - start_time)