changeset 7414c5ecff7c in /home/hg/repos/gajim
author: Jeffrey Baitis jeff@baitis.net branches: details:http://hg.gajim.org/gajim?cmd=changeset;node=7414c5ecff7c description: Modified source to work under python3
diffstat:
plugins/dbus_plugin/__init__.py | 2 +- plugins/dbus_plugin/plugin.py | 8 +- plugins/events_dump/__init__.py | 2 +- plugins/events_dump/plugin.py | 9 +- plugins/new_events_example/__init__.py | 2 +- plugins/new_events_example/plugin.py | 2 +- plugins/roster_buttons/__init__.py | 2 +- src/history_manager.py | 3 + src/plugins/__init__.py | 2 +- src/plugins/gajimplugin.py | 283 +++++++++++++++++++++++++++++++++ src/plugins/plugin.py | 283 --------------------------------- src/plugins/pluginmanager.py | 2 +- 12 files changed, 301 insertions(+), 299 deletions(-)
diffs (truncated from 707 to 300 lines):
diff -r 978573139f4b -r 7414c5ecff7c plugins/dbus_plugin/__init__.py --- a/plugins/dbus_plugin/__init__.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/dbus_plugin/__init__.py Fri Sep 02 13:05:03 2016 -0700 @@ -1,1 +1,1 @@ -from plugin import DBusPlugin +from .plugin import DBusPlugin diff -r 978573139f4b -r 7414c5ecff7c plugins/dbus_plugin/plugin.py --- a/plugins/dbus_plugin/plugin.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/dbus_plugin/plugin.py Fri Sep 02 13:05:03 2016 -0700 @@ -34,7 +34,8 @@ :license: GPL ''' import os -import new +# import new # depricated in python3; use types instead +import types
import gobject
@@ -722,10 +723,9 @@ def _set_handling_methods(self): for event_name in self.events_names: setattr(self, event_name, - new.instancemethod( + types.MethodType( self._generate_handling_method(event_name), - self, - DBusPlugin)) + self)) self.events_handlers[event_name] = (ged.POSTCORE, getattr(self, event_name))
diff -r 978573139f4b -r 7414c5ecff7c plugins/events_dump/__init__.py --- a/plugins/events_dump/__init__.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/events_dump/__init__.py Fri Sep 02 13:05:03 2016 -0700 @@ -1,1 +1,1 @@ -from plugin import EventsDumpPlugin +from .plugin import EventsDumpPlugin diff -r 978573139f4b -r 7414c5ecff7c plugins/events_dump/plugin.py --- a/plugins/events_dump/plugin.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/events_dump/plugin.py Fri Sep 02 13:05:03 2016 -0700 @@ -25,7 +25,7 @@ :license: GPL '''
-import new +import types from pprint import pformat
from plugins import GajimPlugin @@ -110,15 +110,14 @@ def _set_handling_methods(self): for event_name in self.events_names: setattr(self, event_name, - new.instancemethod( + types.MethodType( self._generate_handling_method(event_name), - self, - EventsDumpPlugin)) + self)) self.events_handlers[event_name] = (ged.POSTCORE, getattr(self, event_name))
def _generate_handling_method(self, event_name): def handler(self, *args): - print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name, pformat(args)) + print ("Event '%s' occured. Arguments: %s\n\n===\n" % (event_name, pformat(args)))
return handler diff -r 978573139f4b -r 7414c5ecff7c plugins/new_events_example/__init__.py --- a/plugins/new_events_example/__init__.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/new_events_example/__init__.py Fri Sep 02 13:05:03 2016 -0700 @@ -1,1 +1,1 @@ -from plugin import NewEventsExamplePlugin +from .plugin import NewEventsExamplePlugin diff -r 978573139f4b -r 7414c5ecff7c plugins/new_events_example/plugin.py --- a/plugins/new_events_example/plugin.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/new_events_example/plugin.py Fri Sep 02 13:05:03 2016 -0700 @@ -26,7 +26,7 @@ :license: GPL '''
-import new +#import new # Depricated in python3 for types module from pprint import pformat
from common import helpers diff -r 978573139f4b -r 7414c5ecff7c plugins/roster_buttons/__init__.py --- a/plugins/roster_buttons/__init__.py Sat Aug 20 00:35:57 2016 +0200 +++ b/plugins/roster_buttons/__init__.py Fri Sep 02 13:05:03 2016 -0700 @@ -1,4 +1,4 @@
__all__ = ['RosterButtonsPlugin']
-from plugin import RosterButtonsPlugin +from .plugin import RosterButtonsPlugin diff -r 978573139f4b -r 7414c5ecff7c src/history_manager.py --- a/src/history_manager.py Sat Aug 20 00:35:57 2016 +0200 +++ b/src/history_manager.py Fri Sep 02 13:05:03 2016 -0700 @@ -49,7 +49,10 @@
import sys import signal +import gi +gi.require_version('Gtk', '3.0') from gi.repository import Gtk +gi.require_version('GdkX11', '3.0') from gi.repository import Gdk from gi.repository import GLib import time diff -r 978573139f4b -r 7414c5ecff7c src/plugins/__init__.py --- a/src/plugins/__init__.py Sat Aug 20 00:35:57 2016 +0200 +++ b/src/plugins/__init__.py Fri Sep 02 13:05:03 2016 -0700 @@ -25,6 +25,6 @@ '''
from .pluginmanager import PluginManager -from .plugin import GajimPlugin +from .gajimplugin import GajimPlugin
__all__ = ['PluginManager', 'GajimPlugin'] diff -r 978573139f4b -r 7414c5ecff7c src/plugins/gajimplugin.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/plugins/gajimplugin.py Fri Sep 02 13:05:03 2016 -0700 @@ -0,0 +1,283 @@ +# -*- 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/. +## + +''' +Base class for implementing plugin. + +:author: Mateusz Biliński mateusz@bilinski.it +:since: 1st June 2008 +:copyright: Copyright (2008) Mateusz Biliński mateusz@bilinski.it +:license: GPL +''' + +import os +import locale + +from common import gajim + +from plugins.helpers import log_calls, log +from plugins.gui import GajimPluginConfigDialog + +import logging +log = logging.getLogger('gajim.p.plugin') + + +class GajimPlugin(object): + ''' + Base class for implementing Gajim plugins. + ''' + name = '' + ''' + Name of plugin. + + Will be shown in plugins management GUI. + + :type: str + ''' + short_name = '' + ''' + Short name of plugin. + + Used for quick indentification of plugin. + + :type: str + + :todo: decide whether we really need this one, because class name (with + module name) can act as such short name + ''' + version = '' + ''' + Version of plugin. + + :type: str + + :todo: decide how to compare version between each other (which one + is higher). Also rethink: do we really need to compare versions + of plugins between each other? This would be only useful if we detect + same plugin class but with different version and we want only the newest + one to be active - is such policy good? + ''' + description = '' + ''' + Plugin description. + + :type: str + + :todo: should be allow rich text here (like HTML or reStructuredText)? + ''' + authors = [] + ''' + Plugin authors. + + :type: [] of str + + :todo: should we decide on any particular format of author strings? + Especially: should we force format of giving author's e-mail? + ''' + homepage = '' + ''' + URL to plug-in's homepage. + + :type: str + + :todo: should we check whether provided string is valid URI? (Maybe + using 'property') + ''' + gui_extension_points = {} + ''' + Extension points that plugin wants to connect with and handlers to be used. + + Keys of this string should be strings with name of GUI extension point + to handles. Values should be 2-element tuples with references to handling + functions. First function will be used to connect plugin with extpoint, + the second one to successfuly disconnect from it. Connecting takes places + when plugin is activated and extpoint already exists, or when plugin is + already activated but extpoint is being created (eg. chat window opens). + Disconnecting takes place when plugin is deactivated and extpoint exists + or when extpoint is destroyed and plugin is activate (eg. chat window + closed). + ''' + config_default_values = {} + ''' + Default values for keys that should be stored in plug-in config. + + This dict is used when when someone calls for config option but it has not + been set yet. + + Values are tuples: (default_value, option_description). The first one can + be anything (this is the advantage of using shelve/pickle instead of + custom-made config I/O handling); the second one should be str (gettext + can be used if need and/or translation is planned). + + :type: {} of 2-element tuples + ''' + events_handlers = {} + ''' + Dictionary with events handlers. + + Keys are event names. Values should be 2-element tuples with handler + priority as first element and reference to handler function as second + element. Priority is integer. See `ged` module for predefined priorities + like `ged.PRECORE`, `ged.CORE` or `ged.POSTCORE`. + + :type: {} with 2-element tuples + ''' + events = [] + ''' + New network event classes to be registered in Network Events Controller. + + :type: [] of `nec.NetworkIncomingEvent` or `nec.NetworkOutgoingEvent` + subclasses. + ''' + + @log_calls('GajimPlugin') + def __init__(self): + self.config = GajimPluginConfig(self) + ''' + Plug-in configuration dictionary. + + Automatically saved and loaded and plug-in (un)load. + + :type: `plugins.plugin.GajimPluginConfig` + ''' + self.activatable = True + self.available_text = '' + self.load_config() + self.config_dialog = GajimPluginConfigDialog(self) + self.init() + + @log_calls('GajimPlugin') + def save_config(self): + self.config.save() + + @log_calls('GajimPlugin') + def load_config(self): + self.config.load() + + def __eq__(self, plugin): + if self.short_name == plugin.short_name: + return True + + return False