summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-21 10:38:24 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-21 10:38:24 +0200
commit8a0dccbf227d0ba211a0d66ee4a2882df01ead44 (patch)
treecac0a39a999e95dd474a7463f8499fe2309f6c35
parent1940b51f156273f3faecde6a43c0a8b2fdf8d409 (diff)
Evas: Optimize Smart methods
The methods are now checked on __init__. If a method is not initially defined the calls to it will be skipped entirely. The methods can be rebound later in runtime by initially providing an empty (pass) method.
-rw-r--r--efl/evas/efl.evas_object_smart.pxi267
1 files changed, 110 insertions, 157 deletions
diff --git a/efl/evas/efl.evas_object_smart.pxi b/efl/evas/efl.evas_object_smart.pxi
index a27e05b..087841e 100644
--- a/efl/evas/efl.evas_object_smart.pxi
+++ b/efl/evas/efl.evas_object_smart.pxi
@@ -106,9 +106,6 @@ cdef void _smart_object_delete(Evas_Object *o) with gil:
106 return 106 return
107 cls = <Smart>tmp 107 cls = <Smart>tmp
108 108
109 if "delete" not in cls.__class__.__dict__:
110 return
111
112 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 109 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
113 if tmp == NULL: 110 if tmp == NULL:
114 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 111 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
@@ -134,9 +131,6 @@ cdef void _smart_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) with gi
134 return 131 return
135 cls = <Smart>tmp 132 cls = <Smart>tmp
136 133
137 if "move" not in cls.__class__.__dict__:
138 return
139
140 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 134 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
141 if tmp == NULL: 135 if tmp == NULL:
142 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 136 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
@@ -315,9 +309,6 @@ cdef void _smart_object_calculate(Evas_Object *o) with gil:
315 return 309 return
316 cls = <Smart>tmp 310 cls = <Smart>tmp
317 311
318 if "calculate" not in cls.__class__.__dict__:
319 return
320
321 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 312 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
322 if tmp == NULL: 313 if tmp == NULL:
323 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 314 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
@@ -344,9 +335,6 @@ cdef void _smart_object_member_add(Evas_Object *o, Evas_Object *clip) with gil:
344 return 335 return
345 cls = <Smart>tmp 336 cls = <Smart>tmp
346 337
347 if "member_add" not in cls.__class__.__dict__:
348 return
349
350 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 338 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
351 if tmp == NULL: 339 if tmp == NULL:
352 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 340 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
@@ -375,9 +363,6 @@ cdef void _smart_object_member_del(Evas_Object *o, Evas_Object *clip) with gil:
375 return 363 return
376 cls = <Smart>tmp 364 cls = <Smart>tmp
377 365
378 if "member_del" not in cls.__class__.__dict__:
379 return
380
381 eo_do_ret(o, tmp, eo_key_data_get("python-eo")) 366 eo_do_ret(o, tmp, eo_key_data_get("python-eo"))
382 if tmp == NULL: 367 if tmp == NULL:
383 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL) 368 EINA_LOG_DOM_WARN(PY_EFL_EVAS_LOG_DOMAIN, "obj is NULL!", NULL)
@@ -464,29 +449,70 @@ cdef void _smart_callback(void *data, Evas_Object *o, void *event_info) with gil
464cdef class Smart(object): 449cdef class Smart(object):
465 450
466 """ 451 """
467 An abstract class with callback methods. 452 An abstract class that defines the behavior of the SmartObject.
468 453
469 :param clipped: Make this Smart use a clipped class, ignoring the provided 454 :param clipped: Make this Smart use a clipped class, ignoring the provided
470 callback methods. 455 callback methods, except :meth:`calculate` and :meth:`resize`.
471 :type clipped: bool 456 :type clipped: bool
472 457
473 .. 458 .. versionadded:: 1.14
474 note::
475 You should never instantiate the Smart base class directly,
476 but inherit and implement methods, then instantiate this new subclass.
477 459
478 .. note:: 460 .. staticmethod:: delete(obj)
479 Do not call your parent on methods you want to replace the behavior 461
480 instead of extending it. For example, some methods have default 462 Called in order to remove object from canvas and deallocate its resources.
481 implementation, you may want to remove and replace it with something 463
482 else. 464 Usually you delete object's children here.
465
466 .. staticmethod:: member_add(obj, Object child)
467
468 Called when children is added to object.
469
470 .. staticmethod:: member_del(obj, Object child)
471
472 Called when children is removed from object.
473
474 .. staticmethod:: move(obj, int x, int y)
475
476 Called in order to move object to given position.
477
478 Usually you move children here.
479
480 .. staticmethod:: resize(obj, int w, int h)
481
482 Called in order to resize object.
483
484 .. staticmethod:: show(obj)
485
486 Called in order to show the given element.
487
488 Usually you call the same function on children.
489
490 .. staticmethod:: hide(obj)
491
492 Called in order to hide the given element.
493
494 Usually you call the same function on children.
495
496 .. staticmethod:: color_set(obj, int r, int g, int b, int a)
497
498 Called in order to change object color.
499
500 .. staticmethod:: clip_set(obj, Eo clip)
501
502 Called in order to limit object's visible area.
503
504 .. staticmethod:: clip_unset(obj)
505
506 Called in order to unlimit object's visible area.
507
508 .. staticmethod:: calculate(obj)
509
510 Called before object is used for rendering and it is marked as dirty/changed with :py:func:`changed`.
483 511
484 .. versionadded:: 1.14
485 """ 512 """
486 513
487 def __cinit__(self, Smart parent=None, bint clipped=False, callback_descriptions=[], *args, **kwargs): 514 def __cinit__(self, Smart parent=None, bint clipped=False, callback_descriptions=[], *args, **kwargs):
488 cdef: 515 cdef Evas_Smart_Class *cls_def
489 Evas_Smart_Class *cls_def
490 516
491 cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class)) 517 cls_def = <Evas_Smart_Class*>PyMem_Malloc(sizeof(Evas_Smart_Class))
492 if cls_def == NULL: 518 if cls_def == NULL:
@@ -500,19 +526,65 @@ cdef class Smart(object):
500 526
501 if clipped: 527 if clipped:
502 evas_object_smart_clipped_smart_set(cls_def) 528 evas_object_smart_clipped_smart_set(cls_def)
529 # override add to NULL?
503 else: 530 else:
504 cls_def.add = NULL # use python constructor 531 cls_def.add = NULL # use python constructor
505 cls_def.delete = _smart_object_delete 532
506 cls_def.move = _smart_object_move 533 if "delete" in self.__class__.__dict__:
534 cls_def.delete = _smart_object_delete
535 else:
536 cls_def.delete = NULL
537
538 if "move" in self.__class__.__dict__:
539 cls_def.move = _smart_object_move
540 else:
541 cls_def.move = NULL
542
543 if "show" in self.__class__.__dict__:
544 cls_def.show = _smart_object_show
545 else:
546 cls_def.show = NULL
547
548 if "hide" in self.__class__.__dict__:
549 cls_def.hide = _smart_object_hide
550 else:
551 cls_def.hide = NULL
552
553 if "color_set" in self.__class__.__dict__:
554 cls_def.color_set = _smart_object_color_set
555 else:
556 cls_def.color_set = NULL
557
558 if "clip_set" in self.__class__.__dict__:
559 cls_def.clip_set = _smart_object_clip_set
560 else:
561 cls_def.clip_set = NULL
562
563 if "clip_unset" in self.__class__.__dict__:
564 cls_def.clip_unset = _smart_object_clip_unset
565 else:
566 cls_def.clip_unset = NULL
567
568 if "member_add" in self.__class__.__dict__:
569 cls_def.member_add = _smart_object_member_add
570 else:
571 cls_def.member_add = NULL
572
573 if "member_del" in self.__class__.__dict__:
574 cls_def.member_del = _smart_object_member_del
575 else:
576 cls_def.member_del = NULL
577
578 if "resize" in self.__class__.__dict__:
507 cls_def.resize = _smart_object_resize 579 cls_def.resize = _smart_object_resize
508 cls_def.show = _smart_object_show 580 else:
509 cls_def.hide = _smart_object_hide 581 cls_def.resize = NULL
510 cls_def.color_set = _smart_object_color_set 582
511 cls_def.clip_set = _smart_object_clip_set 583 if "calculate" in self.__class__.__dict__:
512 cls_def.clip_unset = _smart_object_clip_unset
513 cls_def.calculate = _smart_object_calculate 584 cls_def.calculate = _smart_object_calculate
514 cls_def.member_add = _smart_object_member_add 585 else:
515 cls_def.member_del = _smart_object_member_del 586 cls_def.calculate = NULL
587
516 588
517 cls_def.parent = parent.cls_def if parent is not None else NULL 589 cls_def.parent = parent.cls_def if parent is not None else NULL
518 590
@@ -563,125 +635,6 @@ cdef class Smart(object):
563 635
564 return SmartCbDescription.create(desc) 636 return SmartCbDescription.create(desc)
565 637
566 @staticmethod
567 def delete(obj):
568 """
569 Called in order to remove object from canvas and deallocate its resources.
570
571 Usually you delete object's children here.
572
573 ..
574 *Default implementation deletes all registered children.*
575 """
576 pass
577
578 @staticmethod
579 def member_add(obj, Object child):
580 """
581 Called when children is added to object.
582
583 ..
584 *Default implementation does nothing.*
585 """
586 pass
587
588 @staticmethod
589 def member_del(obj, Object child):
590 """
591 Called when children is removed from object.
592
593 ..
594 *Default implementation does nothing.*
595 """
596 pass
597
598 @staticmethod
599 def move(obj, int x, int y):
600 """
601 Called in order to move object to given position.
602
603 Usually you move children here.
604
605 ..
606 *Default implementation calculates offset and move registered children
607 by it.*
608 """
609 pass
610
611 @staticmethod
612 def resize(obj, int w, int h):
613 """
614 Called in order to resize object.
615
616 ..
617 *No default implementation.*
618 """
619 raise NotImplementedError("%s.resize(w, h) not implemented." % obj.__class__.__name__)
620
621 @staticmethod
622 def show(obj):
623 """
624 Called in order to show the given element.
625
626 Usually you call the same function on children.
627
628 ..
629 *No default implementation.*
630 """
631 raise NotImplementedError("%s.show() not implemented." % obj.__class__.__name__)
632
633 @staticmethod
634 def hide(obj):
635 """
636 Called in order to hide the given element.
637
638 Usually you call the same function on children.
639
640 ..
641 *No default implementation.*
642 """
643 raise NotImplementedError("%s.hide() not implemented." % obj.__class__.__name__)
644
645 @staticmethod
646 def color_set(obj, int r, int g, int b, int a):
647 """
648 Called in order to change object color.
649
650 ..
651 *No default implementation.*
652 """
653 raise NotImplementedError("%s.color_set(r, g, b, a) not implemented." % obj.__class__.__name__)
654
655 @staticmethod
656 def clip_set(obj, Object clip):
657 """
658 Called in order to limit object's visible area.
659
660 ..
661 *No default implementation.*
662 """
663 raise NotImplementedError("%s.clip_set(object) not implemented." % obj.__class__.__name__)
664
665 @staticmethod
666 def clip_unset(obj):
667 """
668 Called in order to unlimit object's visible area.
669
670 ..
671 *No default implementation.*
672 """
673 raise NotImplementedError("%s.clip_unset() not implemented." % obj.__class__.__name__)
674
675 @staticmethod
676 def calculate(obj):
677 """
678 Called before object is used for rendering and it is marked as dirty/changed with :py:func:`changed`.
679
680 ..
681 *Default implementation does nothing.*
682 """
683 pass
684
685 638
686cdef class SmartObject(Object): 639cdef class SmartObject(Object):
687 640