def __init__(self, scheduler: 'Scheduler', bus=SYSTEM_BUS): self.interface = DBusInterface(scheduler=scheduler) self.scheduler = scheduler self.scheduler.status_update_callback = self.__status_update_handler self.scheduler.pause_callback = self.__pause_handler self.bus = bus self.service_identifier = get_dbus_service_identifier(bus) self.loop = EventLoop()
def create_loop(*args, **kwargs): loop = EventLoop() GLib.idle_add(run_in_loop, *args, **kwargs) GLib.timeout_add_seconds(self._timeout, kill_loop, loop) loop.run() return self._result
# # Handle changed properties. # Start the server, start the listener and run the client. # from dasbus.loop import EventLoop from common import REGISTER def callback(interface, changed_properties, invalid_properties): """The callback of the DBus signal PropertiesChanged.""" print("Properties of {} has changed: {}".format( interface, changed_properties )) if __name__ == "__main__": # Create a proxy of the object /org/example/Register # provided by the service org.example.Register proxy = REGISTER.get_proxy() # Connect the callback to the DBus signal PropertiesChanged. proxy.PropertiesChanged.connect(callback) # Start the event loop. loop = EventLoop() loop.run()
import pulsectl import dasbus from playsound import playsound from dasbus.loop import EventLoop from dasbus.server.interface import dbus_interface from dasbus.identifier import DBusServiceIdentifier from dasbus.connection import SessionMessageBus from gi.repository import GLib logging.basicConfig(level=logging.INFO) EX_CODE = os.EX_OK VOL_STEP = 0.03 LOOP = EventLoop() if 'XDG_RUNTIME_DIR' in os.environ: XOB_FILE = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'xob') WOB_FILE = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'wob.sock') else: XOB_FILE = "/tmp/%s_xob.pipe" % os.environ['USER'] WOB_FILE = '/tmp/%s_wob.sock' % os.environ['USER'] def term_handler(signum, frame): print('Signal handler called with signal', signum) if SESSION_BUS: logging.debug("disconnecting session bus") SESSION_BUS.disconnect() logging.debug("session bus disconnected") if LOOP: