Properties¶
Property ¶
A single <property>: a typed, named value on a control.
A property's Python value is always a native type -- bool, int, float,
str, Frame or Color -- and is
converted to text only when the file is written.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
The camelCase key as stored in the file. |
|
type |
Which |
|
value |
Any
|
The native Python value. |
Source code in src/py2tosc/properties.py
Frame ¶
Bases: NamedTuple
A control's position and size, in points.
Components are floats: TouchOSC positions controls at sub-pixel offsets, and
its own layouts are full of frames like x=417.439. Rounding them would
move every such control.
Comparable and unpackable as a plain (x, y, w, h) tuple, and an integral
frame compares equal to a tuple of ints.
Source code in src/py2tosc/properties.py
Color ¶
Bases: NamedTuple
An RGBA colour with components from 0.0 to 1.0.
Comparable and unpackable as a plain (r, g, b, a) tuple.
Source code in src/py2tosc/properties.py
to_frame ¶
Coerce a 4-item sequence into a Frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Any sequence of four numbers. |
required |
Returns:
| Type | Description |
|---|---|
Frame
|
The frame, with components as floats. They are not rounded: TouchOSC |
Frame
|
stores sub-pixel positions and rounding would move the control. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/py2tosc/properties.py
to_color ¶
Coerce a colour in any accepted notation into a Color.
Accepts floats already in 0.0-1.0, integers in 0-255, and hex strings with
or without a leading # and with or without an alpha pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
|
required |
Returns:
| Type | Description |
|---|---|
Color
|
The colour normalised to 0.0-1.0. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string is not 6 or 8 hex digits, or the sequence does not hold three or four items. |
Source code in src/py2tosc/properties.py
to_camel ¶
Convert a snake_case Python name to its camelCase format key.
Names that contain no underscore are returned unchanged, so already-camelCase keys pass through untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A property name in either convention. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The camelCase key as it is stored in the file. |
Source code in src/py2tosc/properties.py
to_snake ¶
Convert a camelCase format key to its snake_case Python name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
A property key as stored in the file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The |