浏览代码

i3 status ping pause

master
Robin Thoni 8 年前
父节点
当前提交
139bb89b4f
共有 3 个文件被更改,包括 27 次插入11 次删除
  1. 二进制
      i3/i3/status/i3status/__pycache__/ping.cpython-34.pyc
  2. 20
    7
      i3/i3/status/i3status/ping.py
  3. 7
    4
      i3/i3/status/status.py

二进制
i3/i3/status/i3status/__pycache__/ping.cpython-34.pyc 查看文件


+ 20
- 7
i3/i3/status/i3status/ping.py 查看文件

@@ -10,14 +10,21 @@ class Ping(IntervalModule):
10 10
         ("host", "host to ping"),
11 11
         ("format", "format string"),
12 12
         ("format_down", "format down string"),
13
+        ("format_pause", "format pause string"),
13 14
         ("color", "color"),
14
-        ("color_down", "color down")
15
+        ("color_down", "color down"),
16
+        ("color_pause", "color pause")
15 17
     )
16
-    host = "8.8.8.8"
17
-    format = "{ping} ms"
18
-    format_down = "down"
18
+
19
+    active = True
19 20
     color = "#FFFFFF"
20 21
     color_down = "#FF0000"
22
+    color_pause = "#FF4500"
23
+    format = "{ping} ms"
24
+    format_down = "{ping} ms"
25
+    format_pause = "{ping} ms"
26
+    host = "8.8.8.8"
27
+    on_leftclick = "switch_state"
21 28
 
22 29
     def ping_host(self):
23 30
         p = subprocess.Popen(["ping", "-c1", "-w%d" % self.interval,
@@ -30,6 +37,13 @@ class Ping(IntervalModule):
30 37
             return ""
31 38
 
32 39
     def run(self):
40
+        if not self.active:
41
+            self.output = {
42
+                "full_text": self.format_pause.format(ping=0),
43
+                "color": self.color_pause
44
+            }
45
+            return
46
+
33 47
         ping = self.ping_host()
34 48
         if not ping:
35 49
             self.output = {
@@ -44,6 +58,5 @@ class Ping(IntervalModule):
44 58
             "color": self.color
45 59
         }
46 60
 
47
-
48
-if __name__ == "__main__":
49
-    print(Ping().ping_host())
61
+    def switch_state(self):
62
+        self.active = not self.active

+ 7
- 4
i3/i3/status/status.py 查看文件

@@ -125,7 +125,8 @@ status.register(Ping,
125 125
                 color=g_color_good,
126 126
                 color_down=g_color_alert,
127 127
                 format="\uf07d {ping:03.0f} ms",
128
-                format_down="\uf07d 000 ms")
128
+                format_down="\uf07d 000 ms",
129
+                format_pause="\uf07d 000 ms")
129 130
 
130 131
 def get_iface_param(iface):
131 132
     if isinstance(iface, list):
@@ -133,7 +134,7 @@ def get_iface_param(iface):
133 134
     return iface, iface
134 135
 
135 136
 ifaces_wireless = ["wlan0", "wlan1"]
136
-ifaces_wired = ["eth0", "usb0"]
137
+ifaces_wired = ["eth0", "usb0", "br0"]
137 138
 ifaces_tun = [["tun0", "rthoni.com"], ["tun1", "inet"],
138 139
         ["tun2", "betaclean"]]
139 140
 
@@ -146,7 +147,8 @@ for iface in ifaces_wireless:
146 147
                 format_down="\uf1eb " + iface_name,
147 148
                 format_down_hide="\uf1eb",
148 149
                 format_up="\uf1eb {essid} ({quality:03.0f}%) {v4}",
149
-                format_up_hide="\uf1eb " + iface_name)
150
+                format_up_hide="\uf1eb " + iface_name,
151
+                unknown_up=True)
150 152
 
151 153
 for iface in ifaces_wired:
152 154
     iface, iface_name = get_iface_param(iface)
@@ -157,7 +159,8 @@ for iface in ifaces_wired:
157 159
                 format_down="\uf0e8 " + iface_name,
158 160
                 format_down_hide="\uf0e8",
159 161
                 format_up="\uf0e8 {v4}",
160
-                format_up_hide="\uf0e8 " + iface_name)
162
+                format_up_hide="\uf0e8 " + iface_name,
163
+                unknown_up=True)
161 164
 
162 165
 for iface in ifaces_tun:
163 166
     iface, iface_name = get_iface_param(iface)

正在加载...
取消
保存