Skip to content

Commit

Permalink
add runcat
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesPikachu committed Jan 22, 2020
1 parent 34ff029 commit 82bc6e5
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ You can star this repository to keep track of the project if it's helpful for yo
#### earthWallpaper
- [Introduction](https://mp.weixin.qq.com/s/pDZpzzpd1g5bodtFdEROEg)
- [Code](https://github.com/CharlesPikachu/Tools/tree/master/earthWallpaper)
#### Runcat
- [Introduction]()
- [Code](https://github.com/CharlesPikachu/Tools/tree/master/Runcat)

# More
#### WeChat Official Accounts
Expand Down
13 changes: 13 additions & 0 deletions Runcat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Introduction


# Version
- V0.1

# Usage
```
Step1:
install the dependencies(pip install -r requirements.txt)
Step2:
modify line68 according to your needs, and then run "python scanport.py"
```
Binary file added Runcat/icons/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Runcat/icons/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Runcat/icons/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Runcat/icons/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Runcat/icons/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Runcat/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psutil
74 changes: 74 additions & 0 deletions Runcat/runcat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'''
Function:
用奔跑的猫来代表电脑资源使用情况(CPU/内存)
Author:
Charles
微信公众号:
Charles的皮卡丘
'''
import sys
import time
import psutil
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon


'''奔跑的猫-CPU'''
def runcatCPU():
app = QApplication(sys.argv)
# 最后一个可视的窗口退出时程序不退出
app.setQuitOnLastWindowClosed(False)
icon = QSystemTrayIcon()
icon.setIcon(QIcon('icons/0.png'))
icon.setVisible(True)
cpu_percent = psutil.cpu_percent(interval=1) / 100
cpu_percent_update_fps = 20
fps_count = 0
while True:
fps_count += 1
if fps_count > cpu_percent_update_fps:
cpu_percent = psutil.cpu_percent(interval=1) / 100
fps_count = 0
# 开口向上的抛物线, 左边递减
time_interval = (cpu_percent * cpu_percent - 2 * cpu_percent + 2) / 20
for i in range(5):
icon.setIcon(QIcon('icons/%d.png' % i))
icon.setToolTip('cpu: %.2f' % cpu_percent)
time.sleep(time_interval)
app.exec_()


'''奔跑的猫-内存'''
def runcatMemory():
app = QApplication(sys.argv)
# 最后一个可视的窗口退出时程序不退出
app.setQuitOnLastWindowClosed(False)
icon = QSystemTrayIcon()
icon.setIcon(QIcon('icons/0.png'))
icon.setVisible(True)
memory_percent = psutil.virtual_memory().percent / 100
memory_percent_update_fps = 20
fps_count = 0
while True:
fps_count += 1
if fps_count > memory_percent_update_fps:
memory_percent = psutil.virtual_memory().percent / 100
fps_count = 0
# 开口向上的抛物线, 左边递减
time_interval = (memory_percent * memory_percent - 2 * memory_percent + 2) / 20
for i in range(5):
icon.setIcon(QIcon('icons/%d.png' % i))
icon.setToolTip('memory: %.2f' % memory_percent)
time.sleep(time_interval)
app.exec_()


'''run'''
if __name__ == '__main__':
resource_type = ['cpu', 'memory'][0]
if resource_type == 'cpu':
runcatCPU()
elif resource_type == 'memory':
runcatMemory()
else:
raise ValueError('Unknow resource_type <%s>...' % resource_type)

0 comments on commit 82bc6e5

Please sign in to comment.