1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
qtile-config/widget_custom/memory.py

44 lines
1.1 KiB
Python
Raw Permalink Normal View History

2020-02-10 11:09:07 +01:00
import psutil
from libqtile.widget import base
__all__ = ["Memory"]
class Memory(base.ThreadedPollText):
"""Displays memory/swap usage
MemUsed: Returns memory in use
MemTotal: Returns total amount of memory
MemFree: Returns amount of memory free
Buffers: Returns buffer amount
Active: Returns active memory
Inactive: Returns inactive memory
Shmem: Returns shared memory
SwapTotal: Returns total amount of swap
SwapFree: Returns amount of swap free
SwapUsed: Returns amount of swap in use
"""
orientations = base.ORIENTATION_HORIZONTAL
defaults = [
("format", "{MemUsed}%", "Formatting for field names."),
("update_interval", 1.0, "Update interval for the Memory"),
]
def __init__(self, **config):
super().__init__(**config)
self.add_defaults(Memory.defaults)
def tick(self):
self.update(self.poll())
return self.update_interval
def poll(self):
mem = psutil.virtual_memory()
swap = psutil.swap_memory()
val = {}
val["MemUsed"] = round((mem.used / mem.total) * 100)
return self.format.format(**val)