xnano.expressions
xnano.expressions
¶
xnano.expressions
The expression language: values that are evaluated again on every frame.
An Expression stands for a number, a position or a state that
changes, such as the elapsed time, the width of the parent or the pointer position. Combine
them with arithmetic and give them to anything that takes a number, or read them from the
parent, root and time attributes on a Canvas or a
Placement.
Classes:
-
BufferExpressionScope–A buffer's own position and size, as expressions.
-
Expression–A value or action described now and evaluated later against a buffer or runtime.
-
KeyboardExpressionScope–The latest key event, as expressions.
-
MouseExpressionScope–The latest mouse button or motion report, as expressions.
-
NumericValue–A numeric expression that supports comparisons and arithmetic.
-
ParentExpressionScope–The geometry of the enclosing buffer, as expressions.
-
RootExpressionScope–The geometry and clock of the root terminal, as expressions.
-
ScrollExpressionScope–The mouse wheel steps of the current step, as expressions.
-
Size–A width and a height, counted in cells.
-
Value–An expression that evaluates to a value.
Attributes:
-
FPS(NumericValue[int | float]) –The runtime's estimated frames per second.
-
BufferRegion(Value[Rectangle]) –The rectangle of a buffer on the screen, counting every parent offset.
-
BufferSize(Value[Size]) –The dimensions of a buffer as a
Size. -
DeviceHeight(NumericValue[int | float]) –The terminal height, in cells.
-
DeviceWidth(NumericValue[int | float]) –The terminal width, in cells.
-
Focused(Value[bool]) –Whether the runtime has focus.
-
Height(NumericValue[int | float]) –The height of a buffer or region, in terminal cells.
-
IsVisible(Property[bool]) –Whether a buffer is drawn. Assign it with
IsVisible(False). -
KeyboardChord(Value[str | None]) –The latest key event with its modifiers, such as
'ctrl+s', orNone. -
KeyboardKey(Value[str | None]) –The key of the latest key event, or
Nonewhile the latest input was not a key. -
KeyboardKind(Value[Literal['press', 'repeat', 'release'] | None]) –Whether the latest key event was a press, repeat or release, or
None. -
MouseButtonValue(Value[MouseButton | None]) –The button of the latest button or motion report, or
None. -
MouseIsDown(Predicate) –Whether any mouse button is held.
-
MouseKind(Value[Literal['press', 'release', 'drag', 'move'] | None]) –The kind of the latest button or motion report, or
None(also for a wheel report). -
MousePosition(Value[Point | None]) –The cell of the latest button or motion report, or
None. -
ParentHeight(NumericValue[int]) –The height of the parent buffer, in cells.
-
ParentSize(Value[Size]) –The size of the parent buffer, or of the buffer a region belongs to.
-
ParentWidth(NumericValue[int]) –The width of the parent buffer, in cells.
-
PointerPosition(Value[Point | None]) –The cell under the pointer, or
Noneuntil the runtime has seen the pointer. -
Position(Value[Point]) –The position of a buffer or region as a
Point. -
ScreenBounds(Value[Rectangle]) –The rectangle of a buffer or region on the screen, counting every parent offset.
-
ScreenPosition(Value[Point]) –The top-left cell of a buffer or region on the screen, counting every parent offset.
-
ScrollX(NumericValue[int]) –Horizontal steps of the latest wheel report of the current step (right is positive).
-
ScrollY(NumericValue[int]) –Vertical steps of the latest wheel report of the step (down is positive, up is
-1). -
TimeDelta(NumericValue[int | float]) –The elapsed time since the previous runtime frame, in seconds.
-
TimeDeltaMilliseconds(NumericValue[int | float]) –The elapsed time since the previous runtime frame, in milliseconds.
-
TimeElapsed(NumericValue[int | float]) –The elapsed runtime time, in seconds.
-
TimeElapsedMilliseconds(NumericValue[int | float]) –The elapsed runtime time, in milliseconds.
-
Width(NumericValue[int | float]) –The width of a buffer or region, in terminal cells.
-
X(NumericValue[int | float]) –The horizontal position of a buffer or region, in terminal cells.
-
Y(NumericValue[int | float]) –The vertical position of a buffer or region, in terminal cells.
-
Parent(ParentExpressionScope) –Symbolic expressions for the parent buffer's geometry (
Parent.width,Parent.height). -
Root(RootExpressionScope) –Symbolic expressions for the root canvas's geometry and clock (
Root.width,Root.time). -
BufferExpressions(BufferExpressionScope) –Symbolic expressions for the current buffer's geometry (
BufferExpressions.width, -
Keyboard(KeyboardExpressionScope) –Symbolic expressions for the latest key event (
Keyboard.key,Keyboard.kind,Keyboard.chord). -
Mouse(MouseExpressionScope) –Symbolic expressions for the latest mouse button or movement report (
Mouse.position, -
Scroll(ScrollExpressionScope) –Symbolic expressions for the mouse wheel steps of the current step (
Scroll.x,Scroll.y).
BufferRegion
module-attribute
¶
The rectangle of a buffer on the screen, counting every parent offset.
DeviceHeight
module-attribute
¶
DeviceHeight: NumericValue[int | float]
The terminal height, in cells.
Height
module-attribute
¶
Height: NumericValue[int | float]
The height of a buffer or region, in terminal cells.
IsVisible
module-attribute
¶
Whether a buffer is drawn. Assign it with IsVisible(False).
KeyboardChord
module-attribute
¶
The latest key event with its modifiers, such as 'ctrl+s', or None.
KeyboardKey
module-attribute
¶
The key of the latest key event, or None while the latest input was not a key.
KeyboardKind
module-attribute
¶
Whether the latest key event was a press, repeat or release, or None.
MouseButtonValue
module-attribute
¶
MouseButtonValue: Value[MouseButton | None]
The button of the latest button or motion report, or None.
MouseKind
module-attribute
¶
The kind of the latest button or motion report, or None (also for a wheel report).
MousePosition
module-attribute
¶
The cell of the latest button or motion report, or None.
PointerPosition is the last cell the pointer was seen at, whatever came since; this one
belongs to the event being handled.
ParentHeight
module-attribute
¶
ParentHeight: NumericValue[int]
The height of the parent buffer, in cells.
ParentSize
module-attribute
¶
The size of the parent buffer, or of the buffer a region belongs to.
Evaluating it raises TypeError for a buffer without a parent.
ParentWidth
module-attribute
¶
ParentWidth: NumericValue[int]
The width of the parent buffer, in cells.
PointerPosition
module-attribute
¶
The cell under the pointer, or None until the runtime has seen the pointer.
It is the last known cell, held between events. MousePosition is the cell of the event
being handled. Reading it needs a mounted runtime.
ScreenBounds
module-attribute
¶
The rectangle of a buffer or region on the screen, counting every parent offset.
ScreenPosition
module-attribute
¶
The top-left cell of a buffer or region on the screen, counting every parent offset.
ScrollX
module-attribute
¶
ScrollX: NumericValue[int]
Horizontal steps of the latest wheel report of the current step (right is positive).
ScrollY
module-attribute
¶
ScrollY: NumericValue[int]
Vertical steps of the latest wheel report of the step (down is positive, up is -1).
TimeDelta
module-attribute
¶
TimeDelta: NumericValue[int | float]
The elapsed time since the previous runtime frame, in seconds.
TimeDeltaMilliseconds
module-attribute
¶
TimeDeltaMilliseconds: NumericValue[int | float]
The elapsed time since the previous runtime frame, in milliseconds.
TimeElapsed
module-attribute
¶
TimeElapsed: NumericValue[int | float]
The elapsed runtime time, in seconds.
TimeElapsedMilliseconds
module-attribute
¶
TimeElapsedMilliseconds: NumericValue[int | float]
The elapsed runtime time, in milliseconds.
Width
module-attribute
¶
Width: NumericValue[int | float]
The width of a buffer or region, in terminal cells.
X
module-attribute
¶
X: NumericValue[int | float]
The horizontal position of a buffer or region, in terminal cells.
Y
module-attribute
¶
Y: NumericValue[int | float]
The vertical position of a buffer or region, in terminal cells.
Parent
module-attribute
¶
Parent: ParentExpressionScope = ParentScope
Symbolic expressions for the parent buffer's geometry (Parent.width, Parent.height).
Root
module-attribute
¶
Root: RootExpressionScope = RootScope
Symbolic expressions for the root canvas's geometry and clock (Root.width, Root.time).
BufferExpressions
module-attribute
¶
BufferExpressions: BufferExpressionScope = BufferScope
Symbolic expressions for the current buffer's geometry (BufferExpressions.width,
BufferExpressions.height) and its rectangle on the screen (BufferExpressions.region).
Keyboard
module-attribute
¶
Keyboard: KeyboardExpressionScope = KeyboardScope
Symbolic expressions for the latest key event (Keyboard.key, Keyboard.kind, Keyboard.chord).
Mouse
module-attribute
¶
Mouse: MouseExpressionScope = MouseScope
Symbolic expressions for the latest mouse button or movement report (Mouse.position,
Mouse.button, Mouse.kind) and whether a button is held (Mouse.is_down).
Scroll
module-attribute
¶
Scroll: ScrollExpressionScope = ScrollScope
Symbolic expressions for the mouse wheel steps of the current step (Scroll.x, Scroll.y).
BufferExpressionScope
¶
Bases: ExpressionScope
A buffer's own position and size, as expressions.
Attributes:
-
x(NumericValue[int | float]) –The column in the parent.
-
y(NumericValue[int | float]) –The row in the parent.
-
position(Value[Point]) –The position in the parent.
-
width(NumericValue[int | float]) –The width in cells.
-
height(NumericValue[int | float]) –The height in cells.
-
size(Value[Size]) –The size in cells.
-
region(Value[Rectangle]) –The rectangle on the screen, counting every parent offset.
Examples:
Expression
¶
Bases: Generic[ValueType_co]
A value or action described now and evaluated later against a buffer or runtime.
Evaluation is explicit. Using an expression where Python wants a truth value raises
TypeError; combine conditions with &, | and ~ instead.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
buffer = Buffer(width=8, height=1)
assert buffer.inspect(width + 2) == 10
assert (width + 2).evaluate(EvaluationContext(buffer=buffer)) == 10
-
API Reference
- xnano
-
xnano_core
-
xnano_core -
xnano_core._xnano_core
_xnano_core
-
-
API Reference
- xnano
-
xnano_core
-
xnano_core-
Bar -
BarChartinspect -
BarGroup -
Blockinspect -
BlockTitle -
Bufferinspect -
Calendarinspect -
Canvasinspect -
Chartinspect -
ChartAxis -
ChartDataset -
Clearinspect -
CustomWidgetinspect -
Dissolve -
DynamicStyle -
Effect -
Fade -
Gaugeinspect -
Glitch -
ItemListinspect -
LineGaugeinspect -
ListItem -
Liveinspect -
Margin -
Offset -
Paragraphinspect -
Regioninspect -
Scrollbarinspect -
Sparklineinspect -
SparklineBar -
Surfaceinspect -
Tableinspect -
TableCell -
TableRow -
Tabsinspect -
Widgetinspect
-
-
xnano_core._xnano_core
_xnano_core-
Bar -
BarChartinspect -
BarGroup -
Blockinspect -
BlockTitle -
Bufferinspect -
Calendarinspect -
Canvasinspect -
Chartinspect -
ChartAxis -
ChartDataset -
Clearinspect -
CustomWidgetinspect -
Dissolve -
DynamicStyle -
Effect -
Fade -
Gaugeinspect -
Glitch -
ItemListinspect -
LineGaugeinspect -
ListItem -
Liveinspect -
Margin -
Offset -
Paragraphinspect -
Regioninspect -
Scrollbarinspect -
Sparklineinspect -
SparklineBar -
Surfaceinspect -
Tableinspect -
TableCell -
TableRow -
Tabsinspect -
Widgetinspect
-
-
Methods:
-
evaluate–Compute the expression's value.
evaluate
¶
evaluate(context: EvaluationContext) -> ValueType_co
Compute the expression's value.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
context = EvaluationContext(buffer=Buffer(width=5, height=1))
assert (width * 2).evaluate(context) == 10
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
KeyboardExpressionScope
¶
Bases: ExpressionScope
The latest key event, as expressions.
Every member has no value while the latest input was not a key event, so a condition on a
key is false for mouse, wheel and paste events. Comparing a member with None raises
TypeError; compare it with the key you wait for, such as KeyboardScope.key == 'q'.
Attributes:
-
key(Value[str | None]) –The key name, such as
'q'or'enter'. -
kind(Value[Literal['press', 'repeat', 'release'] | None]) –'press','repeat'or'release'. -
chord(Value[str | None]) –The key with its modifiers, such as
'ctrl+s'.
Examples:
with Runtime.offscreen(width=10, height=3) as runtime:
buffer = Buffer(width=10, height=3)
runtime.mount(buffer)
seen = []
buffer.add_hook(
lambda context: seen.append('quit'),
events=('key',),
condition=KeyboardScope.key == 'q',
)
for key in ('w', 'q'):
runtime.inject(Event.key_press(key))
runtime.step()
assert seen == ['quit']
assert buffer.inspect(KeyboardScope.chord) == 'q'
kind
property
¶
Whether the latest key event was a press, repeat or release.
MouseExpressionScope
¶
Bases: ExpressionScope
The latest mouse button or motion report, as expressions.
position, button and kind describe the event being handled and have no value
while the latest input was a key, a paste or a wheel report, so a condition on them is false
(comparing with None raises TypeError); is_down is the held state
and stays true between events while a button is held. Wheel reports belong to
ScrollScope.
Attributes:
-
position(Value[Point | None]) –The cell of the event.
-
button(Value[MouseButton | None]) –'left','right'or'middle'. -
kind(Value[Literal['press', 'release', 'drag', 'move'] | None]) –'press','release','drag'or'move'. -
is_down(Predicate) –Whether any button is held.
Examples:
with Runtime.offscreen(width=10, height=3) as runtime:
buffer = Buffer(width=4, height=2, x=1, y=1)
runtime.mount(buffer)
clicks = []
buffer.add_hook(
lambda context: clicks.append('inside'),
events=('mouse',),
condition=BufferScope.region.contains(MouseScope.position),
)
runtime.inject(Event.mouse_event(column=2, row=2, kind='move'))
runtime.inject(Event.mouse_event(column=8, row=2, kind='move'))
runtime.step()
assert clicks == ['inside']
assert buffer.inspect(MouseScope.position.x) == 8
button
property
¶
button: Value[MouseButton | None]
The button of the latest button or motion report.
kind
property
¶
The kind of the latest button or motion report.
NumericValue
¶
Bases: Value[NumberType]
A numeric expression that supports comparisons and arithmetic.
Arithmetic and comparisons build new expressions instead of computing right away.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
buffer = Buffer(width=8, height=3)
assert buffer.inspect(width + 2) == 10
assert buffer.inspect(10 - width) == 2
assert buffer.inspect(width > 4)
assert buffer.inspect(-width) == -8
-
API Reference
-
xnano
-
xnano.demo
demo -
xnano.expressions
expressions -
xnano.placement
placementPlacementtime -
xnano.time
timeTime
-
xnano.demo
-
xnano_core
-
xnano_core-
DeviceHeight -
DeviceWidth -
FPS -
Frame -
Height -
ParentHeight -
ParentWidth -
ScrollX -
ScrollY -
TimeDelta -
TimeDeltaMilliseconds -
TimeElapsed -
TimeElapsedMilliseconds -
Width -
X -
Y -
BufferExpressionScope -
NumericProperty -
NumericValue -
ParentExpressionScope -
Predicatechoose -
Property -
RootExpressionScope -
ScrollExpressionScope -
StateReferencenumber -
Value
-
-
xnano_core._xnano_core
_xnano_core-
DeviceHeight -
DeviceWidth -
FPS -
Frame -
Height -
ParentHeight -
ParentWidth -
ScrollX -
ScrollY -
TimeDelta -
TimeDeltaMilliseconds -
TimeElapsed -
TimeElapsedMilliseconds -
Width -
X -
Y -
BufferExpressionScope -
NumericProperty -
NumericValue -
ParentExpressionScope -
Predicatechoose -
Property -
RootExpressionScope -
ScrollExpressionScope -
StateReferencenumber -
Value
-
-
-
xnano
Methods:
-
evaluate–Compute the expression's value.
-
equals–A predicate that is true when the value equals
other. -
not_equals–A predicate that is true when the value differs from
other. -
contains–A condition that is true while this rectangle contains the point
other. -
__eq__–A predicate that is true when the value equals
other; the same asequals. -
__ne__–A predicate that is true when the value differs from
other; the same asnot_equals. -
__hash__–The identity hash, which keeps expressions usable in sets and dictionaries.
-
__lt__–A predicate that is true when the value is less than
other. -
__le__–A predicate that is true when the value is at most
other. -
__gt__–A predicate that is true when the value is greater than
other. -
__ge__–A predicate that is true when the value is at least
other. -
__add__–The sum of the value and
other. -
__sub__–The value minus
other. -
__mul__–The product of the value and
other. -
__truediv__–The value divided by
other. -
__mod__–The remainder of dividing the value by
other. -
__neg__–The value with its sign flipped.
-
__rtruediv__–otherdivided by the value. -
__rmod__–The remainder of dividing
otherby the value. -
__floordiv__–The value divided by
other, rounded toward negative infinity like Python's//. -
__rfloordiv__–otherdivided by the value, rounded toward negative infinity. -
__pow__–The value raised to the power
other. -
__rpow__–otherraised to the power of the value. -
__abs__–The absolute value.
-
__floor__–The value rounded down to a whole number, used by
math.floor. -
__ceil__–The value rounded up to a whole number, used by
math.ceil. -
__round__–The value rounded to the nearest whole number, halves away from zero.
-
minimum–The smaller of the value and
other. -
maximum–The larger of the value and
other. -
clamp–The value limited to the range from
lowesttohighest.
Attributes:
-
x(NumericValue[int]) –The column of a
Pointor the left edge of aRectangle. -
y(NumericValue[int]) –The row of a
Pointor the top edge of aRectangle. -
width(NumericValue[int]) –The width of a
Sizeor aRectangle. -
height(NumericValue[int]) –The height of a
Sizeor aRectangle. -
right(NumericValue[int]) –The first column after a
Rectangle. -
bottom(NumericValue[int]) –The first row after a
Rectangle.
x
property
¶
x: NumericValue[int]
y
property
¶
y: NumericValue[int]
width
property
¶
width: NumericValue[int]
height
property
¶
height: NumericValue[int]
right
property
¶
right: NumericValue[int]
bottom
property
¶
bottom: NumericValue[int]
evaluate
¶
evaluate(context: EvaluationContext) -> ValueType_co
Compute the expression's value.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
context = EvaluationContext(buffer=Buffer(width=5, height=1))
assert (width * 2).evaluate(context) == 10
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
equals
¶
A predicate that is true when the value equals other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width.equals(20))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
not_equals
¶
A predicate that is true when the value differs from other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width.not_equals(5))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
contains
¶
A condition that is true while this rectangle contains the point other.
It is false, never an error, while either side has no value yet, such as a mouse position before any mouse event.
Parameters:
-
other(Point | Value[Point] | Value[Point | None]) –The
Point(or an expression that produces one) to look for.
Examples:
from xnano_core._xnano_core import Bounds, Point
buffer = Buffer(width=4, height=2)
assert buffer.inspect(Bounds.contains(Point(3, 1)))
assert not buffer.inspect(Bounds.contains(Point(4, 1)))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__eq__
¶
A predicate that is true when the value equals other; the same as equals.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width == 20)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__ne__
¶
A predicate that is true when the value differs from other; the same as not_equals.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width != 5)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__lt__
¶
__lt__(other: float | NumericValue[int] | NumericValue[float]) -> Predicate
A predicate that is true when the value is less than other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=3, height=1).inspect(width < 4)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__le__
¶
__le__(other: float | NumericValue[int] | NumericValue[float]) -> Predicate
A predicate that is true when the value is at most other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=4, height=1).inspect(width <= 4)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__gt__
¶
__gt__(other: float | NumericValue[int] | NumericValue[float]) -> Predicate
A predicate that is true when the value is greater than other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=5, height=1).inspect(width > 4)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__ge__
¶
__ge__(other: float | NumericValue[int] | NumericValue[float]) -> Predicate
A predicate that is true when the value is at least other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=4, height=1).inspect(width >= 4)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__add__
¶
__add__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[float]
The sum of the value and other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=4, height=1).inspect(width + 1) == 5
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__sub__
¶
__sub__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[float]
The value minus other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=4, height=1).inspect(width - 1) == 3
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__mul__
¶
__mul__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[float]
The product of the value and other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
height = _reference('Height', 'numeric_property')
assert Buffer(width=4, height=3).inspect(width * height) == 12
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__truediv__
¶
__truediv__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[float]
The value divided by other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=8, height=1).inspect(width / 2) == 4.0
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__mod__
¶
__mod__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[float]
The remainder of dividing the value by other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=8, height=1).inspect(width % 3) == 2
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__neg__
¶
__neg__() -> NumericValue[NumberType]
__rtruediv__
¶
__rtruediv__(other: float) -> NumericValue[float]
__rmod__
¶
__rmod__(other: float) -> NumericValue[float]
The remainder of dividing other by the value.
Examples:
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__floordiv__
¶
__floordiv__(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[int | float]
The value divided by other, rounded toward negative infinity like Python's //.
Dividing by zero raises ZeroDivisionError when the expression is evaluated.
Examples:
from xnano_core._xnano_core import Width
assert Buffer(width=7, height=1).inspect(Width // 2) == 3
assert Buffer(width=7, height=1).inspect(-Width // 2) == -4
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__rfloordiv__
¶
__rfloordiv__(other: float) -> NumericValue[int | float]
other divided by the value, rounded toward negative infinity.
Examples:
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__pow__
¶
__pow__(other: float | NumericValue[int] | NumericValue[float], modulo: None = None) -> NumericValue[int | float]
The value raised to the power other.
Whole-number results stay integers; a negative or fractional exponent gives a float.
Examples:
from xnano_core._xnano_core import Width
assert Buffer(width=3, height=1).inspect(Width**2) == 9
assert Buffer(width=4, height=1).inspect(Width**0.5) == 2.0
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__rpow__
¶
__rpow__(other: float, modulo: None = None) -> NumericValue[int | float]
other raised to the power of the value.
Examples:
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__abs__
¶
__abs__() -> NumericValue[NumberType]
The absolute value.
Examples:
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__floor__
¶
__floor__() -> NumericValue[int]
__ceil__
¶
__ceil__() -> NumericValue[int]
__round__
¶
__round__(digits: None = None) -> NumericValue[int]
The value rounded to the nearest whole number, halves away from zero.
Unlike Python's round, a half rounds away from zero, so 2.5 becomes 3.
Passing a number of digits raises TypeError.
Examples:
from xnano_core._xnano_core import Width
assert Buffer(width=5, height=1).inspect(round(Width / 2)) == 3
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
minimum
¶
minimum(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[NumberType]
maximum
¶
maximum(other: float | NumericValue[int] | NumericValue[float]) -> NumericValue[NumberType]
clamp
¶
clamp(lowest: float | NumericValue[int] | NumericValue[float], highest: float | NumericValue[int] | NumericValue[float]) -> NumericValue[NumberType]
The value limited to the range from lowest to highest.
Raises TypeError when evaluated if lowest is greater than highest.
Examples:
from xnano_core._xnano_core import Width
assert Buffer(width=50, height=1).inspect(Width.clamp(0, 10)) == 10
assert Buffer(width=5, height=1).inspect(Width.clamp(8, 10)) == 8
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
ParentExpressionScope
¶
Bases: ExpressionScope
The geometry of the enclosing buffer, as expressions.
Attributes:
-
width(NumericValue[int]) –The parent's width in cells.
-
height(NumericValue[int]) –The parent's height in cells.
-
size(Value[Size]) –The parent's size in cells.
Examples:
RootExpressionScope
¶
Bases: ExpressionScope
The geometry and clock of the root terminal, as expressions.
Attributes:
-
width(NumericValue[int | float]) –The terminal's width in cells.
-
height(NumericValue[int | float]) –The terminal's height in cells.
-
time(NumericValue[int | float]) –Seconds elapsed on the terminal's clock.
-
delta(NumericValue[int | float]) –Seconds since the previous frame.
-
fps(NumericValue[int | float]) –Measured frames per second.
Examples:
ScrollExpressionScope
¶
Bases: ExpressionScope
The mouse wheel steps of the current step, as expressions.
Each member holds the steps of the latest wheel report of the step; reports of one step do
not add up, and a key, paste, button or motion report that follows a wheel report in the same
step clears them. Both are 0 when no wheel report arrived in the step. Scrolling up gives
a negative y and scrolling left a negative x.
Attributes:
-
x(NumericValue[int]) –Horizontal steps (right is positive).
-
y(NumericValue[int]) –Vertical steps (down is positive).
Examples:
with Runtime.offscreen(width=10, height=3) as runtime:
buffer = Buffer(width=10, height=3)
runtime.mount(buffer)
seen = []
buffer.add_hook(
lambda context: seen.append('up'),
events=('mouse',),
condition=ScrollScope.y < 0,
)
runtime.inject(Event.mouse_event(column=1, row=1, kind='scroll', scroll_y=-1))
runtime.step()
assert seen == ['up'] and buffer.inspect(ScrollScope.y) == -1
Size
¶
A width and a height, counted in cells.
Maps to ratatui::layout::Size.
Parameters:
Attributes:
Examples:
Create a Size.
Parameters:
-
API Reference
- xnano
-
xnano_core
-
xnano_core-
BufferSize -
ParentSize -
BarChartsize -
Blocksize -
Buffersize -
BufferExpressionScopesize -
Calendarsize -
Canvassize -
Chartsize -
Clearsize -
CustomWidgetsize -
Device -
Eventsize -
FrameSnapshotsize -
Gaugesize -
ItemListsize -
LineGaugesize -
Livesize -
Paragraphsize -
ParentExpressionScopesize -
Rectanglesize -
Scrollbarsize -
Sparklinesize -
Tablesize -
Tabssize -
Widgetsize
-
-
xnano_core._xnano_core
_xnano_core-
BufferSize -
ParentSize -
BarChartsize -
Blocksize -
Buffersize -
BufferExpressionScopesize -
Calendarsize -
Canvassize -
Chartsize -
Clearsize -
CustomWidgetsize -
Device -
Eventsize -
FrameSnapshotsize -
Gaugesize -
ItemListsize -
LineGaugesize -
Livesize -
Paragraphsize -
ParentExpressionScopesize -
Rectanglesize -
Scrollbarsize -
Sparklinesize -
Tablesize -
Tabssize -
Widgetsize
-
-
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
Value
¶
Bases: Expression[ValueType]
An expression that evaluates to a value.
== and != build conditions, as equals and not_equals do. A comparison with a
value that has not been seen yet, such as the key before any key was pressed, is false
(!= included) and never an error. Comparing with the literal None raises TypeError
because that condition could never hold; to test that a key arrived, compare with the key
itself or register the hook for the 'key' event. A value is hashed by identity, so expressions stay usable
in sets and dictionaries. Because == builds a condition, in and .index() on a list
or tuple of expressions raise TypeError as soon as they compare an expression with a
different item; look an expression up by identity (any(item is value for item in items))
or keep expressions in a set or dictionary. Comparing an expression with an object that cannot
be an expression, such as object(), gives False for == and True for !=.
Attributes:
-
x(NumericValue[int]) –The column of a
Pointor the left edge of aRectangle. -
y(NumericValue[int]) –The row of a
Pointor the top edge of aRectangle. -
width(NumericValue[int]) –The width of a
Sizeor aRectangle. -
height(NumericValue[int]) –The height of a
Sizeor aRectangle. -
right(NumericValue[int]) –The first column after a
Rectangle. -
bottom(NumericValue[int]) –The first row after a
Rectangle.
Examples:
from xnano_core._xnano_core import _reference
bounds = _reference('Bounds', 'value')
assert isinstance(bounds, Value)
buffer = Buffer(width=4, height=1)
assert buffer.inspect(bounds.equals(Rectangle(0, 0, 4, 1)))
assert buffer.inspect(bounds == Rectangle(0, 0, 4, 1))
-
API Reference
-
xnano
-
xnano.buffers
buffersBufferSize -
xnano.expressions
expressions -
xnano.widgets
widgets
-
xnano.buffers
-
xnano_core
-
xnano_core-
Bounds -
BufferRegion -
BufferSize -
Focused -
KeyboardChord -
KeyboardKey -
KeyboardKind -
MouseButtonValue -
MouseKind -
MousePosition -
ParentSize -
PointerPosition -
Position -
Running -
ScreenBounds -
ScreenPosition -
BufferExpressionScope -
Canvas -
CanvasCircle -
CanvasLabel -
CanvasLine -
CanvasMap -
CanvasMarkermarker -
CanvasPointscolor -
CanvasRectangle -
KeyboardExpressionScope -
MouseExpressionScope -
ParentExpressionScopesize -
Predicatechoose -
StateReferencevalue
-
-
xnano_core._xnano_core
_xnano_core-
Bounds -
BufferRegion -
BufferSize -
Focused -
KeyboardChord -
KeyboardKey -
KeyboardKind -
MouseButtonValue -
MouseKind -
MousePosition -
ParentSize -
PointerPosition -
Position -
Running -
ScreenBounds -
ScreenPosition -
BufferExpressionScope -
Canvas -
CanvasCircle -
CanvasLabel -
CanvasLine -
CanvasMap -
CanvasMarkermarker -
CanvasPointscolor -
CanvasRectangle -
KeyboardExpressionScope -
MouseExpressionScope -
ParentExpressionScopesize -
Predicatechoose -
StateReferencevalue
-
-
-
xnano
Methods:
-
evaluate–Compute the expression's value.
-
equals–A predicate that is true when the value equals
other. -
not_equals–A predicate that is true when the value differs from
other. -
contains–A condition that is true while this rectangle contains the point
other. -
__eq__–A predicate that is true when the value equals
other; the same asequals. -
__ne__–A predicate that is true when the value differs from
other; the same asnot_equals. -
__hash__–The identity hash, which keeps expressions usable in sets and dictionaries.
x
property
¶
x: NumericValue[int]
y
property
¶
y: NumericValue[int]
width
property
¶
width: NumericValue[int]
height
property
¶
height: NumericValue[int]
right
property
¶
right: NumericValue[int]
bottom
property
¶
bottom: NumericValue[int]
evaluate
¶
evaluate(context: EvaluationContext) -> ValueType_co
Compute the expression's value.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
context = EvaluationContext(buffer=Buffer(width=5, height=1))
assert (width * 2).evaluate(context) == 10
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
equals
¶
A predicate that is true when the value equals other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width.equals(20))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
not_equals
¶
A predicate that is true when the value differs from other.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width.not_equals(5))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
contains
¶
A condition that is true while this rectangle contains the point other.
It is false, never an error, while either side has no value yet, such as a mouse position before any mouse event.
Parameters:
-
other(Point | Value[Point] | Value[Point | None]) –The
Point(or an expression that produces one) to look for.
Examples:
from xnano_core._xnano_core import Bounds, Point
buffer = Buffer(width=4, height=2)
assert buffer.inspect(Bounds.contains(Point(3, 1)))
assert not buffer.inspect(Bounds.contains(Point(4, 1)))
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__eq__
¶
A predicate that is true when the value equals other; the same as equals.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width == 20)
Source code in packages/xnano-core/src/xnano_core/_xnano_core/__init__.pyi
__ne__
¶
A predicate that is true when the value differs from other; the same as not_equals.
Examples:
from xnano_core._xnano_core import _reference
width = _reference('Width', 'numeric_property')
assert Buffer(width=20, height=1).inspect(width != 5)