winaccent


Namewinaccent JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/Valer100/winaccent
SummaryA simple and lightweight Python module for getting Windows' accent color or a shade of it. Works on both Windows 10 and 11 and doesn't require additional dependencies.
upload_time2024-09-26 16:13:53
maintainerValer100
docs_urlNone
authorValer100
requires_pythonNone
licenseMIT
keywords accent accent_light accent_dark accent_colortheme tk ttk tkinter modern fluent sun-valley windows-11 windows-10 winui winaccent
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
    <img width="700" src="https://github.com/Valer100/winaccent/blob/main/assets/hero.png?raw=true">
</div>

# winaccent
A simple and lightweight Python module for getting Windows' accent color or a shade of it. Works on both Windows 10 and 11 and doesn't require additional dependencies.

## 📦 Installation
Run this command in your terminal:

```
pip install winaccent
```

To update the module, run this command:

```
pip install --upgrade winaccent
```

## 📜 Documentation

> [!IMPORTANT]
> This is a Windows-only module. Trying to import this module on a OS other than Windows or a Windows version older than 10 will raise a `winaccent.UnsupportedPlatformException` exception. When using this module in cross-platform applications, you should only import and use winaccent on Windows systems to avoid errors. Here's an example:

```python
import sys

if sys.platform == "win32": 
    # The program is running on Windows

    import winaccent
    print(winaccent.accent_light_mode)
```

---

### Get a specific accent color

> [!NOTE]
> The color values and previews shown here are for Windows 11's default accent color (blue). If you have a different accent color, you'll get the color values based on your accent color.

For simplicity, you can get a specific accent color from one of the following variables:

| Variable | Color | Preview |
|----------|:-------:|:-------:|
| accent_dark_mode | #4CC2FF | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark.png?raw=true"> |
| accent_normal | #0078D4 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal.png?raw=true"> |
| accent_light_mode | #0067C0 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light.png?raw=true"> |

If you need a different shade, you can get it from one of these variables:

| Variable | Color | Preview |
|----------|:-------:|:-------:|
| accent_light_3 | #99EBFF | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark_3.png?raw=true"> |
| accent_light_2 | #4CC2FF | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark.png?raw=true"> |
| accent_light_1 | #0091F8 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark_1.png?raw=true"> |
| accent_normal | #0078D4 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal.png?raw=true"> |
| accent_dark_1 | #0067C0 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light.png?raw=true"> |
| accent_dark_2 | #003E92 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light_2.png?raw=true"> |
| accent_dark_3 | #001A68 | <img src="https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light_3.png?raw=true"> |

You can get the accent color used in lockscreen, UAC (Windows 10) and other elements using `accent_menu` variable (usually it's the same color as `accent_normal`, but can be modified in the registry).

> [!TIP]
> `accent_dark_mode` is the same thing as `accent_light` which is the same thing as `accent_light_2`. 
>
> Also, `accent_light_mode` is the same thing as `accent_dark` which is the same thing as `accent_dark_1`.

Example:

```python
import winaccent

print(winaccent.accent_light_mode) # Prints the light mode accent color
```

You may want to take a look at Microsoft's accent color guidelines. You can do that [here](https://learn.microsoft.com/en-us/windows/apps/design/style/color#accent-color-palette).

---

### Get active/inactive titlebar color or window border color

> [!WARNING]
> The colors provided by these variables are the colors used by Windows to colorize the titlebar and the window borders when the "Show accent color on title bars and window borders" option is enabled in Settings.
> <br><br>
> <img src="https://github.com/Valer100/winaccent/blob/main/assets/show_accent_color_on_window_stuff.png?raw=true">
> <br><br>
> Also, the `titlebar_active` and `window_border` variables don't always return the same color. The user can change the color of the titlebar or window borders from the registry. <br><br>
> <img src="https://github.com/Valer100/winaccent/blob/main/assets/custom_window_colors_demo.png?raw=true">

You can get the active titlebar color from `titlebar_active` variable and the inactive titlebar color from `titlebar_inactive`. The window border color can be obtained from `window_border` variable.

You can also check if colored titlebars are enabled using `is_titlebar_colored` boolean.

> [!NOTE]
> `titlebar_inactive` will return `None` if the inactive titlebar color isn't set (this is usually done via registry).

---

### Update accent color values

The accent colors can be updated manually using the ```update_accent_colors()``` function. This function will retrieve the values again.

---

### Accent color change listener

This module allows you to add a listener that will call a specific function when the accent color, active/inactive titlebar color or window border color changes. Here's how you can add it:

```python
import winaccent, threading

# Replace `callback` with the function that you want to be called
thread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(callback), daemon = True)
thread.start()
```

> [!NOTE]
> If you added the listener, there's no need to call `update_accent_colors()` because it will be called automatically every time the accent color or the active/inactive titlebar color changes.

Here's a demo:

https://github.com/user-attachments/assets/5a1f334f-4d04-40a2-816d-f8df6fc523ad


## 💻 Demo
To see a demo, run the following command in your terminal (winaccent must be installed):

```python
python -m winaccent
```

This command has an optional `--mode` argument. It can take the following values:

| Value | Info |
|:------|:-----|
| gui | Shows a GUI demo. The GUI demo responds to accent color changes. |
| console | Shows a console demo. The console demo **does not** respond to accent color changes. |
| auto | If tkinter is installed and works correctly, a GUI demo will be shown. If that's not the case, a console demo will be shown. |

Example usage:

```
python -m winaccent --mode gui
```

The command will run with `--mode` set to `auto` by default.

Here's a GUI demo with 6 different accent colors:

| **Blue** | **Dark green** | **Red** |
|:-------:|:---------:|:------:|
|![Blue](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_blue.png?raw=true) | ![Dark green](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_green.png?raw=true) | ![Red](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_red.png?raw=true) |
| **Gold** | **Iris pastel** | **Camouflage desert** |
|![Gold](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_orange.png?raw=true) | ![Iris pastel](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_purple.png?raw=true) | ![Camouflage desert](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_tan.png?raw=true) |

A console demo looks like this (for default blue accent color):

```
Accent palette
================

accent_light_3:        #99EBFF
accent_light_2:        #4CC2FF
accent_light_1:        #0091F8
accent_normal:         #0078D4
accent_dark_1:         #0067C0
accent_dark_2:         #003E92
accent_dark_3:         #001A68

Titlebar options
================

is_titlebar_colored:   False
titlebar_active:       #0078D4
titlebar_inactive:     None
window_border:         #0078D4
```


## 🤩 Feedback
If you found a bug or want to make a suggestion, open a new issue. If you're ready to add a new feature or fix a bug, pull requests are welcome.

If you find this module useful, please consider starring this repository.

## 📋 To do
- [x] ~~Add an accent color change listener~~
- [x] ~~Add color shades~~
- [x] ~~Allow to get active/inactive titlebar color~~
- [x] ~~Allow to get window border color~~

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Valer100/winaccent",
    "name": "winaccent",
    "maintainer": "Valer100",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "accent, accent_light, accent_dark, accent_colortheme, tk, ttk, tkinter, modern, fluent, sun-valley, windows-11, windows-10, winui, winaccent",
    "author": "Valer100",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/db/2a/4535cb34125684c68cfcdfed9096639b03c84d99cc37f5db4b8136b6ab50/winaccent-1.1.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\r\n    <img width=\"700\" src=\"https://github.com/Valer100/winaccent/blob/main/assets/hero.png?raw=true\">\r\n</div>\r\n\r\n# winaccent\r\nA simple and lightweight Python module for getting Windows' accent color or a shade of it. Works on both Windows 10 and 11 and doesn't require additional dependencies.\r\n\r\n## \ud83d\udce6 Installation\r\nRun this command in your terminal:\r\n\r\n```\r\npip install winaccent\r\n```\r\n\r\nTo update the module, run this command:\r\n\r\n```\r\npip install --upgrade winaccent\r\n```\r\n\r\n## \ud83d\udcdc Documentation\r\n\r\n> [!IMPORTANT]\r\n> This is a Windows-only module. Trying to import this module on a OS other than Windows or a Windows version older than 10 will raise a `winaccent.UnsupportedPlatformException` exception. When using this module in cross-platform applications, you should only import and use winaccent on Windows systems to avoid errors. Here's an example:\r\n\r\n```python\r\nimport sys\r\n\r\nif sys.platform == \"win32\": \r\n    # The program is running on Windows\r\n\r\n    import winaccent\r\n    print(winaccent.accent_light_mode)\r\n```\r\n\r\n---\r\n\r\n### Get a specific accent color\r\n\r\n> [!NOTE]\r\n> The color values and previews shown here are for Windows 11's default accent color (blue). If you have a different accent color, you'll get the color values based on your accent color.\r\n\r\nFor simplicity, you can get a specific accent color from one of the following variables:\r\n\r\n| Variable | Color | Preview |\r\n|----------|:-------:|:-------:|\r\n| accent_dark_mode | #4CC2FF | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark.png?raw=true\"> |\r\n| accent_normal | #0078D4 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal.png?raw=true\"> |\r\n| accent_light_mode | #0067C0 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light.png?raw=true\"> |\r\n\r\nIf you need a different shade, you can get it from one of these variables:\r\n\r\n| Variable | Color | Preview |\r\n|----------|:-------:|:-------:|\r\n| accent_light_3 | #99EBFF | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark_3.png?raw=true\"> |\r\n| accent_light_2 | #4CC2FF | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark.png?raw=true\"> |\r\n| accent_light_1 | #0091F8 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_dark_1.png?raw=true\"> |\r\n| accent_normal | #0078D4 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_normal.png?raw=true\"> |\r\n| accent_dark_1 | #0067C0 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light.png?raw=true\"> |\r\n| accent_dark_2 | #003E92 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light_2.png?raw=true\"> |\r\n| accent_dark_3 | #001A68 | <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/colors/accent_light_3.png?raw=true\"> |\r\n\r\nYou can get the accent color used in lockscreen, UAC (Windows 10) and other elements using `accent_menu` variable (usually it's the same color as `accent_normal`, but can be modified in the registry).\r\n\r\n> [!TIP]\r\n> `accent_dark_mode` is the same thing as `accent_light` which is the same thing as `accent_light_2`. \r\n>\r\n> Also, `accent_light_mode` is the same thing as `accent_dark` which is the same thing as `accent_dark_1`.\r\n\r\nExample:\r\n\r\n```python\r\nimport winaccent\r\n\r\nprint(winaccent.accent_light_mode) # Prints the light mode accent color\r\n```\r\n\r\nYou may want to take a look at Microsoft's accent color guidelines. You can do that [here](https://learn.microsoft.com/en-us/windows/apps/design/style/color#accent-color-palette).\r\n\r\n---\r\n\r\n### Get active/inactive titlebar color or window border color\r\n\r\n> [!WARNING]\r\n> The colors provided by these variables are the colors used by Windows to colorize the titlebar and the window borders when the \"Show accent color on title bars and window borders\" option is enabled in Settings.\r\n> <br><br>\r\n> <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/show_accent_color_on_window_stuff.png?raw=true\">\r\n> <br><br>\r\n> Also, the `titlebar_active` and `window_border` variables don't always return the same color. The user can change the color of the titlebar or window borders from the registry. <br><br>\r\n> <img src=\"https://github.com/Valer100/winaccent/blob/main/assets/custom_window_colors_demo.png?raw=true\">\r\n\r\nYou can get the active titlebar color from `titlebar_active` variable and the inactive titlebar color from `titlebar_inactive`. The window border color can be obtained from `window_border` variable.\r\n\r\nYou can also check if colored titlebars are enabled using `is_titlebar_colored` boolean.\r\n\r\n> [!NOTE]\r\n> `titlebar_inactive` will return `None` if the inactive titlebar color isn't set (this is usually done via registry).\r\n\r\n---\r\n\r\n### Update accent color values\r\n\r\nThe accent colors can be updated manually using the ```update_accent_colors()``` function. This function will retrieve the values again.\r\n\r\n---\r\n\r\n### Accent color change listener\r\n\r\nThis module allows you to add a listener that will call a specific function when the accent color, active/inactive titlebar color or window border color changes. Here's how you can add it:\r\n\r\n```python\r\nimport winaccent, threading\r\n\r\n# Replace `callback` with the function that you want to be called\r\nthread = threading.Thread(target = lambda: winaccent.on_accent_changed_listener(callback), daemon = True)\r\nthread.start()\r\n```\r\n\r\n> [!NOTE]\r\n> If you added the listener, there's no need to call `update_accent_colors()` because it will be called automatically every time the accent color or the active/inactive titlebar color changes.\r\n\r\nHere's a demo:\r\n\r\nhttps://github.com/user-attachments/assets/5a1f334f-4d04-40a2-816d-f8df6fc523ad\r\n\r\n\r\n## \ud83d\udcbb Demo\r\nTo see a demo, run the following command in your terminal (winaccent must be installed):\r\n\r\n```python\r\npython -m winaccent\r\n```\r\n\r\nThis command has an optional `--mode` argument. It can take the following values:\r\n\r\n| Value | Info |\r\n|:------|:-----|\r\n| gui | Shows a GUI demo. The GUI demo responds to accent color changes. |\r\n| console | Shows a console demo. The console demo **does not** respond to accent color changes. |\r\n| auto | If tkinter is installed and works correctly, a GUI demo will be shown. If that's not the case, a console demo will be shown. |\r\n\r\nExample usage:\r\n\r\n```\r\npython -m winaccent --mode gui\r\n```\r\n\r\nThe command will run with `--mode` set to `auto` by default.\r\n\r\nHere's a GUI demo with 6 different accent colors:\r\n\r\n| **Blue** | **Dark green** | **Red** |\r\n|:-------:|:---------:|:------:|\r\n|![Blue](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_blue.png?raw=true) | ![Dark green](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_green.png?raw=true) | ![Red](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_red.png?raw=true) |\r\n| **Gold** | **Iris pastel** | **Camouflage desert** |\r\n|![Gold](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_orange.png?raw=true) | ![Iris pastel](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_purple.png?raw=true) | ![Camouflage desert](https://github.com/Valer100/winaccent/blob/main/assets/demo/demo_tan.png?raw=true) |\r\n\r\nA console demo looks like this (for default blue accent color):\r\n\r\n```\r\nAccent palette\r\n================\r\n\r\naccent_light_3:        #99EBFF\r\naccent_light_2:        #4CC2FF\r\naccent_light_1:        #0091F8\r\naccent_normal:         #0078D4\r\naccent_dark_1:         #0067C0\r\naccent_dark_2:         #003E92\r\naccent_dark_3:         #001A68\r\n\r\nTitlebar options\r\n================\r\n\r\nis_titlebar_colored:   False\r\ntitlebar_active:       #0078D4\r\ntitlebar_inactive:     None\r\nwindow_border:         #0078D4\r\n```\r\n\r\n\r\n## \ud83e\udd29 Feedback\r\nIf you found a bug or want to make a suggestion, open a new issue. If you're ready to add a new feature or fix a bug, pull requests are welcome.\r\n\r\nIf you find this module useful, please consider starring this repository.\r\n\r\n## \ud83d\udccb To do\r\n- [x] ~~Add an accent color change listener~~\r\n- [x] ~~Add color shades~~\r\n- [x] ~~Allow to get active/inactive titlebar color~~\r\n- [x] ~~Allow to get window border color~~\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple and lightweight Python module for getting Windows' accent color or a shade of it. Works on both Windows 10 and 11 and doesn't require additional dependencies.",
    "version": "1.1.0",
    "project_urls": {
        "Documentation": "https://github.com/Valer100/winaccent?tab=readme-ov-file#-documentation",
        "Homepage": "https://github.com/Valer100/winaccent",
        "Issues": "https://github.com/Valer100/winaccent/issues",
        "Source": "https://github.com/Valer100/winaccent"
    },
    "split_keywords": [
        "accent",
        " accent_light",
        " accent_dark",
        " accent_colortheme",
        " tk",
        " ttk",
        " tkinter",
        " modern",
        " fluent",
        " sun-valley",
        " windows-11",
        " windows-10",
        " winui",
        " winaccent"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3393d0578ef2d001746f799ebf2c41e99966cd2b3782881502515a80d9705795",
                "md5": "2fe40496f887fd11ec379aea149231a5",
                "sha256": "5bfba3a6f4a5afdc0390ec76e72e2b5a835df072018d401ce92c99ad8bc98a71"
            },
            "downloads": -1,
            "filename": "winaccent-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2fe40496f887fd11ec379aea149231a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8046,
            "upload_time": "2024-09-26T16:13:52",
            "upload_time_iso_8601": "2024-09-26T16:13:52.321497Z",
            "url": "https://files.pythonhosted.org/packages/33/93/d0578ef2d001746f799ebf2c41e99966cd2b3782881502515a80d9705795/winaccent-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db2a4535cb34125684c68cfcdfed9096639b03c84d99cc37f5db4b8136b6ab50",
                "md5": "36df2ae313feb72f3f765ab5cf2885fd",
                "sha256": "2880b34c4dce765775386ba27a5a0ad72a5c597ee53aa96992be77e01fd428ad"
            },
            "downloads": -1,
            "filename": "winaccent-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "36df2ae313feb72f3f765ab5cf2885fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9823,
            "upload_time": "2024-09-26T16:13:53",
            "upload_time_iso_8601": "2024-09-26T16:13:53.894229Z",
            "url": "https://files.pythonhosted.org/packages/db/2a/4535cb34125684c68cfcdfed9096639b03c84d99cc37f5db4b8136b6ab50/winaccent-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 16:13:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Valer100",
    "github_project": "winaccent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "winaccent"
}
        
Elapsed time: 0.34982s