gajim-plural/plugins/length_notifier.py
Mateusz Biliński 95b1e45920 Initial commit related to plug-in system:
- basic PluginManager class that loads plugins from *.py files
  in given directories
- Singleton metaclass was created to use with PluginManager;
  notice: __init__ of class is called only once (not like in code
	that is included in Python Cookbook)
- variable to keep paths of plugin directories has been created
  (common.gajim.PLUGINS_DIRS); also added initilization of these
  paths to common.ConfigPaths
- added global variable with PluginManager object:
  common.gajim.plugin_manager
- created customized logger for plugin system ('gajim.plugin_system')
- created function decorator plugins.helpers.log_calls which logs
  each call of function/method; it also logs when function is left
- base class Plugin for plug-in implementation added; not much
  here - only empty class attributes: name, short_name, authors,
	version, description
- based on Plugin class, first plugin was created named
  LengthNotifierPlugin; it is used to notify users when they
  exceed given length of message during writing it (text entry
  field highlights)
- first GUI extension points works when ChatControl object
  is created (it is used in mentioned plugin)
- added 'epydoc.conf' file customized a little bit (file
	is also in trunk now)
- fixed indentation in common.sleepy module (also in trunk
	now)
2008-06-01 23:33:51 +00:00

95 lines
No EOL
2.9 KiB
Python

# -*- coding: utf-8 -*-
## This file is part of Gajim.
##
## Gajim is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## Gajim is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
'''
Message length notifier plugin.
:author: Mateusz Biliński <mateusz@bilinski.it>
:since: 06/01/2008
:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
:license: GPL
'''
import sys
import gtk
from plugins import GajimPlugin
from plugins.helpers import log, log_calls
class LengthNotifierPlugin(GajimPlugin):
name = 'Message Length Notifier'
short_name = 'length_notifier'
version = '0.1'
description = '''Highlights message entry field in chat window when given
length of message is exceeded.'''
authors = ['Mateusz Biliński <mateusz@bilinski.it>']
@log_calls('LengthNotifierPlugin')
def __init__(self):
super(LengthNotifierPlugin, self).__init__()
self.__class__.gui_extension_points = {
'chat_control' : (self.connect_with_chat_control,
self.disconnect_from_chat_control)
}
self.MESSAGE_WARNING_LENGTH = 140
self.WARNING_COLOR = gtk.gdk.color_parse('#F0DB3E')
self.JIDS = []
@log_calls('LengthNotifierPlugin')
def textview_length_warning(self, tb, chat_control):
tv = chat_control.msg_textview
d = chat_control.length_notifier_plugin_data
t = tb.get_text(tb.get_start_iter(), tb.get_end_iter())
if t:
len_t = len(t)
#print("len_t: %d"%(len_t))
if len_t>self.MESSAGE_WARNING_LENGTH:
if not d['prev_color']:
d['prev_color'] = tv.style.copy().base[gtk.STATE_NORMAL]
tv.modify_base(gtk.STATE_NORMAL, self.WARNING_COLOR)
elif d['prev_color']:
tv.modify_base(gtk.STATE_NORMAL, d['prev_color'])
d['prev_color'] = None
@log_calls('LengthNotifierPlugin')
def connect_with_chat_control(self, chat_control):
jid = chat_control.contact.jid
if self.jid_is_ok(jid):
d = {'prev_color' : None}
tv = chat_control.msg_textview
b = tv.get_buffer()
h_id = b.connect('changed', self.textview_length_warning, chat_control)
d['h_id'] = h_id
chat_control.length_notifier_plugin_data = d
return True
return False
@log_calls('LengthNotifierPlugin')
def disconnect_from_chat_control(self, chat_control):
d = chat_control.length_notifier_plugin_data
chat_control.msg_textview.get_buffer().disconnect(d['h_id'])
if d['prev_color']:
tv.modify_base(gtk.STATE_NORMAL, self.PREV_COLOR)
@log_calls('LengthNotifierPlugin')
def jid_is_ok(self, jid):
return True