Pyolian: new API eolian_object_unit_get
authorDave Andreoli <dave@gurumeditation.it>
Sat, 17 Mar 2018 09:01:24 +0000 (10:01 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 10 Apr 2018 11:21:58 +0000 (20:21 +0900)
Also implemented __repr__ for Unit and State

src/scripts/pyolian/eolian.py
src/scripts/pyolian/eolian_lib.py
src/scripts/pyolian/test_eolian.py

index 56b7913..580cc1f 100644 (file)
@@ -312,6 +312,8 @@ class EolianBaseObject(object):
 ###  Main Eolian Unit  ########################################################
 
 class Eolian_Unit(EolianBaseObject):
+    def __repr__(self):
+        return "<eolian.Eolian_Unit '{0.file}'>".format(self)
 
     @property
     def children(self):
@@ -404,6 +406,9 @@ class Eolian_State(Eolian_Unit):
         if not _already_halted:  # do not free after eolian_shutdown
             lib.eolian_state_free(self._obj)
 
+    def __repr__(self):
+        return "<eolian.Eolian_State, %d units loaded>" % len(list(self.units))
+
     def file_parse(self, filepath):
         c_unit = lib.eolian_state_file_parse(self._obj, _str_to_bytes(filepath))
         return Eolian_Unit(c_unit) if c_unit else None
@@ -573,6 +578,11 @@ class Object(EolianBaseObject):
         return "<eolian.Object '{0.name}', {0.type!s}>".format(self)
 
     @cached_property
+    def unit(self):
+        c_unit = lib.eolian_object_unit_get(self._obj)
+        return Eolian_Unit(c_unit) if c_unit else None
+
+    @cached_property
     def name(self):
         return _str_to_py(lib.eolian_object_name_get(self._obj))
 
index 4b79265..8d3f830 100644 (file)
@@ -196,6 +196,10 @@ lib.eolian_unit_globals_get.restype = c_void_p
 lib.eolian_object_type_get.argtypes = [c_void_p]
 lib.eolian_object_type_get.restype = c_int
 
+# EAPI const Eolian_Unit *eolian_object_unit_get(const Eolian_Object *obj);
+lib.eolian_object_unit_get.argtypes = [c_void_p,]
+lib.eolian_object_unit_get.restype = c_void_p
+
 # EAPI const char *eolian_object_file_get(const Eolian_Object *obj);
 lib.eolian_object_file_get.argtypes = [c_void_p]
 lib.eolian_object_file_get.restype = c_char_p
index 5ce260e..39936bb 100755 (executable)
@@ -270,6 +270,11 @@ class TestEolianObject(unittest.TestCase):
         self.assertIsInstance(obj, eolian.Class)
         self.assertEqual(obj.name, 'Efl.Ui.Frame')
 
+    def test_unit(self):
+        obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
+        self.assertIsInstance(obj.unit, eolian.Eolian_Unit)
+        self.assertEqual(obj.unit.file, 'efl_ui_frame.eo')
+
     def test_name(self):
         obj = eolian_db.object_by_name_get('Efl.Ui.Frame')
         self.assertEqual(obj.name, 'Efl.Ui.Frame')