config.py_Debian 4.5 KB

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