Pen Tablet Support/Unconstrained Drawing API


Jump to: navigation, search

"Unconstrained drawing" describes the case where the area that the user wishes to draw on is bigger and/or does not have the same aspect ratio as the physical Pen Tablet. The Paint activity is a good example of this case.

This is a first cut at an API for unconstrained drawing. Comments are welcome.


An activity that already supports some form of drawing using the mouse/touchpad can add tablet support by using the TabletBox container widget to wrap the window that receives the mouse events for drawing (e.g. a gtk.gdk.Window or a gtk.DrawingArea)

 from import TabletBox
 class MyDrawingActivity(activity.Activity):
     def __init__(self, handle):
         activity.Activity.__init__(self, handle)
         self._drawing_area = gtk.DrawingArea()
         self._tablet_box = TabletBox()

then the activity can connect to the appropriate tablet events:

         self.connect("tablet_down_event", self._handle_tablet_down)
         self.connect("tablet_up_event", self._handle_tablet_up)
         self.connect("tablet_motion_event", self._handle_tablet_motion)

If your activity already supports drawing with the mouse, the event handlers should trivially map to your existing event handlers -- i.e., tablet_down_event -> button_press_event; tablet_up_event -> button_release_event; tablet_motion_event -> motion_notify_event (with the mouse button held down)


  • the TabletBox needs to be a container widget, because the Pen Tablet UI requires that we draw UI elements on top of the activity's drawing area
  • this solution may not work for a canvas that needs to be scrolled. It might be necessary for the TabletBox to inherit from gtk.Layout to provide scrolling capabilities.
Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
OLPC wiki
In other languages