Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fdev31 committed Sep 29, 2024
1 parent ecacaf0 commit b443341
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions pyprland/plugins/scratchpads/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,27 @@ def forced_monitor(self) -> str | None:
return cast(str, forced_monitor)
return None

def set_config(self, full_config: dict[str, Any]) -> None:
"""Apply constraints to the configuration."""
def _get_intial_config(self, config: dict) -> dict:
"""Return a fresh configuration for the scratchpad."""
opts = {}
scratch_config = full_config[self.uid]
# apply inheritance
scratch_config = config[self.uid]
if "use" in scratch_config:
inheritance = scratch_config["use"]
if isinstance(inheritance, str):
inheritance = [inheritance]

for source in inheritance:
if source in full_config:
opts.update(full_config[source])
if source in config:
opts.update(config[source])
else:
text = f"Scratchpad {self.uid} tried to use {source}, but it doesn't exist"
self.log.exception(text)

# apply specific config
opts.update(scratch_config)
return opts

def set_config(self, full_config: dict[str, Any]) -> None:
"""Apply constraints to the configuration."""
opts = self._get_intial_config(full_config)

# apply the config
self.conf = DynMonitorConfig(opts, opts.get("monitor", {}))
Expand Down
2 changes: 1 addition & 1 deletion pyprland/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package version."""

VERSION = "2.4.0-62"
VERSION = "2.4.0-63"

0 comments on commit b443341

Please sign in to comment.