qtsass


Nameqtsass JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/spyder-ide/qtsass
SummaryCompile SCSS files to valid Qt stylesheets.
upload_time2023-03-27 22:48:14
maintainerThe Spyder Project Contributors
docs_urlNone
authorYann Lanthony
requires_python>=3.7
licenseMIT
keywords qt sass qtsass scss css qss stylesheets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # QtSASS: Compile SCSS files to Qt stylesheets

[![License - MIT](https://img.shields.io/github/license/spyder-ide/qtsass.svg)](./LICENSE.txt)
[![OpenCollective Backers](https://opencollective.com/spyder/backers/badge.svg?color=blue)](#backers)
[![Join the chat at https://gitter.im/spyder-ide/public](https://badges.gitter.im/spyder-ide/spyder.svg)](https://gitter.im/spyder-ide/public)<br>
[![Github build status](https://github.com/spyder-ide/qtsass/workflows/Tests/badge.svg)](https://github.com/spyder-ide/qtsass/actions)
[![Codecov coverage](https://img.shields.io/codecov/c/github/spyder-ide/qtsass/master.svg)](https://codecov.io/gh/spyder-ide/qtsass)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spyder-ide/qtsass/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spyder-ide/qtsass/?branch=master)

*Copyright © 2015 Yann Lanthony*

*Copyright © 2017–2018 Spyder Project Contributors*


## Overview

[SASS](http://sass-lang.com/) brings countless amazing features to CSS.
Besides being used in web development, CSS is also the way to stylize Qt-based desktop applications.
However, Qt's CSS has a few variations that prevent the direct use of SASS compiler.

The purpose of this tool is to fill the gap between SASS and Qt-CSS by handling those variations.


## Qt's CSS specificities

The goal of QtSASS is to be able to generate a Qt-CSS stylesheet based on a 100% valid SASS file.
This is how it deals with Qt's specifics and how you should modify your CSS stylesheet to use QtSASS.

#### "!" in selectors
Qt allows to define the style of a widget according to its states, like this:

```css
QLineEdit:enabled {
...
}
```

However, a "not" state is problematic because it introduces an exclamation mark in the selector's name, which is not valid SASS/CSS:

```css
QLineEdit:!editable {
...
}
```

QtSASS allows "!" in selectors' names; the SASS file is preprocessed and any occurence of `:!` is replaced by `:_qnot_` (for "Qt not").
However, using this feature prevents from having a 100% valid SASS file, so this support of `!` might change in the future.
This can be replaced by the direct use of the `_qnot_` keyword in your SASS file:

```css
QLineEdit:_qnot_editable { /* will generate QLineEdit:!editable { */
...
}
```

#### qlineargradient
The qlineargradient function also has a non-valid CSS syntax.

```css
qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.1 blue, stop: 0.8 green)
```

To support qlineargradient QtSASS provides a preprocessor and a SASS implementation of the qlineargradient function. The above QSS syntax will be replaced with the following:

```css
qlineargradient(0, 0, 0, 1, (0.1 blue, 0.8 green))
```

You may also use this syntax directly in your QtSASS.

```
qlineargradient(0, 0, 0, 1, (0.1 blue, 0.8 green))
# the stops parameter is a list, so you can also use variables:
$stops = 0.1 blue, 0.8 green
qlineargradient(0, 0, 0, 0, $stops)
```

#### qrgba
Qt's rgba:

```css
rgba(255, 128, 128, 50%)
```

is replaced by CSS rgba:

```css
rgba(255, 128, 128, 0.5)
```


## Executable usage

To compile your SASS stylesheet to a Qt compliant CSS file:

```bash
# If -o is omitted, output will be printed to console
qtsass style.scss -o style.css
```

To use the watch mode and get your stylesheet auto recompiled on each file save:

```bash
# If -o is omitted, output will be print to console
qtsass style.scss -o style.css -w
```

To compile a directory containing SASS stylesheets to Qt compliant CSS files:

```bash
qtsass ./static/scss -o ./static/css
```

You can also use watch mode to watch the entire directory for changes.

```bash
qtsass ./static/scss -o ./static/css -w
```

Set the Environment Variable QTSASS_DEBUG to 1 or pass the --debug flag to enable logging.

```bash
qtsass ./static/scss -o ./static/css --debug
```

## API methods

### `compile(string, **kwargs)`

Conform and Compile QtSASS source code to CSS.

This function conforms QtSASS to valid SCSS before passing it to
sass.compile. Any keyword arguments you provide will be combined with
qtsass's default keyword arguments and passed to sass.compile.

Examples:

```bash
>>> import qtsass
>>> qtsass.compile("QWidget {background: rgb(0, 0, 0);}")
QWidget {background:black;}
```

Arguments:
- string: QtSASS source code to conform and compile.
- kwargs: Keyword arguments to pass to sass.compile

Returns:
- Qt compliant CSS string

### `compile_filename(input_file, output_file=None, **kwargs)`:

Compile and return a QtSASS file as Qt compliant CSS. Optionally save to a file.

Examples:

```bash
>>> import qtsass
>>> qtsass.compile_filename("dummy.scss", "dummy.css")
>>> css = qtsass.compile_filename("dummy.scss")
```

Arguments:
- input_file: Path to QtSass file.
- output_file: Path to write Qt compliant CSS.
- kwargs: Keyword arguments to pass to sass.compile

Returns:
- Qt compliant CSS string

### `compile_dirname(input_dir, output_dir, **kwargs)`:

Compiles QtSASS files in a directory including subdirectories.

```bash
>>> import qtsass
>>> qtsass.compile_dirname("./scss", "./css")
```

Arguments:
- input_dir: Path to directory containing QtSass files.
- output_dir: Directory to write compiled Qt compliant CSS files to.
- kwargs: Keyword arguments to pass to sass.compile

### `enable_logging(level=None, handler=None)`:
Enable logging for qtsass.

Sets the qtsass logger's level to:
    1. the provided logging level
    2. logging.DEBUG if the QTSASS_DEBUG envvar is a True value
    3. logging.WARNING

```bash
>>> import logging
>>> import qtsass
>>> handler = logging.StreamHandler()
>>> formatter = logging.Formatter('%(level)-8s: %(name)s> %(message)s')
>>> handler.setFormatter(formatter)
>>> qtsass.enable_logging(level=logging.DEBUG, handler=handler)
```

Arguments:
- level: Optional logging level
- handler: Optional handler to add

### `watch(source, destination, compiler=None, Watcher=None)`:
Watches a source file or directory, compiling QtSass files when modified.

The compiler function defaults to compile_filename when source is a file
and compile_dirname when source is a directory.

Arguments:
- source: Path to source QtSass file or directory.
- destination: Path to output css file or directory.
- compiler: Compile function (optional)
- Watcher: Defaults to qtsass.watchers.Watcher (optional)

Returns:
- qtsass.watchers.Watcher instance

## Contributing

Everyone is welcome to contribute!


## Sponsors

Spyder and its subprojects are funded thanks to the generous support of

[![Quansight](https://static.wixstatic.com/media/095d2c_2508c560e87d436ea00357abc404cf1d~mv2.png/v1/crop/x_0,y_9,w_915,h_329/fill/w_380,h_128,al_c,usm_0.66_1.00_0.01/095d2c_2508c560e87d436ea00357abc404cf1d~mv2.png)](https://www.quansight.com/)[![Numfocus](https://i2.wp.com/numfocus.org/wp-content/uploads/2017/07/NumFocus_LRG.png?fit=320%2C148&ssl=1)](https://numfocus.org/)


and the donations we have received from our users around the world through [Open Collective](https://opencollective.com/spyder/):

[![Sponsors](https://opencollective.com/spyder/sponsors.svg)](https://opencollective.com/spyder#support)

Please consider becoming a sponsor!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/spyder-ide/qtsass",
    "name": "qtsass",
    "maintainer": "The Spyder Project Contributors",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "qtsass@spyder-ide.org",
    "keywords": "qt sass qtsass scss css qss stylesheets",
    "author": "Yann Lanthony",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cf/a9/7e03e21e72aa503c18a76e6e847b46f3c953ca39c0e684b01f10c29976db/qtsass-0.4.0.tar.gz",
    "platform": null,
    "description": "# QtSASS: Compile SCSS files to Qt stylesheets\n\n[![License - MIT](https://img.shields.io/github/license/spyder-ide/qtsass.svg)](./LICENSE.txt)\n[![OpenCollective Backers](https://opencollective.com/spyder/backers/badge.svg?color=blue)](#backers)\n[![Join the chat at https://gitter.im/spyder-ide/public](https://badges.gitter.im/spyder-ide/spyder.svg)](https://gitter.im/spyder-ide/public)<br>\n[![Github build status](https://github.com/spyder-ide/qtsass/workflows/Tests/badge.svg)](https://github.com/spyder-ide/qtsass/actions)\n[![Codecov coverage](https://img.shields.io/codecov/c/github/spyder-ide/qtsass/master.svg)](https://codecov.io/gh/spyder-ide/qtsass)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spyder-ide/qtsass/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spyder-ide/qtsass/?branch=master)\n\n*Copyright \u00a9 2015 Yann Lanthony*\n\n*Copyright \u00a9 2017\u20132018 Spyder Project Contributors*\n\n\n## Overview\n\n[SASS](http://sass-lang.com/) brings countless amazing features to CSS.\nBesides being used in web development, CSS is also the way to stylize Qt-based desktop applications.\nHowever, Qt's CSS has a few variations that prevent the direct use of SASS compiler.\n\nThe purpose of this tool is to fill the gap between SASS and Qt-CSS by handling those variations.\n\n\n## Qt's CSS specificities\n\nThe goal of QtSASS is to be able to generate a Qt-CSS stylesheet based on a 100% valid SASS file.\nThis is how it deals with Qt's specifics and how you should modify your CSS stylesheet to use QtSASS.\n\n#### \"!\" in selectors\nQt allows to define the style of a widget according to its states, like this:\n\n```css\nQLineEdit:enabled {\n...\n}\n```\n\nHowever, a \"not\" state is problematic because it introduces an exclamation mark in the selector's name, which is not valid SASS/CSS:\n\n```css\nQLineEdit:!editable {\n...\n}\n```\n\nQtSASS allows \"!\" in selectors' names; the SASS file is preprocessed and any occurence of `:!` is replaced by `:_qnot_` (for \"Qt not\").\nHowever, using this feature prevents from having a 100% valid SASS file, so this support of `!` might change in the future.\nThis can be replaced by the direct use of the `_qnot_` keyword in your SASS file:\n\n```css\nQLineEdit:_qnot_editable { /* will generate QLineEdit:!editable { */\n...\n}\n```\n\n#### qlineargradient\nThe qlineargradient function also has a non-valid CSS syntax.\n\n```css\nqlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.1 blue, stop: 0.8 green)\n```\n\nTo support qlineargradient QtSASS provides a preprocessor and a SASS implementation of the qlineargradient function. The above QSS syntax will be replaced with the following:\n\n```css\nqlineargradient(0, 0, 0, 1, (0.1 blue, 0.8 green))\n```\n\nYou may also use this syntax directly in your QtSASS.\n\n```\nqlineargradient(0, 0, 0, 1, (0.1 blue, 0.8 green))\n# the stops parameter is a list, so you can also use variables:\n$stops = 0.1 blue, 0.8 green\nqlineargradient(0, 0, 0, 0, $stops)\n```\n\n#### qrgba\nQt's rgba:\n\n```css\nrgba(255, 128, 128, 50%)\n```\n\nis replaced by CSS rgba:\n\n```css\nrgba(255, 128, 128, 0.5)\n```\n\n\n## Executable usage\n\nTo compile your SASS stylesheet to a Qt compliant CSS file:\n\n```bash\n# If -o is omitted, output will be printed to console\nqtsass style.scss -o style.css\n```\n\nTo use the watch mode and get your stylesheet auto recompiled on each file save:\n\n```bash\n# If -o is omitted, output will be print to console\nqtsass style.scss -o style.css -w\n```\n\nTo compile a directory containing SASS stylesheets to Qt compliant CSS files:\n\n```bash\nqtsass ./static/scss -o ./static/css\n```\n\nYou can also use watch mode to watch the entire directory for changes.\n\n```bash\nqtsass ./static/scss -o ./static/css -w\n```\n\nSet the Environment Variable QTSASS_DEBUG to 1 or pass the --debug flag to enable logging.\n\n```bash\nqtsass ./static/scss -o ./static/css --debug\n```\n\n## API methods\n\n### `compile(string, **kwargs)`\n\nConform and Compile QtSASS source code to CSS.\n\nThis function conforms QtSASS to valid SCSS before passing it to\nsass.compile. Any keyword arguments you provide will be combined with\nqtsass's default keyword arguments and passed to sass.compile.\n\nExamples:\n\n```bash\n>>> import qtsass\n>>> qtsass.compile(\"QWidget {background: rgb(0, 0, 0);}\")\nQWidget {background:black;}\n```\n\nArguments:\n- string: QtSASS source code to conform and compile.\n- kwargs: Keyword arguments to pass to sass.compile\n\nReturns:\n- Qt compliant CSS string\n\n### `compile_filename(input_file, output_file=None, **kwargs)`:\n\nCompile and return a QtSASS file as Qt compliant CSS. Optionally save to a file.\n\nExamples:\n\n```bash\n>>> import qtsass\n>>> qtsass.compile_filename(\"dummy.scss\", \"dummy.css\")\n>>> css = qtsass.compile_filename(\"dummy.scss\")\n```\n\nArguments:\n- input_file: Path to QtSass file.\n- output_file: Path to write Qt compliant CSS.\n- kwargs: Keyword arguments to pass to sass.compile\n\nReturns:\n- Qt compliant CSS string\n\n### `compile_dirname(input_dir, output_dir, **kwargs)`:\n\nCompiles QtSASS files in a directory including subdirectories.\n\n```bash\n>>> import qtsass\n>>> qtsass.compile_dirname(\"./scss\", \"./css\")\n```\n\nArguments:\n- input_dir: Path to directory containing QtSass files.\n- output_dir: Directory to write compiled Qt compliant CSS files to.\n- kwargs: Keyword arguments to pass to sass.compile\n\n### `enable_logging(level=None, handler=None)`:\nEnable logging for qtsass.\n\nSets the qtsass logger's level to:\n    1. the provided logging level\n    2. logging.DEBUG if the QTSASS_DEBUG envvar is a True value\n    3. logging.WARNING\n\n```bash\n>>> import logging\n>>> import qtsass\n>>> handler = logging.StreamHandler()\n>>> formatter = logging.Formatter('%(level)-8s: %(name)s> %(message)s')\n>>> handler.setFormatter(formatter)\n>>> qtsass.enable_logging(level=logging.DEBUG, handler=handler)\n```\n\nArguments:\n- level: Optional logging level\n- handler: Optional handler to add\n\n### `watch(source, destination, compiler=None, Watcher=None)`:\nWatches a source file or directory, compiling QtSass files when modified.\n\nThe compiler function defaults to compile_filename when source is a file\nand compile_dirname when source is a directory.\n\nArguments:\n- source: Path to source QtSass file or directory.\n- destination: Path to output css file or directory.\n- compiler: Compile function (optional)\n- Watcher: Defaults to qtsass.watchers.Watcher (optional)\n\nReturns:\n- qtsass.watchers.Watcher instance\n\n## Contributing\n\nEveryone is welcome to contribute!\n\n\n## Sponsors\n\nSpyder and its subprojects are funded thanks to the generous support of\n\n[![Quansight](https://static.wixstatic.com/media/095d2c_2508c560e87d436ea00357abc404cf1d~mv2.png/v1/crop/x_0,y_9,w_915,h_329/fill/w_380,h_128,al_c,usm_0.66_1.00_0.01/095d2c_2508c560e87d436ea00357abc404cf1d~mv2.png)](https://www.quansight.com/)[![Numfocus](https://i2.wp.com/numfocus.org/wp-content/uploads/2017/07/NumFocus_LRG.png?fit=320%2C148&ssl=1)](https://numfocus.org/)\n\n\nand the donations we have received from our users around the world through [Open Collective](https://opencollective.com/spyder/):\n\n[![Sponsors](https://opencollective.com/spyder/sponsors.svg)](https://opencollective.com/spyder#support)\n\nPlease consider becoming a sponsor!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Compile SCSS files to valid Qt stylesheets.",
    "version": "0.4.0",
    "split_keywords": [
        "qt",
        "sass",
        "qtsass",
        "scss",
        "css",
        "qss",
        "stylesheets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c69b718ae0cf4425ef4b1feb21d1f5cd4fb3fd5bfd74db3123f5a811116efc8",
                "md5": "c365b3311dcc93f6e3f36e3e630329d4",
                "sha256": "877a8ded1046cb3eb371accca9ba0a346d5a4f946d5b2d6fa301b7359ae9b287"
            },
            "downloads": -1,
            "filename": "qtsass-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c365b3311dcc93f6e3f36e3e630329d4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 20008,
            "upload_time": "2023-03-27T22:48:12",
            "upload_time_iso_8601": "2023-03-27T22:48:12.297079Z",
            "url": "https://files.pythonhosted.org/packages/5c/69/b718ae0cf4425ef4b1feb21d1f5cd4fb3fd5bfd74db3123f5a811116efc8/qtsass-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cfa97e03e21e72aa503c18a76e6e847b46f3c953ca39c0e684b01f10c29976db",
                "md5": "da3bd7c3c6a4b9a41fdd8bb37e82f0b8",
                "sha256": "8341c6d2690f75d651916dcaf96b4fa8c6dc54ef1d96bbc39958cbaa475fbf41"
            },
            "downloads": -1,
            "filename": "qtsass-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "da3bd7c3c6a4b9a41fdd8bb37e82f0b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 25595,
            "upload_time": "2023-03-27T22:48:14",
            "upload_time_iso_8601": "2023-03-27T22:48:14.063470Z",
            "url": "https://files.pythonhosted.org/packages/cf/a9/7e03e21e72aa503c18a76e6e847b46f3c953ca39c0e684b01f10c29976db/qtsass-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-27 22:48:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "spyder-ide",
    "github_project": "qtsass",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "qtsass"
}
        
Elapsed time: 0.04890s