Giter Club home page Giter Club logo

change-theme's Introduction

Python application to change themes in my Linux system

I was wondering if there was a better way to change the colorscheme of an app, and I've seen in a video that some people use custom scripts for those. So, that is what I did, but in Python.

How it works

This program is based of Theme objects created by the user, whose definition is the following:

@dataclass
class Theme:
    name: str
    background: str
    contrast: list[str]  # higher index -> lighter color
    foreground: str
    wallpaper: Path
    accent: str
    alert: str

And programs that will be changed accordingly to the things that vary in this class.

In my system, I only require one color per theme to be the accent color because I find hard to make good looking things with more than one accent color.

As it is right now, you can do two things:

Add a new program

To do so, you need to add your program to the programs.py file, inside of the ChangesToApply objects list, which represent the changes made to a single file. There, you need to provide the file that you're going to change and the changes that will be made. Is also highly recommended that you add a comment with the name of the program which the changes refer to.

The file is a Path object and the changes are passed in as a list of tuples. The first item on the tuple is the regular expression that match the text that will be changed and the second is the changed text itself. Make sure to add replacement texts that are similar to the old ones, otherwise the match will fail on multiple uses. Here's an example of a possible entrance:

[
    # Alacritty
    ChangesToApply(
        file=Path.home() / ".config/alacritty/alacritty.yml",
        replacements=[(r"colors:\s\*.*", f"colors: *{theme.name}")],
    ),
]

You can also provide one command to be executed, which is useful if you have to reset something for the changes to apply. The command needs to be a list of the arguments, and here, Path objects are allowed. If you need to execute a internal command, prefer to use the full path for the program, e.g. /usr/bin/echo.

Templating

When a file is hard to change and don't support the use of variables, you can force variables to exist through templating. In this case, you must provide a template entrance, which is a File object, inside the dictionary. In this case, the changes will only be applied in the actual file, the template won't be touched by the program.

Add a new theme

To do so, choose a theme that you like and pick a color to be the accent and another color to be the alert color (usually is red). Then, pick the background and foreground and use a color program to generate intermediate colors between them, I usually use coolors pallete generator. I stick to four accent colors.

From here, you can copy a path from a wallpaper of your choice and fill in the blanks. For me, I find easier to search for Alacritty themes that already exist and start from there. Finally, add your theme to the THEMES dictionary, here's an example of a valid entrance:

{
    "gruvbox": Theme(
        name="gruvbox",
        background="#282828",
        contrast=[
            "#3c3836",
            "#504945",
            "#665c54",
            "#7c6f64",
        ],
        foreground="#ebdbb2",
        wallpaper=Path.home()
        / "Themes/Gruvbox-GTK-Theme/wallpapers/gruvbox20.png",
        accent="#d65d0e",  # Orange
        alert="#cc241d",
    ),
}

How to run it

You run it by executing the python file with the theme name afterwords, like:

python change_theme.py gruvbox

In my case, I've created a shell script linked to a menu launcher to do it for me. The script mentioned is the change-theme.sh.

change-theme's People

Contributors

caiolaytynher avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.