Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. xinput set-prop $DEVICE_ID "Synaptics Click Action" 1 3 2
  2.  
  3. #!/usr/bin/env python
  4.  
  5. import sys
  6. import signal
  7. import logging
  8. import dbus
  9. import dbus.service
  10. import dbus.mainloop.glib
  11. import gobject
  12.  
  13. LOG_LEVEL = logging.INFO
  14. #LOG_LEVEL = logging.DEBUG
  15. LOG_FILE = "/dev/stdout"
  16. #LOG_FILE = "/var/log/syslog"
  17. LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s"
  18.  
  19. def device_property_changed_cb(property_name, value, path, interface):
  20. device = dbus.Interface(bus.get_object("org.bluez", path), "org.bluez.Device")
  21. properties = device.GetProperties()
  22.  
  23. if (property_name == "Connected"):
  24. action = "connected" if value else "disconnected"
  25. #
  26. # Replace with your code to write to the PiFace
  27. #
  28. print("The device %s [%s] is %s " % (properties["Alias"], properties["Address"], action))
  29.  
  30. def shutdown(signum, frame):
  31. mainloop.quit()
  32.  
  33. if __name__ == "__main__":
  34. # shut down on a TERM signal
  35. signal.signal(signal.SIGTERM, shutdown)
  36.  
  37. # start logging
  38. logging.basicConfig(filename=LOG_FILE, format=LOG_FORMAT, level=LOG_LEVEL)
  39. logging.info("Starting btminder to monitor Bluetooth connections")
  40.  
  41. # Get the system bus
  42. try:
  43. dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
  44. bus = dbus.SystemBus()
  45. except Exception as ex:
  46. logging.error("Unable to get the system dbus: '{0}'. Exiting btminder. Is dbus running?".format(ex.message))
  47. sys.exit(1)
  48.  
  49. # listen for signals on the Bluez bus
  50. bus.add_signal_receiver(device_property_changed_cb, bus_name="org.bluez", signal_name="PropertyChanged",
  51. dbus_interface="org.bluez.Device", path_keyword="path", interface_keyword="interface")
  52.  
  53. try:
  54. mainloop = gobject.MainLoop()
  55. mainloop.run()
  56. except KeyboardInterrupt:
  57. pass
  58. except:
  59. logging.error("Unable to run the gobject main loop")
  60.  
  61. logging.info("Shutting down btminder")
  62. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement