77 lines
2.3 KiB
Python
Raw Normal View History

2007-02-22 10:50:16 +00:00
"""
This script shows buffer list in infobar. Nothing more.
It's inspired by `awl.pl` irssi script, but is less advanced. :)
The script is in the public domain.
Leonid Evdokimov (weechat at darkk dot net dot ru)
http://darkk.net.ru/weechat/awl.py
2007-05-11 08:22:39 +00:00
0.1 - initial commit
0.2 - added `show_servers` option
0.3 - infobar is actually redrawed only if that's necessary
2007-02-22 10:50:16 +00:00
"""
#######################################################################
import weechat
2007-05-11 08:22:39 +00:00
from itertools import ifilter
2007-02-22 10:50:16 +00:00
2007-05-11 08:22:39 +00:00
VERSION = "0.3"
NAME = "awl"
2007-02-22 10:50:16 +00:00
# how often to refresh infobar
timer_interval = 1
2007-05-11 08:22:39 +00:00
blist = ()
2007-02-22 10:50:16 +00:00
def cleanup():
weechat.remove_infobar(-1)
return weechat.PLUGIN_RC_OK
2007-05-11 08:22:39 +00:00
def cfg_boolean(key, default = False):
map = {True: 'ON', False: 'OFF'}
value = weechat.get_plugin_config(key).upper()
if not value in map.values():
if value:
weechat.prnt("[%s]: invalid %s value (%s), resetting to %s" % (NAME, key, value, map[default]))
weechat.set_plugin_config(key, map[default])
value = default
else:
value = ifilter(lambda p: p[1] == value, map.iteritems()).next()[0]
return value
2007-02-22 10:50:16 +00:00
def update_channels():
2007-05-11 08:22:39 +00:00
global blist
names = ()
2007-02-22 10:50:16 +00:00
buffers = weechat.get_buffer_info()
if buffers != None:
for index, buffer in buffers.iteritems():
#**** info for buffer no 8 ****
# > log_filename, notify_level, server, num_displayed, type, channel
if len(buffer['channel']):
name = buffer['channel']
elif len(buffer['server']):
2007-05-11 08:22:39 +00:00
if cfg_boolean('show_servers'):
name = "[" + buffer['server'] + "]"
else:
continue
2007-02-22 10:50:16 +00:00
else:
name = "?"
2007-05-11 08:22:39 +00:00
names += ("%i:%s" % (index, name), )
if (names != blist):
the_string = " ".join(names)
blist = names
weechat.remove_infobar(-1)
weechat.print_infobar(0, the_string);
2007-02-22 10:50:16 +00:00
def on_timer():
update_channels()
return weechat.PLUGIN_RC_OK
2007-05-11 08:22:39 +00:00
if weechat.register(NAME, VERSION, "cleanup", "bufferlist in infobar"):
2007-02-22 10:50:16 +00:00
#message handlers are called __before__ buflist is changed, so we don't use them
weechat.add_timer_handler(timer_interval, "on_timer")
2007-05-11 08:22:39 +00:00
cfg_boolean('show_servers', False)
2007-02-22 10:50:16 +00:00
update_channels()
2007-05-11 08:22:39 +00:00
# vim:set tabstop=4 softtabstop=4 shiftwidth=4:
# vim:set expandtab: