Add files
commit
600bbafaa6
|
@ -0,0 +1,9 @@
|
||||||
|
Copyright 2024 Nakidai
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,3 @@
|
||||||
|
from dwmbar.bar import Bar
|
||||||
|
import dwmbar.modules
|
||||||
|
from dwmbar.other import get_command_out
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,48 @@
|
||||||
|
from dwmbar.modules import BarItem
|
||||||
|
import os
|
||||||
|
from time import sleep, time
|
||||||
|
|
||||||
|
|
||||||
|
class Bar:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
items_count: int = 10,
|
||||||
|
sep: str = ''
|
||||||
|
) -> None:
|
||||||
|
self.sep = sep
|
||||||
|
self.items = [BarItem(False) for _ in range(items_count)]
|
||||||
|
|
||||||
|
def start(self, update_time: float = 0) -> None:
|
||||||
|
"""After call this function program will start infinity loop"""
|
||||||
|
while True:
|
||||||
|
start = time()
|
||||||
|
for i in range(len(self.items)):
|
||||||
|
self[i].update()
|
||||||
|
self.write()
|
||||||
|
finish = time()
|
||||||
|
sleep_time = update_time - (finish - start)
|
||||||
|
sleep(0 if sleep_time < 0 else sleep_time)
|
||||||
|
|
||||||
|
def __getitem__(
|
||||||
|
self,
|
||||||
|
key: int
|
||||||
|
) -> BarItem:
|
||||||
|
return self.items[key]
|
||||||
|
|
||||||
|
def __setitem__(
|
||||||
|
self,
|
||||||
|
key: int,
|
||||||
|
value: BarItem
|
||||||
|
) -> None:
|
||||||
|
self.items[key] = value
|
||||||
|
|
||||||
|
def __len__(self) -> int:
|
||||||
|
return len(self.items)
|
||||||
|
|
||||||
|
def write(self, reversed: bool = True) -> None:
|
||||||
|
out = ' ' + ''.join(
|
||||||
|
[str(self[i]) + ' / ' for i in range(len(self))
|
||||||
|
if self[i]
|
||||||
|
]
|
||||||
|
)[:-3] + ' '
|
||||||
|
os.system(f"xsetroot -name \"{out}\"")
|
|
@ -0,0 +1,125 @@
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
import psutil
|
||||||
|
from datetime import datetime
|
||||||
|
from dwmbar.other import get_command_out
|
||||||
|
|
||||||
|
|
||||||
|
class BarItem:
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
filled: bool = True
|
||||||
|
) -> None:
|
||||||
|
self.filled = bool(filled)
|
||||||
|
self.out = ''
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.out
|
||||||
|
|
||||||
|
def __bool__(self) -> bool:
|
||||||
|
return self.filled
|
||||||
|
|
||||||
|
|
||||||
|
class TimeItem(BarItem):
|
||||||
|
def update(self) -> None:
|
||||||
|
#
|
||||||
|
now = datetime.now()
|
||||||
|
if now.strftime("%p") == "AM":
|
||||||
|
self.out = " "
|
||||||
|
else:
|
||||||
|
self.out = " "
|
||||||
|
self.out += datetime.now().strftime("%I:%M")
|
||||||
|
|
||||||
|
|
||||||
|
class RAMItem(BarItem):
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""RAM in G"""
|
||||||
|
super().__init__(True)
|
||||||
|
self.divider = 2**30
|
||||||
|
self.total = round(psutil.virtual_memory()[0] / self.divider, 1)
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
used = round(psutil.virtual_memory()[3] / self.divider, 1)
|
||||||
|
self.out = f" {used}G"
|
||||||
|
|
||||||
|
|
||||||
|
class LayoutItem(BarItem):
|
||||||
|
def update(self) -> None:
|
||||||
|
self.out = ' ' + get_command_out(
|
||||||
|
"setxkbmap -query | grep layout"
|
||||||
|
).split()[-1].upper()
|
||||||
|
|
||||||
|
|
||||||
|
class CPUUsageItem(BarItem):
|
||||||
|
def update(self) -> None:
|
||||||
|
usage = psutil.cpu_percent()
|
||||||
|
usage = f"{usage}" if usage % 1 else f"{int(usage)}.0"
|
||||||
|
self.out = f" {usage:0>4}%"
|
||||||
|
|
||||||
|
|
||||||
|
class DiskUsageItem(BarItem):
|
||||||
|
def __init__(self, divider: int = 10**9) -> None:
|
||||||
|
super().__init__(True)
|
||||||
|
"""Disk in GB"""
|
||||||
|
self.divider = 10**9
|
||||||
|
self.total = round(psutil.disk_usage('/').total / self.divider, 1)
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
used = round(psutil.disk_usage('/').used / self.divider, 1)
|
||||||
|
self.out = F" {used}G/{self.total}G"
|
||||||
|
|
||||||
|
|
||||||
|
class BatteryItem(BarItem):
|
||||||
|
def __init__(self, hide_if_full: bool = False) -> None:
|
||||||
|
super().__init__(True)
|
||||||
|
# self.hide_if_full = hide_if_full
|
||||||
|
|
||||||
|
def update(self) -> None:
|
||||||
|
battery = psutil.sensors_battery()
|
||||||
|
# plugged = battery.power_plugged
|
||||||
|
percent = round(battery.percent)
|
||||||
|
# self.out = f" {'#' if plugged else '*'}{percent}%"
|
||||||
|
self.out = f" {percent}%"
|
||||||
|
# self.filled = False if self.hide_if_full and percent == 100 else True
|
||||||
|
|
||||||
|
|
||||||
|
class VolumeItem(BarItem):
|
||||||
|
def update(self) -> None:
|
||||||
|
volume = get_command_out(
|
||||||
|
"amixer get Master | awk -F'[][]' 'END{ print $4\":\"$2 }'"
|
||||||
|
)
|
||||||
|
self.out = " " + volume[volume.find(":") + 1:-1]
|
||||||
|
|
||||||
|
|
||||||
|
class MusicItem(BarItem):
|
||||||
|
def update(self) -> None:
|
||||||
|
try:
|
||||||
|
status = get_command_out("cmus-remote -Q")
|
||||||
|
except CalledProcessError:
|
||||||
|
self.out = " cmus"
|
||||||
|
return
|
||||||
|
if "file" not in status:
|
||||||
|
self.out = " cmus"
|
||||||
|
return
|
||||||
|
for var in status.split("\n"):
|
||||||
|
args = var.split()
|
||||||
|
if not args:
|
||||||
|
continue
|
||||||
|
match args[0]:
|
||||||
|
case "status":
|
||||||
|
if args[1] == "playing":
|
||||||
|
self.out = ""
|
||||||
|
else:
|
||||||
|
self.out = ""
|
||||||
|
case "file":
|
||||||
|
filename = var[var.rfind("/") + 1:var.rfind(".")]
|
||||||
|
self.out += " " + filename
|
||||||
|
|
||||||
|
|
||||||
|
class InfoItem(BarItem):
|
||||||
|
def __init__(self, text: str) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.out = text
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def get_command_out(command: str) -> None:
|
||||||
|
return subprocess.check_output(
|
||||||
|
command,
|
||||||
|
shell=True
|
||||||
|
).decode("utf-8")
|
|
@ -0,0 +1,28 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
states = ["us", "ru"]
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
state = states[1]
|
||||||
|
if os.path.exists("/tmp/layout.json"):
|
||||||
|
with open("/tmp/layout.json") as f:
|
||||||
|
state = json.load(f)["layout"]
|
||||||
|
for i, val in enumerate(states):
|
||||||
|
if val == state:
|
||||||
|
state = states[(i + 1) % len(states)]
|
||||||
|
break
|
||||||
|
with open("/tmp/layout.json", 'w') as f:
|
||||||
|
json.dump({"layout": state}, f, indent=4)
|
||||||
|
os.system(f"setxkbmap {state}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
main()
|
||||||
|
else:
|
||||||
|
if "-s" in sys.argv:
|
||||||
|
os.system(f"setxkbmap {states[0]}")
|
|
@ -0,0 +1,36 @@
|
||||||
|
import psutil
|
||||||
|
from pypresence import Presence
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
client_id = '1149335280072020078'
|
||||||
|
RPC = Presence(client_id, pipe=0)
|
||||||
|
RPC.connect()
|
||||||
|
|
||||||
|
start_time = psutil.boot_time()
|
||||||
|
while True:
|
||||||
|
# waiting = time.time() - start_time
|
||||||
|
# minutes = waiting // 60
|
||||||
|
# hours = minutes // 60
|
||||||
|
# minutes = minutes % 60
|
||||||
|
# waiting_days = int(time.time() - start_time) // 60 // 60 // 24
|
||||||
|
waiting_days = int(time.time() - start_time) // 60 // 60 // 24
|
||||||
|
# state=f"{int(hours):02}:{int(minutes):02}:{int(waiting % 60):02}",
|
||||||
|
RPC.update(
|
||||||
|
# details=details_list[i1],
|
||||||
|
state=f"{waiting_days} days,",
|
||||||
|
large_image="superpuper",
|
||||||
|
large_text="This is a picture, isn't it?",
|
||||||
|
buttons=[{
|
||||||
|
"label": "This is not rickroll",
|
||||||
|
"url": "https://goo.su/eriA6eD"
|
||||||
|
}],
|
||||||
|
start=start_time
|
||||||
|
)
|
||||||
|
RPC.update
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -0,0 +1,22 @@
|
||||||
|
import dwmbar
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
# kernel_ver = dwmbar.get_command_out("uname -r")[:-1]
|
||||||
|
|
||||||
|
bar = dwmbar.Bar()
|
||||||
|
bar[9] = dwmbar.modules.TimeItem()
|
||||||
|
bar[8] = dwmbar.modules.RAMItem()
|
||||||
|
# bar[7] = dwmbar.modules.DiskUsageItem()
|
||||||
|
# bar[6] = dwmbar.modules.CPUUsageItem()
|
||||||
|
bar[5] = dwmbar.modules.BatteryItem(True)
|
||||||
|
|
||||||
|
# bar[1] = dwmbar.modules.InfoItem(kernel_ver)
|
||||||
|
bar[2] = dwmbar.modules.VolumeItem()
|
||||||
|
bar[1] = dwmbar.modules.LayoutItem()
|
||||||
|
bar[0] = dwmbar.modules.MusicItem()
|
||||||
|
bar.start(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -0,0 +1 @@
|
||||||
|
sleep 1 && xset -display :0.0 dpms force off
|
Loading…
Reference in New Issue