# qtsasstheme
Set the Qt theme (e.g. darkgray/lightgray/darkblue/lightblue) easily
This is using SCSS to set the light/dark theme to PyQt GUI, which is quite efficient.
Old name of this is `qt-sass-theme-getter`.
## Setup
* `git clone ~` (recommended)
* `python -m pip install qtsasstheme` - install as pypi package (good for test only)
## Using with <a href="https://pyinstaller.org/en/stable/">pyinstaller</a>
1. make main.py inside the qtsasstheme directory
2. `python -m PyInstaller main.py --add-data "qt_sass_theme;./qt_sass_theme"` (if your main script is main.py)
3. go to the dist/test folder and start the *.exe file
## Included Packages
* <a href="https://github.com/spyder-ide/qtpy">qtpy</a> - support pyqt5/pyside2/pyqt6/pyside6
* <a href="https://github.com/spyder-ide/qtsass">qtsass</a> - for converting sass into css
## Detailed Description
### Method Overview
#### `getThemeFiles(theme: str = 'dark_gray', font=QFont('Arial', 9), background_darker=False, output_path=os.getcwd())`
Currently there are 4 official theme being supported:
* dark_gray
* dark_blue
* light_gray
* light_blue
You can also make your own theme with [customizing theme](#customizing-theme).
`background_darker` decides whether the background color is going to be darker than general widget color or not.
If that is set to `True`, background color is darker than general widget color. See image below.

If that is set to `False`(which is set by default), background color is lighter than general widget color. See image below.

`output_path` is the path that 'res' directory will be made which is holding a bunch of theme files after you called `getThemeFiles`.
'res' directory looks like below.

`ico` directory holds icon files which will be being used in theme. For example, light icons will be being used in dark theme, dark icons will be being used in light theme. `_icons.scss` makes sass files in `sass` directory refer to icons in this directory.
`sass` directory holds the scss files which will be converted into css files.
`var` directory holds the `_variables.scss` which contains the color(e.g. color of background/widget/border...) variables.
<hr>
#### `setThemeFiles(main_window: QWidget, input_path='res')`
Right after calling `getThemeFiles`, you can set the style with calling `setThemeFiles`.
After calling it, 'res' directory looks like this:

scss files successfully convert into css files.
Note: Don't change the current directory with function such as `os.chdir` after calling `getThemeFiles` and before calling `setThemeFiles`. `FileNotFoundError` will be most likely occurred.
### Customizing Theme
There are two ways to customize theme.
#### 1. Giving color string to <a href="https://github.com/yjg30737/qtsasstheme#getthemefilestheme-str--dark_gray-background_darkerfalse-output_pathosgetcwd">`getThemeFiles`</a>
You can give the 6-digit hex string(e.g. #FF0000) to `getThemeFiles`'s `theme` argument.
In this case, widget's color will be set based on the hex color you given.
This is the way how to do it:
```python
//..
app = QApplication(sys.argv)
w = SampleWidget()
g = QtSassTheme()
g.getThemeFiles(theme='#6f495f')
g.setThemeFiles(w)
w.show()
app.exec()
```

#### 2. Modify `_variables.scss`'s color directly
This is the way how to do it:
1. Calling `getThemeFiles`
```python
g = QtSassTheme()
g.getThemeFiles()
```

'res' directory like above will be generated. You can see `_variables.scss`.
2. Change the variables
open the `_variables.scss` and change the `$bgcolor`'s value.
This is `_variables.scss`'s contents(dark-gray theme).
```scss
$bgcolor: #555555;
$widgetcolor: darken($bgcolor, 10);
$altwidgetcolor: lighten($widgetcolor, 18);
$textcolor: #DDDDDD;
$hovercolor: lighten($widgetcolor, 6);
$bordercolor: lighten($widgetcolor, 20);
$selectcolor: darken($widgetcolor, 6);
$disabledcolor: #AAAAAA;
$textwidgetcolor: darken($widgetcolor, 12);
$scrollhandlecolor: lighten($widgetcolor, 30);
$splitterhandlecolor: darken($widgetcolor, 10);
```
You can change any colors.
In this example i will change the $bgcolor from #555555 to #006600(dark-green).
3. Calling `setThemeFiles`
```python
//..
app = QApplication(sys.argv)
w = SampleWidget()
g = QtSassTheme()
g.setThemeFiles(w)
w.show()
app.exec()
```

## Example
### Code Sample
```python
from PyQt5.QtWidgets import QApplication
# from PyQt6.QtWidgets import QApplication
# from PySide2.QtWidgets import QApplication
# from PySide6.QtWidgets import QApplication
from pyqt_timer.settingsDialog import SettingsDialog
from qt_sass_theme import QtSassTheme
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
widget = SettingsDialog()
g = QtSassTheme()
g.getThemeFiles(theme='dark_gray')
# g.getThemeFiles(theme='dark_blue') - if you want to set dark blue theme
g.setThemeFiles(main_window=widget)
widget.show()
app.exec()
```
### Result
Preview widget is <a href="https://github.com/yjg30737/pyqt-timer.git">pyqt-timer</a>'s settings dialog.
Dark gray theme

Dark blue theme

Light gray theme

Light blue theme

Raw data
{
"_id": null,
"home_page": "https://github.com/yjg30737/qtsasstheme.git",
"name": "qtsasstheme",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Jung Gyu Yoon",
"author_email": "yjg30737@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/cc/3b/cf19a622acaaa906b61dba10fd9b5c59b63156259182b701c22726105d0e/qtsasstheme-0.0.68.tar.gz",
"platform": null,
"description": "\r\n# qtsasstheme\r\n\r\nSet the Qt theme (e.g. darkgray/lightgray/darkblue/lightblue) easily\r\n\r\n\r\n\r\nThis is using SCSS to set the light/dark theme to PyQt GUI, which is quite efficient.\r\n\r\n\r\n\r\nOld name of this is `qt-sass-theme-getter`.\r\n\r\n\r\n\r\n## Setup\r\n\r\n* `git clone ~` (recommended)\r\n\r\n* `python -m pip install qtsasstheme` - install as pypi package (good for test only)\r\n\r\n\r\n\r\n## Using with <a href=\"https://pyinstaller.org/en/stable/\">pyinstaller</a>\r\n\r\n1. make main.py inside the qtsasstheme directory\r\n\r\n2. `python -m PyInstaller main.py --add-data \"qt_sass_theme;./qt_sass_theme\"` (if your main script is main.py)\r\n\r\n3. go to the dist/test folder and start the *.exe file\r\n\r\n\r\n\r\n## Included Packages\r\n\r\n* <a href=\"https://github.com/spyder-ide/qtpy\">qtpy</a> - support pyqt5/pyside2/pyqt6/pyside6\r\n\r\n* <a href=\"https://github.com/spyder-ide/qtsass\">qtsass</a> - for converting sass into css\r\n\r\n\r\n\r\n## Detailed Description \r\n\r\n### Method Overview\r\n\r\n#### `getThemeFiles(theme: str = 'dark_gray', font=QFont('Arial', 9), background_darker=False, output_path=os.getcwd())`\r\n\r\nCurrently there are 4 official theme being supported:\r\n\r\n* dark_gray\r\n\r\n* dark_blue\r\n\r\n* light_gray\r\n\r\n* light_blue\r\n\r\n\r\n\r\nYou can also make your own theme with [customizing theme](#customizing-theme).\r\n\r\n\r\n\r\n`background_darker` decides whether the background color is going to be darker than general widget color or not.\r\n\r\n\r\n\r\nIf that is set to `True`, background color is darker than general widget color. See image below.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nIf that is set to `False`(which is set by default), background color is lighter than general widget color. See image below.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n`output_path` is the path that 'res' directory will be made which is holding a bunch of theme files after you called `getThemeFiles`.\r\n\r\n\r\n\r\n'res' directory looks like below.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n`ico` directory holds icon files which will be being used in theme. For example, light icons will be being used in dark theme, dark icons will be being used in light theme. `_icons.scss` makes sass files in `sass` directory refer to icons in this directory.\r\n\r\n\r\n\r\n`sass` directory holds the scss files which will be converted into css files.\r\n\r\n\r\n\r\n`var` directory holds the `_variables.scss` which contains the color(e.g. color of background/widget/border...) variables. \r\n\r\n\r\n\r\n<hr>\r\n\r\n\r\n\r\n#### `setThemeFiles(main_window: QWidget, input_path='res')`\r\n\r\nRight after calling `getThemeFiles`, you can set the style with calling `setThemeFiles`.\r\n\r\n\r\n\r\nAfter calling it, 'res' directory looks like this:\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nscss files successfully convert into css files.\r\n\r\n\r\n\r\nNote: Don't change the current directory with function such as `os.chdir` after calling `getThemeFiles` and before calling `setThemeFiles`. `FileNotFoundError` will be most likely occurred.\r\n\r\n\r\n\r\n### Customizing Theme\r\n\r\n\r\n\r\nThere are two ways to customize theme.\r\n\r\n\r\n\r\n#### 1. Giving color string to <a href=\"https://github.com/yjg30737/qtsasstheme#getthemefilestheme-str--dark_gray-background_darkerfalse-output_pathosgetcwd\">`getThemeFiles`</a>\r\n\r\n\r\n\r\nYou can give the 6-digit hex string(e.g. #FF0000) to `getThemeFiles`'s `theme` argument.\r\n\r\n\r\n\r\nIn this case, widget's color will be set based on the hex color you given.\r\n\r\n\r\n\r\nThis is the way how to do it:\r\n\r\n\r\n\r\n```python\r\n\r\n//..\r\n\r\napp = QApplication(sys.argv)\r\n\r\nw = SampleWidget()\r\n\r\ng = QtSassTheme()\r\n\r\ng.getThemeFiles(theme='#6f495f')\r\n\r\ng.setThemeFiles(w)\r\n\r\nw.show()\r\n\r\napp.exec()\r\n\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n#### 2. Modify `_variables.scss`'s color directly\r\n\r\n\r\n\r\nThis is the way how to do it:\r\n\r\n\r\n\r\n1. Calling `getThemeFiles`\r\n\r\n```python\r\n\r\ng = QtSassTheme()\r\n\r\ng.getThemeFiles() \r\n\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n'res' directory like above will be generated. You can see `_variables.scss`.\r\n\r\n\r\n\r\n2. Change the variables\r\n\r\n\r\n\r\nopen the `_variables.scss` and change the `$bgcolor`'s value.\r\n\r\n\r\n\r\nThis is `_variables.scss`'s contents(dark-gray theme).\r\n\r\n\r\n\r\n```scss\r\n\r\n$bgcolor: #555555;\r\n\r\n$widgetcolor: darken($bgcolor, 10);\r\n\r\n$altwidgetcolor: lighten($widgetcolor, 18);\r\n\r\n$textcolor: #DDDDDD;\r\n\r\n$hovercolor: lighten($widgetcolor, 6);\r\n\r\n$bordercolor: lighten($widgetcolor, 20);\r\n\r\n$selectcolor: darken($widgetcolor, 6);\r\n\r\n$disabledcolor: #AAAAAA;\r\n\r\n$textwidgetcolor: darken($widgetcolor, 12);\r\n\r\n$scrollhandlecolor: lighten($widgetcolor, 30);\r\n\r\n$splitterhandlecolor: darken($widgetcolor, 10);\r\n\r\n```\r\n\r\n\r\n\r\nYou can change any colors.\r\n\r\n\r\n\r\nIn this example i will change the $bgcolor from #555555 to #006600(dark-green).\r\n\r\n\r\n\r\n3. Calling `setThemeFiles`\r\n\r\n```python\r\n\r\n//..\r\n\r\napp = QApplication(sys.argv)\r\n\r\nw = SampleWidget()\r\n\r\ng = QtSassTheme()\r\n\r\ng.setThemeFiles(w)\r\n\r\nw.show()\r\n\r\napp.exec()\r\n\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n## Example\r\n\r\n### Code Sample\r\n\r\n\r\n\r\n```python\r\n\r\nfrom PyQt5.QtWidgets import QApplication\r\n\r\n# from PyQt6.QtWidgets import QApplication\r\n\r\n# from PySide2.QtWidgets import QApplication\r\n\r\n# from PySide6.QtWidgets import QApplication\r\n\r\nfrom pyqt_timer.settingsDialog import SettingsDialog\r\n\r\nfrom qt_sass_theme import QtSassTheme\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\r\n import sys\r\n\r\n\r\n\r\n app = QApplication(sys.argv)\r\n\r\n widget = SettingsDialog()\r\n\r\n g = QtSassTheme()\r\n\r\n g.getThemeFiles(theme='dark_gray')\r\n\r\n # g.getThemeFiles(theme='dark_blue') - if you want to set dark blue theme\r\n\r\n g.setThemeFiles(main_window=widget)\r\n\r\n widget.show()\r\n\r\n app.exec()\r\n\r\n```\r\n\r\n\r\n\r\n### Result\r\n\r\nPreview widget is <a href=\"https://github.com/yjg30737/pyqt-timer.git\">pyqt-timer</a>'s settings dialog.\r\n\r\n\r\n\r\nDark gray theme\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nDark blue theme\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nLight gray theme\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nLight blue theme\r\n\r\n\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Set the Qt theme (e.g. darkgray/lightgray/darkblue/lightblue) easily",
"version": "0.0.68",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cbe5eb20910e79ca3cc4138df2a49e3b05a1835c6bc7ac3a6e3b9fc7649272bf",
"md5": "0ed3b877a0415f7d69efa31bba3faadb",
"sha256": "8c5818311dc903a024fd82c672b5cfa72e80dd23ee9a9482788cecfd8b0899d6"
},
"downloads": -1,
"filename": "qtsasstheme-0.0.68-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0ed3b877a0415f7d69efa31bba3faadb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 28867,
"upload_time": "2023-02-12T01:33:46",
"upload_time_iso_8601": "2023-02-12T01:33:46.038153Z",
"url": "https://files.pythonhosted.org/packages/cb/e5/eb20910e79ca3cc4138df2a49e3b05a1835c6bc7ac3a6e3b9fc7649272bf/qtsasstheme-0.0.68-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cc3bcf19a622acaaa906b61dba10fd9b5c59b63156259182b701c22726105d0e",
"md5": "626c0b71cdd54fb536a3ad2ee3027143",
"sha256": "835ee3a0a6948e1b89c61bb0c0f8abd03b4d6728671f3796012a18d90ae06c39"
},
"downloads": -1,
"filename": "qtsasstheme-0.0.68.tar.gz",
"has_sig": false,
"md5_digest": "626c0b71cdd54fb536a3ad2ee3027143",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 16358,
"upload_time": "2023-02-12T01:33:48",
"upload_time_iso_8601": "2023-02-12T01:33:48.282185Z",
"url": "https://files.pythonhosted.org/packages/cc/3b/cf19a622acaaa906b61dba10fd9b5c59b63156259182b701c22726105d0e/qtsasstheme-0.0.68.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-12 01:33:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "yjg30737",
"github_project": "qtsasstheme.git",
"lcname": "qtsasstheme"
}