-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bar): improve structure and organization
- Loading branch information
Showing
10 changed files
with
147 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
from core.bar import theme | ||
|
||
bar, tags = theme.bar | ||
from core.bar.base import Bar | ||
|
||
__all__ = [ | ||
"bar", | ||
"tags", | ||
"Bar", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from importlib import import_module | ||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
from libqtile import bar | ||
|
||
from extras import PowerLineDecoration, RectDecoration | ||
from utils.config import cfg | ||
|
||
defaults = { | ||
"font": "SauceCodePro Nerd Font Medium", | ||
"fontsize": 10, | ||
"padding": None, | ||
} | ||
|
||
|
||
class Bar: | ||
def __init__(self, theme: str) -> None: | ||
self.theme = theme | ||
|
||
@property | ||
def themes(self) -> set[str]: | ||
path = join(cfg.path(), "core", "bar") | ||
excluded_files = {"__init__.py", "base.py"} | ||
return { | ||
file.removesuffix(".py") | ||
for file in listdir(path) | ||
if isfile(join(path, file)) and file not in excluded_files | ||
} | ||
|
||
@property | ||
def config(self) -> dict | None: | ||
if self.theme not in self.themes: | ||
return None | ||
module = import_module(f"core.bar.{self.theme}") | ||
return {"widgets": module.widgets(), **module.bar} | ||
|
||
def create(self) -> bar.BarType | None: | ||
if not self.config: | ||
return None | ||
return bar.Bar(**self.config) | ||
|
||
|
||
def base(bg: str | None, fg: str) -> dict: | ||
return { | ||
"background": bg, | ||
"foreground": fg, | ||
} | ||
|
||
|
||
def icon_font(size=15) -> dict: | ||
font = "SauceCodePro Nerd Font" | ||
return {"font": font, "fontsize": size} | ||
|
||
|
||
def powerline(path: str | list[tuple], size=9) -> dict: | ||
return { "decorations": [ | ||
PowerLineDecoration( | ||
path=path, | ||
size=size, | ||
) | ||
]} # fmt: skip | ||
|
||
|
||
def rectangle(side: str = "") -> dict: | ||
return { "decorations": [ | ||
RectDecoration( | ||
filled = True, | ||
radius = { | ||
"left": [8, 0, 0, 8], | ||
"right": [0, 8, 8, 0] | ||
}.get(side, 8), | ||
use_widget_background = True, | ||
) | ||
]} # fmt: skip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
from libqtile.config import Screen | ||
|
||
from core.bar import bar | ||
from core.bar import Bar | ||
from utils.config import cfg | ||
|
||
screens = [ | ||
Screen( | ||
wallpaper=cfg.wallpaper, | ||
wallpaper_mode="fill", | ||
top=bar, | ||
top=Bar(cfg.bar).create(), | ||
), | ||
Screen( | ||
wallpaper=cfg.wallpaper, | ||
wallpaper_mode="fill", | ||
top=Bar(cfg.bar2).create(), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import json | ||
import os | ||
from dataclasses import asdict, dataclass | ||
from os import path | ||
from os import getcwd | ||
from os.path import exists, expanduser, join | ||
|
||
|
||
@dataclass | ||
class Config: | ||
bar: str | None = "decorated" | ||
bar: str = "shapes" | ||
bar2: str = "" | ||
browser: str = "" | ||
term: str | None = "" | ||
term2: str | None = "" | ||
term2: str = "" | ||
wallpaper: str = "" | ||
|
||
@staticmethod | ||
def path() -> str: | ||
xdg = expanduser("~/.config/qtile") | ||
return xdg if exists(xdg) else getcwd() | ||
|
||
def get_directory(): | ||
XDG = path.expanduser("~/.config/qtile") | ||
if path.exists(XDG): | ||
return XDG | ||
return os.getcwd() | ||
@classmethod | ||
def load(cls) -> "Config": | ||
file = join(cls.path(), "cfg.json") | ||
if not exists(file): | ||
cls.generate(file) | ||
return cls() | ||
with open(file, "r") as f: | ||
content = json.load(f) | ||
return cls(**content) | ||
|
||
@classmethod | ||
def generate(cls, file: str) -> None: | ||
with open(file, "w") as f: | ||
content = asdict(cls()) | ||
f.write(json.dumps(content, indent=2)) | ||
|
||
file = f"{get_directory()}/cfg.json" | ||
|
||
if not path.exists(file): | ||
cfg = Config() | ||
with open(file, "w") as f: | ||
content = asdict(cfg) | ||
f.write(json.dumps(content, indent=2)) | ||
else: | ||
with open(file, "r") as f: | ||
content = json.load(f) | ||
cfg = Config(**content) | ||
cfg = Config.load() |