Moved DBus type related instructions to scope which is executed only when there's a DBus support. No NameError exceptions are thrown anymore.

Makes debugging of plugins easier under WingIDE (which does not remember - at least it looks like that - the "ignore exception at this location" option when module is imported 'manually').

This could also be applied to src/remote_control.py .
This commit is contained in:
Mateusz Biliński 2009-04-16 08:37:16 +00:00
parent da928f9183
commit 369ea5544b

View file

@ -45,94 +45,24 @@ if dbus_support.supported:
if dbus_support: if dbus_support:
import dbus.service import dbus.service
import dbus.glib import dbus.glib
# type mapping
INTERFACE = 'org.gajim.dbusplugin.RemoteInterface' # in most cases it is a utf-8 string
OBJ_PATH = '/org/gajim/dbusplugin/RemoteObject' DBUS_STRING = dbus.String
SERVICE = 'org.gajim.dbusplugin'
from common import gajim # general type (for use in dicts, where all values should have the same type)
from common import helpers DBUS_BOOLEAN = dbus.Boolean
from time import time DBUS_DOUBLE = dbus.Double
from dialogs import AddNewContactWindow, NewChatDialog, JoinGroupchatWindow DBUS_INT32 = dbus.Int32
# dictionary with string key and binary value
DBUS_DICT_SV = lambda : dbus.Dictionary({}, signature="sv")
# dictionary with string key and value
DBUS_DICT_SS = lambda : dbus.Dictionary({}, signature="ss")
# empty type (there is no equivalent of None on D-Bus, but historically gajim
# used 0 instead)
DBUS_NONE = lambda : dbus.Int32(0)
from plugins import GajimPlugin def get_dbus_struct(obj):
from plugins.helpers import log_calls, log
from common import ged
class DBusPlugin(GajimPlugin):
name = u'D-Bus Support'
short_name = u'dbus'
version = u'0.1'
description = u'''D-Bus support. Based on remote_control module from
Gajim core but uses new events handling system.'''
authors = [u'Mateusz Biliński <mateusz@bilinski.it>']
homepage = u'http://blog.bilinski.it'
@log_calls('DBusPlugin')
def init(self):
self.config_dialog = None
#self.gui_extension_points = {}
#self.config_default_values = {}
self.events_names = ['Roster', 'AccountPresence', 'ContactPresence',
'ContactAbsence', 'ContactStatus', 'NewMessage',
'Subscribe', 'Subscribed', 'Unsubscribed',
'NewAccount', 'VcardInfo', 'LastStatusTime',
'OsInfo', 'GCPresence', 'GCMessage', 'RosterInfo',
'NewGmail']
self.signal_object = None
self.events_handlers = {}
self._set_handling_methods()
def activate(self):
session_bus = dbus_support.session_bus.SessionBus()
bus_name = dbus.service.BusName(SERVICE, bus=session_bus)
self.signal_object = SignalObject(bus_name)
def deactivate(self):
self.signal_object.remove_from_connection()
self.signal_object = None
def _set_handling_methods(self):
for event_name in self.events_names:
setattr(self, event_name,
new.instancemethod(
self._generate_handling_method(event_name),
self,
DBusPlugin))
self.events_handlers[event_name] = (ged.POSTCORE,
getattr(self, event_name))
def _generate_handling_method(self, event_name):
def handler(self, arg):
#print "Handler of event %s called"%(event_name)
if self.signal_object:
getattr(self.signal_object, event_name)(get_dbus_struct(arg))
return handler
# type mapping
# in most cases it is a utf-8 string
DBUS_STRING = dbus.String
# general type (for use in dicts, where all values should have the same type)
DBUS_BOOLEAN = dbus.Boolean
DBUS_DOUBLE = dbus.Double
DBUS_INT32 = dbus.Int32
# dictionary with string key and binary value
DBUS_DICT_SV = lambda : dbus.Dictionary({}, signature="sv")
# dictionary with string key and value
DBUS_DICT_SS = lambda : dbus.Dictionary({}, signature="ss")
# empty type (there is no equivalent of None on D-Bus, but historically gajim
# used 0 instead)
DBUS_NONE = lambda : dbus.Int32(0)
def get_dbus_struct(obj):
''' recursively go through all the items and replace ''' recursively go through all the items and replace
them with their casted dbus equivalents them with their casted dbus equivalents
''' '''
@ -162,7 +92,7 @@ def get_dbus_struct(obj):
# unknown type # unknown type
return DBUS_NONE() return DBUS_NONE()
class SignalObject(dbus.service.Object): class SignalObject(dbus.service.Object):
''' Local object definition for /org/gajim/dbus/RemoteObject. ''' Local object definition for /org/gajim/dbus/RemoteObject.
(This docstring is not be visible, because the clients can access only the remote object.)''' (This docstring is not be visible, because the clients can access only the remote object.)'''
@ -736,3 +666,74 @@ class SignalObject(dbus.service.Object):
else: else:
gajim.interface.join_gc_room(account, room_jid, nick, password) gajim.interface.join_gc_room(account, room_jid, nick, password)
INTERFACE = 'org.gajim.dbusplugin.RemoteInterface'
OBJ_PATH = '/org/gajim/dbusplugin/RemoteObject'
SERVICE = 'org.gajim.dbusplugin'
from common import gajim
from common import helpers
from time import time
from dialogs import AddNewContactWindow, NewChatDialog, JoinGroupchatWindow
from plugins import GajimPlugin
from plugins.helpers import log_calls, log
from common import ged
class DBusPlugin(GajimPlugin):
name = u'D-Bus Support'
short_name = u'dbus'
version = u'0.1'
description = u'''D-Bus support. Based on remote_control module from
Gajim core but uses new events handling system.'''
authors = [u'Mateusz Biliński <mateusz@bilinski.it>']
homepage = u'http://blog.bilinski.it'
@log_calls('DBusPlugin')
def init(self):
self.config_dialog = None
#self.gui_extension_points = {}
#self.config_default_values = {}
self.events_names = ['Roster', 'AccountPresence', 'ContactPresence',
'ContactAbsence', 'ContactStatus', 'NewMessage',
'Subscribe', 'Subscribed', 'Unsubscribed',
'NewAccount', 'VcardInfo', 'LastStatusTime',
'OsInfo', 'GCPresence', 'GCMessage', 'RosterInfo',
'NewGmail']
self.signal_object = None
self.events_handlers = {}
self._set_handling_methods()
def activate(self):
session_bus = dbus_support.session_bus.SessionBus()
bus_name = dbus.service.BusName(SERVICE, bus=session_bus)
self.signal_object = SignalObject(bus_name)
def deactivate(self):
self.signal_object.remove_from_connection()
self.signal_object = None
def _set_handling_methods(self):
for event_name in self.events_names:
setattr(self, event_name,
new.instancemethod(
self._generate_handling_method(event_name),
self,
DBusPlugin))
self.events_handlers[event_name] = (ged.POSTCORE,
getattr(self, event_name))
def _generate_handling_method(self, event_name):
def handler(self, arg):
#print "Handler of event %s called"%(event_name)
if self.signal_object:
getattr(self.signal_object, event_name)(get_dbus_struct(arg))
return handler