This repository was archived by the owner on May 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
55 lines (40 loc) · 1.42 KB
/
Copy pathconfig.py
File metadata and controls
55 lines (40 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from pathlib import Path
import yaml
# will be used probably to generate config
defaults = {
"icon_size": 44,
"hidden_width": 2,
"hide_timeout_msec": 900,
"layout_spacing": 5
}
class Config:
configLocation = Path(Path.home(), '.config/simple-bar-launcher/config.yaml')
def __init__(self):
self.config = self.getConfig()
def getConfig(self):
if not self.configLocation.is_file():
self.configLocation.parent.mkdir(parents=True, exist_ok=True)
raise EnvironmentError(f"Config '{self.configLocation}' doesn't exist. Exiting.")
with open(self.configLocation, 'r') as file:
config = yaml.safe_load(file)
return config
@property
def launchers(self):
launchers = self.config.get('launchers')
if not launchers:
raise EnvironmentError(f"Fix launcher section in {self.configLocation}")
return launchers
def getFromConfigOrDefault(self, value):
return self.config.get(value, defaults[value])
@property
def hiddenWidth(self):
return self.getFromConfigOrDefault('hidden_width')
@property
def iconSize(self):
return self.getFromConfigOrDefault('icon_size')
@property
def hideTimeoutMsec(self):
return self.getFromConfigOrDefault('hide_timeout_msec')
@property
def layoutSpacing(self):
return self.getFromConfigOrDefault('layout_spacing')