DString
DString (Dynamic String) is a Python library that provides a simple and intuitive syntax for creating richly styled text in Flet applications. With DString, you can easily add colors, fonts, decorations, gradients, and other text styling effects to your Flet UI components.
Features
- Simple, intuitive syntax for text styling
- Support for multiple styling parameters
- Color gradients
- Font styling (size, family, weight)
- Text decorations (underline, overline, strikethrough)
- Spacing controls (letter spacing, word spacing)
- Text shadows
- Overflow handling
- Baseline control
- Combination of multiple styles
- Gradient text effects
Installation
pip install flet-dstring
Quick Start
import flet as ft
from flet_dstring import DString
def main(page: ft.Page):
# Create styled text
styled_text = "d[<f=ff6b6b,b>, <Hello>] d[<f=4ecdc4,i>, <World>]"
text = DString(styled_text).to_flet()
# Add to page
page.add(text)
ft.app(target=main)
Syntax
The basic syntax for DString is:
d[<style_params>, <text>]
Multiple style parameters can be combined using commas. For example:
d[<f=ff6b6b,b,size=20>, <Hello World>]
Available Style Parameters
| Parameter | Format | Description | Example |
|---|---|---|---|
| f | XXXXXX | Foreground color (hex) | f=ff6b6b |
| b | XXXXXX | Background color (hex) | b=000000 |
| dc | XXXXXX | Decoration color (hex) | dc=ff0000 |
| size | N | Font size (integer) | size=20 |
| ff | name | Font family | ff=Arial |
| h | N | Height (float) | h=1.5 |
| ls | N | Letter spacing (float) | ls=2 |
| ws | N | Word spacing (float) | ws=10 |
| dt | N | Decoration thickness (float) | dt=2 |
| ds | style | Decoration style | ds=solid |
| d | type | Decoration type | d=underline |
| bl | type | Baseline | bl=alphabetic |
| o | type | Overflow | o=ellipsis |
| w | weight | Font weight | w=bold |
| shadow | color,x,y,blur,spread | Box shadow | shadow=000000,2,2,4,0 |
| gs | XXXXXX | Gradient start color (hex) | gs=ff0000 |
| ge | XXXXXX | Gradient end color (hex) | ge=0000ff |
| i | - | Italic | i |
| u | - | Underline | u |
| b | - | Bold | b |
Style Values
Decoration Types
- underline
- overline
- line-through
Decoration Styles
- solid
- double
- dotted
- dashed
- wavy
Baseline Types
- alphabetic
- ideographic
Overflow Types
- clip
- ellipsis
- fade
- visible
Font Weights
- normal
- bold
- w100 through w900
Examples
Basic Styling
# Bold red text
"d[<f=ff6b6b,b>, <Bold Red Text>]"
# Italic green text
"d[<f=4ecdc4,i>, <Italic Green Text>]"
# Underlined blue text
"d[<f=45b7d1,u>, <Underlined Blue Text>]"
Colors and Sizes
# Large red text
"d[<f=ff0000,size=20>, <Large Red Text>]"
# Medium green text
"d[<f=00ff00,size=16>, <Medium Green Text>]"
# Small blue text
"d[<f=0000ff,size=12>, <Small Blue Text>]"
Text Decorations
# Solid underline
"d[<d=underline,ds=solid,dc=ff0000>, <Solid Underline>]"
# Dotted overline
"d[<d=overline,ds=dotted,dc=00ff00>, <Dotted Overline>]"
# Wavy strikethrough
"d[<d=line-through,ds=wavy,dc=0000ff>, <Wavy Strikethrough>]"
Gradients
# Basic gradient
"d[<gs=ff0000,ge=0000ff>, <Red to Blue Gradient>]"
# Styled gradient
"d[<gs=ff0000,ge=00ff00,size=24,b>, <Bold Gradient Text>]"
Complex Styling
text = (
"d[<f=ff6b6b,w=bold,size=32,b=000000>, <Welcome>] to the "
"d[<f=4ecdc4,i,ff=Arial>, <Extended>] "
"d[<f=45b7d1,d=underline,ds=wavy,dc=ff0000>, <Styling>] "
"d[<f=96ceb4,h=1.5>, <System>]!"
)
Configuration
You can customize the default behavior of DString using the DStringConfig class:
from flet_dstring import DString, DStringConfig
config = DStringConfig(
default_color="ff0000", # Default text color
default_size=16, # Default font size
pattern=r"d\[<(.*?)>, <(.*?)>\]" # Custom pattern
)
dstring = DString("d[<b>, <Hello>]", config)
Error Handling
DString provides several exception classes for error handling:
DStringError: Base exception for DString-related errorsDStringParseError: Raised when parsing a DString failsDStringStyleError: Raised when creating a text style fails
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for flet-dstring 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flet_dstring-0.1.1.tar.gz | 9.7 kB | Without provenance | Details for flet_dstring-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flet_dstring-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for flet_dstring-0.1.1-py3-none-any.whl |
Total release size: 18.9 kB
Release files / flet_dstring-0.1.1.tar.gz
| Download URL | flet_dstring-0.1.1.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a242b609a426d7a06ec3a76a4aeb2f1e30db522fb7de2063d1805041bcaa1c1b
|
|
BLAKE2b-256 checksum How to use checksums |
e1098e185e0ff1cec15bfdc5c354fe4f5bdda88ec22bfdc79abab10043befae5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.0
|
Release files / flet_dstring-0.1.1-py3-none-any.whl
| Download URL | flet_dstring-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a8ebc8a32465c9d214862cd58e9f713595cda93da6e65cd06afdf43315a6344
|
|
BLAKE2b-256 checksum How to use checksums |
99928899a5393b9c040ca09d40ae0443001cb1024162fff19ddc7b28c8c6a86d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.0
|
Security for flet-dstring 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.