Guest User

Untitled

a guest
Apr 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import time
  4. import sys
  5. import json
  6. import subprocess
  7. from signal import signal, SIGTERM, SIGUSR1, SIGUSR2, SIGTSTP, SIGCONT, SIGIO, SIGRTMIN
  8.  
  9. def read_line():
  10. """ Interrupted respecting reader for stdin. """
  11. # try reading a line, removing any extra whitespace
  12. try:
  13. line = sys.stdin.readline().strip()
  14. # i3status sends EOF, or an empty line
  15. if not line:
  16. sys.exit(3)
  17. return line
  18. # exit on ctrl-c
  19. except KeyboardInterrupt:
  20. sys.exit()
  21.  
  22. if __name__ == '__main__':
  23.  
  24. def handle_signal(signum, frame):
  25. line = read_line()
  26. if line.startswith('['):
  27. line = ''
  28. else:
  29. if line.startswith(','):
  30. line = line[1:]
  31. event = json.loads(line)
  32. event['name'] = 'click'
  33. event['full_textl'] = 'click'
  34. sys.stdout.write(',[{}]\n'.format(json.dumps(event)))
  35.  
  36. signal(SIGTSTP, handle_signal)
  37. signal(SIGCONT, handle_signal)
  38. signal(SIGIO, handle_signal)
  39. signal(SIGUSR1, handle_signal)
  40. signal(SIGUSR2, handle_signal)
  41. signal(SIGRTMIN, handle_signal)
  42.  
  43. header = {
  44. 'version': 1,
  45. 'click_events': True
  46. }
  47.  
  48. sys.stdout.write(json.dumps(header))
  49.  
  50. # begining of an infinite array.
  51. sys.stdout.write('\n[[]\n')
  52.  
  53. # ibar 3 object
  54. j = [
  55. {
  56. "full_text": "full test",
  57. # "short_text": "test",
  58. # "color": "#00ff00",
  59. # "background": "#1c1c1c",
  60. # "border": "#ee0000",
  61. # "min_width": 300,
  62. # "align": "right",
  63. # "urgent": False,
  64. "name": "test",
  65. # "instance": "eth1",
  66. # "separator": True,
  67. # "separator_block_width": 90,
  68. "button":1
  69. }
  70. ]
  71.  
  72. sys.stdout.write(',{}\n'.format(json.dumps(j)))
  73. sys.stdout.flush()
  74. while True:
  75. time.sleep(3)
  76. sys.stdout.write(',{}\n'.format(json.dumps(j)))
  77. sys.stdout.flush()
Add Comment
Please, Sign In to add comment