Changes

no edit summary
Line 56: Line 56:  
== Text and Graphics for Sugar Activities ==
 
== Text and Graphics for Sugar Activities ==
 
* [[Pango]]
 
* [[Pango]]
 +
 +
== Mouse ==
 +
=== How do I change the cursor in my activity to the wait cursor? ===
 +
In your activity subclass:
 +
 +
<pre>
 +
self.window.set_cursor( gtk.gdk.Cursor(gtk.gdk.WATCH) )
 +
</pre>
 +
 +
and to switch it back to the default:
 +
 +
<pre>
 +
self.window.set_cursor( None );
 +
</pre>
 +
 +
=== How do I track the position of the mouse? ===
 +
There are many different reasons you might want to track the position of the mouse in your activity, ranging from the entertaining ([[http://en.wikipedia.org/wiki/Xeyes]]) to the functional (hiding certain windows when the mouse hasn't moved for a couple of seconds and making those ui elements re-appear when the mouse has moved again).  Here is one way you can implement this functionality:
 +
 +
<pre>
 +
 +
...
 +
self.hideWidgetsTime = time.time()
 +
self.mx = -1
 +
self.my = -1
 +
self.HIDE_WIDGET_TIMEOUT_ID = gobject.timeout_add( 500, self.mouseMightHaveMovedCb )
 +
 +
def _mouseMightHaveMovedCb( self ):
 +
x, y = self.get_pointer()
 +
passedTime = 0
 +
 +
if (x != self.mx or y != self.my):
 +
self.hideWidgetsTime = time.time()
 +
if (self.hiddenWidgets):
 +
self.showWidgets()
 +
self.hiddenWidgets = False
 +
else:
 +
passedTime = time.time() - self.hideWidgetsTime
 +
 +
 +
if (passedTime >= 3):
 +
if (not self.hiddenWidgets):
 +
self.hideWidgets()
 +
self.hiddenWidgets = True
 +
 +
self.mx = x
 +
self.my = y
 +
return True
 +
 +
</pre>
    
== Miscellaneous==
 
== Miscellaneous==
Anonymous user