### Terminal title plugin for pytone ### """""""""""""""""""""""""""""""" ### This plugin updates terminal and screen titles whenever pytone ### changes to a new song. You can install this plugin by simply ### copying it to your pytone system-wide plugin directory ### (eg. /usr/share/pytone/plugins) or ~/pytone/plugins/). And ### enable it by adding it to the plugins list in the general ### section, like: ### ### [general] ### plugins = termtitle ### ### You can customize the title by adding the following to ### /etc/pytonerc or ~/.pytone/pytonerc ### ### [plugin.termtitle] ### songformat = pytone: %(artist)s - %(title)s - %(length)s ### ### You can find the latest release at: ### ### http://dag.wieers.com/home-made/pytone/ ### ### If you have improvements or changes to this plugin, please ### send them to the pytone mailinglist and include me as well: ### ### pytone-users@luga.de, Dag Wieers import events, plugin, config, sys, os, re class config(config.configsection): songformat = config.configstring('%(artist)s - %(title)s') term = os.getenv('TERM') termre = re.compile('(screen|xterm-*)') class plugin(plugin.plugin): def start(self): self.channel.subscribe(events.playbackinfochanged, self.playbackinfochanged) self.previoussong = '' self.previouscross = False def playbackinfochanged(self, event): if event.playbackinfo.song != self.previoussong: self.changetermtitle(event) self.previoussong = event.playbackinfo.song if event.playbackinfo.iscrossfading() != self.previouscross: self.changetermtitle(event) self.previouscross = event.playbackinfo.iscrossfading() def changetermtitle(self, event): prefix = (event.playbackinfo.iscrossfading() and "-> " or "") song = event.playbackinfo.song.format(self.config.songformat, safe=True) sys.stdout.write('\033]0;' + prefix + song + '\007') # vim:ts=4:sw=4