flexablelib-components 3.6.0__tar.gz → 3.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexablelib_components-3.6.0/flexablelib_components.egg-info → flexablelib_components-3.7.0}/PKG-INFO +3 -3
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/__init__.py +8 -6
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/data.py +122 -11
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/display.py +86 -1
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/navigation.py +201 -14
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0/flexablelib_components.egg-info}/PKG-INFO +3 -3
- flexablelib_components-3.7.0/flexablelib_components.egg-info/requires.txt +2 -0
- flexablelib_components-3.6.0/flexablelib_components.egg-info/requires.txt +0 -2
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/LICENSE +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/MANIFEST.in +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/README.md +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/base.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/dates.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/inputs.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/media.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/overlays.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/py.typed +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components.egg-info/SOURCES.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components.egg-info/dependency_links.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components.egg-info/top_level.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/setup.cfg +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib-components
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.0
|
|
4
4
|
Summary: Interactive terminal components for flexablelib: inputs, dates, tables, forms, menus, tabs, dialogs and more.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -17,8 +17,8 @@ Classifier: Topic :: Software Development :: User Interfaces
|
|
|
17
17
|
Requires-Python: >=3.8
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
|
-
Requires-Dist: flexablelib>=3.
|
|
21
|
-
Requires-Dist: flexablelib-tui>=3.
|
|
20
|
+
Requires-Dist: flexablelib>=3.7.0
|
|
21
|
+
Requires-Dist: flexablelib-tui>=3.7.0
|
|
22
22
|
Dynamic: author
|
|
23
23
|
Dynamic: author-email
|
|
24
24
|
Dynamic: classifier
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/__init__.py
RENAMED
|
@@ -18,7 +18,7 @@ keys to the focused component) and also renders on its own with
|
|
|
18
18
|
``render(width)``. See docs/COMPONENTS.md.
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
__version__ = '3.
|
|
21
|
+
__version__ = '3.7.0'
|
|
22
22
|
|
|
23
23
|
from .base import Theme, DEFAULT_THEME, Input, Box, Button, frame
|
|
24
24
|
from .inputs import (TextInput, PasswordInput, NumberInput, ExpressionInput,
|
|
@@ -34,13 +34,13 @@ from .display import (Badge, Tag, StatusBadge, Alert, Link, Breadcrumbs,
|
|
|
34
34
|
EmptyState, ErrorPanel, Spinner, Skeleton, Code,
|
|
35
35
|
MarkdownView, HtmlView, DetailView, Timeline, Stepper,
|
|
36
36
|
CommentList, AttachmentList, Stat, LineChart,
|
|
37
|
-
human_size)
|
|
37
|
+
StatusLine, human_size)
|
|
38
38
|
from .navigation import (Tabs, Menu, ContextMenu, MenuButton, Pagination,
|
|
39
39
|
Sidebar, TopBar, Toolbar, Wizard, Accordion,
|
|
40
40
|
Carousel, Tree, CommandPalette, Split, Stack,
|
|
41
|
-
VStack, AppShell, SortControl)
|
|
41
|
+
VStack, GridView, AppShell, SortControl)
|
|
42
42
|
from .data import (DataTable, FilterBar, EditableTable, CatalogGrid, Form,
|
|
43
|
-
ValidationSummary, LoginForm, FilePreview, parse_query)
|
|
43
|
+
FormCell, ValidationSummary, LoginForm, FilePreview, parse_query)
|
|
44
44
|
from .media import Image, ImageViewer, IMAGE_EXTENSIONS
|
|
45
45
|
from .overlays import (Modal, ConfirmDialog, PromptDialog, LoadingOverlay,
|
|
46
46
|
Popover, HelpLine)
|
|
@@ -58,11 +58,13 @@ __all__ = [
|
|
|
58
58
|
'Badge', 'Tag', 'StatusBadge', 'Alert', 'Link', 'Breadcrumbs',
|
|
59
59
|
'EmptyState', 'ErrorPanel', 'Spinner', 'Skeleton', 'Code',
|
|
60
60
|
'MarkdownView', 'HtmlView', 'DetailView', 'Timeline', 'Stepper',
|
|
61
|
-
'CommentList', 'AttachmentList', 'Stat', 'LineChart', '
|
|
61
|
+
'CommentList', 'AttachmentList', 'Stat', 'LineChart', 'StatusLine',
|
|
62
|
+
'human_size',
|
|
62
63
|
'Tabs', 'Menu', 'ContextMenu', 'MenuButton', 'Pagination', 'Sidebar',
|
|
63
64
|
'TopBar', 'Toolbar', 'Wizard', 'Accordion', 'Carousel', 'Tree',
|
|
64
|
-
'CommandPalette', 'Split', 'Stack', 'VStack', 'AppShell', 'SortControl',
|
|
65
|
+
'CommandPalette', 'Split', 'Stack', 'VStack', 'GridView', 'AppShell', 'SortControl',
|
|
65
66
|
'DataTable', 'FilterBar', 'EditableTable', 'CatalogGrid', 'Form',
|
|
67
|
+
'FormCell',
|
|
66
68
|
'ValidationSummary', 'LoginForm', 'FilePreview', 'parse_query',
|
|
67
69
|
'Modal', 'ConfirmDialog', 'PromptDialog', 'LoadingOverlay', 'Popover',
|
|
68
70
|
'HelpLine', 'Image', 'ImageViewer', 'IMAGE_EXTENSIONS', '__version__',
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/data.py
RENAMED
|
@@ -16,7 +16,8 @@ from .base import Button, Input, _Themed, frame, join_columns
|
|
|
16
16
|
from .inputs import TextInput, PasswordInput, Checkbox
|
|
17
17
|
|
|
18
18
|
__all__ = ['DataTable', 'FilterBar', 'EditableTable', 'CatalogGrid', 'Form',
|
|
19
|
-
'ValidationSummary', 'LoginForm', 'FilePreview',
|
|
19
|
+
'FormCell', 'ValidationSummary', 'LoginForm', 'FilePreview',
|
|
20
|
+
'parse_query']
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
def _cell_text(value, fmt=None):
|
|
@@ -67,9 +68,21 @@ class DataTable(_Themed):
|
|
|
67
68
|
``on_activate(row)``. ``filters`` are extra predicates (a
|
|
68
69
|
:class:`FilterBar`'s ``predicate``). ``page_size`` pages instead of
|
|
69
70
|
scrolling.
|
|
71
|
+
|
|
72
|
+
Height: given one (``height=``, or the slot of a layout that passes
|
|
73
|
+
it, such as :class:`VStack` or the app's body) the table shows as many
|
|
74
|
+
rows as fit and scrolls to keep the cursor in view; ``visible_rows`` is
|
|
75
|
+
how many it showed. ``fill=True`` makes it take its whole slot (a
|
|
76
|
+
:class:`VStack` then gives it the rows left over) with the status line
|
|
77
|
+
at the bottom.
|
|
70
78
|
"""
|
|
71
79
|
|
|
72
80
|
focusable = True
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def visible_rows(self):
|
|
84
|
+
"""Rows shown in the last frame."""
|
|
85
|
+
return self._rows_shown
|
|
73
86
|
expand = True
|
|
74
87
|
role = 'grid'
|
|
75
88
|
|
|
@@ -128,8 +141,11 @@ class DataTable(_Themed):
|
|
|
128
141
|
def __init__(self, columns, rows=(), height=None, selectable=False,
|
|
129
142
|
on_activate=None, on_select=None, zebra=True,
|
|
130
143
|
page_size=None, status=True, empty='Sin registros',
|
|
131
|
-
id_columns='auto', id_names=None, **kwargs):
|
|
144
|
+
id_columns='auto', id_names=None, fill=False, **kwargs):
|
|
132
145
|
super(DataTable, self).__init__(**kwargs)
|
|
146
|
+
self.fill = bool(fill)
|
|
147
|
+
if self.fill:
|
|
148
|
+
self.expand = True
|
|
133
149
|
self.id_columns = id_columns
|
|
134
150
|
self.id_names = id_names
|
|
135
151
|
self.columns = [self._column(c, i) for i, c in enumerate(columns)]
|
|
@@ -444,6 +460,9 @@ class DataTable(_Themed):
|
|
|
444
460
|
elif self.zebra and n % 2 and self._active():
|
|
445
461
|
line = self.paint(line, 'on #1c1c1c')
|
|
446
462
|
out.append(line)
|
|
463
|
+
if self.fill and height:
|
|
464
|
+
# Fill the slot: the query and status lines stay at its bottom.
|
|
465
|
+
out.extend([''] * max(0, 2 + rows_h - len(out)))
|
|
447
466
|
if self.typing or self.query:
|
|
448
467
|
cur = self.cursor(' ') if self.typing else ''
|
|
449
468
|
out.append(self.paint('/', self.theme.accent) + self.query + cur)
|
|
@@ -1046,6 +1065,20 @@ class ValidationSummary(_Themed):
|
|
|
1046
1065
|
self.paint)
|
|
1047
1066
|
|
|
1048
1067
|
|
|
1068
|
+
class FormCell(object):
|
|
1069
|
+
"""
|
|
1070
|
+
A field of a :class:`Form` with its layout: ``span`` columns of the
|
|
1071
|
+
form's grid (capped at the columns there are) and ``min_width``, the
|
|
1072
|
+
narrowest it may be -- below that it takes more columns, up to the whole
|
|
1073
|
+
row. The form keeps the field itself (``fields()``, ``values()``).
|
|
1074
|
+
"""
|
|
1075
|
+
|
|
1076
|
+
def __init__(self, field, span=1, min_width=None):
|
|
1077
|
+
self.field = field
|
|
1078
|
+
self.span = max(1, int(span))
|
|
1079
|
+
self.min_width = None if min_width is None else max(1, int(min_width))
|
|
1080
|
+
|
|
1081
|
+
|
|
1049
1082
|
class Form(_Themed):
|
|
1050
1083
|
"""
|
|
1051
1084
|
Fields with labels, help and validation, laid out in ``columns``, with
|
|
@@ -1074,14 +1107,17 @@ class Form(_Themed):
|
|
|
1074
1107
|
|
|
1075
1108
|
def __init__(self, fields, on_submit=None, on_cancel=None,
|
|
1076
1109
|
submit_label='Guardar', cancel_label='Cancelar', columns=1,
|
|
1077
|
-
title=None, summary=True, **kwargs):
|
|
1110
|
+
title=None, summary=True, min_column_width=None, **kwargs):
|
|
1078
1111
|
super(Form, self).__init__(**kwargs)
|
|
1079
1112
|
self.rows = []
|
|
1113
|
+
self.layout = {}
|
|
1080
1114
|
for item in fields:
|
|
1081
1115
|
if isinstance(item, (tuple, list)):
|
|
1082
|
-
self.rows.append(
|
|
1116
|
+
self.rows.append([self._unwrap(f) for f in item])
|
|
1083
1117
|
else:
|
|
1084
|
-
self.rows.append([item])
|
|
1118
|
+
self.rows.append([self._unwrap(item)])
|
|
1119
|
+
self.min_column_width = None if min_column_width is None else \
|
|
1120
|
+
max(1, int(min_column_width))
|
|
1085
1121
|
self.on_submit = on_submit
|
|
1086
1122
|
self.on_cancel = on_cancel
|
|
1087
1123
|
self.columns = max(1, int(columns))
|
|
@@ -1100,6 +1136,26 @@ class Form(_Themed):
|
|
|
1100
1136
|
if isinstance(field, TextInput) and field.on_submit is None:
|
|
1101
1137
|
field.on_submit = self._next_from(field)
|
|
1102
1138
|
|
|
1139
|
+
def _unwrap(self, item):
|
|
1140
|
+
if isinstance(item, FormCell):
|
|
1141
|
+
self.layout[id(item.field)] = (item.span, item.min_width)
|
|
1142
|
+
return item.field
|
|
1143
|
+
return item
|
|
1144
|
+
|
|
1145
|
+
def set_layout(self, field, span=1, min_width=None):
|
|
1146
|
+
"""Give ``field`` ``span`` columns and a ``min_width``."""
|
|
1147
|
+
self.layout[id(field)] = (max(1, int(span)), min_width)
|
|
1148
|
+
self.refresh()
|
|
1149
|
+
|
|
1150
|
+
def grid_columns(self, width):
|
|
1151
|
+
"""How many columns the fields get at ``width``: ``columns``, fewer
|
|
1152
|
+
when they would be narrower than ``min_column_width``."""
|
|
1153
|
+
cols = self.columns
|
|
1154
|
+
if self.min_column_width:
|
|
1155
|
+
cols = min(cols, max(1, (width + 2) //
|
|
1156
|
+
(self.min_column_width + 2)))
|
|
1157
|
+
return max(1, cols)
|
|
1158
|
+
|
|
1103
1159
|
def _next_from(self, field):
|
|
1104
1160
|
def advance(value):
|
|
1105
1161
|
if self.app is not None:
|
|
@@ -1199,6 +1255,67 @@ class Form(_Themed):
|
|
|
1199
1255
|
out.extend(ValidationSummary(self.errors, theme=self._theme,
|
|
1200
1256
|
use_colors=self.use_colors)
|
|
1201
1257
|
.render(width=width).split('\n'))
|
|
1258
|
+
if self.layout or self.min_column_width:
|
|
1259
|
+
out.extend(self._draw_grid(width))
|
|
1260
|
+
else:
|
|
1261
|
+
out.extend(self._draw_rows(width))
|
|
1262
|
+
buttons = self.submit_button.render(
|
|
1263
|
+
width=self.submit_button.natural_width())
|
|
1264
|
+
if self.cancel_button is not None:
|
|
1265
|
+
buttons = self.cancel_button.render(
|
|
1266
|
+
width=self.cancel_button.natural_width()) + ' ' + buttons
|
|
1267
|
+
out.append(_fx.fit_line(buttons, width, 'r'))
|
|
1268
|
+
return out
|
|
1269
|
+
|
|
1270
|
+
def _section(self, title, width):
|
|
1271
|
+
return [self.paint(title, 'bold'),
|
|
1272
|
+
self.paint('─' * width, self.theme.border)]
|
|
1273
|
+
|
|
1274
|
+
def _draw_grid(self, width):
|
|
1275
|
+
"""Responsive layout: ``grid_columns(width)`` columns, each field
|
|
1276
|
+
taking its span (more when narrower than its ``min_width``)."""
|
|
1277
|
+
cols = self.grid_columns(width)
|
|
1278
|
+
each = (width - 2 * (cols - 1)) // cols
|
|
1279
|
+
|
|
1280
|
+
def span_width(n):
|
|
1281
|
+
return each * n + 2 * (n - 1)
|
|
1282
|
+
out = []
|
|
1283
|
+
pending = []
|
|
1284
|
+
|
|
1285
|
+
def flush():
|
|
1286
|
+
if not pending:
|
|
1287
|
+
return
|
|
1288
|
+
used = sum(n for _, n in pending)
|
|
1289
|
+
widths = [span_width(n) for _, n in pending]
|
|
1290
|
+
widths[-1] += width - (sum(widths) + 2 * (len(widths) - 1)) \
|
|
1291
|
+
if used == cols else 0
|
|
1292
|
+
blocks = [f.render(width=max(1, w)).split('\n')
|
|
1293
|
+
for (f, _), w in zip(pending, widths)]
|
|
1294
|
+
out.extend(join_columns(blocks, widths, gap=2))
|
|
1295
|
+
out.append('')
|
|
1296
|
+
del pending[:]
|
|
1297
|
+
for row in self.rows:
|
|
1298
|
+
if len(row) == 1 and isinstance(row[0], str):
|
|
1299
|
+
flush()
|
|
1300
|
+
out.extend(self._section(row[0], width))
|
|
1301
|
+
continue
|
|
1302
|
+
if len(row) > 1:
|
|
1303
|
+
flush()
|
|
1304
|
+
for field in row:
|
|
1305
|
+
span, low = self.layout.get(id(field), (1, None))
|
|
1306
|
+
span = min(span, cols)
|
|
1307
|
+
while low and span < cols and span_width(span) < low:
|
|
1308
|
+
span += 1
|
|
1309
|
+
if sum(n for _, n in pending) + span > cols:
|
|
1310
|
+
flush()
|
|
1311
|
+
pending.append((field, span))
|
|
1312
|
+
if len(row) > 1:
|
|
1313
|
+
flush()
|
|
1314
|
+
flush()
|
|
1315
|
+
return out
|
|
1316
|
+
|
|
1317
|
+
def _draw_rows(self, width):
|
|
1318
|
+
out = []
|
|
1202
1319
|
pending = []
|
|
1203
1320
|
|
|
1204
1321
|
def flush():
|
|
@@ -1225,12 +1342,6 @@ class Form(_Themed):
|
|
|
1225
1342
|
if len(pending) >= self.columns:
|
|
1226
1343
|
flush()
|
|
1227
1344
|
flush()
|
|
1228
|
-
buttons = self.submit_button.render(
|
|
1229
|
-
width=self.submit_button.natural_width())
|
|
1230
|
-
if self.cancel_button is not None:
|
|
1231
|
-
buttons = self.cancel_button.render(
|
|
1232
|
-
width=self.cancel_button.natural_width()) + ' ' + buttons
|
|
1233
|
-
out.append(_fx.fit_line(buttons, width, 'r'))
|
|
1234
1345
|
return out
|
|
1235
1346
|
|
|
1236
1347
|
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/display.py
RENAMED
|
@@ -20,7 +20,7 @@ __all__ = ['Badge', 'Tag', 'StatusBadge', 'Alert', 'Link', 'Breadcrumbs',
|
|
|
20
20
|
'EmptyState', 'ErrorPanel', 'Spinner', 'Skeleton', 'Code',
|
|
21
21
|
'highlight', 'MarkdownView', 'HtmlView', 'DetailView', 'Timeline',
|
|
22
22
|
'Stepper', 'CommentList', 'AttachmentList', 'Stat', 'LineChart',
|
|
23
|
-
'human_size']
|
|
23
|
+
'StatusLine', 'human_size']
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def _wrap(text, width):
|
|
@@ -1274,3 +1274,88 @@ class LineChart(_Themed):
|
|
|
1274
1274
|
return out
|
|
1275
1275
|
|
|
1276
1276
|
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
class StatusLine(_Themed):
|
|
1280
|
+
"""
|
|
1281
|
+
A one-line status bar with ``left``, ``center`` and ``right`` text
|
|
1282
|
+
(strings or callables returning text, read on every frame). ``kind``
|
|
1283
|
+
(``'info'``, ``'success'``, ``'warning'``, ``'error'``) colours it and
|
|
1284
|
+
puts its symbol (``✔``, ``⚠``, ``✖``...) before the left text, so the
|
|
1285
|
+
state never depends on colour alone. Its role is ``status``: with
|
|
1286
|
+
``announce=True`` (the default) :meth:`set` and :meth:`message` tell
|
|
1287
|
+
screen readers about the change -- politely, or at once for errors.
|
|
1288
|
+
"""
|
|
1289
|
+
|
|
1290
|
+
role = 'status'
|
|
1291
|
+
|
|
1292
|
+
def __init__(self, left='', center='', right='', kind=None,
|
|
1293
|
+
announce=True, color=None, **kwargs):
|
|
1294
|
+
super(StatusLine, self).__init__(**kwargs)
|
|
1295
|
+
self.left = left
|
|
1296
|
+
self.center = center
|
|
1297
|
+
self.right = right
|
|
1298
|
+
self.kind = kind
|
|
1299
|
+
self.announce_changes = bool(announce)
|
|
1300
|
+
self.color = color
|
|
1301
|
+
|
|
1302
|
+
@staticmethod
|
|
1303
|
+
def _value(part):
|
|
1304
|
+
part = part() if callable(part) else part
|
|
1305
|
+
return '' if part is None else str(part)
|
|
1306
|
+
|
|
1307
|
+
def parts(self):
|
|
1308
|
+
"""``(left, center, right)`` as text."""
|
|
1309
|
+
return (self._value(self.left), self._value(self.center),
|
|
1310
|
+
self._value(self.right))
|
|
1311
|
+
|
|
1312
|
+
def a11y_name(self):
|
|
1313
|
+
return str(self.a11y_label) if self.a11y_label else 'Estado'
|
|
1314
|
+
|
|
1315
|
+
def a11y_value(self):
|
|
1316
|
+
text = ' · '.join(p for p in self.parts() if p)
|
|
1317
|
+
if self.kind:
|
|
1318
|
+
word = _a11y.status_symbol(self.kind, word=True).split(' ', 1)
|
|
1319
|
+
if len(word) == 2 and word[1]:
|
|
1320
|
+
text = word[1] + ': ' + text if text else word[1]
|
|
1321
|
+
return text
|
|
1322
|
+
|
|
1323
|
+
def set(self, left=None, center=None, right=None, kind=False):
|
|
1324
|
+
"""Change some parts (and ``kind``; ``None`` clears it)."""
|
|
1325
|
+
before = self.a11y_value()
|
|
1326
|
+
if left is not None:
|
|
1327
|
+
self.left = left
|
|
1328
|
+
if center is not None:
|
|
1329
|
+
self.center = center
|
|
1330
|
+
if right is not None:
|
|
1331
|
+
self.right = right
|
|
1332
|
+
if kind is not False:
|
|
1333
|
+
self.kind = kind
|
|
1334
|
+
after = self.a11y_value()
|
|
1335
|
+
if self.announce_changes and after and after != before:
|
|
1336
|
+
self.announce(after, 'assertive' if self.kind == 'error'
|
|
1337
|
+
else 'polite')
|
|
1338
|
+
self.refresh()
|
|
1339
|
+
return True
|
|
1340
|
+
|
|
1341
|
+
def message(self, text, kind='info'):
|
|
1342
|
+
"""Show ``text`` on the left with ``kind``."""
|
|
1343
|
+
return self.set(left=text, kind=kind)
|
|
1344
|
+
|
|
1345
|
+
def natural_width(self):
|
|
1346
|
+
return sum(_fx.visible_width(p) + 2 for p in self.parts()) + 2
|
|
1347
|
+
|
|
1348
|
+
def draw(self, width, height):
|
|
1349
|
+
left, center, right = self.parts()
|
|
1350
|
+
if self.kind:
|
|
1351
|
+
left = _a11y.status_symbol(self.kind) + ' ' + left
|
|
1352
|
+
left, right = ' ' + left, right + ' ' if right else right
|
|
1353
|
+
room = max(0, width - _fx.visible_width(left) -
|
|
1354
|
+
_fx.visible_width(right))
|
|
1355
|
+
mid = _fx.fit_line(_fx.truncate(center, room, '…'), room, 'c')
|
|
1356
|
+
line = _fx.fit_line(left + mid + right, width)
|
|
1357
|
+
if not self._active():
|
|
1358
|
+
return [line]
|
|
1359
|
+
spec = self.color or ('black on ' + self.theme.kind(self.kind)
|
|
1360
|
+
if self.kind else 'reverse')
|
|
1361
|
+
return [self.paint(line, spec)]
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/navigation.py
RENAMED
|
@@ -17,7 +17,7 @@ _Enter = Key('enter')
|
|
|
17
17
|
__all__ = ['Tabs', 'Menu', 'ContextMenu', 'MenuButton', 'Pagination',
|
|
18
18
|
'Sidebar', 'TopBar', 'Toolbar', 'Wizard', 'Accordion',
|
|
19
19
|
'Carousel', 'Tree', 'CommandPalette', 'Split', 'Stack',
|
|
20
|
-
'VStack', 'AppShell', 'SortControl', 'render_into']
|
|
20
|
+
'VStack', 'GridView', 'AppShell', 'SortControl', 'render_into']
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def render_into(child, width, height=None):
|
|
@@ -119,6 +119,58 @@ class Tabs(_Themed):
|
|
|
119
119
|
return out
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def _window(comp, out, row, height):
|
|
123
|
+
"""The rows of ``out`` that fit ``height``, kept around ``row`` (the
|
|
124
|
+
current item) with ``▲ n``/``▼ n`` lines saying how many are hidden
|
|
125
|
+
above and below; clickable spots move with the rows. ``comp.top`` is
|
|
126
|
+
the first row shown (kept between frames)."""
|
|
127
|
+
total = len(out)
|
|
128
|
+
if not height or total <= height:
|
|
129
|
+
comp.top = 0
|
|
130
|
+
return out
|
|
131
|
+
height = max(1, int(height))
|
|
132
|
+
top = max(0, min(getattr(comp, 'top', 0), total - 1))
|
|
133
|
+
for _ in range(3):
|
|
134
|
+
up = 1 if top > 0 and height > 2 else 0
|
|
135
|
+
room = height - up
|
|
136
|
+
down = 1 if top + room < total and height > 2 else 0
|
|
137
|
+
room -= down
|
|
138
|
+
room = max(1, room)
|
|
139
|
+
if row is not None:
|
|
140
|
+
if row < top:
|
|
141
|
+
top = row
|
|
142
|
+
elif row >= top + room:
|
|
143
|
+
top = row - room + 1
|
|
144
|
+
top = max(0, min(top, total - room))
|
|
145
|
+
up = 1 if top > 0 and height > 2 else 0
|
|
146
|
+
room = height - up
|
|
147
|
+
down = 1 if top + room < total and height > 2 else 0
|
|
148
|
+
room = max(1, room - down)
|
|
149
|
+
comp.top = top
|
|
150
|
+
shown = out[top:top + room]
|
|
151
|
+
arrows = ('^', 'v') if not comp._active() else ('▲', '▼')
|
|
152
|
+
lines = []
|
|
153
|
+
if up:
|
|
154
|
+
lines.append(comp.paint(' {0} {1} más'.format(arrows[0], top),
|
|
155
|
+
comp.theme.muted))
|
|
156
|
+
lines.extend(shown)
|
|
157
|
+
if down:
|
|
158
|
+
lines.append(comp.paint(' {0} {1} más'.format(
|
|
159
|
+
arrows[1], total - top - room), comp.theme.muted))
|
|
160
|
+
if isinstance(comp._hot, list):
|
|
161
|
+
moved = []
|
|
162
|
+
for r, x0, x1, action in comp._hot:
|
|
163
|
+
if top <= r < top + room:
|
|
164
|
+
moved.append((r - top + up, x0, x1, action))
|
|
165
|
+
if up:
|
|
166
|
+
moved.append((0, 0, None, lambda: comp.scroll_items(-room)))
|
|
167
|
+
if down:
|
|
168
|
+
moved.append((len(lines) - 1, 0, None,
|
|
169
|
+
lambda: comp.scroll_items(room)))
|
|
170
|
+
comp._hot = moved
|
|
171
|
+
return lines
|
|
172
|
+
|
|
173
|
+
|
|
122
174
|
class Menu(_Themed):
|
|
123
175
|
"""
|
|
124
176
|
A vertical menu. ``items``: labels, ``(label, action)``, or dicts with
|
|
@@ -126,6 +178,9 @@ class Menu(_Themed):
|
|
|
126
178
|
separator. Up/Down move (skipping separators and disabled items), Enter
|
|
127
179
|
runs the action, a letter jumps to the item starting with it, and an
|
|
128
180
|
item's ``shortcut`` runs it directly. ``on_select(index, item)``.
|
|
181
|
+
With more items than the height it gets (or ``max_visible``) it shows
|
|
182
|
+
a window around the current item with ``▲ n más`` / ``▼ n más`` lines
|
|
183
|
+
(click them to page); PgUp/PgDn move a page and the wheel scrolls.
|
|
129
184
|
"""
|
|
130
185
|
|
|
131
186
|
focusable = True
|
|
@@ -231,14 +286,34 @@ class Menu(_Themed):
|
|
|
231
286
|
self.refresh()
|
|
232
287
|
return True
|
|
233
288
|
|
|
289
|
+
_page = 5
|
|
290
|
+
|
|
291
|
+
def scroll_items(self, delta):
|
|
292
|
+
"""Move the current item ``delta`` enabled items (a page)."""
|
|
293
|
+
step = 1 if delta > 0 else -1
|
|
294
|
+
for _ in range(abs(int(delta))):
|
|
295
|
+
before = self.index
|
|
296
|
+
self._step(step)
|
|
297
|
+
if (step > 0 and self.index < before) or \
|
|
298
|
+
(step < 0 and self.index > before):
|
|
299
|
+
self.index = before
|
|
300
|
+
break
|
|
301
|
+
self.refresh()
|
|
302
|
+
return True
|
|
303
|
+
|
|
304
|
+
def handle_key(self, key):
|
|
305
|
+
k = str(key)
|
|
306
|
+
if k in ('pageup', 'pagedown', 'scrollup', 'scrolldown') and \
|
|
307
|
+
self.items and k not in self.bindings:
|
|
308
|
+
page = self._page if k.startswith('page') else 3
|
|
309
|
+
return self.scroll_items(page if k.endswith('down') else -page)
|
|
310
|
+
return super(Menu, self).handle_key(key)
|
|
311
|
+
|
|
234
312
|
def draw(self, width, height):
|
|
235
313
|
rows = self.max_visible or height or len(self.items)
|
|
236
|
-
|
|
237
|
-
self.top = self.index
|
|
238
|
-
if self.index >= self.top + rows:
|
|
239
|
-
self.top = self.index - rows + 1
|
|
314
|
+
self._page = max(1, rows - 2)
|
|
240
315
|
out = []
|
|
241
|
-
for i in range(
|
|
316
|
+
for i in range(len(self.items)):
|
|
242
317
|
item = self.items[i]
|
|
243
318
|
if item.get('separator'):
|
|
244
319
|
out.append(self.paint('─' * width, self.theme.border))
|
|
@@ -262,7 +337,7 @@ class Menu(_Themed):
|
|
|
262
337
|
text = text[:-len(shortcut) - 1] + self.paint(
|
|
263
338
|
shortcut, self.theme.muted) + ' '
|
|
264
339
|
out.append(text)
|
|
265
|
-
return out
|
|
340
|
+
return _window(self, out, self.index, rows)
|
|
266
341
|
|
|
267
342
|
|
|
268
343
|
class ContextMenu(Menu):
|
|
@@ -415,6 +490,8 @@ class Sidebar(Menu):
|
|
|
415
490
|
"""
|
|
416
491
|
Navigation down the side: ``sections`` maps a heading to items (as in
|
|
417
492
|
:class:`Menu`). ``collapsed=True`` (or Ctrl-B) shows only the icons.
|
|
493
|
+
It keeps to the height it gets: a window around the current item with
|
|
494
|
+
``▲`` / ``▼`` lines, the title staying on top.
|
|
418
495
|
"""
|
|
419
496
|
|
|
420
497
|
role = 'navigation'
|
|
@@ -456,12 +533,17 @@ class Sidebar(Menu):
|
|
|
456
533
|
return super(Sidebar, self).on_key(key)
|
|
457
534
|
|
|
458
535
|
def draw(self, width, height):
|
|
459
|
-
|
|
536
|
+
head = []
|
|
460
537
|
if self.title and not self.collapsed:
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
538
|
+
head.append(self.paint(' ' + self.title, 'bold ' +
|
|
539
|
+
self.theme.accent))
|
|
540
|
+
head.append('')
|
|
541
|
+
self._hot_base = len(head)
|
|
542
|
+
out = []
|
|
543
|
+
current = None
|
|
464
544
|
for i, item in enumerate(self.items):
|
|
545
|
+
if i == self.index:
|
|
546
|
+
current = len(out)
|
|
465
547
|
if item.get('heading'):
|
|
466
548
|
if not self.collapsed:
|
|
467
549
|
out.append(self.paint(' ' + item['label'].upper(),
|
|
@@ -488,7 +570,20 @@ class Sidebar(Menu):
|
|
|
488
570
|
elif item.get('disabled'):
|
|
489
571
|
text = self.paint(text, 'dim')
|
|
490
572
|
out.append(text)
|
|
491
|
-
|
|
573
|
+
rows = self.max_visible or (max(1, height - len(head)) if height
|
|
574
|
+
else None)
|
|
575
|
+
if rows:
|
|
576
|
+
self._page = max(1, rows - 2)
|
|
577
|
+
if isinstance(self._hot, list):
|
|
578
|
+
# _window works in the item rows' own coordinates.
|
|
579
|
+
self._hot = [(r - len(head), x0, x1, a)
|
|
580
|
+
for r, x0, x1, a in self._hot]
|
|
581
|
+
lines = _window(self, out, current, rows)
|
|
582
|
+
if isinstance(self._hot, list):
|
|
583
|
+
self._hot = [(r + len(head), x0, x1, a)
|
|
584
|
+
for r, x0, x1, a in self._hot]
|
|
585
|
+
self._hot_base = 0
|
|
586
|
+
return head + lines
|
|
492
587
|
|
|
493
588
|
|
|
494
589
|
class TopBar(_Themed):
|
|
@@ -1366,8 +1461,9 @@ class VStack(_Themed):
|
|
|
1366
1461
|
Children one below the other that share the height the stack gets.
|
|
1367
1462
|
|
|
1368
1463
|
``weights`` (one per child) split the rows left over: a child with
|
|
1369
|
-
weight 0
|
|
1370
|
-
|
|
1464
|
+
weight 0 keeps its own height, the others grow in proportion. By
|
|
1465
|
+
default (3.7.0) children with ``expand`` -- a ``DataTable(fill=True)``,
|
|
1466
|
+
a ``ScrollView``, a ``Sidebar``, ``Tabs`` -- get weight 1, the rest 0. ``min_heights`` / ``max_heights`` (one per child, None for
|
|
1371
1467
|
no limit) bound each one; ``gap`` puts blank rows between them and
|
|
1372
1468
|
``height`` fixes the stack's own height (otherwise it takes its slot's).
|
|
1373
1469
|
When the children need more rows than there are, the stack scrolls and
|
|
@@ -1394,6 +1490,11 @@ class VStack(_Themed):
|
|
|
1394
1490
|
raise ValueError('{0} needs one value per child ({1})'
|
|
1395
1491
|
.format(name, n))
|
|
1396
1492
|
return values
|
|
1493
|
+
if weights is None:
|
|
1494
|
+
# Children that fill their slot (expand: tables with fill=True,
|
|
1495
|
+
# scroll views, sidebars, tabs) share the rows left over.
|
|
1496
|
+
weights = [1 if getattr(c, 'expand', False) else 0
|
|
1497
|
+
for c in self.items]
|
|
1397
1498
|
self.weights = [max(0.0, float(w or 0))
|
|
1398
1499
|
for w in per_child(weights, 0, 'weights')]
|
|
1399
1500
|
self.min_heights = [max(0, int(v or 0)) for v in
|
|
@@ -1534,6 +1635,92 @@ class VStack(_Themed):
|
|
|
1534
1635
|
return True
|
|
1535
1636
|
return False
|
|
1536
1637
|
|
|
1638
|
+
_COMPONENT_KWARGS = ('theme', 'use_colors', 'bindings', 'disabled',
|
|
1639
|
+
'a11y_label', 'description', 'role', 'tab_index')
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
class GridView(_Themed):
|
|
1643
|
+
"""
|
|
1644
|
+
A :class:`flexablelib.Grid` as a component, with an accessible name and
|
|
1645
|
+
role: ``children`` and every other keyword (``columns``, ``min_width``,
|
|
1646
|
+
``gap``, ``border``, ``column_widths``...) are the grid's; ``title``
|
|
1647
|
+
(drawn above it, bold) or ``a11y_label`` names it for screen readers,
|
|
1648
|
+
and ``role`` is ``'group'`` unless given. Its components keep their
|
|
1649
|
+
focus order. :meth:`audit` checks the grid and everything inside it
|
|
1650
|
+
(role, label, focus shown without colour) and returns
|
|
1651
|
+
:class:`flexablelib_tui.accessibility.AuditIssue` s.
|
|
1652
|
+
"""
|
|
1653
|
+
|
|
1654
|
+
role = 'group'
|
|
1655
|
+
expand = False
|
|
1656
|
+
|
|
1657
|
+
def __init__(self, children, title=None, **kwargs):
|
|
1658
|
+
own = dict((k, kwargs.pop(k)) for k in _COMPONENT_KWARGS
|
|
1659
|
+
if k in kwargs)
|
|
1660
|
+
super(GridView, self).__init__(**own)
|
|
1661
|
+
self.items = list(children)
|
|
1662
|
+
self.title = title
|
|
1663
|
+
self.options = kwargs
|
|
1664
|
+
|
|
1665
|
+
def a11y_name(self):
|
|
1666
|
+
if self.a11y_label:
|
|
1667
|
+
return str(self.a11y_label)
|
|
1668
|
+
return self.title or ''
|
|
1669
|
+
|
|
1670
|
+
def a11y_value(self):
|
|
1671
|
+
return '{0} elementos'.format(len(self.items))
|
|
1672
|
+
|
|
1673
|
+
def children(self):
|
|
1674
|
+
from flexablelib.layout import GridCell
|
|
1675
|
+
kids = []
|
|
1676
|
+
for item in self.items:
|
|
1677
|
+
if isinstance(item, GridCell):
|
|
1678
|
+
item = item.child
|
|
1679
|
+
elif isinstance(item, tuple) and item:
|
|
1680
|
+
item = item[0]
|
|
1681
|
+
if item is not None and not isinstance(item, str):
|
|
1682
|
+
kids.append(item)
|
|
1683
|
+
return kids
|
|
1684
|
+
|
|
1685
|
+
def grid(self):
|
|
1686
|
+
"""The :class:`flexablelib.Grid` drawn."""
|
|
1687
|
+
from flexablelib.layout import Grid
|
|
1688
|
+
return Grid(self.items, **self.options)
|
|
1689
|
+
|
|
1690
|
+
def natural_width(self):
|
|
1691
|
+
return _natural_width(self.grid())
|
|
1692
|
+
|
|
1693
|
+
def draw(self, width, height):
|
|
1694
|
+
out = []
|
|
1695
|
+
if self.title:
|
|
1696
|
+
out.append(self.paint(self.title, 'bold'))
|
|
1697
|
+
room = None if height is None else max(1, height - len(out))
|
|
1698
|
+
grid = self.grid()
|
|
1699
|
+
text = grid.render(width=width, height=room) if room else \
|
|
1700
|
+
grid.render(width=width)
|
|
1701
|
+
out.extend(text.split('\n') if text else [])
|
|
1702
|
+
return out
|
|
1703
|
+
|
|
1704
|
+
def audit(self, width=40, check_focus=True):
|
|
1705
|
+
"""Accessibility problems of the grid and of every component in
|
|
1706
|
+
it (see :func:`flexablelib_tui.accessibility.audit`)."""
|
|
1707
|
+
from flexablelib_tui import accessibility as a11y
|
|
1708
|
+
from flexablelib_tui.app import Component, _child_nodes
|
|
1709
|
+
found = []
|
|
1710
|
+
stack = list(reversed(self.children()))
|
|
1711
|
+
seen = set()
|
|
1712
|
+
while stack:
|
|
1713
|
+
node = stack.pop()
|
|
1714
|
+
if id(node) in seen:
|
|
1715
|
+
continue
|
|
1716
|
+
seen.add(id(node))
|
|
1717
|
+
if isinstance(node, Component):
|
|
1718
|
+
found.append(node)
|
|
1719
|
+
stack.extend(reversed(_child_nodes(node)))
|
|
1720
|
+
return a11y.audit([self] + found, width=width,
|
|
1721
|
+
check_focus=check_focus)
|
|
1722
|
+
|
|
1723
|
+
|
|
1537
1724
|
class SortControl(_Themed):
|
|
1538
1725
|
"""
|
|
1539
1726
|
Choose the sort field and direction: Left/Right pick the field, Space or
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib-components
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.0
|
|
4
4
|
Summary: Interactive terminal components for flexablelib: inputs, dates, tables, forms, menus, tabs, dialogs and more.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -17,8 +17,8 @@ Classifier: Topic :: Software Development :: User Interfaces
|
|
|
17
17
|
Requires-Python: >=3.8
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
License-File: LICENSE
|
|
20
|
-
Requires-Dist: flexablelib>=3.
|
|
21
|
-
Requires-Dist: flexablelib-tui>=3.
|
|
20
|
+
Requires-Dist: flexablelib>=3.7.0
|
|
21
|
+
Requires-Dist: flexablelib-tui>=3.7.0
|
|
22
22
|
Dynamic: author
|
|
23
23
|
Dynamic: author-email
|
|
24
24
|
Dynamic: classifier
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/base.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/dates.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/inputs.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/media.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/overlays.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.0}/flexablelib_components/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|