Python新手在这里。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import commands,time
def get_vol():
vol =int(commands.getoutput("amixer get Master | grep -E -o '[0-9]
{1,3}?%' | head -1 | sed 's/.$//'"))
full_block =(vol+10)/10-1
if vol%10==0:
half_block =0
else:
half_block =1
empty_block =10-(full_block+half_block)
return '▮'*full_block+'▯'*half_block+'-'*empty_block
def NTime():
return commands.getoutput("date '+%H:%M'")
def battery():
prenBat =int(commands.getoutput('acpi battery | grep -o "[0-9]*[0-9]" | sed "1d"'))
bat_icon =prenBat/20
status =commands.getoutput('acpi battery | egrep -o -m1 "Discharging|Charging|AC|Full|Unknown"')
if status== "Charging":
return '❖'+' ●'*bat_icon+' ○'*(5-bat_icon)
elif status=="Full":
return '✔'+' ●'*bat_icon+' ○'*(5-bat_icon)
else:
return ' ●'*bat_icon+' ○'*(5-bat_icon)
battime =1
batNum =battery()
while True:
time.sleep(0.1)
volume =get_vol()
nTime =NTime()
while battime ==30:
batNum =str(battery())
battime =1
else:
battime =battime+1
print batNum+" | "+volume+" | "+nTime
我直接使用这个脚本到 i3bar(没有 i3blocks),它什么也没显示。然后我等了一会儿。它显示了 barttery,但没有音量部分和时间部分。然后,我猜大约 10 秒。它从体积部分显示了一两个块(▮)。没有别的。
我尝试在终端中对其进行测试,结果很好。这是我来自 i3config 的 i3bar 部分。
bar {
position top
colors {
statusline #414149
background #8cb194
separator #414149
focused_workspace #8cb194 #c8d087 #000000
inactive_workspace #8cb194 #868974 #000000
}
# status_command i3blocks -c ~/.config/i3blocks.conf
status_command ~/.config/bar.py
}
对不起我的英语和新手代码。