/usr/share/weechat/python/windicate.py is in weechat-scripts 20120603-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | # Author: Leon Bogaert <leon AT tim-online DOT nl>
# This Plugin Calls the libindicate bindings via python when somebody says your
# nickname, sends you a query, etc.
# To make it work, you may need to download: python-indicate and python-dbus
# Requires Weechat 0.3.0
# Released under GNU GPL v2
#
# 2010-09-22, Leon <leon@tim-online.nl>:
# version 0.0.1 Intial release
#
# @TODO: find out how to jump to buffer/line
# @TODO: how to communicate the click to weechat
# @TODO: decide what to do if a user clicks an indicator an then start typing:
# * leave indicators alone
# * remove indicators in the "neighbourhood"
# * If a user cliks indicator: indactor dissapears
# * On click group: remove all indicators
# * When visiting buffer: remove indicators
import dbus.service
import inspect
import os
import tempfile
class DBUSService(dbus.service.Object):
def __init__(self, messageMenu):
bus_name = dbus.service.BusName('org.weechat.scripts.windicate', bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, '/org/weechat/scripts/windicate')
self.messageMenu = messageMenu
@dbus.service.method('org.weechat.scripts.windicate')
def add_message(self, channel, sender, body):
return self.messageMenu.add_message(channel, sender, body)
class MessageMenu(object):
def __init__(self):
self.messages = []
server = pyindicate.indicate_server_ref_default()
server.set_type("message.im")
server.set_desktop_file(self.desktop_file())
server.connect("server-display", self.server_click)
server.show()
def desktop_file(self):
file = "/usr/share/applications/weechat.desktop"
if os.path.isfile(file):
return file
f = tempfile.NamedTemporaryFile(suffix='indicator', delete=False)
f.write("[Desktop Entry]\nEncoding=UTF-8\nMultipleArgs=false\nTerminal=true\nExec=weechat-curses\nIcon=weechat\nType=Application\nCategories=Network;IRCClient;\nStartupNotify=false\nName=Weechat\nGenericName=IRC Client")
f.close()
self.tmp_file = f
return f.name
def __del__(self):
if self.tmp_file and os.file.exists(self.tmp_file):
os.unlink(self.tmp_file)
def server_click(self, server, time):
print "Server clicked!"
def add_message(self, channel, sender, body):
for message in self.messages:
if message.channel == channel and message.sender == sender:
return message.update_time()
return self.messages.append(Message(self, channel, sender, body))
class Message(object):
def __init__(self, mm, channel, sender, message):
# Setup the message
try:
# Ubuntu 9.10 and above
indicator = pyindicate.Indicator()
except:
# Ubuntu 9.04
indicator = pyindicate.IndicatorMessage()
indicator.set_property("subtype", "im")
indicator.set_property("sender", "%s (%s)" % (sender, channel))
indicator.set_property("body", message)
indicator.set_property_time("time", time())
indicator.set_property('draw-attention', 'true');
indicator.show()
indicator.connect("user-display", self.message_clicked)
self.indicator = indicator
self.sender = sender
self.message = message
self.channel = channel
self.messageMenu = mm
def update_time(self):
self.indicator.set_property_time("time", time())
def message_clicked(self, indicator, time):
#How can I make weechat go there?? (/buffer self.channeli)
#Maybe if I can get dbus running in a weechat script...
self.messageMenu.messages.remove(self)
indicator.hide()
class WindicateServer(object):
def __init__(self):
DBusGMainLoop(set_as_default=True)
mm = MessageMenu()
dbs = DBUSService(mm)
loop = gobject.MainLoop()
loop.run()
class Subprocess(object):
p = None
@classmethod
def start(cls):
file = inspect.getfile( inspect.currentframe())
import subprocess
args = ["/usr/bin/python", file]
cls.p = subprocess.Popen(args)
@classmethod
def stop(cls):
cls.p.terminate()
try:
import weechat
except ImportError:
"""Ran from seperate process: start server!"""
import gobject
gobject.threads_init()
import indicate as pyindicate
import gtk
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from time import time
ws = WindicateServer()
##### FUNCTIONS #####
def windicate_server_ended(data, command, rc, stdout, stderr):
print "windicate_server_ended"
return weechat.WEECHAT_RC_OK
def weechat_script_end():
Subprocess.stop()
return weechat.WEECHAT_RC_OK
def notify_msg(data, bufferp, time, tags, display, is_hilight, prefix, msg):
"""Sends highlighted message to be printed on notification"""
if ('notify_private' in tags and
weechat.config_get_plugin('show_priv_msg') == "on") \
or (is_hilight == "1" and \
weechat.config_get_plugin('show_hilights') == "on"):
if not weechat.buffer_get_string(bufferp, "short_name"):
buffer = weechat.buffer_get_string(bufferp, "name")
else:
buffer = weechat.buffer_get_string(bufferp, "short_name")
if ('notify_private' in tags):
buffer = "private"
add_message(buffer, prefix, msg)
if weechat.config_get_plugin('debug') == "on":
print prefix
return weechat.WEECHAT_RC_OK
def notify_show_hi(data, signal, message):
print "data: " + data
print "signal: " + data
print "message: " + message
return weechat.WEECHAT_RC_OK
def notify_show_priv(data, signal, message):
print "data: " + data
print "signal: " + data
print "message: " + message
return weechat.WEECHAT_RC_OK
def add_message(channel, sender, body):
bus = dbus.SessionBus()
# Create an object that will proxy for a particular remote object.
remote_object = bus.get_object("org.weechat.scripts.windicate", # Connection name
"/org/weechat/scripts/windicate" # Object's path
)
remote_object.add_message(channel, sender, body)
##### END FUNCTIONS #####
weechat.register("windicate", "Leon Bogaert", "0.0.1", "GPL",
"fills the indicate applet", "weechat_script_end", "")
# script options
settings = {
"show_hilights" : "on",
"show_priv_msg" : "on",
"time_between_msg" : "5",
}
# Init everything
for option, default_value in settings.items():
if weechat.config_get_plugin(option) == "":
weechat.config_set_plugin(option, default_value)
Subprocess.start()
#weechat.hook_process("/usr/bin/python %s" % (file,),
#-1, "windicate_server_ended", "")
# Hook privmsg/hilights
weechat.hook_print("", "", "", 1, "notify_msg", "")
#weechat.hook_signal("weechat_highlight", "notify_show_hi", "")
#weechat.hook_signal("weechat_pv", "notify_show_priv", "")
|