Skip to content

Commit

Permalink
argparse to click
Browse files Browse the repository at this point in the history
  • Loading branch information
justjokiing committed Jan 7, 2025
1 parent de01406 commit c29b1f6
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 273 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

71 changes: 44 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# [KShift](https://github.com/justjokiing/kshift): A KDE Plasma Theme Switcher
# [kshift](https://github.com/justjokiing/kshift): A KDE Plasma Theme Switcher

## Overview

KShift is a dynamic theme manager for KDE Plasma that automatically changes your system's theme (color scheme, icon theme, desktop theme, and wallpaper) based on predefined schedules, times of day, or solar events (e.g., sunrise and sunset). It supports advanced configurations using `systemd` timers, making it a highly customizable solution for KDE Plasma users who want seamless transitions between themes.
kshift is a dynamic theme manager for KDE Plasma that automatically changes your system's theme (color scheme, icon theme, desktop theme, and wallpaper) based on predefined schedules, times of day, or solar events (e.g., sunrise and sunset). It supports advanced configurations using `systemd` timers, making it a highly customizable solution for KDE Plasma users who want seamless transitions between themes.

## Demo

This demo shows a shift from one theme to another manually, then kshift determining the correct theme to switch to.

https://github.com/justjokiing/kshift/assets/64444712/02e64459-5f5b-477b-a0aa-bdfcd431772d

## Why Use KShift?
## Why Use kshift?

**Effortless and Dynamic Theme Automation**: Save time by automating theme changes for morning, evening, or specific events without manual adjustments. Coordinate your system's appearance with wallpapers, icon themes, and desktop themes that match the time of day or occasion.

**Customizable and Reliable Schedules**: Define unique schedules for themes using flexible time settings or solar events like sunrise and sunset. With systemd integration, theme changes are guaranteed to occur on time, even after system reboots.

**Simple and Lightweight**: KShift is built around a straightforward CLI interface and a single YAML configuration file. This design keeps it lightweight and efficient, with no background processes required. By leveraging systemd for scheduling, KShift ensures seamless theme transitions with minimal system resource usage.
**Simple and Lightweight**: kshift is built around a straightforward CLI interface and a single YAML configuration file. This design keeps it lightweight and efficient, with no background processes required. By leveraging systemd for scheduling, kshift ensures seamless theme transitions with minimal system resource usage.


## Installation
Expand All @@ -38,17 +38,17 @@ pip install kshift

### Setup

Run the following command to install KShift's systemd services and timers:
Run the following command to install kshift's systemd services and timers:

```bash
kshift --install
kshift install
```

This creates necessary configuration and systemd files in your user directory.

## Configuration

KShift uses a YAML configuration file, created during `--install` and located at `~/.config/kshift/kshift.yml`. Below is a guide to setting up and customizing your configuration.
kshift uses a YAML configuration file, created during `install` and located at `~/.config/kshift/kshift.yml`. Below is a guide to setting up and customizing your configuration.

### Default Configuration

Expand Down Expand Up @@ -107,55 +107,72 @@ All parameters are optional, but to enable automatic theme switching, a `time` v

Run `kshift` with various options:

- `-t, --theme <theme>`: Apply a specific theme.
- `-c, --colorscheme <scheme>`: Change the current color scheme.
- `-dk, --desktop_theme <theme>`: Change the current desktop theme
- `-i, --icontheme <theme>`: Change the icon current theme.
- `-w, --wallpaper <path>`: Change the current desktop wallpaper.
- `--install`: Install systemd timers/services.
- `--remove`: Remove systemd timers/services.
- `-s, --status`: Display KShift status and active timers.
- `theme [THEME_NAME]`: Apply a specific theme by name. If no name is provided, kshift determines the appropriate theme to apply based on time and configuration.
- Positional argument `[THEME_NAME]`: Optional. Specify the theme to apply.
- `-c, --colorscheme <scheme>`: Apply a specific colorscheme (overrides the theme configuration).
- `-i, --icontheme <theme>`: Apply a specific icon theme (overrides the theme configuration).
- `-w, --wallpaper <path>`: Apply a specific wallpaper (overrides the theme configuration).
- `-dk, --desktop_theme <theme>`: Apply a specific desktop theme (overrides the theme configuration).
- `install`: Install systemd services and timers for kshift.
- `remove`: Remove systemd services and timers for kshift.
- `status`: Display the current status of kshift and active timers.
- `config`: Open the kshift configuration file in the default editor for editing.
- `logs`: View the most recent entries from the kshift log file.

### Examples

- Apply a theme by name:

```bash
kshift -t night
kshift theme night
```
- Have kshift determine the current theme and apply it:

```bash
kshift
```

- Check current status:

```bash
kshift --status
kshift status
```

- Apply a theme with modification:

```bash
kshift -t night -c BreezeLight -w ~/cat.png
kshift theme night -c BreezeLight -w ~/cat.png
```

- Apply a theme attribute with no theme:

```bash
kshift theme -w ~/cat.png
```

## Systemd Integration

KShift leverages `systemd` timers to provide robust and reliable automation of theme changes. This integration ensures that:
kshift leverages `systemd` timers to provide robust and reliable automation of theme changes. This integration ensures that:

1. **Timely Theme Switching**: Each theme is tied to a `systemd` timer, which allows precise scheduling of theme changes based on time or solar events.
2. **Automatic Startup**: A dedicated startup timer ensures that KShift applies the correct theme when your system boots up.
2. **Automatic Startup**: A dedicated startup timer ensures that kshift applies the correct theme when your system boots up.
3. **Flexibility with OnCalendar**: `systemd`'s `OnCalendar` expressions provide flexibility for advanced scheduling. For example, you can schedule themes to activate at exact times, specific days of the week, or even recurring intervals.
### How It Works
- When you install KShift (`kshift --install`), it creates a `systemd` service and timer for each theme defined in your configuration.
- When you install kshift (`kshift install`), it creates a `systemd` service and timer for each theme defined in your configuration.
- The templates used for the services and timers are located in your configuration directory, where if you edit them, their changes will be reflected in the next write.
- The timers are then activated, and `systemd` ensures that the correct theme is applied at the scheduled time.
- The startup timer runs shortly after the system boots, ensuring that KShift applies the most relevant theme based on the current time.
- The startup timer runs shortly after the system boots, ensuring that kshift applies the most relevant theme based on the current time.
## Uninstallation
To remove KShift, run:
To remove kshift, run:
```bash
kshift --remove
```
1. `kshift remove`
This disables and removes all related systemd timers and services.
2. `pip uninstall kshift`
This disables and removes all related systemd timers and services.
Removes the `kshift` package from your computer
68 changes: 49 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "kshift"
Expand All @@ -12,32 +12,62 @@ description = "KDE Theme Shift"
license = { text = "GPL-3.0-or-later" }
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Dependent",
"Programming Language :: Python",

# Development Status
"Development Status :: 4 - Beta", # If your project is stable, switch to "5 - Production/Stable"

# Environment
"Environment :: X11 Applications :: KDE",
"Environment :: Console",

# Intended Audience
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",

# Topic
"Topic :: Desktop Environment :: K Desktop Environment (KDE)",
"Topic :: Desktop Environment :: K Desktop Environment (KDE) :: Themes",
"Topic :: Utilities",

# Operating System
"Operating System :: POSIX :: Linux",

# License
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
]
keywords = [
"KDE",
"theme",
"desktop environment",
"automation",
"script",
"theme switching",
"Linux",
"color scheme",
"wallpaper",
"icon theme",
"Plasma",
"KDE Plasma",
"desktop customization",
"timers",
"systemd",
"sunrise sunset",
"cron replacement"
]
keywords = ["KDE", "theme", "script"]
dependencies = [
"pyyaml",
"click",
"colorama",
"requests",
"pydantic"
"pydantic",
"PyYAML",
"Requests"
]

[project.urls]
"Homepage" = "https://github.com/justjokiing/kshift"

[tool.setuptools]
packages = ["kshift"] # Indicate that your package is inside the "src" folder
include-package-data = true # Ensures non-code files are included

[tool.setuptools.package-data]
src = [
"templates/*", # Include all files in the templates directory
"defaults.yml" # Include the defaults.yml configuration file
]

[project.scripts]
kshift = "kshift.main:main"
kshift = "kshift.main:cli"

[tool.pytest.ini_options]
pythonpath = ["src"]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
click
colorama
pydantic
pytest
Expand Down
30 changes: 10 additions & 20 deletions src/kshift/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, time, timedelta
from datetime import datetime, timedelta
import os
import yaml
import re
Expand Down Expand Up @@ -282,10 +282,7 @@ def apply_delay(time_obj: datetime, delay_hours: int) -> datetime:

# Prints the status of Kshift, the timer, and the current config file
def status(self):
if os.path.exists(self.systemd_loc) and os.path.exists(
self.config_loc):

print("##################################")
if self.systemd_loc.exists() and self.config_loc.exists():

timer_status_cmd = "systemctl --user is-enabled "
enabled = False
Expand All @@ -307,28 +304,20 @@ def status(self):
m = re.search("OnCalendar=(.*)", line)
if m:
time = m.group(1)
timed_outputs += theme_name.center(
10) + " @ " + time + "\n"
timed_outputs += f"{theme_name:<10} {time}\n"

timer.close()

if enabled:
print("Kshift " + colorama.Fore.GREEN + "ENABLED" +
colorama.Fore.WHITE + ":")
print(timed_outputs)
print("kshift status: " + colorama.Fore.GREEN + "ENABLED" +
colorama.Fore.WHITE)
print(timed_outputs, end='')
else:
print("Kshift " + colorama.Fore.RED + "DISABLED." +
print("kshift status: " + colorama.Fore.RED + "DISABLED." +
colorama.Fore.WHITE)

print("##################################")
print(f"kshift configuration @{self.config_loc}")
print("##################################")

if self.config_loc.exists():
print(open(self.config_loc).read().strip())
else:
print(
"Kshift not installed. Edit 'defaults.yml' and run again with --install"
"kshift not installed. Run again with `--install` and edit your config with `--config`"
)

def _select_sunstate(self, sunstate) -> datetime:
Expand Down Expand Up @@ -370,7 +359,8 @@ def web_sundata(self, sunstate):
with open(self.api_file, "w") as file:
json.dump(cache_data, file)

except (requests.RequestException, requests.ConnectionError, KeyError, ValueError) as e:
except (requests.RequestException, requests.ConnectionError, KeyError,
ValueError) as e:
print(f"Error fetching sun data: {e}")
raise

Expand Down
Loading

0 comments on commit c29b1f6

Please sign in to comment.