Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multitouch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
multitouch
Commits
d78ee60a
Commit
d78ee60a
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added a test program that uses GTK with Cairo to draw widgets and tests event propagation.
parent
73e05a5d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/cairotest.py
+148
-0
148 additions, 0 deletions
tests/cairotest.py
with
148 additions
and
0 deletions
tests/cairotest.py
0 → 100755
+
148
−
0
View file @
d78ee60a
#!/usr/bin/env python
from
__future__
import
division
import
gtk
import
cairo
from
math
import
radians
from
threading
import
Thread
import
src
as
mt
def
quit
(
*
args
):
gtk
.
main_quit
()
class
Rectangle
(
mt
.
RectangularWidget
):
def
__init__
(
self
,
x
,
y
,
width
,
height
,
color
=
(
1
,
0
,
0
)):
super
(
Rectangle
,
self
).
__init__
(
x
,
y
,
width
,
height
)
self
.
angle
=
0
self
.
scale
=
1
self
.
color
=
color
def
scale
(
self
,
angle
):
self
.
scale
*=
scale
def
rotate
(
self
,
angle
):
self
.
angle
+=
angle
def
get_transformation_matrix
(
self
):
t
=
cairo
.
Matrix
()
t
.
translate
(
*
self
.
get_position
())
t
.
rotate
(
self
.
angle
)
t
.
scale
(
self
.
scale
,
self
.
scale
)
return
t
def
draw
(
self
,
cr
):
cr
.
transform
(
self
.
get_transformation_matrix
())
w
,
h
=
self
.
get_size
()
cr
.
rectangle
(
-
w
/
2
,
-
h
/
2
,
w
,
h
)
cr
.
set_source_rgb
(
*
self
.
color
)
cr
.
fill
()
fullscreen
=
False
W
,
H
=
mt
.
screen
.
screen_size
def
create_context_window
(
w
,
h
,
callback
):
def
create_context
(
area
,
event
):
"""
Add Cairo context to GTK window and draw initial state.
"""
global
cr
#if cr:
# return
cr
=
area
.
window
.
cairo_create
()
draw
()
def
move_window
(
win
,
event
):
"""
Synchronize root multi-touch widget with GTK window.
"""
root
.
set_position
(
*
event
.
get_coords
())
root
.
set_size
(
event
.
width
,
event
.
height
)
draw
()
def
handle_key
(
win
,
event
):
"""
Handle key event.
'
f
'
toggles fullscreen,
'
q
'
exits the program.
"""
if
event
.
keyval
>=
256
:
return
key
=
chr
(
event
.
keyval
)
if
key
==
'
f
'
:
global
fullscreen
(
win
.
unfullscreen
if
fullscreen
else
win
.
fullscreen
)()
fullscreen
=
not
fullscreen
elif
key
==
'
q
'
:
quit
()
# Root widget (will be synchronized with GTK window)
global
root
root
=
mt
.
RectangularWidget
(
0
,
0
,
w
,
h
)
# GTK window
win
=
gtk
.
Window
()
win
.
set_title
(
'
Cairo test
'
)
win
.
connect
(
'
destroy
'
,
quit
)
win
.
connect
(
'
key-press-event
'
,
handle_key
)
win
.
connect
(
'
configure-event
'
,
move_window
)
win
.
connect
(
'
show
'
,
callback
)
# Drawing area, needed by cairo context for drawing
area
=
gtk
.
DrawingArea
()
area
.
set_size_request
(
w
,
h
)
area
.
connect
(
'
expose-event
'
,
create_context
)
win
.
add
(
area
)
area
.
show
()
win
.
show
()
def
draw
():
# Background
cr
.
rectangle
(
0
,
0
,
*
root
.
get_size
())
cr
.
set_source_rgb
(
0
,
1
,
0
)
cr
.
fill
()
# Drawable objects (use save and restore to allow transformations)
for
obj
in
draw_objects
:
#cr.save()
obj
.
draw
(
cr
)
#cr.restore()
# Initialization
cr
=
root
=
None
draw_objects
=
[]
def
on_show
(
window
):
def
root_dtap
(
g
):
print
'
double tapped on root
'
root
.
on_double_tap
(
root_dtap
)
# Create blue rectangle
rect
=
Rectangle
(
300
,
200
,
250
,
150
,
color
=
(
0
,
0
,
1
))
draw_objects
.
append
(
rect
)
root
.
add_widget
(
rect
)
def
rect_tap
(
g
):
print
'
tapped on rectangle
'
rect
.
on_tap
(
rect_tap
,
propagate_up_event
=
False
)
if
__name__
==
'
__main__
'
:
# Parse arguments
from
tests.parse_arguments
import
create_parser
,
parse_args
parse_args
(
create_parser
())
# Create a window with a Cairo context in it and a multi-touch widget
# syncronized with it
create_context_window
(
640
,
460
,
on_show
)
# Run multi-touch gesture server in separate thread
server
=
mt
.
EventServer
(
root
)
mt_thread
=
Thread
(
target
=
server
.
start
)
mt_thread
.
daemon
=
True
mt_thread
.
start
()
# Initialize threads in GTK so that the thread started above will work
gtk
.
gdk
.
threads_init
()
# Start main loop in current thread
gtk
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment