Pyolian: new API eolian_unit_state_get

This commit is contained in:
Davide Andreoli 2018-03-17 10:19:28 +01:00
parent 0a00e4cca1
commit 6ef5f30a85
3 changed files with 19 additions and 3 deletions

View File

@ -319,10 +319,15 @@ class Eolian_Unit(EolianBaseObject):
def children(self):
return Iterator(Eolian_Unit, lib.eolian_unit_children_get(self._obj))
@property
@cached_property
def file(self):
return _str_to_py(lib.eolian_unit_file_get(self._obj))
@cached_property
def state(self):
c_state = lib.eolian_unit_state_get(self._obj)
return Eolian_State(c_state) if c_state else None
@property
def objects(self):
return Iterator(Object, lib.eolian_unit_objects_get(self._obj))
@ -399,8 +404,10 @@ class Eolian_Unit(EolianBaseObject):
class Eolian_State(Eolian_Unit):
def __init__(self):
self._obj = lib.eolian_state_new() # Eolian_State *
def __init__(self, c_state=None):
if c_state is None:
c_state = lib.eolian_state_new() # Eolian_State *
EolianBaseObject.__init__(self, c_state)
def __del__(self):
if not _already_halted: # do not free after eolian_shutdown

View File

@ -130,6 +130,10 @@ lib.eolian_state_enums_by_file_get.restype = c_void_p
lib.eolian_unit_children_get.argtypes = [c_void_p,]
lib.eolian_unit_children_get.restype = c_void_p
# EAPI const Eolian_State *eolian_unit_state_get(const Eolian_Unit *unit);
lib.eolian_unit_state_get.argtypes = [c_void_p,]
lib.eolian_unit_state_get.restype = c_void_p
# EAPI const char *eolian_unit_file_get(const Eolian_Unit *unit);
lib.eolian_unit_file_get.argtypes = [c_void_p,]
lib.eolian_unit_file_get.restype = c_char_p

View File

@ -87,6 +87,11 @@ class TestEolianState(unittest.TestCase):
class TestEolianUnit(unittest.TestCase):
def test_unit_get(self):
unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
self.assertIsInstance(unit.state, eolian.Eolian_State)
self.assertEqual(unit.state, eolian_db)
def test_file_get(self):
unit = eolian_db.unit_by_file_get('efl_ui_win.eo')
self.assertIsInstance(unit, eolian.Eolian_Unit)