您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

change_i3pystatus.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 = 18
  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) + 1
  28. width, height = 0, 0
  29. for mn_curr in range(mn_number):
  30. mn = screen.get_monitor_geometry(mn_curr)
  31. width += mn.width
  32. height += mn.height
  33. return width, height
  34. ###############################################################################
  35. # Command end point
  36. ###############################################################################
  37. def change_command_end_point():
  38. """ We create a modified version of _command_endpoint that add the support
  39. of x and y"""
  40. def _command_endpoint(self):
  41. for command in self.io_handler_factory().read():
  42. target_module = self.modules.get(command["instance"])
  43. if target_module:
  44. try:
  45. target_module._pos_x = int(command["x"])
  46. target_module._pos_y = int(command["y"])
  47. target_module.on_click(command["button"])
  48. except Exception:
  49. continue
  50. CommandEndpoint._command_endpoint = _command_endpoint
  51. ###############################################################################
  52. # Clock
  53. ###############################################################################
  54. def change_clock():
  55. def display_calendar(quit, s):
  56. if "_pid" in s.__dict__ and check_pid(s._pid):
  57. return
  58. x, y = s._pos_x, s._pos_y
  59. width_calendar, height_calendar = 300, 210 # fixed values...
  60. width, height = get_current_screen_size(x, y)
  61. if (x > width - width_calendar):
  62. x = width - width_calendar
  63. if (y < g_i3bar_size):
  64. y = g_i3bar_size
  65. if (y > height - height_calendar):
  66. y = height - height_calendar - g_i3bar_size
  67. s._pid = exec("calendar-window --size=%d-%d --position=%d-%d "
  68. "--onLostFocus=%s" % (width_calendar, height_calendar,
  69. x, y, "quit" if quit else "ignore"))
  70. #s._pid = exec("yad --no-buttons --geometry=+%d+%d --class "
  71. # "\"i3bar-gui\" --calendar" % (x, y))
  72. def display_calendar_quit(s):
  73. display_calendar(True, s)
  74. def display_calendar_ignore(s):
  75. display_calendar(False, s)
  76. Clock.display_calendar = display_calendar_quit
  77. Clock.on_leftclick = display_calendar_quit
  78. Clock.on_rightclick = display_calendar_ignore
  79. ###############################################################################
  80. # Network
  81. ###############################################################################
  82. def change_network():
  83. # We create the switch function
  84. def switch_hide(s):
  85. s.format_up, s.format_up_hide = s.format_up_hide, s.format_up
  86. s.format_down, s.format_down_hide = s.format_down_hide, s.format_down
  87. # We add it to the module
  88. Network.switch_hide = switch_hide
  89. # We add the correct settings and we init everything properly
  90. Network.format_up_hide = Network.format_up
  91. Network.format_down_hide = Network.format_down
  92. Network.on_leftclick = switch_hide
  93. Network.settings += (("format_down_hide", ""),)
  94. Network.settings += (("format_up_hide", ""),)
  95. # We change the mouse control
  96. Network.format_up_hide = Network.format_up
  97. Network.on_rightclick = Network.on_leftclick
  98. Network.on_upscroll = Network.on_leftclick
  99. Network.on_downscroll = Network.on_leftclick
  100. ###############################################################################
  101. # Change that we apply
  102. ###############################################################################
  103. def change_all():
  104. change_command_end_point()
  105. change_clock()
  106. change_network()