|
|
@@ -6,11 +6,11 @@ from trackers import create_tracker
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
|
|
|
|
-class Widget(Positionable, Logger):
|
|
|
+class Area(Positionable, Logger):
|
|
|
"""
|
|
|
- Abstract class for widget implementations. A widget represents a 2D object
|
|
|
+ Abstract class for area implementations. A area represents a 2D object
|
|
|
on the screen in which gestures can occur. Handlers for a specific gesture
|
|
|
- type can be bound to a widget.
|
|
|
+ type can be bound to a area.
|
|
|
"""
|
|
|
__metaclass__ = ABCMeta
|
|
|
|
|
|
@@ -23,16 +23,16 @@ class Widget(Positionable, Logger):
|
|
|
# Map of gesture types to a list of handlers for that type
|
|
|
self.handlers = {}
|
|
|
|
|
|
- # Widget tree references
|
|
|
+ # Area tree references
|
|
|
self.parent = None
|
|
|
self.children = []
|
|
|
|
|
|
- def get_root_widget(self):
|
|
|
+ def get_root_area(self):
|
|
|
"""
|
|
|
- Traverse up in the widget tree to find the root widget.
|
|
|
+ Traverse up in the area tree to find the root area.
|
|
|
"""
|
|
|
if self.parent:
|
|
|
- return self.parent.get_root_widget()
|
|
|
+ return self.parent.get_root_area()
|
|
|
|
|
|
return self
|
|
|
|
|
|
@@ -40,17 +40,17 @@ class Widget(Positionable, Logger):
|
|
|
"""
|
|
|
Get the position relative to the screen.
|
|
|
"""
|
|
|
- root = self.get_root_widget()
|
|
|
+ root = self.get_root_area()
|
|
|
return root + self.get_offset(root)
|
|
|
|
|
|
def get_offset(self, offset_parent=None):
|
|
|
"""
|
|
|
Get the position relative to an offset parent. If no offset parent is
|
|
|
- specified, the position relative to the root widget is returned. The
|
|
|
- position of the root widget itself is (0, 0).
|
|
|
+ specified, the position relative to the root area is returned. The
|
|
|
+ position of the root area itself is (0, 0).
|
|
|
"""
|
|
|
if not offset_parent:
|
|
|
- offset_parent = self.get_root_widget()
|
|
|
+ offset_parent = self.get_root_area()
|
|
|
|
|
|
if not self.parent:
|
|
|
if offset_parent is self:
|
|
|
@@ -65,29 +65,29 @@ class Widget(Positionable, Logger):
|
|
|
|
|
|
return x - ox, y - oy
|
|
|
|
|
|
- def add_widget(self, widget):
|
|
|
+ def add_area(self, area):
|
|
|
"""
|
|
|
- Add a new child widget.
|
|
|
+ Add a new child area.
|
|
|
"""
|
|
|
- self.children.append(widget)
|
|
|
- widget.set_parent(self)
|
|
|
+ self.children.append(area)
|
|
|
+ area.set_parent(self)
|
|
|
|
|
|
- def remove_widget(self, widget):
|
|
|
+ def remove_area(self, area):
|
|
|
"""
|
|
|
- Remove a child widget.
|
|
|
+ Remove a child area.
|
|
|
"""
|
|
|
- self.children.remove(widget)
|
|
|
- widget.set_parent(None)
|
|
|
+ self.children.remove(area)
|
|
|
+ area.set_parent(None)
|
|
|
|
|
|
- def set_parent(self, widget):
|
|
|
+ def set_parent(self, area):
|
|
|
"""
|
|
|
- Set a new parent widget. If a parent widget has already been assigned,
|
|
|
- remove the widget from that parent first.
|
|
|
+ Set a new parent area. If a parent area has already been assigned,
|
|
|
+ remove the area from that parent first.
|
|
|
"""
|
|
|
- if widget and self.parent:
|
|
|
- self.parent.remove_widget(self)
|
|
|
+ if area and self.parent:
|
|
|
+ self.parent.remove_area(self)
|
|
|
|
|
|
- self.parent = widget
|
|
|
+ self.parent = area
|
|
|
|
|
|
def unbind(self, gesture_type, handler=None):
|
|
|
"""
|
|
|
@@ -154,9 +154,9 @@ class Widget(Positionable, Logger):
|
|
|
def __getattr__(self, name):
|
|
|
"""
|
|
|
Allow calls like:
|
|
|
- widget.on_gesture(...)
|
|
|
+ area.on_gesture(...)
|
|
|
instead of:
|
|
|
- widget.bind('gesture', ...)
|
|
|
+ area.bind('gesture', ...)
|
|
|
"""
|
|
|
if len(name) < 4 or name[:3] != 'on_':
|
|
|
raise AttributeError("'%s' has no attribute '%s'"
|
|
|
@@ -167,14 +167,14 @@ class Widget(Positionable, Logger):
|
|
|
@abstractmethod
|
|
|
def contains_event(self, event):
|
|
|
"""
|
|
|
- Check if the coordinates of an event are contained within this widget.
|
|
|
+ Check if the coordinates of an event are contained within this area.
|
|
|
"""
|
|
|
raise NotImplementedError
|
|
|
|
|
|
def delegate_event(self, event):
|
|
|
"""
|
|
|
- Delegate a triggered event to all child widgets. If a child stops
|
|
|
- propagation, return so that its siblings and the parent widget will not
|
|
|
+ Delegate a triggered event to all child areas. If a child stops
|
|
|
+ propagation, return so that its siblings and the parent area will not
|
|
|
delegate the event to their trackers.
|
|
|
"""
|
|
|
child_found = False
|
|
|
@@ -182,7 +182,7 @@ class Widget(Positionable, Logger):
|
|
|
if self.children:
|
|
|
event.set_offset(self.get_offset())
|
|
|
|
|
|
- # Delegate to children in reverse order because widgets that are
|
|
|
+ # Delegate to children in reverse order because areas that are
|
|
|
# added later, should be placed over previously added siblings
|
|
|
for child in reversed(self.children):
|
|
|
if child.contains_event(event):
|