Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

change_i3pystatus.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from i3pystatus.core import CommandEndpoint
  2. from i3pystatus.network import Network
  3. from i3pystatus.clock import Clock
  4. from gi.repository import Gtk
  5. import subprocess
  6. import sys
  7. import psutil
  8. import os
  9. import traceback
  10. ###############################################################################
  11. # Tools
  12. ###############################################################################
  13. g_i3bar_size = 20
  14. def exec(s):
  15. p = subprocess.Popen(s.split(), stdout=sys.stderr.buffer)
  16. return p.pid
  17. def check_pid(pid):
  18. if psutil.pid_exists(pid):
  19. proc = psutil.Process(pid)
  20. if proc.status() == psutil.STATUS_ZOMBIE:
  21. os.kill(pid, 2)
  22. return False
  23. return True
  24. return False
  25. def get_current_screen_size(x, y):
  26. screen = Gtk.Window().get_screen()
  27. mn_number = screen.get_monitor_at_point(x, y)
  28. return screen.get_monitor_geometry(mn_number)
  29. ###############################################################################
  30. # Command end point
  31. ###############################################################################
  32. def change_command_end_point():
  33. """ We create a modified version of _command_endpoint that add the support
  34. of x and y"""
  35. def _command_endpoint(self):
  36. for command in self.io_handler_factory().read():
  37. target_module = self.modules.get(command["instance"])
  38. if target_module:
  39. try:
  40. target_module._pos_x = int(command["x"])
  41. target_module._pos_y = int(command["y"])
  42. target_module.on_click(command["button"])
  43. except Exception:
  44. continue
  45. CommandEndpoint._command_endpoint = _command_endpoint
  46. ###############################################################################
  47. # Clock
  48. ###############################################################################
  49. def change_clock():
  50. def display_calendar(quit, s):
  51. if "_pid" in s.__dict__ and check_pid(s._pid):
  52. return
  53. x, y = s._pos_x, s._pos_y
  54. width_calendar, height_calendar = 300, 210 # fixed values...
  55. rect = get_current_screen_size(x, y)
  56. x = rect.width + rect.x - width_calendar
  57. if (y < g_i3bar_size):
  58. y = rect.y + g_i3bar_size
  59. else:
  60. y = rect.height + rect.y - height_calendar - g_i3bar_size
  61. s._pid = exec("calendar-window --size=%d-%d --position=%d-%d "
  62. "--onLostFocus=%s" % (width_calendar, height_calendar,
  63. x, y, "quit" if quit else "ignore"))
  64. def display_calendar_quit(s):
  65. display_calendar(True, s)
  66. def display_calendar_ignore(s):
  67. display_calendar(False, s)
  68. Clock.display_calendar_quit = display_calendar_quit
  69. Clock.display_calendar_ignore = display_calendar_ignore
  70. Clock.on_leftclick = "display_calendar_quit"
  71. Clock.on_rightclick = "display_calendar_ignore"
  72. ###############################################################################
  73. # Network
  74. ###############################################################################
  75. def change_network():
  76. # We create the switch function
  77. def switch_hide(s):
  78. s.format_up, s.format_up_hide = s.format_up_hide, s.format_up
  79. s.format_down, s.format_down_hide = s.format_down_hide, s.format_down
  80. # We add it to the module
  81. Network.switch_hide = switch_hide
  82. # We add the correct settings and we init everything properly
  83. Network.format_up_hide = Network.format_up
  84. Network.format_down_hide = Network.format_down
  85. Network.on_leftclick = "switch_hide"
  86. Network.settings += (("format_down_hide", ""),)
  87. Network.settings += (("format_up_hide", ""),)
  88. # We change the mouse control
  89. Network.format_up_hide = Network.format_up
  90. Network.on_rightclick = Network.on_leftclick
  91. Network.on_upscroll = Network.on_leftclick
  92. Network.on_downscroll = Network.on_leftclick
  93. ###############################################################################
  94. # Change that we apply
  95. ###############################################################################
  96. def change_all():
  97. change_command_end_point()
  98. change_clock()
  99. change_network()