summaryrefslogtreecommitdiff
path: root/eorepo/eodefault.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'eorepo/eodefault.pyx')
-rw-r--r--eorepo/eodefault.pyx149
1 files changed, 149 insertions, 0 deletions
diff --git a/eorepo/eodefault.pyx b/eorepo/eodefault.pyx
new file mode 100644
index 0000000..0842514
--- /dev/null
+++ b/eorepo/eodefault.pyx
@@ -0,0 +1,149 @@
1cimport eodefault
2import sys, operator
3
4
5##########################################################
6##
7## Wrapping for Elementary functions
8##
9
10PRIORITY_BEFORE = eodefault.EO_CALLBACK_PRIORITY_BEFORE
11PRIORITY_DEFAULT = eodefault.EO_CALLBACK_PRIORITY_DEFAULT
12PRIORITY_AFTER = eodefault.EO_CALLBACK_PRIORITY_AFTER
13CALLBACK_STOP = 12345
14
15#cdef const_char_ptr py_eo = <const_char_ptr>"python-ej"
16
17
18def init():
19 return bool(eodefault.eo_init())
20
21#########################################################
22
23cdef Eo *_eo_instance_get(EoDefault pyobj):
24 """
25if x is a Python object, (x is None) and (x is not None) are very efficient because they translate directly to C pointer comparisons.
26Whereas (x == None) and (x != None), or simply using x as a boolean value (as in if x: ...) will invoke Python operations and therefore be much slower.
27"""
28 if pyobj is not None:
29 return pyobj.eo
30 else:
31 NULL
32
33def pytext_to_utf8(text):
34
35 if not isinstance(text, basestring):
36 raise TypeError("Argument '%s' has incorrect type (expected %s, got %s)"%("text", "basestring", type(text).__name__))
37 utf8_data = ""
38
39 if isinstance(text, unicode):
40 utf8_data = text.encode('UTF-8')
41 elif isinstance(text, str):
42 utf8_data = text
43
44 return utf8_data
45
46#===========
47
48cdef class EoDefault:
49
50 PY_EO_NAME = "python-eo"
51 def __cinit__(self):
52 self.eo = NULL
53
54 def __dealloc__(self):
55 cdef Eo *eo
56 #self.print_func_name("__dealloc__base__")
57
58 eo = self.eo
59 if eo == NULL:
60 return
61 #eodefault._eo_instance_get(self)
62 eodefault.eo_do(eo, eodefault.EO_BASE_BASE_ID + eodefault.EO_BASE_SUB_ID_DATA_DEL, <const_char_ptr>EoDefault.PY_EO_NAME)
63 eodefault.eo_unref(eo)
64 self.eo = NULL
65
66 # eo_del()
67 def delete(self):
68 self.ref()
69 eodefault.eo_del(self.eo)
70
71 # eo_ref()
72 def ref(self):
73 eodefault.eo_ref(self.eo)
74 return self
75
76 def unref(self):
77 eodefault.eo_unref(self.eo)
78
79 # eo_ref_get()
80 def ref_get(self):
81 ref_count = <object>eodefault.eo_ref_get(self.eo)
82 return ref_count
83
84 # eo_parent_get()
85 def parent_get(self):
86 cdef Eo * parent
87 cdef void * data
88 parent = eodefault.eo_parent_get(self.eo)
89 eodefault.eo_do(parent, eodefault.EO_BASE_BASE_ID+eodefault.EO_BASE_SUB_ID_DATA_GET, <const_char_ptr>EoDefault.PY_EO_NAME, &data)
90 obj = <object>data
91 return obj
92
93 # eo_class_name_get()
94 def class_name_get(self):
95 name = eodefault.eo_class_name_get(eodefault.eo_class_get(self.eo))
96 return name
97
98 def name_get(self):
99 return self.name
100 #this func can be called only from this (c-styled)module
101 cdef int _eo_instance_set(self, Eo *eo):
102 assert self.eo == NULL, "Object must be clean"
103 self.eo = eo
104 self.name = self.__class__.__name__
105
106 # this func is main routine to add new object
107 # using default constructor
108 # and connect C and Py objects
109 cpdef _eo_instance_set2(self, unsigned long long _kl, EoDefault p):
110 cdef Eo_Class *kl = <Eo_Class*>_kl
111 cdef Eo *o = eodefault.eo_add(kl, eodefault._eo_instance_get(p))
112 self._eo_instance_set(o)
113 self._data_set(EoDefault.PY_EO_NAME, self)
114
115 # this func can be called outside(this c-styled module), because receives Eo* as long.
116 # it was added to be able to call eo_add_custom with different params
117 # and connect C and Py objects after it
118 def _eo_instance_set3(self, unsigned long long _eo):
119 cdef Eo *o = <Eo*>_eo
120 self._eo_instance_set(o)
121 self._data_set(EoDefault.PY_EO_NAME, self)
122
123 cdef int print_func_name(self, f_name):
124 print self.__class__, " :: ", f_name, " :: ", sys.getsizeof(self)
125
126#================================================================
127
128cdef Eina_Bool _object_callback(void *data, Eo *o,
129 Eo_Event_Description *desc, void *event_info):
130 cdef EoDefault obj
131 cdef void *p
132
133#passing "this" object to callback function
134 cdef void * c_py_obj
135 eodefault.eo_do(o, eodefault.EO_BASE_BASE_ID+eodefault.EO_BASE_SUB_ID_DATA_GET, <const_char_ptr>EoDefault.PY_EO_NAME, &c_py_obj)
136 py_obj = <object>c_py_obj
137
138 #cb_struct is tuple: (func, data)
139 cb_struct = <object>data
140 f = cb_struct[0]
141 cb_data = cb_struct[1]
142 res = f(py_obj, cb_data)
143
144 if res == CALLBACK_STOP:
145 return EINA_FALSE
146 else:
147 return EINA_TRUE
148
149