summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-04-11 23:07:13 +0200
committerDave Andreoli <dave@gurumeditation.it>2016-04-11 23:07:13 +0200
commit810badf67f104e2e82ad0179d2213e6f9d517381 (patch)
treed1eaea60f4c522ad3b0f8d71d3ad561baed4d851
parent04b846b0f9e5396b7ca847d75a37d60e0d8dab40 (diff)
Clean up a bit the generator
-rw-r--r--.gitignore3
-rw-r--r--Makefile5
-rw-r--r--pyolian/generator.py139
-rw-r--r--tests/test_ecore.py4
-rw-r--r--tests/test_elm.py25
5 files changed, 82 insertions, 94 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..891d01c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
1build/
2dist/
3*.pyc
diff --git a/Makefile b/Makefile
index 2c41d4a..4cdd86c 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,11 @@
19PY = python 19PY = python
20 20
21 21
22.PHONY: generate
23generate:
24 $(PY) setup.py generate
25
26
22.PHONY: build 27.PHONY: build
23build: 28build:
24 $(PY) setup.py build 29 $(PY) setup.py build
diff --git a/pyolian/generator.py b/pyolian/generator.py
index bdf4cf9..aa55ef8 100644
--- a/pyolian/generator.py
+++ b/pyolian/generator.py
@@ -26,7 +26,14 @@ def uncapitalize(s):
26 26
27EO_FILES = [ 27EO_FILES = [
28('ecore_mainloop.eo', 'ecore'), 28('ecore_mainloop.eo', 'ecore'),
29('ecore_timer.eo', 'ecore'), 29# ('ecore_timer.eo', 'ecore'), # double constructor & custom event system
30# ('ecore_mainloop.eo', 'ecore'),
31# ('ecore_timer.eo', 'ecore'),
32# ('efl_gfx_base.eo', 'gfx'), # should be efl/gfx
33('evas_object.eo', 'evas'),
34('elm_widget.eo', 'elm'),
35# ('elm_win.eo', 'elm'),
36# ('elm_label.eo', 'elm'),
30] 37]
31 38
32### Templates ### 39### Templates ###
@@ -140,6 +147,19 @@ MANUAL_CONSTRUCTORS = {
140 147
141MANUAL_EXCLUDES = [ 148MANUAL_EXCLUDES = [
142'ecore_mainloop_select_func_get', # type @extern Ecore_Select_Function: __undefined_type; 149'ecore_mainloop_select_func_get', # type @extern Ecore_Select_Function: __undefined_type;
150'evas_obj_clipees_get', # Eina_list*
151'evas_obj_map_get', # const Evas_Map *
152'evas_obj_smart_data_get', # void *
153'elm_obj_widget_cursor_add','elm_obj_widget_cursor_del', # Elm_Cursor *
154'elm_obj_widget_event', # void *
155'elm_obj_widget_event_callback_add', # Elm_Event_Cb
156'elm_obj_widget_event_callback_del', # Elm_Event_Cb
157'elm_obj_widget_event_propagate', # void *
158'elm_obj_widget_focus_highlight_geometry_get', # 'Evas_Coord * THIS IS STRANGE! WRONG EO FILE?
159'elm_obj_widget_focus_list_direction_get', # const Eina_List *
160'elm_obj_widget_focus_list_next_get', # const Eina_List *
161
162
143# 'elm_obj_widget_event_callback_del', # return void * 163# 'elm_obj_widget_event_callback_del', # return void *
144# 'elm_obj_win_illume_command_send', # eolian.Type 'Elm.Illume_Command' 164# 'elm_obj_win_illume_command_send', # eolian.Type 'Elm.Illume_Command'
145# 'evas_obj_clipees_get', # return Eina_List * 165# 'evas_obj_clipees_get', # return Eina_List *
@@ -175,13 +195,6 @@ class Generator(object):
175 195
176 for eo_file, dest_module in EO_FILES: 196 for eo_file, dest_module in EO_FILES:
177 ret = self.generate_eo_file(eo_file, dest_module) 197 ret = self.generate_eo_file(eo_file, dest_module)
178 # ret = self.generate_eo_file('ecore_mainloop.eo', 'ecore')
179 # ret = self.generate_eo_file('ecore_timer.eo', 'ecore')
180 # ret = self.generate_eo_file('efl_gfx_base.eo', 'gfx') # should be efl/gfx
181 # ret = self.generate_eo_file('evas_object.eo', 'evas')
182 # ret = self.generate_eo_file('elm_widget.eo', 'elm')
183 # ret = self.generate_eo_file('elm_win.eo', 'elm')
184 # ret = self.generate_eo_file('elm_label.eo', 'elm')
185 198
186 INF('generation complete') 199 INF('generation complete')
187 return ret 200 return ret
@@ -317,7 +330,8 @@ class Generator(object):
317 if func.is_constructor: 330 if func.is_constructor:
318 continue 331 continue
319 332
320 self.emit_function(klass, func, eolian.EOLIAN_METHOD, f, headerf) 333 # self.emit_function(klass, func, eolian.EOLIAN_METHOD, f, headerf)
334 self.emit_method(klass, func, f, headerf)
321 335
322 # header file 336 # header file
323 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_METHOD))) 337 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_METHOD)))
@@ -352,8 +366,7 @@ class Generator(object):
352 366
353 # header file 367 # header file
354 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_PROP_GET))) 368 # headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_PROP_GET)))
355 369
356
357 def emit_constructor(self, klass, f, headerf): 370 def emit_constructor(self, klass, f, headerf):
358 std = True 371 std = True
359 ctors_py_code = '' 372 ctors_py_code = ''
@@ -378,46 +391,51 @@ class Generator(object):
378 else: 391 else:
379 ERR('cannot find manual constructor for class', klass.full_name) 392 ERR('cannot find manual constructor for class', klass.full_name)
380 393
381 def emit_function(self, klass, func, ftype, f, headerf): 394 def emit_method(self, klass, func, f, headerf):
382 # header file 395 VRB('gen method: {}.{}()'.format(klass.full_name, func.name))
383 headerf.write('{};\n'.format(func.full_c_define_get(ftype)))
384
385 # function name (for setter and getters)
386 if ftype == eolian.EOLIAN_PROP_GET:
387 name = func.name + '_get'
388 name2 = 'prop get'
389 elif ftype == eolian.EOLIAN_PROP_SET:
390 name = func.name + '_set'
391 name2 = 'prop set'
392 else:
393 name = func.name
394 name2 = 'method'
395 396
396 VRB('gen {}: {}.{}()'.format(name2, klass.full_name, name)) 397 # header file
398 headerf.write('{};\n'.format(func.full_c_define_get(eolian.EOLIAN_METHOD)))
397 399
398 # split in and out params in 2 lists 400 # split in and out params in 2 lists
399 in_pars = ['self'] 401 in_pars = ['self']
400 out_pars = [] 402 out_pars = []
401 if ftype == eolian.EOLIAN_PROP_GET: 403 for p in func.parameters:
402 for v in func.getter_values: 404 print(p)
403 out_pars.append(_type_conv(v.type, v.name, False)) 405 if p.direction == eolian.EOLIAN_IN_PARAM:
404 elif ftype == eolian.EOLIAN_PROP_SET: 406 in_pars.append(p.name)
405 for v in func.setter_values: 407 elif p.direction == eolian.EOLIAN_OUT_PARAM:
406 in_pars.append(v.name) 408 out_pars.append(_type_conv(p.type, p.name, False))
407 else:
408 for p in func.parameters:
409 if p.direction == eolian.EOLIAN_IN_PARAM:
410 in_pars.append(p.name)
411 elif p.direction == eolian.EOLIAN_OUT_PARAM:
412 out_pars.append(_type_conv(p.type, p.name, False))
413 409
414 # function definition (+ docs) 410 # function definition (+ docs)
415 in_pars = ', '.join(in_pars) 411 in_pars = ', '.join(in_pars)
416 docs = 'TODO ' + func.full_c_define_get(ftype) # TODO 412 docs = 'TODO ' + func.full_c_define_get(eolian.EOLIAN_METHOD) # TODO
417 f.write(CLASS_METHOD.format(name, in_pars, docs)) 413 f.write(CLASS_METHOD.format(func.name, in_pars, docs))
414
418 415
419 # c function call (+ allocs) 416 # c function call (+ allocs)
420 self.emit_c_function_call(func, ftype, f) 417 params = ['self._obj']
418 allocs = []
419 for p in func.parameters:
420 direction = p.direction
421 ptype = p.type
422 if direction == eolian.EOLIAN_IN_PARAM:
423 params.append(_type_conv(ptype, p.name, True))
424 elif direction == eolian.EOLIAN_OUT_PARAM:
425 allocs.append('{0} = ffi.new("{1}")'.format(p.name, ptype.c_type))
426 params.append('&' + p.name)
427 else:
428 WRN('Unsupported INOUT param direction')
429
430 for a in allocs:
431 f.write(' ' + a + '\n')
432
433 params = ', '.join(params)
434 ret = ''
435 if func.return_type_get(eolian.EOLIAN_METHOD):# or ftype == eolian.EOLIAN_PROP_GET:
436 ret = 'ret = '
437
438 f.write(' {}lib.{}({})\n'.format(ret, func.full_c_name_get(eolian.EOLIAN_METHOD), params))
421 439
422 # return a tuple with all the out args 440 # return a tuple with all the out args
423 if len(out_pars) > 1: 441 if len(out_pars) > 1:
@@ -431,11 +449,12 @@ class Generator(object):
431 return 449 return
432 450
433 # or return the value returned from the c call (converted) 451 # or return the value returned from the c call (converted)
434 rtype = func.return_type_get(ftype) 452 rtype = func.return_type_get(eolian.EOLIAN_METHOD)
435 if rtype is not None: 453 if rtype is not None:
436 f.write(' return {}\n'.format(_type_conv(rtype, 'ret', False))) 454 f.write(' return {}\n'.format(_type_conv(rtype, 'ret', False)))
437 455
438 def emit_getter(self, klass, func, f, headerf): 456 def emit_getter(self, klass, func, f, headerf):
457
439 VRB('gen prop get: {}.{}_get()'.format(klass.full_name, func.name)) 458 VRB('gen prop get: {}.{}_get()'.format(klass.full_name, func.name))
440 vals = list(func.getter_values) 459 vals = list(func.getter_values)
441 460
@@ -519,42 +538,6 @@ class Generator(object):
519 if rtype: 538 if rtype:
520 f.write(' return {}\n'.format(_type_conv(rtype, '_ret_', False))) 539 f.write(' return {}\n'.format(_type_conv(rtype, '_ret_', False)))
521 540
522 def emit_c_function_call(self, func, ftype, f, indent=8):
523 indent = ' ' * indent
524 params = ['self._obj']
525 allocs = []
526
527 ###################################################################
528 ###################################################################
529 # SIAMO QUI
530 # sistemare i parametri per i getter e setter
531 ###################################################################
532 ###################################################################
533 if ftype == eolian.EOLIAN_METHOD: pars = func.parameters
534 elif ftype == eolian.EOLIAN_PROP_GET: pars = func.getter_values
535 elif ftype == eolian.EOLIAN_PROP_SET: pars = func.setter_values
536 else: raise RuntimeError('Unsupported function type: %d' % ftype)
537
538 for p in pars:
539 direction = p.direction
540 ptype = p.type
541 if direction == eolian.EOLIAN_IN_PARAM:
542 params.append(_type_conv(ptype, p.name, True))
543 elif direction == eolian.EOLIAN_OUT_PARAM:
544 allocs.append('{0} = ffi.new("{1}")'.format(p.name, ptype.c_type))
545 params.append('&' + p.name)
546 else:
547 WRN('Unsupported INOUT param direction')
548
549 for a in allocs:
550 f.write(indent + a + '\n')
551
552 params = ', '.join(params)
553 ret = ''
554 if func.return_type_get(ftype):# or ftype == eolian.EOLIAN_PROP_GET:
555 ret = 'ret = '
556
557 f.write(indent + '{}lib.{}({})\n'.format(ret, func.full_c_name_get(ftype), params))
558 541
559def _type_conv(ty, expr, isin): 542def _type_conv(ty, expr, isin):
560 543
diff --git a/tests/test_ecore.py b/tests/test_ecore.py
index 94d4ae2..7350141 100644
--- a/tests/test_ecore.py
+++ b/tests/test_ecore.py
@@ -1,6 +1,6 @@
1 1
2from efl2 import ecore 2from efl2 import ecore
3from efl2.ecore import Timer 3# from efl2.ecore import Timer
4 4
5 5
6print("starting ecore ml :)") 6print("starting ecore ml :)")
@@ -17,7 +17,7 @@ def mycb2():
17 # return ecore.ECORE_CALLBACK_RENEW 17 # return ecore.ECORE_CALLBACK_RENEW
18 18
19# t = Timer(5.0, mycb, 567, asd='AsD') 19# t = Timer(5.0, mycb, 567, asd='AsD')
20t2 = Timer(1.0, mycb2) 20# t2 = Timer(1.0, mycb2)
21 21
22ml = ecore.Ecore_Mainloop() 22ml = ecore.Ecore_Mainloop()
23print(ml) 23print(ml)
diff --git a/tests/test_elm.py b/tests/test_elm.py
index 77a3b07..bf702e8 100644
--- a/tests/test_elm.py
+++ b/tests/test_elm.py
@@ -21,22 +21,19 @@ from efl2 import elementary as elm, __version__
21# 21#
22 22
23 23
24def my_timer_cb(): 24# def my_timer_cb():
25 global lb 25 # global lb
26 print("t") 26 # print("t")
27 if lb: 27 # if lb:
28 print("TIMER") 28 # print("TIMER")
29 lb.delete() 29 # lb.delete()
30 lb = None 30 # lb = None
31 return ecore.ECORE_CALLBACK_RENEW 31 # return ecore.ECORE_CALLBACK_RENEW
32 32
33 33
34# t = Timer(5.0, mycb, 567, asd='AsD') 34# t = Timer(5.0, mycb, 567, asd='AsD')
35t2 = efl.ecore.Timer(3.0, my_timer_cb) 35# t2 = efl.ecore.Timer(3.0, my_timer_cb)
36 36
37# ecore.main_loop_begin()
38
39# ml = ecore.Mainloop()
40 37
41def mycb3(*args): 38def mycb3(*args):
42 print("CB!!!!!!!!!!!!" + str(args)) 39 print("CB!!!!!!!!!!!!" + str(args))
@@ -50,8 +47,8 @@ if __name__ == '__main__':
50 title = 'Python EFL version %s (on python: %s)' % ( 47 title = 'Python EFL version %s (on python: %s)' % (
51 __version__, platform.python_version()) 48 __version__, platform.python_version())
52 49
53 # win = elm.Win('pyefl-test', elm.ELM_WIN_BASIC) 50 win = elm.Win('pyefl-test', elm.ELM_WIN_BASIC)
54 win = elm.Win_Standard(None, title='pyefl-test') 51 # win = elm.Win_Standard(None, title='pyefl-test')
55 win.title = "asdasd àèìòù ね の は " * 3 52 win.title = "asdasd àèìòù ね の は " * 3
56 # print("** " + win.title) 53 # print("** " + win.title)
57 # print("** " + str(type(win.title))) 54 # print("** " + str(type(win.title)))