Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
9fe3fe36
Commit
9fe3fe36
authored
Jun 09, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup.
parent
a2f08297
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
+26
-16
src/widget.py
src/widget.py
+26
-16
No files found.
src/widget.py
View file @
9fe3fe36
...
@@ -17,8 +17,8 @@ class Widget(Positionable, Logger):
...
@@ -17,8 +17,8 @@ class Widget(Positionable, Logger):
def
__init__
(
self
,
x
=
None
,
y
=
None
):
def
__init__
(
self
,
x
=
None
,
y
=
None
):
Positionable
.
__init__
(
self
,
x
,
y
)
Positionable
.
__init__
(
self
,
x
,
y
)
#
Map of gesture types to gestur
e trackers
#
List of all activ
e trackers
self
.
trackers
=
{}
self
.
trackers
=
[]
# Map of gesture types to a list of handlers for that type
# Map of gesture types to a list of handlers for that type
self
.
handlers
=
{}
self
.
handlers
=
{}
...
@@ -109,17 +109,27 @@ class Widget(Positionable, Logger):
...
@@ -109,17 +109,27 @@ class Widget(Positionable, Logger):
# Remove handler list
# Remove handler list
del
self
.
handlers
[
gesture_type
][:]
del
self
.
handlers
[
gesture_type
][:]
tracker
=
self
.
find_tracker
(
gesture_type
)
# Check if any other handlers need the tracker
# Check if any other handlers need the tracker
for
gtype
in
self
.
trackers
[
gesture_type
]
.
gesture_types
:
for
gtype
in
tracker
.
gesture_types
:
if
gtype
in
self
.
handlers
:
if
gtype
in
self
.
handlers
:
return
return
# No more handlers are bound, remove unused tracker and handlers
# No more handlers are bound, remove unused tracker and handlers
del
self
.
trackers
[
gesture_type
]
self
.
trackers
.
remove
(
gesture_type
)
for
gtype
in
self
.
trackers
[
gesture_type
]
.
gesture_types
:
for
gtype
in
tracker
.
gesture_types
:
del
self
.
handlers
[
gtype
]
del
self
.
handlers
[
gtype
]
def
find_tracker
(
self
,
gesture_type
):
"""
Find a tracker that is tracking some gesture type.
"""
for
tracker
in
self
.
trackers
:
if
gesture_type
in
tracker
.
gesture_types
:
return
tracker
def
bind
(
self
,
gesture_type
,
handler
,
remove_existing
=
False
,
**
kwargs
):
def
bind
(
self
,
gesture_type
,
handler
,
remove_existing
=
False
,
**
kwargs
):
"""
"""
Bind a handler to the specified type of gesture. Create a tracker for
Bind a handler to the specified type of gesture. Create a tracker for
...
@@ -130,7 +140,7 @@ class Widget(Positionable, Logger):
...
@@ -130,7 +140,7 @@ class Widget(Positionable, Logger):
if
gesture_type
not
in
self
.
handlers
:
if
gesture_type
not
in
self
.
handlers
:
tracker
=
create_tracker
(
gesture_type
,
self
)
tracker
=
create_tracker
(
gesture_type
,
self
)
tracker
.
configure
(
**
kwargs
)
tracker
.
configure
(
**
kwargs
)
self
.
trackers
[
gesture_type
]
=
tracker
self
.
trackers
.
append
(
tracker
)
self
.
handlers
[
gesture_type
]
=
[]
self
.
handlers
[
gesture_type
]
=
[]
# Create empty tracker lists for all supported gestures
# Create empty tracker lists for all supported gestures
...
@@ -163,15 +173,15 @@ class Widget(Positionable, Logger):
...
@@ -163,15 +173,15 @@ class Widget(Positionable, Logger):
def
delegate_event
(
self
,
event
):
def
delegate_event
(
self
,
event
):
"""
"""
Delegate a triggered event to child widgets. If a child stops
Delegate a triggered event to all child widgets. If a child stops
propagation
propagation, return so that its siblings and the parent widget will not
delegate the event to their trackers.
"""
"""
if
not
self
.
children
:
self
.
propagate_event
(
event
)
else
:
event
.
set_offset
(
self
.
get_offset
())
child_found
=
False
child_found
=
False
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 widgets that are
# added later, should be placed over previously added siblings
# added later, should be placed over previously added siblings
for
child
in
reversed
(
self
.
children
):
for
child
in
reversed
(
self
.
children
):
...
@@ -180,13 +190,13 @@ class Widget(Positionable, Logger):
...
@@ -180,13 +190,13 @@ class Widget(Positionable, Logger):
child
.
delegate_event
(
event
)
child
.
delegate_event
(
event
)
if
event
.
is_propagation_stopped
():
if
event
.
is_propagation_stopped
():
break
return
if
not
child_found
:
if
not
child_found
:
self
.
propagate_event
(
event
)
self
.
propagate_event
(
event
)
def
propagate_event
(
self
,
event
):
def
propagate_event
(
self
,
event
):
for
tracker
in
se
t
(
self
.
trackers
.
itervalues
())
:
for
tracker
in
se
lf
.
trackers
:
tracker
.
handle_event
(
event
)
tracker
.
handle_event
(
event
)
if
event
.
is_immediate_propagation_stopped
():
if
event
.
is_immediate_propagation_stopped
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment