flexablelib-components 3.6.0__tar.gz → 3.7.1__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.1}/PKG-INFO +3 -3
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/__init__.py +8 -6
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/data.py +158 -19
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/dates.py +10 -1
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/display.py +95 -1
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/inputs.py +13 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/navigation.py +252 -20
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1/flexablelib_components.egg-info}/PKG-INFO +3 -3
- flexablelib_components-3.7.1/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.1}/LICENSE +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/MANIFEST.in +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/README.md +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/base.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/media.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/overlays.py +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/py.typed +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/SOURCES.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/dependency_links.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components.egg-info/top_level.txt +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/setup.cfg +0 -0
- {flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/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.1
|
|
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.1
|
|
21
|
+
Requires-Dist: flexablelib-tui>=3.7.1
|
|
22
22
|
Dynamic: author
|
|
23
23
|
Dynamic: author-email
|
|
24
24
|
Dynamic: classifier
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/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.1'
|
|
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.1}/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)]
|
|
@@ -389,7 +405,12 @@ class DataTable(_Themed):
|
|
|
389
405
|
extra = (1 if self.status else 0) + (1 if self.typing or self.query
|
|
390
406
|
else 0)
|
|
391
407
|
rows_h = self.height or (height - 2 - extra if height else None)
|
|
408
|
+
room = None
|
|
392
409
|
if self.page_size:
|
|
410
|
+
# A page taller than the slot scrolls inside the page, so the
|
|
411
|
+
# cursor row stays on screen.
|
|
412
|
+
room = max(1, rows_h) if rows_h is not None and \
|
|
413
|
+
rows_h < self.page_size else None
|
|
393
414
|
rows_h = self.page_size
|
|
394
415
|
if rows_h is None:
|
|
395
416
|
rows_h = len(view)
|
|
@@ -398,13 +419,27 @@ class DataTable(_Themed):
|
|
|
398
419
|
self.cursor_row = max(0, min(self.cursor_row, len(view) - 1))
|
|
399
420
|
if self.page_size:
|
|
400
421
|
self.page = self.cursor_row // self.page_size + 1
|
|
401
|
-
|
|
422
|
+
start = (self.page - 1) * self.page_size
|
|
423
|
+
if room is None:
|
|
424
|
+
self.top = start
|
|
425
|
+
else:
|
|
426
|
+
end = min(len(view), start + self.page_size)
|
|
427
|
+
top = max(start, min(self.top, end - room))
|
|
428
|
+
if self.cursor_row < top:
|
|
429
|
+
top = self.cursor_row
|
|
430
|
+
elif self.cursor_row >= top + room:
|
|
431
|
+
top = self.cursor_row - room + 1
|
|
432
|
+
self.top = max(start, top)
|
|
433
|
+
rows_h = room
|
|
402
434
|
else:
|
|
403
435
|
if self.cursor_row < self.top:
|
|
404
436
|
self.top = self.cursor_row
|
|
405
437
|
if self.cursor_row >= self.top + rows_h:
|
|
406
438
|
self.top = self.cursor_row - rows_h + 1
|
|
407
|
-
|
|
439
|
+
stop = self.top + rows_h
|
|
440
|
+
if self.page_size:
|
|
441
|
+
stop = min(stop, (self.page) * self.page_size)
|
|
442
|
+
shown = view[self.top:stop]
|
|
408
443
|
if not view:
|
|
409
444
|
if self.focused:
|
|
410
445
|
# Focus on an empty table: a marker and reverse video, not
|
|
@@ -444,6 +479,9 @@ class DataTable(_Themed):
|
|
|
444
479
|
elif self.zebra and n % 2 and self._active():
|
|
445
480
|
line = self.paint(line, 'on #1c1c1c')
|
|
446
481
|
out.append(line)
|
|
482
|
+
if self.fill and height:
|
|
483
|
+
# Fill the slot: the query and status lines stay at its bottom.
|
|
484
|
+
out.extend([''] * max(0, 2 + rows_h - len(out)))
|
|
447
485
|
if self.typing or self.query:
|
|
448
486
|
cur = self.cursor(' ') if self.typing else ''
|
|
449
487
|
out.append(self.paint('/', self.theme.accent) + self.query + cur)
|
|
@@ -864,11 +902,13 @@ class CatalogGrid(_Themed):
|
|
|
864
902
|
self.paint, style='heavy' if selected else 'rounded')
|
|
865
903
|
|
|
866
904
|
def _card_rows(self):
|
|
867
|
-
|
|
905
|
+
# A card is at least its border and one line inside.
|
|
906
|
+
return max(3, (self.card_height or 0) + self._picture_rows())
|
|
868
907
|
|
|
869
908
|
def draw(self, width, height):
|
|
870
909
|
card_rows = self._card_rows()
|
|
871
|
-
|
|
910
|
+
step = max(1, (self.min_width or 0) + 1)
|
|
911
|
+
cols = max(1, (width + 1) // step)
|
|
872
912
|
self._columns = cols
|
|
873
913
|
card_w = (width - (cols - 1)) // cols
|
|
874
914
|
n_rows = int(math.ceil(len(self.items) / float(cols)))
|
|
@@ -1046,6 +1086,20 @@ class ValidationSummary(_Themed):
|
|
|
1046
1086
|
self.paint)
|
|
1047
1087
|
|
|
1048
1088
|
|
|
1089
|
+
class FormCell(object):
|
|
1090
|
+
"""
|
|
1091
|
+
A field of a :class:`Form` with its layout: ``span`` columns of the
|
|
1092
|
+
form's grid (capped at the columns there are) and ``min_width``, the
|
|
1093
|
+
narrowest it may be -- below that it takes more columns, up to the whole
|
|
1094
|
+
row. The form keeps the field itself (``fields()``, ``values()``).
|
|
1095
|
+
"""
|
|
1096
|
+
|
|
1097
|
+
def __init__(self, field, span=1, min_width=None):
|
|
1098
|
+
self.field = field
|
|
1099
|
+
self.span = max(1, int(span))
|
|
1100
|
+
self.min_width = None if min_width is None else max(1, int(min_width))
|
|
1101
|
+
|
|
1102
|
+
|
|
1049
1103
|
class Form(_Themed):
|
|
1050
1104
|
"""
|
|
1051
1105
|
Fields with labels, help and validation, laid out in ``columns``, with
|
|
@@ -1074,14 +1128,17 @@ class Form(_Themed):
|
|
|
1074
1128
|
|
|
1075
1129
|
def __init__(self, fields, on_submit=None, on_cancel=None,
|
|
1076
1130
|
submit_label='Guardar', cancel_label='Cancelar', columns=1,
|
|
1077
|
-
title=None, summary=True, **kwargs):
|
|
1131
|
+
title=None, summary=True, min_column_width=None, **kwargs):
|
|
1078
1132
|
super(Form, self).__init__(**kwargs)
|
|
1079
1133
|
self.rows = []
|
|
1134
|
+
self.layout = {}
|
|
1080
1135
|
for item in fields:
|
|
1081
1136
|
if isinstance(item, (tuple, list)):
|
|
1082
|
-
self.rows.append(
|
|
1137
|
+
self.rows.append([self._unwrap(f) for f in item])
|
|
1083
1138
|
else:
|
|
1084
|
-
self.rows.append([item])
|
|
1139
|
+
self.rows.append([self._unwrap(item)])
|
|
1140
|
+
self.min_column_width = None if min_column_width is None else \
|
|
1141
|
+
max(1, int(min_column_width))
|
|
1085
1142
|
self.on_submit = on_submit
|
|
1086
1143
|
self.on_cancel = on_cancel
|
|
1087
1144
|
self.columns = max(1, int(columns))
|
|
@@ -1100,6 +1157,28 @@ class Form(_Themed):
|
|
|
1100
1157
|
if isinstance(field, TextInput) and field.on_submit is None:
|
|
1101
1158
|
field.on_submit = self._next_from(field)
|
|
1102
1159
|
|
|
1160
|
+
def _unwrap(self, item):
|
|
1161
|
+
if isinstance(item, FormCell):
|
|
1162
|
+
self.layout[id(item.field)] = (item.span, item.min_width)
|
|
1163
|
+
return item.field
|
|
1164
|
+
return item
|
|
1165
|
+
|
|
1166
|
+
def set_layout(self, field, span=1, min_width=None):
|
|
1167
|
+
"""Give ``field`` ``span`` columns and a ``min_width``."""
|
|
1168
|
+
self.layout[id(field)] = (max(1, int(span)), min_width)
|
|
1169
|
+
self.refresh()
|
|
1170
|
+
|
|
1171
|
+
def grid_columns(self, width):
|
|
1172
|
+
"""How many columns the fields get at ``width``: ``columns``, fewer
|
|
1173
|
+
when they would be narrower than ``min_column_width``."""
|
|
1174
|
+
cols = self.columns
|
|
1175
|
+
if self.min_column_width:
|
|
1176
|
+
cols = min(cols, max(1, (width + 2) //
|
|
1177
|
+
(self.min_column_width + 2)))
|
|
1178
|
+
# Never more columns than get one cell each.
|
|
1179
|
+
cols = min(cols, (width + 2) // 3)
|
|
1180
|
+
return max(1, cols)
|
|
1181
|
+
|
|
1103
1182
|
def _next_from(self, field):
|
|
1104
1183
|
def advance(value):
|
|
1105
1184
|
if self.app is not None:
|
|
@@ -1199,17 +1278,83 @@ class Form(_Themed):
|
|
|
1199
1278
|
out.extend(ValidationSummary(self.errors, theme=self._theme,
|
|
1200
1279
|
use_colors=self.use_colors)
|
|
1201
1280
|
.render(width=width).split('\n'))
|
|
1281
|
+
if self.layout or self.min_column_width:
|
|
1282
|
+
out.extend(self._draw_grid(width))
|
|
1283
|
+
else:
|
|
1284
|
+
out.extend(self._draw_rows(width))
|
|
1285
|
+
buttons = self.submit_button.render(
|
|
1286
|
+
width=self.submit_button.natural_width())
|
|
1287
|
+
if self.cancel_button is not None:
|
|
1288
|
+
buttons = self.cancel_button.render(
|
|
1289
|
+
width=self.cancel_button.natural_width()) + ' ' + buttons
|
|
1290
|
+
out.append(_fx.fit_line(buttons, width, 'r'))
|
|
1291
|
+
return out
|
|
1292
|
+
|
|
1293
|
+
def _section(self, title, width):
|
|
1294
|
+
return [self.paint(title, 'bold'),
|
|
1295
|
+
self.paint('─' * width, self.theme.border)]
|
|
1296
|
+
|
|
1297
|
+
def _draw_grid(self, width):
|
|
1298
|
+
"""Responsive layout: ``grid_columns(width)`` columns, each field
|
|
1299
|
+
taking its span (more when narrower than its ``min_width``)."""
|
|
1300
|
+
cols = self.grid_columns(width)
|
|
1301
|
+
each = (width - 2 * (cols - 1)) // cols
|
|
1302
|
+
|
|
1303
|
+
def span_width(n):
|
|
1304
|
+
return each * n + 2 * (n - 1)
|
|
1305
|
+
out = []
|
|
1202
1306
|
pending = []
|
|
1203
1307
|
|
|
1204
1308
|
def flush():
|
|
1205
1309
|
if not pending:
|
|
1206
1310
|
return
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1311
|
+
used = sum(n for _, n in pending)
|
|
1312
|
+
widths = [span_width(n) for _, n in pending]
|
|
1313
|
+
widths[-1] += width - (sum(widths) + 2 * (len(widths) - 1)) \
|
|
1314
|
+
if used == cols else 0
|
|
1315
|
+
blocks = [f.render(width=max(1, w)).split('\n')
|
|
1316
|
+
for (f, _), w in zip(pending, widths)]
|
|
1317
|
+
out.extend(join_columns(blocks, widths, gap=2))
|
|
1211
1318
|
out.append('')
|
|
1212
1319
|
del pending[:]
|
|
1320
|
+
for row in self.rows:
|
|
1321
|
+
if len(row) == 1 and isinstance(row[0], str):
|
|
1322
|
+
flush()
|
|
1323
|
+
out.extend(self._section(row[0], width))
|
|
1324
|
+
continue
|
|
1325
|
+
if len(row) > 1:
|
|
1326
|
+
flush()
|
|
1327
|
+
for field in row:
|
|
1328
|
+
span, low = self.layout.get(id(field), (1, None))
|
|
1329
|
+
span = min(span, cols)
|
|
1330
|
+
while low and span < cols and span_width(span) < low:
|
|
1331
|
+
span += 1
|
|
1332
|
+
if sum(n for _, n in pending) + span > cols:
|
|
1333
|
+
flush()
|
|
1334
|
+
pending.append((field, span))
|
|
1335
|
+
if len(row) > 1:
|
|
1336
|
+
flush()
|
|
1337
|
+
flush()
|
|
1338
|
+
return out
|
|
1339
|
+
|
|
1340
|
+
def _draw_rows(self, width):
|
|
1341
|
+
out = []
|
|
1342
|
+
pending = []
|
|
1343
|
+
|
|
1344
|
+
def flush():
|
|
1345
|
+
if not pending:
|
|
1346
|
+
return
|
|
1347
|
+
# At most as many side by side as get one cell each: a narrow
|
|
1348
|
+
# form stacks the rest below instead of failing.
|
|
1349
|
+
fit = max(1, (width + 2) // 3)
|
|
1350
|
+
for start in range(0, len(pending), fit):
|
|
1351
|
+
chunk = pending[start:start + fit]
|
|
1352
|
+
n = len(chunk)
|
|
1353
|
+
each = (width - 2 * (n - 1)) // n
|
|
1354
|
+
blocks = [p.render(width=each).split('\n') for p in chunk]
|
|
1355
|
+
out.extend(join_columns(blocks, [each] * n, gap=2))
|
|
1356
|
+
out.append('')
|
|
1357
|
+
del pending[:]
|
|
1213
1358
|
for row in self.rows:
|
|
1214
1359
|
if len(row) == 1 and isinstance(row[0], str):
|
|
1215
1360
|
flush()
|
|
@@ -1225,12 +1370,6 @@ class Form(_Themed):
|
|
|
1225
1370
|
if len(pending) >= self.columns:
|
|
1226
1371
|
flush()
|
|
1227
1372
|
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
1373
|
return out
|
|
1235
1374
|
|
|
1236
1375
|
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/dates.py
RENAMED
|
@@ -991,6 +991,7 @@ class Stopwatch(Input):
|
|
|
991
991
|
self.precision = max(0, min(3, int(precision)))
|
|
992
992
|
self.max_laps = max_laps
|
|
993
993
|
self.laps = []
|
|
994
|
+
self._lap_count = 0
|
|
994
995
|
self._accum = 0.0
|
|
995
996
|
self._since = None
|
|
996
997
|
super(Stopwatch, self).__init__(label=label, value=value, **kwargs)
|
|
@@ -1050,6 +1051,7 @@ class Stopwatch(Input):
|
|
|
1050
1051
|
return False
|
|
1051
1052
|
split = self.value
|
|
1052
1053
|
self.laps.append(split)
|
|
1054
|
+
self._lap_count += 1
|
|
1053
1055
|
if self.max_laps:
|
|
1054
1056
|
del self.laps[:-int(self.max_laps)]
|
|
1055
1057
|
if self.on_lap is not None:
|
|
@@ -1061,6 +1063,7 @@ class Stopwatch(Input):
|
|
|
1061
1063
|
self._accum = 0.0
|
|
1062
1064
|
self._since = self.clock() if self._since is not None else None
|
|
1063
1065
|
self.laps = []
|
|
1066
|
+
self._lap_count = 0
|
|
1064
1067
|
if self.on_change is not None:
|
|
1065
1068
|
self.on_change(self.value)
|
|
1066
1069
|
self.refresh()
|
|
@@ -1121,7 +1124,13 @@ class Stopwatch(Input):
|
|
|
1121
1124
|
' · l: vuelta · r: reiniciar',
|
|
1122
1125
|
self.theme.muted)
|
|
1123
1126
|
out = [line]
|
|
1124
|
-
|
|
1127
|
+
shown = self.laps[-5:]
|
|
1128
|
+
# Numbered by lap, also when max_laps dropped the first ones (and
|
|
1129
|
+
# when laps was set from code).
|
|
1130
|
+
total = len(self.laps)
|
|
1131
|
+
if self.max_laps and self._lap_count > total:
|
|
1132
|
+
total = self._lap_count
|
|
1133
|
+
for n, split in enumerate(shown, total - len(shown) + 1):
|
|
1125
1134
|
out.append(' {0:>2}. {1}'.format(n, self.format_duration(
|
|
1126
1135
|
split.total_seconds(), self.precision)))
|
|
1127
1136
|
return out
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/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,97 @@ class LineChart(_Themed):
|
|
|
1274
1274
|
return out
|
|
1275
1275
|
|
|
1276
1276
|
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
_LINE_BREAKS = re.compile('[\t\n\v\f\r\x1c-\x1e\x85\u2028\u2029]+')
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
class StatusLine(_Themed):
|
|
1283
|
+
"""
|
|
1284
|
+
A one-line status bar with ``left``, ``center`` and ``right`` text
|
|
1285
|
+
(strings or callables returning text, read on every frame). ``kind``
|
|
1286
|
+
(``'info'``, ``'success'``, ``'warning'``, ``'error'``) colours it and
|
|
1287
|
+
puts its symbol (``✔``, ``⚠``, ``✖``...) before the left text, so the
|
|
1288
|
+
state never depends on colour alone. Its role is ``status``: with
|
|
1289
|
+
``announce=True`` (the default) :meth:`set` and :meth:`message` tell
|
|
1290
|
+
screen readers about the change -- politely, or at once for errors.
|
|
1291
|
+
"""
|
|
1292
|
+
|
|
1293
|
+
role = 'status'
|
|
1294
|
+
|
|
1295
|
+
def __init__(self, left='', center='', right='', kind=None,
|
|
1296
|
+
announce=True, color=None, **kwargs):
|
|
1297
|
+
super(StatusLine, self).__init__(**kwargs)
|
|
1298
|
+
self.left = left
|
|
1299
|
+
self.center = center
|
|
1300
|
+
self.right = right
|
|
1301
|
+
self.kind = kind
|
|
1302
|
+
self.announce_changes = bool(announce)
|
|
1303
|
+
self.color = color
|
|
1304
|
+
|
|
1305
|
+
@staticmethod
|
|
1306
|
+
def _value(part):
|
|
1307
|
+
part = part() if callable(part) else part
|
|
1308
|
+
# One line: line breaks and tabs in a part become spaces.
|
|
1309
|
+
return '' if part is None else _LINE_BREAKS.sub(' ', str(part))
|
|
1310
|
+
|
|
1311
|
+
def parts(self):
|
|
1312
|
+
"""``(left, center, right)`` as text."""
|
|
1313
|
+
return (self._value(self.left), self._value(self.center),
|
|
1314
|
+
self._value(self.right))
|
|
1315
|
+
|
|
1316
|
+
def a11y_name(self):
|
|
1317
|
+
return str(self.a11y_label) if self.a11y_label else 'Estado'
|
|
1318
|
+
|
|
1319
|
+
def a11y_value(self):
|
|
1320
|
+
text = ' · '.join(p for p in self.parts() if p)
|
|
1321
|
+
if self.kind:
|
|
1322
|
+
word = _a11y.status_symbol(self.kind, word=True).split(' ', 1)
|
|
1323
|
+
if len(word) == 2 and word[1]:
|
|
1324
|
+
text = word[1] + ': ' + text if text else word[1]
|
|
1325
|
+
return text
|
|
1326
|
+
|
|
1327
|
+
def set(self, left=None, center=None, right=None, kind=False):
|
|
1328
|
+
"""Change some parts (and ``kind``; ``None`` clears it)."""
|
|
1329
|
+
before = self.a11y_value()
|
|
1330
|
+
if left is not None:
|
|
1331
|
+
self.left = left
|
|
1332
|
+
if center is not None:
|
|
1333
|
+
self.center = center
|
|
1334
|
+
if right is not None:
|
|
1335
|
+
self.right = right
|
|
1336
|
+
if kind is not False:
|
|
1337
|
+
self.kind = kind
|
|
1338
|
+
after = self.a11y_value()
|
|
1339
|
+
if self.announce_changes and after and after != before:
|
|
1340
|
+
self.announce(after, 'assertive' if self.kind == 'error'
|
|
1341
|
+
else 'polite')
|
|
1342
|
+
self.refresh()
|
|
1343
|
+
return True
|
|
1344
|
+
|
|
1345
|
+
def message(self, text, kind='info'):
|
|
1346
|
+
"""Show ``text`` on the left with ``kind``."""
|
|
1347
|
+
return self.set(left=text, kind=kind)
|
|
1348
|
+
|
|
1349
|
+
def natural_width(self):
|
|
1350
|
+
return sum(_fx.visible_width(p) + 2 for p in self.parts()) + 2
|
|
1351
|
+
|
|
1352
|
+
def draw(self, width, height):
|
|
1353
|
+
left, center, right = self.parts()
|
|
1354
|
+
if self.kind:
|
|
1355
|
+
left = _a11y.status_symbol(self.kind) + ' ' + left
|
|
1356
|
+
left, right = ' ' + left, right + ' ' if right else right
|
|
1357
|
+
right_w = _fx.visible_width(right)
|
|
1358
|
+
if right and _fx.visible_width(left) + right_w > width and \
|
|
1359
|
+
width - right_w >= 4:
|
|
1360
|
+
# Too long: the left text gives way so the right one (often a
|
|
1361
|
+
# position or a count) stays in view.
|
|
1362
|
+
left = _fx.truncate(left, width - right_w - 1, '…') + ' '
|
|
1363
|
+
room = max(0, width - _fx.visible_width(left) - right_w)
|
|
1364
|
+
mid = _fx.fit_line(_fx.truncate(center, room, '…'), room, 'c')
|
|
1365
|
+
line = _fx.fit_line(left + mid + right, width)
|
|
1366
|
+
if not self._active():
|
|
1367
|
+
return [line]
|
|
1368
|
+
spec = self.color or ('black on ' + self.theme.kind(self.kind)
|
|
1369
|
+
if self.kind else 'reverse')
|
|
1370
|
+
return [self.paint(line, spec)]
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/inputs.py
RENAMED
|
@@ -1839,6 +1839,16 @@ class SignatureInput(Input):
|
|
|
1839
1839
|
strokes.append(points)
|
|
1840
1840
|
return strokes
|
|
1841
1841
|
|
|
1842
|
+
@property
|
|
1843
|
+
def value(self):
|
|
1844
|
+
# A copy: what a Form collected (or on_change got) does not change
|
|
1845
|
+
# as the user keeps drawing.
|
|
1846
|
+
return [list(stroke) for stroke in self._value]
|
|
1847
|
+
|
|
1848
|
+
@value.setter
|
|
1849
|
+
def value(self, new):
|
|
1850
|
+
self._value = self.coerce(new)
|
|
1851
|
+
|
|
1842
1852
|
@property
|
|
1843
1853
|
def strokes(self):
|
|
1844
1854
|
return self._value
|
|
@@ -1891,6 +1901,9 @@ class SignatureInput(Input):
|
|
|
1891
1901
|
|
|
1892
1902
|
def erase(self, point):
|
|
1893
1903
|
point = self._inside(point)
|
|
1904
|
+
# Erasing lifts the pen: moving on must not join what is left of
|
|
1905
|
+
# the stroke (or the one before it) to the pen with a line.
|
|
1906
|
+
self.pen_down = False
|
|
1894
1907
|
kept = []
|
|
1895
1908
|
for stroke in self._value:
|
|
1896
1909
|
rest = [p for p in stroke if p != point]
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/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,66 @@ class Tabs(_Themed):
|
|
|
119
119
|
return out
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def _rows_for(max_visible, height):
|
|
123
|
+
"""The rows a menu window gets: ``max_visible``, never more than the
|
|
124
|
+
``height`` it is drawn in (either may be None)."""
|
|
125
|
+
if max_visible and height:
|
|
126
|
+
return max(1, min(int(max_visible), int(height)))
|
|
127
|
+
return max_visible or height
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _window(comp, out, row, height):
|
|
131
|
+
"""The rows of ``out`` that fit ``height``, kept around ``row`` (the
|
|
132
|
+
current item) with ``▲ n``/``▼ n`` lines saying how many are hidden
|
|
133
|
+
above and below; clickable spots move with the rows. ``comp.top`` is
|
|
134
|
+
the first row shown (kept between frames)."""
|
|
135
|
+
total = len(out)
|
|
136
|
+
if not height or total <= height:
|
|
137
|
+
comp.top = 0
|
|
138
|
+
return out
|
|
139
|
+
height = max(1, int(height))
|
|
140
|
+
top = max(0, min(getattr(comp, 'top', 0), total - 1))
|
|
141
|
+
for _ in range(3):
|
|
142
|
+
up = 1 if top > 0 and height > 2 else 0
|
|
143
|
+
room = height - up
|
|
144
|
+
down = 1 if top + room < total and height > 2 else 0
|
|
145
|
+
room -= down
|
|
146
|
+
room = max(1, room)
|
|
147
|
+
if row is not None:
|
|
148
|
+
if row < top:
|
|
149
|
+
top = row
|
|
150
|
+
elif row >= top + room:
|
|
151
|
+
top = row - room + 1
|
|
152
|
+
top = max(0, min(top, total - room))
|
|
153
|
+
up = 1 if top > 0 and height > 2 else 0
|
|
154
|
+
room = height - up
|
|
155
|
+
down = 1 if top + room < total and height > 2 else 0
|
|
156
|
+
room = max(1, room - down)
|
|
157
|
+
comp.top = top
|
|
158
|
+
shown = out[top:top + room]
|
|
159
|
+
arrows = ('^', 'v') if not comp._active() else ('▲', '▼')
|
|
160
|
+
lines = []
|
|
161
|
+
if up:
|
|
162
|
+
lines.append(comp.paint(' {0} {1} más'.format(arrows[0], top),
|
|
163
|
+
comp.theme.muted))
|
|
164
|
+
lines.extend(shown)
|
|
165
|
+
if down:
|
|
166
|
+
lines.append(comp.paint(' {0} {1} más'.format(
|
|
167
|
+
arrows[1], total - top - room), comp.theme.muted))
|
|
168
|
+
if isinstance(comp._hot, list):
|
|
169
|
+
moved = []
|
|
170
|
+
for r, x0, x1, action in comp._hot:
|
|
171
|
+
if top <= r < top + room:
|
|
172
|
+
moved.append((r - top + up, x0, x1, action))
|
|
173
|
+
if up:
|
|
174
|
+
moved.append((0, 0, None, lambda: comp.scroll_items(-room)))
|
|
175
|
+
if down:
|
|
176
|
+
moved.append((len(lines) - 1, 0, None,
|
|
177
|
+
lambda: comp.scroll_items(room)))
|
|
178
|
+
comp._hot = moved
|
|
179
|
+
return lines
|
|
180
|
+
|
|
181
|
+
|
|
122
182
|
class Menu(_Themed):
|
|
123
183
|
"""
|
|
124
184
|
A vertical menu. ``items``: labels, ``(label, action)``, or dicts with
|
|
@@ -126,6 +186,9 @@ class Menu(_Themed):
|
|
|
126
186
|
separator. Up/Down move (skipping separators and disabled items), Enter
|
|
127
187
|
runs the action, a letter jumps to the item starting with it, and an
|
|
128
188
|
item's ``shortcut`` runs it directly. ``on_select(index, item)``.
|
|
189
|
+
With more items than the height it gets (or ``max_visible``) it shows
|
|
190
|
+
a window around the current item with ``▲ n más`` / ``▼ n más`` lines
|
|
191
|
+
(click them to page); PgUp/PgDn move a page and the wheel scrolls.
|
|
129
192
|
"""
|
|
130
193
|
|
|
131
194
|
focusable = True
|
|
@@ -231,14 +294,34 @@ class Menu(_Themed):
|
|
|
231
294
|
self.refresh()
|
|
232
295
|
return True
|
|
233
296
|
|
|
297
|
+
_page = 5
|
|
298
|
+
|
|
299
|
+
def scroll_items(self, delta):
|
|
300
|
+
"""Move the current item ``delta`` enabled items (a page)."""
|
|
301
|
+
step = 1 if delta > 0 else -1
|
|
302
|
+
for _ in range(abs(int(delta))):
|
|
303
|
+
before = self.index
|
|
304
|
+
self._step(step)
|
|
305
|
+
if (step > 0 and self.index < before) or \
|
|
306
|
+
(step < 0 and self.index > before):
|
|
307
|
+
self.index = before
|
|
308
|
+
break
|
|
309
|
+
self.refresh()
|
|
310
|
+
return True
|
|
311
|
+
|
|
312
|
+
def handle_key(self, key):
|
|
313
|
+
k = str(key)
|
|
314
|
+
if k in ('pageup', 'pagedown', 'scrollup', 'scrolldown') and \
|
|
315
|
+
self.items and k not in self.bindings:
|
|
316
|
+
page = self._page if k.startswith('page') else 3
|
|
317
|
+
return self.scroll_items(page if k.endswith('down') else -page)
|
|
318
|
+
return super(Menu, self).handle_key(key)
|
|
319
|
+
|
|
234
320
|
def draw(self, width, height):
|
|
235
|
-
rows = self.max_visible
|
|
236
|
-
|
|
237
|
-
self.top = self.index
|
|
238
|
-
if self.index >= self.top + rows:
|
|
239
|
-
self.top = self.index - rows + 1
|
|
321
|
+
rows = _rows_for(self.max_visible, height) or len(self.items)
|
|
322
|
+
self._page = max(1, rows - 2)
|
|
240
323
|
out = []
|
|
241
|
-
for i in range(
|
|
324
|
+
for i in range(len(self.items)):
|
|
242
325
|
item = self.items[i]
|
|
243
326
|
if item.get('separator'):
|
|
244
327
|
out.append(self.paint('─' * width, self.theme.border))
|
|
@@ -262,7 +345,7 @@ class Menu(_Themed):
|
|
|
262
345
|
text = text[:-len(shortcut) - 1] + self.paint(
|
|
263
346
|
shortcut, self.theme.muted) + ' '
|
|
264
347
|
out.append(text)
|
|
265
|
-
return out
|
|
348
|
+
return _window(self, out, self.index, rows)
|
|
266
349
|
|
|
267
350
|
|
|
268
351
|
class ContextMenu(Menu):
|
|
@@ -415,6 +498,8 @@ class Sidebar(Menu):
|
|
|
415
498
|
"""
|
|
416
499
|
Navigation down the side: ``sections`` maps a heading to items (as in
|
|
417
500
|
:class:`Menu`). ``collapsed=True`` (or Ctrl-B) shows only the icons.
|
|
501
|
+
It keeps to the height it gets: a window around the current item with
|
|
502
|
+
``▲`` / ``▼`` lines, the title staying on top.
|
|
418
503
|
"""
|
|
419
504
|
|
|
420
505
|
role = 'navigation'
|
|
@@ -456,12 +541,17 @@ class Sidebar(Menu):
|
|
|
456
541
|
return super(Sidebar, self).on_key(key)
|
|
457
542
|
|
|
458
543
|
def draw(self, width, height):
|
|
459
|
-
|
|
544
|
+
head = []
|
|
460
545
|
if self.title and not self.collapsed:
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
546
|
+
head.append(self.paint(' ' + self.title, 'bold ' +
|
|
547
|
+
self.theme.accent))
|
|
548
|
+
head.append('')
|
|
549
|
+
self._hot_base = len(head)
|
|
550
|
+
out = []
|
|
551
|
+
current = None
|
|
464
552
|
for i, item in enumerate(self.items):
|
|
553
|
+
if i == self.index:
|
|
554
|
+
current = len(out)
|
|
465
555
|
if item.get('heading'):
|
|
466
556
|
if not self.collapsed:
|
|
467
557
|
out.append(self.paint(' ' + item['label'].upper(),
|
|
@@ -488,7 +578,25 @@ class Sidebar(Menu):
|
|
|
488
578
|
elif item.get('disabled'):
|
|
489
579
|
text = self.paint(text, 'dim')
|
|
490
580
|
out.append(text)
|
|
491
|
-
|
|
581
|
+
base = len(head)
|
|
582
|
+
if height:
|
|
583
|
+
# Too short for the title and an item: the item wins (the
|
|
584
|
+
# blank line goes first, then the title).
|
|
585
|
+
del head[max(0, int(height) - 1):]
|
|
586
|
+
rows = _rows_for(self.max_visible,
|
|
587
|
+
max(1, height - len(head)) if height else None)
|
|
588
|
+
if rows:
|
|
589
|
+
self._page = max(1, rows - 2)
|
|
590
|
+
if isinstance(self._hot, list):
|
|
591
|
+
# _window works in the item rows' own coordinates.
|
|
592
|
+
self._hot = [(r - base, x0, x1, a)
|
|
593
|
+
for r, x0, x1, a in self._hot]
|
|
594
|
+
lines = _window(self, out, current, rows)
|
|
595
|
+
if isinstance(self._hot, list):
|
|
596
|
+
self._hot = [(r + len(head), x0, x1, a)
|
|
597
|
+
for r, x0, x1, a in self._hot]
|
|
598
|
+
self._hot_base = 0
|
|
599
|
+
return head + lines
|
|
492
600
|
|
|
493
601
|
|
|
494
602
|
class TopBar(_Themed):
|
|
@@ -1366,8 +1474,9 @@ class VStack(_Themed):
|
|
|
1366
1474
|
Children one below the other that share the height the stack gets.
|
|
1367
1475
|
|
|
1368
1476
|
``weights`` (one per child) split the rows left over: a child with
|
|
1369
|
-
weight 0
|
|
1370
|
-
|
|
1477
|
+
weight 0 keeps its own height, the others grow in proportion. By
|
|
1478
|
+
default (3.7.0) children with ``expand`` -- a ``DataTable(fill=True)``,
|
|
1479
|
+
a ``ScrollView``, a ``Sidebar``, ``Tabs`` -- get weight 1, the rest 0. ``min_heights`` / ``max_heights`` (one per child, None for
|
|
1371
1480
|
no limit) bound each one; ``gap`` puts blank rows between them and
|
|
1372
1481
|
``height`` fixes the stack's own height (otherwise it takes its slot's).
|
|
1373
1482
|
When the children need more rows than there are, the stack scrolls and
|
|
@@ -1394,6 +1503,11 @@ class VStack(_Themed):
|
|
|
1394
1503
|
raise ValueError('{0} needs one value per child ({1})'
|
|
1395
1504
|
.format(name, n))
|
|
1396
1505
|
return values
|
|
1506
|
+
if weights is None:
|
|
1507
|
+
# Children that fill their slot (expand: tables with fill=True,
|
|
1508
|
+
# scroll views, sidebars, tabs) share the rows left over.
|
|
1509
|
+
weights = [1 if getattr(c, 'expand', False) else 0
|
|
1510
|
+
for c in self.items]
|
|
1397
1511
|
self.weights = [max(0.0, float(w or 0))
|
|
1398
1512
|
for w in per_child(weights, 0, 'weights')]
|
|
1399
1513
|
self.min_heights = [max(0, int(v or 0)) for v in
|
|
@@ -1448,6 +1562,10 @@ class VStack(_Themed):
|
|
|
1448
1562
|
for i in range(len(self.items))]
|
|
1449
1563
|
room = height - gaps - sum(fixed)
|
|
1450
1564
|
sizes = _share(room, self.weights, fixed, self.max_heights)
|
|
1565
|
+
# No rows left for a growing child: it keeps one (the stack
|
|
1566
|
+
# scrolls) rather than vanishing -- Tab could land on it.
|
|
1567
|
+
sizes = [self._clamp(i, 1) if not size and self.weights[i] and
|
|
1568
|
+
naturals[i] else size for i, size in enumerate(sizes)]
|
|
1451
1569
|
blocks = []
|
|
1452
1570
|
for child, rows in zip(self.items, sizes):
|
|
1453
1571
|
lines = render_into(child, width, rows) if rows else []
|
|
@@ -1464,8 +1582,29 @@ class VStack(_Themed):
|
|
|
1464
1582
|
return i
|
|
1465
1583
|
return None
|
|
1466
1584
|
|
|
1585
|
+
def _focus_span(self, i, width, rows):
|
|
1586
|
+
"""``(first, last)`` rows of the focused component inside child
|
|
1587
|
+
``i`` drawn ``rows`` high, or None when it is not drawn there."""
|
|
1588
|
+
from flexablelib_tui.app import _HIT
|
|
1589
|
+
target = getattr(self.app, 'focused', None)
|
|
1590
|
+
saved = _HIT['on'], _HIT['items']
|
|
1591
|
+
_HIT['on'], _HIT['items'] = True, []
|
|
1592
|
+
try:
|
|
1593
|
+
lines = render_into(self.items[i], width, rows)
|
|
1594
|
+
items = _HIT['items']
|
|
1595
|
+
finally:
|
|
1596
|
+
_HIT['on'], _HIT['items'] = saved
|
|
1597
|
+
_lines, regions = _fx.extract_marks(lines)
|
|
1598
|
+
found = [row for k, row, x0, x1, depth in regions
|
|
1599
|
+
if 0 <= k < len(items) and items[k] is target]
|
|
1600
|
+
return (min(found), max(found)) if found else None
|
|
1601
|
+
|
|
1467
1602
|
def draw(self, width, height):
|
|
1468
1603
|
h = self.height or height
|
|
1604
|
+
if self.height and height:
|
|
1605
|
+
# Never taller than the slot: what does not fit scrolls (and
|
|
1606
|
+
# the focus is followed) instead of being cut off.
|
|
1607
|
+
h = min(self.height, height)
|
|
1469
1608
|
sizes, blocks = self._layout(width, h)
|
|
1470
1609
|
lines = []
|
|
1471
1610
|
starts = []
|
|
@@ -1497,11 +1636,18 @@ class VStack(_Themed):
|
|
|
1497
1636
|
self._followed = target
|
|
1498
1637
|
i = self._holder()
|
|
1499
1638
|
if i is not None:
|
|
1500
|
-
|
|
1501
|
-
if
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1639
|
+
first, last = starts[i], starts[i] + sizes[i] - 1
|
|
1640
|
+
if sizes[i] > h:
|
|
1641
|
+
# A child taller than the view: follow the focused
|
|
1642
|
+
# component inside it, not the child's first row.
|
|
1643
|
+
span = self._focus_span(i, inner, sizes[i])
|
|
1644
|
+
if span is not None:
|
|
1645
|
+
first, last = starts[i] + span[0], \
|
|
1646
|
+
starts[i] + span[1]
|
|
1647
|
+
if first < self.offset or last - first + 1 > h:
|
|
1648
|
+
self.offset = first
|
|
1649
|
+
elif last >= self.offset + h:
|
|
1650
|
+
self.offset = last - h + 1
|
|
1505
1651
|
self.offset = max(0, min(self.offset, self.max_offset))
|
|
1506
1652
|
visible = lines[self.offset:self.offset + h]
|
|
1507
1653
|
if not (self.scrollbar and inner < width):
|
|
@@ -1534,6 +1680,92 @@ class VStack(_Themed):
|
|
|
1534
1680
|
return True
|
|
1535
1681
|
return False
|
|
1536
1682
|
|
|
1683
|
+
_COMPONENT_KWARGS = ('theme', 'use_colors', 'bindings', 'disabled',
|
|
1684
|
+
'a11y_label', 'description', 'role', 'tab_index')
|
|
1685
|
+
|
|
1686
|
+
|
|
1687
|
+
class GridView(_Themed):
|
|
1688
|
+
"""
|
|
1689
|
+
A :class:`flexablelib.Grid` as a component, with an accessible name and
|
|
1690
|
+
role: ``children`` and every other keyword (``columns``, ``min_width``,
|
|
1691
|
+
``gap``, ``border``, ``column_widths``...) are the grid's; ``title``
|
|
1692
|
+
(drawn above it, bold) or ``a11y_label`` names it for screen readers,
|
|
1693
|
+
and ``role`` is ``'group'`` unless given. Its components keep their
|
|
1694
|
+
focus order. :meth:`audit` checks the grid and everything inside it
|
|
1695
|
+
(role, label, focus shown without colour) and returns
|
|
1696
|
+
:class:`flexablelib_tui.accessibility.AuditIssue` s.
|
|
1697
|
+
"""
|
|
1698
|
+
|
|
1699
|
+
role = 'group'
|
|
1700
|
+
expand = False
|
|
1701
|
+
|
|
1702
|
+
def __init__(self, children, title=None, **kwargs):
|
|
1703
|
+
own = dict((k, kwargs.pop(k)) for k in _COMPONENT_KWARGS
|
|
1704
|
+
if k in kwargs)
|
|
1705
|
+
super(GridView, self).__init__(**own)
|
|
1706
|
+
self.items = list(children)
|
|
1707
|
+
self.title = title
|
|
1708
|
+
self.options = kwargs
|
|
1709
|
+
|
|
1710
|
+
def a11y_name(self):
|
|
1711
|
+
if self.a11y_label:
|
|
1712
|
+
return str(self.a11y_label)
|
|
1713
|
+
return self.title or ''
|
|
1714
|
+
|
|
1715
|
+
def a11y_value(self):
|
|
1716
|
+
return '{0} elementos'.format(len(self.items))
|
|
1717
|
+
|
|
1718
|
+
def children(self):
|
|
1719
|
+
from flexablelib.layout import GridCell
|
|
1720
|
+
kids = []
|
|
1721
|
+
for item in self.items:
|
|
1722
|
+
if isinstance(item, GridCell):
|
|
1723
|
+
item = item.child
|
|
1724
|
+
elif isinstance(item, tuple) and item:
|
|
1725
|
+
item = item[0]
|
|
1726
|
+
if item is not None and not isinstance(item, str):
|
|
1727
|
+
kids.append(item)
|
|
1728
|
+
return kids
|
|
1729
|
+
|
|
1730
|
+
def grid(self):
|
|
1731
|
+
"""The :class:`flexablelib.Grid` drawn."""
|
|
1732
|
+
from flexablelib.layout import Grid
|
|
1733
|
+
return Grid(self.items, **self.options)
|
|
1734
|
+
|
|
1735
|
+
def natural_width(self):
|
|
1736
|
+
return _natural_width(self.grid())
|
|
1737
|
+
|
|
1738
|
+
def draw(self, width, height):
|
|
1739
|
+
out = []
|
|
1740
|
+
if self.title:
|
|
1741
|
+
out.append(self.paint(self.title, 'bold'))
|
|
1742
|
+
room = None if height is None else max(1, height - len(out))
|
|
1743
|
+
grid = self.grid()
|
|
1744
|
+
text = grid.render(width=width, height=room) if room else \
|
|
1745
|
+
grid.render(width=width)
|
|
1746
|
+
out.extend(text.split('\n') if text else [])
|
|
1747
|
+
return out
|
|
1748
|
+
|
|
1749
|
+
def audit(self, width=40, check_focus=True):
|
|
1750
|
+
"""Accessibility problems of the grid and of every component in
|
|
1751
|
+
it (see :func:`flexablelib_tui.accessibility.audit`)."""
|
|
1752
|
+
from flexablelib_tui import accessibility as a11y
|
|
1753
|
+
from flexablelib_tui.app import Component, _child_nodes
|
|
1754
|
+
found = []
|
|
1755
|
+
stack = list(reversed(self.children()))
|
|
1756
|
+
seen = set()
|
|
1757
|
+
while stack:
|
|
1758
|
+
node = stack.pop()
|
|
1759
|
+
if id(node) in seen:
|
|
1760
|
+
continue
|
|
1761
|
+
seen.add(id(node))
|
|
1762
|
+
if isinstance(node, Component):
|
|
1763
|
+
found.append(node)
|
|
1764
|
+
stack.extend(reversed(_child_nodes(node)))
|
|
1765
|
+
return a11y.audit([self] + found, width=width,
|
|
1766
|
+
check_focus=check_focus)
|
|
1767
|
+
|
|
1768
|
+
|
|
1537
1769
|
class SortControl(_Themed):
|
|
1538
1770
|
"""
|
|
1539
1771
|
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.1
|
|
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.1
|
|
21
|
+
Requires-Dist: flexablelib-tui>=3.7.1
|
|
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.1}/flexablelib_components/base.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/media.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/overlays.py
RENAMED
|
File without changes
|
{flexablelib_components-3.6.0 → flexablelib_components-3.7.1}/flexablelib_components/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|