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
1 changed files with 620 additions and 619 deletions

View File

@ -45,76 +45,6 @@ if dbus_support.supported:
if dbus_support:
import dbus.service
import dbus.glib
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
# type mapping
# in most cases it is a utf-8 string
@ -736,3 +666,74 @@ class SignalObject(dbus.service.Object):
else:
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