当前位置: 首页>>代码示例>>Python>>正文


Python SessionBus.add_signal_receiver方法代码示例

本文整理汇总了Python中dbus.SessionBus.add_signal_receiver方法的典型用法代码示例。如果您正苦于以下问题:Python SessionBus.add_signal_receiver方法的具体用法?Python SessionBus.add_signal_receiver怎么用?Python SessionBus.add_signal_receiver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dbus.SessionBus的用法示例。


在下文中一共展示了SessionBus.add_signal_receiver方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dbus_receiver

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
def dbus_receiver():
    """
    Start Qt loop that loads messages from Pidgin.

    :return: [no return value]
    """

    DBusQtMainLoop(set_as_default=True)
    bus = SessionBus()
    bus.add_signal_receiver(pidgin_to_rxm_queue,
                            dbus_interface="im.pidgin.purple.PurpleInterface",
                            signal_name="ReceivedImMsg")
开发者ID:regina-book,项目名称:tfc-nacl,代码行数:14,代码来源:NH.py

示例2: Vibra_Plugin

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
class Vibra_Plugin(Plugin):
    def __init__(self):
        DBusGMainLoop(set_as_default=True)

        self.bus = SystemBus()
        self.sessionbus = SessionBus()
        try:
            self.mce = self.bus.get_object("com.nokia.mce", "/com/nokia/mce")
        except DBusException:
            warning("Nokia MCE not found. Vibra is disabled\n")
            return

        self.profiled = self.sessionbus.get_object("com.nokia.profiled", "/com/nokia/profiled")

        self.sessionbus.add_signal_receiver(
            self.profile_changed_handler,
            "profile_changed",
            "com.nokia.profiled",
            "com.nokia.profiled",
            "/com/nokia/profiled",
        )

        profile = self.profiled.get_profile(dbus_interface="com.nokia.profiled")
        self.get_vibra_enabled(profile)

        self.register_plugin(PLUGIN_TYPE_VIBRA)

    def ready(self):
        self.notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION)

        sendfile = get_plugin_by_type(PLUGIN_TYPE_SEND_FILE)
        sendfile.receive_cb.append(self.file_receive)

    def get_vibra_enabled(self, profile):
        self.enabled = (
            self.profiled.get_value(profile, "vibrating.alert.enabled", dbus_interface="com.nokia.profiled") == "On"
        )
        debug("Vibra enabled: %s\n" % self.enabled)

    def profile_changed_handler(self, foo, bar, profile, *args):
        self.get_vibra_enabled(profile)

    def vibrate(self):
        if self.enabled:
            self.mce.req_vibrator_pattern_activate("PatternChatAndEmail", dbus_interface="com.nokia.mce.request")

    def file_receive(self, cb, user, fname):
        self.vibrate()

    def user_appears(self, user):
        if user.get("friend"):
            self.vibrate()
开发者ID:proximate,项目名称:proximate,代码行数:54,代码来源:vibra.py

示例3: run_client

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
    def run_client(self):
        bus = SessionBus()
        obj = bus.get_object(CROSS_TEST_BUS_NAME, CROSS_TEST_PATH)
        self.obj = obj

        self.run_synchronous_tests(obj)

        # Signal tests
        logger.info("Binding signal handler for Triggered")
        # FIXME: doesn't seem to work when going via the Interface method
        # FIXME: should be possible to ask the proxy object for its
        # bus name
        bus.add_signal_receiver(self.triggered_cb, 'Triggered',
                                INTERFACE_SIGNAL_TESTS,
                                CROSS_TEST_BUS_NAME,
                                path_keyword='sender_path')
        logger.info("method/signal: Triggering signal")
        self.expected.add('%s.Trigger' % INTERFACE_TESTS)
        Interface(obj, INTERFACE_TESTS).Trigger(u'/Where/Ever', dbus.UInt64(42), reply_handler=self.trigger_returned_cb, error_handler=self.trigger_error_handler)
开发者ID:tizenorg,项目名称:external.dbus-python,代码行数:21,代码来源:cross-test-client.py

示例4: __init__

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
class SSTrigger:
    def __init__(self):
        DBusGMainLoop(set_as_default=True)
        self.mem='ActiveChanged'
        self.dest='org.gnome.ScreenSaver'
        self.bus=SessionBus()
        self.loop=MainLoop()
        self.bus.add_signal_receiver(self.catch,self.mem,self.dest)

    def catch(self,ssOn):
        conn = mdb.connect('localhost', 'root','mysql_password', 'working_time');
        cursor = conn.cursor()
        now = datetime.datetime.now()

        if ssOn == 1: #Screensaver turned on
            sql = "UPDATE working_time SET end='%s' WHERE date='%s' AND end='0:0'"\
                    %(now.strftime("%H:%M"),now.strftime("%Y-%m-%d"))
            #logging.info(" sql=%s "%sql)
            logging.info("end=%s" % str(now.strftime("%H:%M")))
            res = cursor.execute(sql)
            if conn.affected_rows() != 1:
                cursor.execute("SELECT * from working_time")
                if cursor.rowcount != 1: # ignore error if it is a very first record in database
                    logging.error("ERROR!!! It should be only one (the last) record with end=0:0")

        else: #Screensaver turned off
            sql = "INSERT INTO working_time (date, start, end) VALUES('%s','%s','%s')"\
                    %(now.strftime("%Y-%m-%d"),now.strftime("%H:%M"),"0:0")
            #logging.info(" sql=%s "%sql)
            res=cursor.execute(sql)
            logging.info("start=%s "%now.strftime("%H:%M"))
            os.system("xmessage -nearmouse 'If you were out then start: log_working_time.py break'")

        conn.commit()	
        cursor.close()
        conn.close()
开发者ID:duleorlovic,项目名称:log_working_time,代码行数:38,代码来源:ssTriger.py

示例5: Server

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
class Server(SingleTestsImpl, TestsImpl, SignalTestsImpl):

    def triggered_by_client(self, parameter1, parameter2, sender, sender_path):
        # Called when the client emits TestSignals.Trigger from any object.
        logger.info('signal/callback: Triggered by client (%s:%s): (%r,%r)', sender, sender_path, parameter1, parameter2)
        tested_things.add(INTERFACE_SIGNAL_TESTS + '.Trigger')
        dbus.Interface(dbus.SessionBus().get_object(sender, sender_path),
                       INTERFACE_CALLBACK_TESTS).Response(parameter1, parameter2)
        logger.info('signal/callback: Sent Response')



if __name__ == '__main__':
    bus = SessionBus()
    bus_name = BusName(CROSS_TEST_BUS_NAME, bus=bus)
    loop = gobject.MainLoop()
    obj = Server(bus_name, CROSS_TEST_PATH, loop.quit)
    objects[CROSS_TEST_PATH] = obj
    bus.add_signal_receiver(obj.triggered_by_client,
                            signal_name='Trigger',
                            dbus_interface=INTERFACE_SIGNAL_TESTS,
                            named_service=None,
                            path=None,
                            sender_keyword='sender',
                            path_keyword='sender_path',
                            utf8_strings=True)

    logger.info("running...")
    loop.run()
    logger.info("main loop exited.")
开发者ID:tizenorg,项目名称:external.dbus-python,代码行数:32,代码来源:cross-test-server.py

示例6: _ISkypeAPI

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
class _ISkypeAPI(_ISkypeAPIBase):
    def __init__(self, handler, opts):
        _ISkypeAPIBase.__init__(self, opts)
        self.RegisterHandler(handler)
        self.skype_in = self.skype_out = self.dbus_name_owner_watch = None
        self.bus = opts.pop('Bus', None)
        try:
            mainloop = opts.pop('MainLoop')
            if self.bus is not None:
                raise TypeError('Bus and MainLoop cannot be used at the same time!')
        except KeyError:
            if self.bus is None:
                import dbus.mainloop.glib
                import gobject
                gobject.threads_init()
                dbus.mainloop.glib.threads_init()
                mainloop = dbus.mainloop.glib.DBusGMainLoop()
                self.mainloop = gobject.MainLoop()
        if self.bus is None:
            from dbus import SessionBus
            self.bus = SessionBus(private=True, mainloop=mainloop)
        if opts:
            raise TypeError('Unexpected parameter(s): %s' % ', '.join(opts.keys()))

    def run(self):
        self.DebugPrint('thread started')
        if hasattr(self, 'mainloop'):
            self.mainloop.run()
        self.DebugPrint('thread finished')

    def Close(self):
        if hasattr(self, 'mainloop'):
            self.mainloop.quit()
        self.skype_in = self.skype_out = None
        if self.dbus_name_owner_watch is not None:
            self.bus.remove_signal_receiver(self.dbus_name_owner_watch)
        self.dbus_name_owner_watch = None
        self.DebugPrint('closed')

    def SetFriendlyName(self, FriendlyName):
        self.FriendlyName = FriendlyName
        if self.skype_out:
            self.SendCommand(ICommand(-1, 'NAME %s' % FriendlyName))

    def StartWatcher(self):
        self.dbus_name_owner_watch = self.bus.add_signal_receiver(self.dbus_name_owner_changed,
            'NameOwnerChanged',
            'org.freedesktop.DBus',
            'org.freedesktop.DBus',
            '/org/freedesktop/DBus',
            arg0='com.Skype.API')

    def __Attach_ftimeout(self):
        self.wait = False

    def Attach(self, Timeout=30000, Wait=True):
        try:
            if not self.isAlive():
                self.StartWatcher()
                self.start()
        except AssertionError:
            pass
        try:
            self.wait = True
            t = threading.Timer(Timeout / 1000.0, self.__Attach_ftimeout)
            if Wait:
                t.start()
            while self.wait:
                if not Wait:
                    self.wait = False
                try:
                    if not self.skype_out:
                        self.skype_out = self.bus.get_object('com.Skype.API', '/com/Skype')
                    if not self.skype_in:
                        self.skype_in = _SkypeNotifyCallback(self.bus, self.notify)
                except dbus.DBusException:
                    if not Wait:
                        break
                    time.sleep(1.0)
                else:
                    break
            else:
                raise ISkypeAPIError('Skype attach timeout')
        finally:
            t.cancel()
        c = ICommand(-1, 'NAME %s' % self.FriendlyName, '', True, Timeout)
        if self.skype_out:
            self.SendCommand(c)
        if c.Reply != 'OK':
            self.skype_out = None
            self.SetAttachmentStatus(apiAttachRefused)
            return
        self.SendCommand(ICommand(-1, 'PROTOCOL %s' % self.Protocol))
        self.SetAttachmentStatus(apiAttachSuccess)

    def IsRunning(self):
        try:
            self.bus.get_object('com.Skype.API', '/com/Skype')
            return True
        except dbus.DBusException:
#.........这里部分代码省略.........
开发者ID:brianhlin,项目名称:htcondor,代码行数:103,代码来源:posix_dbus.py

示例7: __init__

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
class SSTrigger:
	
    # FORMAT MESSAGE : [START/STOP] [X] [Y]

    MAIN_DIR = "/usr/bin/ProActiveScreenSaver"

    start = 'START'
    stop = 'STOP'

    #log path of proxy
    config_file = 'log/proxy.txt'

    #named pipe path
    pipe_path = "/tmp/ss.pipe"

    #Initialize dbus
    def __init__(self):
        DBusGMainLoop(set_as_default=True)
        self.mem='ActiveChanged'
        self.dest='org.gnome.ScreenSaver'
        self.bus=SessionBus()
        self.loop=MainLoop()
        self.bus.add_signal_receiver(self.catch,self.mem,self.dest)

    # log method
    def writeLOG(self, txt):
    	f = open( self.MAIN_DIR + "/" + self.config_file ,'a')
        f.write( txt )
        f.close()

    # receive signal and write message on dbus
    def catch(self,ssOn):
        
        screen = commands.getoutput("xrandr | grep \* | tr -s ' ' | cut -d' ' -f2")
        screen_res = screen.split('x')
    
        #Screensize	
        length = screen_res[0]
        width = screen_res[1]
        
        if ssOn == 1: #Screensaver turned on

            data = self.start + " " + length + " " + width
            
            pipe = open(self.pipe_path, 'w')
	    
            pipe.write(data)		
            pipe.close()

            self.writeLOG(time.ctime() + "proxy has send : " + data + "\n")
            print "proxy has send : " + data

        else: #Screensaver turned off
 	    
            data = self.stop + " " + length + " " + width
            
            pipe = open(self.pipe_path, 'w')
	    
            pipe.write(data)		
            pipe.close()

            self.writeLOG(time.ctime() + "proxy has send : " + data + "\n")
            print "proxy has send : " + data
开发者ID:ow2-proactive,项目名称:agent-common,代码行数:65,代码来源:proxy.py

示例8: SessionBus

# 需要导入模块: from dbus import SessionBus [as 别名]
# 或者: from dbus.SessionBus import add_signal_receiver [as 别名]
        tested_things.add(INTERFACE_SIGNAL_TESTS + ".Trigger")
        dbus.Interface(dbus.SessionBus().get_object(sender, sender_path), INTERFACE_CALLBACK_TESTS).Response(
            parameter1, parameter2
        )
        logger.info("signal/callback: Sent Response")


if __name__ == "__main__":
    bus = SessionBus()
    bus_name = BusName(CROSS_TEST_BUS_NAME, bus=bus)
    loop = gobject.MainLoop()
    obj = Server(bus_name, CROSS_TEST_PATH, loop.quit)
    objects[CROSS_TEST_PATH] = obj
    kwargs = {}
    if is_py2:
        kwargs["utf8_strings"] = True
    bus.add_signal_receiver(
        obj.triggered_by_client,
        signal_name="Trigger",
        dbus_interface=INTERFACE_SIGNAL_TESTS,
        named_service=None,
        path=None,
        sender_keyword="sender",
        path_keyword="sender_path",
        **kwargs
    )

    logger.info("running...")
    loop.run()
    logger.info("main loop exited.")
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:32,代码来源:cross-test-server.py


注:本文中的dbus.SessionBus.add_signal_receiver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。