Spaceship! code at GitHub
I cloned the code for Spaceship! at GitHub to facilitate easier development by anyone interested. I'll push any future improvements I make there and consider my personal subversion repository dead.
pyttsx
pyttsx is a cross-platform text-to-speech package for Python. It has a simple API for producing speech, setting some basic engine properties, and getting start/stop/word callbacks. pyttsx currently supports SAPI5, NSSpeechSynthesizer, and espeak, but it can be extended to support other engines and libraries.
The project BSD licensed and hosted on Launchpad. PyPI tracks downloads for the latest stable version and documentation.
GtkBuilder/Glade on IronPython
Thanks to Stephane for his answer to my query about using GtkBuilder in IronPython. It turns out his Gtk#Beans package provides the magic sauce that is currently missing from gtk# trunk the current stable release.
For completeness, here's the code I sent him that accomplishes the same thing using the older Glade.XML object for those that are interested. It answers a long standing mailing list question about using Glade.XML.Autoconnect in IronPython.
import clr clr.AddReference('gtk-sharp') clr.AddReference('glade-sharp') import Gtk import Glade def PyGladeAutoconnect(gxml, target): def _connect(handler_name, event_obj, signal_name, *args): name = ''.join([frag.title() for frag in signal_name.split('_')]) event = getattr(event_obj, name) event += getattr(target, handler_name) # add all widgets for widget in gxml.GetWidgetPrefix(''): setattr(target, gxml.GetWidgetName(widget), widget) # connect all signals gxml.SignalAutoconnectFull(_connect) class Application: def __init__(self): gxml = Glade.XML("test.glade", "window1", None) PyGladeAutoconnect(gxml, self) # window1 comes from glade file self.window1.ShowAll() def onWindowDelete(self, o, args): # connected via glade file definition Gtk.Application.Quit() Gtk.Application.Init() app = Application() Gtk.Application.Run()
Outfox in Greasemonkey revisited
There was some traffic in the Outfox group about my GMail announcer userscript failing in Outfox 0.3.x. The Outfox API has improved quite a bit since 0.1.0, so it's no surprise my script no longer works.
Here's a new example script that does work with the latest Outfox 0.3.5 release. Instead of polluting the example with all the complications of navigating the GMail DOM, I've picked a much simpler target. This script simply speaks the number of major sections (level 2 headings) in a Wikipedia article when the page loads. It's not as sexy, but the code is much easier to understand.
To try this script, make sure you have the Greasemonkey 0.8 and Outfox 0.3.5 extensions installed on Firefox 3.0 or 3.5. Then visit the following link to have GM install the script: citation_announcer.user.js.
// ==UserScript== // @name Sections count // @namespace http://www.mindtrove.info/ // @description Speaks the number of h2 sections in a Wikipedia article // @include http://*.wikipedia.org/wiki/* // @require http://www.json.org/json2.js // @require http://outfox.googlecode.com/svn/trunk/js/outfox.js // ==/UserScript== // number of major sections var sections = 0; function onOutfoxAudioInit(response) { // say the number of main sections outfox.audio.say(sections + ' main sections'); // return the parameter for other outfox deferred callbacks return response; } function onOutfoxInit(version) { var content = document.getElementById('bodyContent'); // count the number of main sections sections = content.getElementsByTagName('h2').length; // take one back for the TOC heading if it's present if(document.getElementById('toc')) { --sections; } // start the outfox audio service var def = outfox.startService('audio'); def.addCallback(onOutfoxAudioInit); // return the parameter for other outfox deferred callbacks return version; } function onDOMContentLoaded() { // create a node for outfox use var div = document.createElement('div'); document.body.appendChild(div); // initialize outfox var def = outfox.init(div, JSON.stringify, JSON.parse); def.addCallback(onOutfoxInit); } // this event triggers execution of the GM script onDOMContentLoaded();