config.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. '''i3pystatus config
  2. '''
  3. from i3pystatus import Status
  4. # from i3pystatus.updates import aptget
  5. from i3pystatus.updates import pacman
  6. from i3pystatus.updates import paru
  7. from i3pystatus.updates import checkupdates_plus_aur
  8. from i3pystatus.weather import weathercom
  9. from i3pystatus import get_module
  10. import os
  11. import subprocess
  12. from modules import show_updates
  13. # Colors:
  14. # Materia Manjaro
  15. colors = {
  16. "background": "#263238",
  17. "foreground": "#dbdcd5",
  18. "alert": "#cc241d",
  19. "current_screen_tab": "#585E72",
  20. "group_names": "#dbdcd5",
  21. "line_color_curr_tab": "#009185",
  22. "line_color_other_tab": "#8d62a9",
  23. "even_widgets": "#6182b8",
  24. "window_name": "#24d2af",
  25. "cpu": "#e2a0a5",
  26. "memory": "#ffb62c",
  27. "net_speed_up": "#24d2af",
  28. "net_speed_down": "#91b859",
  29. "layout_widget": "#ffffff",
  30. "keyboard": "#6182b8",
  31. "date_time": "#39adb5",
  32. "date_time2": "#f2b06a",
  33. "sys_tray": "#404555",
  34. "updates": "#ffcb6b",
  35. "updates2": "#e2e0a5",
  36. "weather": "#eb7bef",
  37. "weather2": "#ec30f3",
  38. "weather3": "#e2e0a5",
  39. "chord": "#d79921",
  40. "active": "#00ff00",
  41. "inactive": "#ff0000"
  42. }
  43. def get_all_netifaces(path_to_state="/sys/class/net/"):
  44. """
  45. Get all netifaces in the /sys/class/net/ and
  46. add all to the list except 'lo'.
  47. """
  48. netifaces_list = []
  49. for dir in os.listdir(path_to_state):
  50. if os.path.isdir("{}{}".format(path_to_state, dir)):
  51. if dir != "lo":
  52. netifaces_list.append(dir)
  53. return netifaces_list
  54. def which_netiface_upped(netifaces=[]):
  55. """
  56. Check which interface is upped for widget.Net.
  57. Returns the first upped netiface.
  58. """
  59. if netifaces:
  60. for netiface in netifaces:
  61. state = subprocess.check_output(["cat", "{}{}{}".format(path_to_state, netiface, "/operstate")]).decode("utf-8").rstrip()
  62. if state == "up":
  63. return netiface
  64. return None
  65. my_term = "alacritty"
  66. my_term_extra = "terminator"
  67. home = os.path.expanduser("~")
  68. # Check which network iface is upped.
  69. path_to_state = "/sys/class/net/" # enp2s0/operstate"
  70. # default_upped_netiface = "wlo1"
  71. netifaces = get_all_netifaces(path_to_state)
  72. upped_netiface = which_netiface_upped(netifaces)
  73. status = Status(
  74. standalone=True,
  75. logfile="$HOME/.config/i3pystatus/i3pystatus.log"
  76. ) # pylint: disable=invalid-name
  77. status.register(
  78. "my_xkblayout",
  79. # color=colors["keyboard"],
  80. # color=colors["updates2"],
  81. # "🇺🇸", "🇷🇺"],
  82. layouts=["us", "ru"],
  83. # format=" {symbol}",
  84. format="{flag}",
  85. )
  86. status.register(
  87. "clock",
  88. # color="#888888",
  89. color=colors["date_time"],
  90. # format=('%a, %d %b <span color="#0099ff">%H:%M:%S</span> Gomel', 'Europe/Minsk'),
  91. format=(" %a,%d %b %H:%M:%S", "Europe/Minsk"),
  92. on_leftclick="gsimplecal",
  93. hints={"markup": "pango"})
  94. # Note: the network module requires PyPI package netifaces
  95. status.register(
  96. "network",
  97. dynamic_color=False,
  98. color_up=colors["net_speed_down"],
  99. interface=upped_netiface,
  100. format_up=" {bytes_recv}KB/s  {bytes_sent}KB/s",
  101. hints={"markup": "pango"}
  102. )
  103. status.register(
  104. "my_mem",
  105. color=colors["memory"],
  106. divisor=1024**3,
  107. format=" {used_mem}GiB ({percent_used_mem}%)",
  108. interval=1,
  109. on_rightclick=my_term + " -e htop",
  110. on_leftclick=home + "/.myScripts/top5_mem_usage.sh"
  111. )
  112. status.register(
  113. "cpu_usage",
  114. color=colors["cpu"],
  115. format=" {usage:02}%",
  116. interval=1,
  117. on_rightclick=my_term + " -e htop",
  118. on_leftclick=home + "/.myScripts/top5_cpu_usage.sh"
  119. )
  120. status.register(
  121. "open_weather",
  122. format="🌡{location_city}: {temp}°{units_temperature} {weather_details}",
  123. color=colors["weather"],
  124. coordinates={"longitude": "30.9754", "latitude": "52.4345"},
  125. # language="ru",
  126. interval=1800
  127. )
  128. status.register(
  129. "my_syncthing",
  130. label="Syncthing:  ",
  131. # inactive_color="#0000ff",
  132. # active_color="#ff00ff",
  133. interval=60,
  134. path_to_script="{}/.myScripts/get_syncthing_status.sh".format(home),
  135. on_rightclick="xdg-open 'http://127.0.0.1:8384/'"
  136. )
  137. status.register(
  138. "updates",
  139. color=colors["updates"],
  140. format=" {count}",
  141. # format_working="🔃",
  142. format_working="⟳ ",
  143. # backends=[pacman.Pacman(), paru.Paru(False)], # paru counts only AUR
  144. # backends=[paru.Paru()],
  145. backends=[checkupdates_plus_aur.CheckupdatesPlusAur()],
  146. interval=10800, # 3 hours (60*60*3)
  147. on_rightclick=show_updates.show_updates_arch,
  148. on_middleclick=my_term_extra + " -e 'sudo yay -Syu'"
  149. )
  150. # # status.register(
  151. # # "window_title",
  152. # # color=colors["window_name"],
  153. # # format="{class_name} - {title}",
  154. # # hints={"markup": "pango", "separator": True},
  155. # # max_width=40
  156. # # )
  157. #
  158. status.run()