urwid 3.0.3__py3-none-any.whl → 3.0.5__py3-none-any.whl
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.
- urwid/__init__.py +29 -16
- urwid/display/__init__.py +53 -48
- urwid/display/_raw_display_base.py +2 -2
- urwid/display/common.py +17 -17
- urwid/display/curses.py +1 -3
- urwid/display/web.py +1 -1
- urwid/event_loop/asyncio_loop.py +3 -1
- urwid/event_loop/main_loop.py +5 -5
- urwid/font.py +6 -4
- urwid/numedit.py +65 -65
- urwid/signals.py +17 -26
- urwid/split_repr.py +9 -3
- urwid/str_util.py +90 -42
- urwid/text_layout.py +8 -6
- urwid/util.py +1 -1
- urwid/version.py +2 -2
- urwid/vterm.py +2 -2
- urwid/widget/attr_map.py +10 -10
- urwid/widget/attr_wrap.py +3 -3
- urwid/widget/big_text.py +0 -3
- urwid/widget/box_adapter.py +2 -2
- urwid/widget/divider.py +6 -6
- urwid/widget/edit.py +42 -42
- urwid/widget/filler.py +8 -8
- urwid/widget/frame.py +3 -3
- urwid/widget/line_box.py +19 -19
- urwid/widget/listbox.py +1 -1
- urwid/widget/monitored_list.py +69 -45
- urwid/widget/padding.py +20 -20
- urwid/widget/progress_bar.py +7 -7
- urwid/widget/solid_fill.py +3 -3
- urwid/widget/text.py +44 -30
- urwid/widget/widget.py +6 -6
- urwid/widget/widget_decoration.py +2 -2
- urwid/widget/wimp.py +61 -61
- {urwid-3.0.3.dist-info → urwid-3.0.5.dist-info}/METADATA +6 -5
- urwid-3.0.5.dist-info/RECORD +74 -0
- {urwid-3.0.3.dist-info → urwid-3.0.5.dist-info}/WHEEL +1 -1
- urwid-3.0.3.dist-info/RECORD +0 -74
- {urwid-3.0.3.dist-info → urwid-3.0.5.dist-info}/licenses/COPYING +0 -0
- {urwid-3.0.3.dist-info → urwid-3.0.5.dist-info}/top_level.txt +0 -0
urwid/widget/edit.py
CHANGED
|
@@ -99,11 +99,11 @@ class Edit(Text):
|
|
|
99
99
|
|
|
100
100
|
>>> Edit()
|
|
101
101
|
<Edit selectable flow widget '' edit_pos=0>
|
|
102
|
-
>>> Edit(
|
|
102
|
+
>>> Edit("Y/n? ", "yes")
|
|
103
103
|
<Edit selectable flow widget 'yes' caption='Y/n? ' edit_pos=3>
|
|
104
|
-
>>> Edit(
|
|
104
|
+
>>> Edit("Name ", "Smith", edit_pos=1)
|
|
105
105
|
<Edit selectable flow widget 'Smith' caption='Name ' edit_pos=1>
|
|
106
|
-
>>> Edit(
|
|
106
|
+
>>> Edit("", "3.14", align="right")
|
|
107
107
|
<Edit selectable flow widget '3.14' align='right' edit_pos=4>
|
|
108
108
|
"""
|
|
109
109
|
|
|
@@ -140,11 +140,11 @@ class Edit(Text):
|
|
|
140
140
|
|
|
141
141
|
Text returned includes the caption and edit_text, possibly masked.
|
|
142
142
|
|
|
143
|
-
>>> Edit(
|
|
143
|
+
>>> Edit("What? ", "oh, nothing.").get_text()
|
|
144
144
|
('What? oh, nothing.', [])
|
|
145
|
-
>>> Edit((
|
|
145
|
+
>>> Edit(("bright", "user@host:~$ "), "ls").get_text()
|
|
146
146
|
('user@host:~$ ls', [('bright', 13)])
|
|
147
|
-
>>> Edit(
|
|
147
|
+
>>> Edit("password:", "seekrit", mask="*").get_text()
|
|
148
148
|
('password:*******', [])
|
|
149
149
|
"""
|
|
150
150
|
|
|
@@ -184,21 +184,21 @@ class Edit(Text):
|
|
|
184
184
|
>>> size = (10,)
|
|
185
185
|
>>> Edit().get_pref_col(size)
|
|
186
186
|
0
|
|
187
|
-
>>> e = Edit(
|
|
187
|
+
>>> e = Edit("", "word")
|
|
188
188
|
>>> e.get_pref_col(size)
|
|
189
189
|
4
|
|
190
|
-
>>> e.keypress(size,
|
|
190
|
+
>>> e.keypress(size, "left")
|
|
191
191
|
>>> e.get_pref_col(size)
|
|
192
192
|
3
|
|
193
|
-
>>> e.keypress(size,
|
|
193
|
+
>>> e.keypress(size, "end")
|
|
194
194
|
>>> e.get_pref_col(size)
|
|
195
195
|
<Align.RIGHT: 'right'>
|
|
196
|
-
>>> e = Edit(
|
|
197
|
-
>>> e.keypress(size,
|
|
198
|
-
>>> e.keypress(size,
|
|
196
|
+
>>> e = Edit("", "2\\nwords")
|
|
197
|
+
>>> e.keypress(size, "left")
|
|
198
|
+
>>> e.keypress(size, "up")
|
|
199
199
|
>>> e.get_pref_col(size)
|
|
200
200
|
4
|
|
201
|
-
>>> e.keypress(size,
|
|
201
|
+
>>> e.keypress(size, "left")
|
|
202
202
|
>>> e.get_pref_col(size)
|
|
203
203
|
0
|
|
204
204
|
"""
|
|
@@ -220,7 +220,7 @@ class Edit(Text):
|
|
|
220
220
|
>>> e.set_caption("cap1")
|
|
221
221
|
>>> print(e.caption)
|
|
222
222
|
cap1
|
|
223
|
-
>>> e.set_caption((
|
|
223
|
+
>>> e.set_caption(("bold", "cap2"))
|
|
224
224
|
>>> print(e.caption)
|
|
225
225
|
cap2
|
|
226
226
|
>>> e.attrib
|
|
@@ -247,7 +247,7 @@ class Edit(Text):
|
|
|
247
247
|
:param pos: cursor position
|
|
248
248
|
:type pos: int
|
|
249
249
|
|
|
250
|
-
>>> e = Edit(
|
|
250
|
+
>>> e = Edit("", "word")
|
|
251
251
|
>>> e.edit_pos
|
|
252
252
|
4
|
|
253
253
|
>>> e.set_edit_pos(2)
|
|
@@ -294,12 +294,12 @@ class Edit(Text):
|
|
|
294
294
|
:type text: bytes or unicode
|
|
295
295
|
|
|
296
296
|
>>> e = Edit()
|
|
297
|
-
>>> e.set_edit_text(
|
|
297
|
+
>>> e.set_edit_text("yes")
|
|
298
298
|
>>> print(e.edit_text)
|
|
299
299
|
yes
|
|
300
300
|
>>> e
|
|
301
301
|
<Edit selectable flow widget 'yes' edit_pos=0>
|
|
302
|
-
>>> e.edit_text =
|
|
302
|
+
>>> e.edit_text = "no" # Urwid 0.9.9 or later
|
|
303
303
|
>>> print(e.edit_text)
|
|
304
304
|
no
|
|
305
305
|
"""
|
|
@@ -317,7 +317,7 @@ class Edit(Text):
|
|
|
317
317
|
"""
|
|
318
318
|
Return the edit text for this widget.
|
|
319
319
|
|
|
320
|
-
>>> e = Edit(
|
|
320
|
+
>>> e = Edit("What? ", "oh, nothing.")
|
|
321
321
|
>>> print(e.get_edit_text())
|
|
322
322
|
oh, nothing.
|
|
323
323
|
>>> print(e.edit_text)
|
|
@@ -343,12 +343,12 @@ class Edit(Text):
|
|
|
343
343
|
must match the text in the caption
|
|
344
344
|
:type text: bytes or unicode
|
|
345
345
|
|
|
346
|
-
>>> e = Edit(
|
|
347
|
-
>>> e.insert_text(
|
|
346
|
+
>>> e = Edit("", "42")
|
|
347
|
+
>>> e.insert_text(".5")
|
|
348
348
|
>>> e
|
|
349
349
|
<Edit selectable flow widget '42.5' edit_pos=4>
|
|
350
350
|
>>> e.set_edit_pos(2)
|
|
351
|
-
>>> e.insert_text(
|
|
351
|
+
>>> e.insert_text("a")
|
|
352
352
|
>>> print(e.edit_text)
|
|
353
353
|
42a.5
|
|
354
354
|
"""
|
|
@@ -381,7 +381,7 @@ class Edit(Text):
|
|
|
381
381
|
# if there's highlighted text, it'll get replaced by the new text
|
|
382
382
|
text = self._normalize_to_caption(text)
|
|
383
383
|
if self.highlight:
|
|
384
|
-
start, stop = self.highlight
|
|
384
|
+
start, stop = self.highlight
|
|
385
385
|
btext, etext = self.edit_text[:start], self.edit_text[stop:]
|
|
386
386
|
result_text = btext + etext
|
|
387
387
|
result_pos = start
|
|
@@ -406,17 +406,17 @@ class Edit(Text):
|
|
|
406
406
|
Handle editing keystrokes, return others.
|
|
407
407
|
|
|
408
408
|
>>> e, size = Edit(), (20,)
|
|
409
|
-
>>> e.keypress(size,
|
|
410
|
-
>>> e.keypress(size,
|
|
411
|
-
>>> e.keypress(size,
|
|
409
|
+
>>> e.keypress(size, "x")
|
|
410
|
+
>>> e.keypress(size, "left")
|
|
411
|
+
>>> e.keypress(size, "1")
|
|
412
412
|
>>> print(e.edit_text)
|
|
413
413
|
1x
|
|
414
|
-
>>> e.keypress(size,
|
|
415
|
-
>>> e.keypress(size,
|
|
416
|
-
>>> e.keypress(size,
|
|
414
|
+
>>> e.keypress(size, "backspace")
|
|
415
|
+
>>> e.keypress(size, "end")
|
|
416
|
+
>>> e.keypress(size, "2")
|
|
417
417
|
>>> print(e.edit_text)
|
|
418
418
|
x2
|
|
419
|
-
>>> e.keypress(size,
|
|
419
|
+
>>> e.keypress(size, "shift f1")
|
|
420
420
|
'shift f1'
|
|
421
421
|
"""
|
|
422
422
|
pos = self.edit_pos
|
|
@@ -517,7 +517,7 @@ class Edit(Text):
|
|
|
517
517
|
Returns True if move succeeded, False otherwise.
|
|
518
518
|
|
|
519
519
|
>>> size = (10,)
|
|
520
|
-
>>> e = Edit("","edit\\ntext")
|
|
520
|
+
>>> e = Edit("", "edit\\ntext")
|
|
521
521
|
>>> e.move_cursor_to_coords(size, 5, 0)
|
|
522
522
|
True
|
|
523
523
|
>>> e.edit_pos
|
|
@@ -555,8 +555,8 @@ class Edit(Text):
|
|
|
555
555
|
Move the cursor to the location clicked for button 1.
|
|
556
556
|
|
|
557
557
|
>>> size = (20,)
|
|
558
|
-
>>> e = Edit("","words here")
|
|
559
|
-
>>> e.mouse_event(size,
|
|
558
|
+
>>> e = Edit("", "words here")
|
|
559
|
+
>>> e.mouse_event(size, "mouse press", 1, 2, 0, True)
|
|
560
560
|
True
|
|
561
561
|
>>> e.edit_pos
|
|
562
562
|
2
|
|
@@ -572,7 +572,7 @@ class Edit(Text):
|
|
|
572
572
|
"""
|
|
573
573
|
if not self.highlight:
|
|
574
574
|
return False
|
|
575
|
-
start, stop = self.highlight
|
|
575
|
+
start, stop = self.highlight
|
|
576
576
|
btext, etext = self.edit_text[:start], self.edit_text[stop:]
|
|
577
577
|
self.set_edit_text(btext + etext)
|
|
578
578
|
self.edit_pos = start
|
|
@@ -588,7 +588,7 @@ class Edit(Text):
|
|
|
588
588
|
Render edit widget and return canvas. Include cursor when in
|
|
589
589
|
focus.
|
|
590
590
|
|
|
591
|
-
>>> edit = Edit("? ","yes")
|
|
591
|
+
>>> edit = Edit("? ", "yes")
|
|
592
592
|
>>> c = edit.render((10,), focus=True)
|
|
593
593
|
>>> c.text
|
|
594
594
|
[b'? yes ']
|
|
@@ -639,7 +639,7 @@ class Edit(Text):
|
|
|
639
639
|
"""
|
|
640
640
|
Return the (*x*, *y*) coordinates of cursor within widget.
|
|
641
641
|
|
|
642
|
-
>>> Edit("? ","yes").get_cursor_coords((10,))
|
|
642
|
+
>>> Edit("? ", "yes").get_cursor_coords((10,))
|
|
643
643
|
(5, 0)
|
|
644
644
|
"""
|
|
645
645
|
(maxcol,) = size
|
|
@@ -672,7 +672,7 @@ class IntEdit(Edit):
|
|
|
672
672
|
caption -- caption markup
|
|
673
673
|
default -- default edit value
|
|
674
674
|
|
|
675
|
-
>>> IntEdit(
|
|
675
|
+
>>> IntEdit("", 42)
|
|
676
676
|
<IntEdit selectable flow widget '42' edit_pos=2>
|
|
677
677
|
"""
|
|
678
678
|
if default is not None:
|
|
@@ -689,12 +689,12 @@ class IntEdit(Edit):
|
|
|
689
689
|
"""
|
|
690
690
|
Handle editing keystrokes. Remove leading zeros.
|
|
691
691
|
|
|
692
|
-
>>> e, size = IntEdit(
|
|
693
|
-
>>> e.keypress(size,
|
|
694
|
-
>>> e.keypress(size,
|
|
692
|
+
>>> e, size = IntEdit("", 5002), (10,)
|
|
693
|
+
>>> e.keypress(size, "home")
|
|
694
|
+
>>> e.keypress(size, "delete")
|
|
695
695
|
>>> print(e.edit_text)
|
|
696
696
|
002
|
|
697
|
-
>>> e.keypress(size,
|
|
697
|
+
>>> e.keypress(size, "end")
|
|
698
698
|
>>> print(e.edit_text)
|
|
699
699
|
2
|
|
700
700
|
"""
|
|
@@ -713,8 +713,8 @@ class IntEdit(Edit):
|
|
|
713
713
|
Return the numeric value of self.edit_text.
|
|
714
714
|
|
|
715
715
|
>>> e, size = IntEdit(), (10,)
|
|
716
|
-
>>> e.keypress(size,
|
|
717
|
-
>>> e.keypress(size,
|
|
716
|
+
>>> e.keypress(size, "5")
|
|
717
|
+
>>> e.keypress(size, "1")
|
|
718
718
|
>>> e.value() == 51
|
|
719
719
|
True
|
|
720
720
|
"""
|
urwid/widget/filler.py
CHANGED
|
@@ -361,21 +361,21 @@ def calculate_top_bottom_filler(
|
|
|
361
361
|
bottom -- a fixed number of rows to fill on the bottom
|
|
362
362
|
|
|
363
363
|
>>> ctbf = calculate_top_bottom_filler
|
|
364
|
-
>>> ctbf(15,
|
|
364
|
+
>>> ctbf(15, "top", 0, "given", 10, None, 2, 0)
|
|
365
365
|
(2, 3)
|
|
366
|
-
>>> ctbf(15,
|
|
366
|
+
>>> ctbf(15, "relative", 0, "given", 10, None, 2, 0)
|
|
367
367
|
(2, 3)
|
|
368
|
-
>>> ctbf(15,
|
|
368
|
+
>>> ctbf(15, "relative", 100, "given", 10, None, 2, 0)
|
|
369
369
|
(5, 0)
|
|
370
|
-
>>> ctbf(15,
|
|
370
|
+
>>> ctbf(15, "middle", 0, "given", 4, None, 2, 0)
|
|
371
371
|
(6, 5)
|
|
372
|
-
>>> ctbf(15,
|
|
372
|
+
>>> ctbf(15, "middle", 0, "given", 18, None, 2, 0)
|
|
373
373
|
(0, 0)
|
|
374
|
-
>>> ctbf(20,
|
|
374
|
+
>>> ctbf(20, "top", 0, "relative", 60, None, 0, 0)
|
|
375
375
|
(0, 8)
|
|
376
|
-
>>> ctbf(20,
|
|
376
|
+
>>> ctbf(20, "relative", 30, "relative", 60, None, 0, 0)
|
|
377
377
|
(2, 6)
|
|
378
|
-
>>> ctbf(20,
|
|
378
|
+
>>> ctbf(20, "relative", 30, "relative", 60, 14, 0, 0)
|
|
379
379
|
(2, 4)
|
|
380
380
|
"""
|
|
381
381
|
if height_type == WHSettings.RELATIVE:
|
urwid/widget/frame.py
CHANGED
|
@@ -275,9 +275,9 @@ class Frame(Widget, WidgetContainerMixin, typing.Generic[BodyWidget, HeaderWidge
|
|
|
275
275
|
a dict-like object similar to::
|
|
276
276
|
|
|
277
277
|
{
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
"body": (body_widget, None),
|
|
279
|
+
"header": (header_widget, None), # if frame has a header
|
|
280
|
+
"footer": (footer_widget, None), # if frame has a footer
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
This object may be used to read or update the contents of the Frame.
|
urwid/widget/line_box.py
CHANGED
|
@@ -68,29 +68,29 @@ class LineBox(WidgetDecoration[WrappedWidget], delegate_to_widget_mixin("_wrappe
|
|
|
68
68
|
│Some text│
|
|
69
69
|
└─────────┘
|
|
70
70
|
>>> print(
|
|
71
|
-
...
|
|
72
|
-
...
|
|
73
|
-
...
|
|
74
|
-
...
|
|
75
|
-
...
|
|
76
|
-
...
|
|
77
|
-
...
|
|
71
|
+
... LineBox(
|
|
72
|
+
... Text("Some text"),
|
|
73
|
+
... tlcorner=LineBox.Symbols.LIGHT.TOP_LEFT_ROUNDED,
|
|
74
|
+
... trcorner=LineBox.Symbols.LIGHT.TOP_RIGHT_ROUNDED,
|
|
75
|
+
... blcorner=LineBox.Symbols.LIGHT.BOTTOM_LEFT_ROUNDED,
|
|
76
|
+
... brcorner=LineBox.Symbols.LIGHT.BOTTOM_RIGHT_ROUNDED,
|
|
77
|
+
... ).render(())
|
|
78
78
|
... )
|
|
79
79
|
╭─────────╮
|
|
80
80
|
│Some text│
|
|
81
81
|
╰─────────╯
|
|
82
82
|
>>> print(
|
|
83
|
-
...
|
|
84
|
-
...
|
|
85
|
-
...
|
|
86
|
-
...
|
|
87
|
-
...
|
|
88
|
-
...
|
|
89
|
-
...
|
|
90
|
-
...
|
|
91
|
-
...
|
|
92
|
-
...
|
|
93
|
-
...
|
|
83
|
+
... LineBox(
|
|
84
|
+
... Text("Some text"),
|
|
85
|
+
... tline=LineBox.Symbols.HEAVY.HORIZONTAL,
|
|
86
|
+
... bline=LineBox.Symbols.HEAVY.HORIZONTAL,
|
|
87
|
+
... lline=LineBox.Symbols.HEAVY.VERTICAL,
|
|
88
|
+
... rline=LineBox.Symbols.HEAVY.VERTICAL,
|
|
89
|
+
... tlcorner=LineBox.Symbols.HEAVY.TOP_LEFT,
|
|
90
|
+
... trcorner=LineBox.Symbols.HEAVY.TOP_RIGHT,
|
|
91
|
+
... blcorner=LineBox.Symbols.HEAVY.BOTTOM_LEFT,
|
|
92
|
+
... brcorner=LineBox.Symbols.HEAVY.BOTTOM_RIGHT,
|
|
93
|
+
... ).render(())
|
|
94
94
|
... )
|
|
95
95
|
┏━━━━━━━━━┓
|
|
96
96
|
┃Some text┃
|
|
@@ -178,7 +178,7 @@ class LineBox(WidgetDecoration[WrappedWidget], delegate_to_widget_mixin("_wrappe
|
|
|
178
178
|
middle: Columns = typing.cast("Columns", self._wrapped_widget[v_index])
|
|
179
179
|
_old_widget, options = middle.contents[h_index]
|
|
180
180
|
middle.contents[h_index] = (original_widget, options)
|
|
181
|
-
WidgetDecoration.original_widget.fset(self, original_widget)
|
|
181
|
+
WidgetDecoration.original_widget.fset(self, original_widget) # pylint: disable=no-member
|
|
182
182
|
|
|
183
183
|
@property
|
|
184
184
|
def _w(self) -> Pile:
|
urwid/widget/listbox.py
CHANGED
|
@@ -1197,7 +1197,7 @@ class ListBox(Widget, WidgetContainerMixin):
|
|
|
1197
1197
|
# start from closest edge and move inwards
|
|
1198
1198
|
(pref_col,) = cursor_coords
|
|
1199
1199
|
if coming_from == "above":
|
|
1200
|
-
attempt_rows = range(
|
|
1200
|
+
attempt_rows = range(tgt_rows)
|
|
1201
1201
|
else:
|
|
1202
1202
|
if coming_from != "below":
|
|
1203
1203
|
raise ValueError("must specify coming_from ('above' or 'below') if cursor row is not specified")
|
urwid/widget/monitored_list.py
CHANGED
|
@@ -63,7 +63,7 @@ class MonitoredList(list[_T], typing.Generic[_T]):
|
|
|
63
63
|
time the list is modified. Callback's return value is ignored.
|
|
64
64
|
|
|
65
65
|
>>> import sys
|
|
66
|
-
>>> ml = MonitoredList([1,2,3])
|
|
66
|
+
>>> ml = MonitoredList([1, 2, 3])
|
|
67
67
|
>>> ml.set_modified_callback(lambda: sys.stdout.write("modified\\n"))
|
|
68
68
|
>>> ml
|
|
69
69
|
MonitoredList([1, 2, 3])
|
|
@@ -167,7 +167,7 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
167
167
|
>>> ml = MonitoredFocusList([10, 11, 12, 13, 14], focus=3)
|
|
168
168
|
>>> ml
|
|
169
169
|
MonitoredFocusList([10, 11, 12, 13, 14], focus=3)
|
|
170
|
-
>>> del
|
|
170
|
+
>>> del ml[1]
|
|
171
171
|
>>> ml
|
|
172
172
|
MonitoredFocusList([10, 12, 13, 14], focus=2)
|
|
173
173
|
>>> ml[:2] = [50, 51, 52, 53]
|
|
@@ -199,7 +199,7 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
199
199
|
Return the index of the item "in focus" or None if
|
|
200
200
|
the list is empty.
|
|
201
201
|
|
|
202
|
-
>>> MonitoredFocusList([1,2,3], focus=2).focus
|
|
202
|
+
>>> MonitoredFocusList([1, 2, 3], focus=2).focus
|
|
203
203
|
2
|
|
204
204
|
>>> MonitoredFocusList().focus
|
|
205
205
|
"""
|
|
@@ -221,9 +221,11 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
221
221
|
instance with set_focus_changed_callback().
|
|
222
222
|
|
|
223
223
|
>>> ml = MonitoredFocusList([9, 10, 11])
|
|
224
|
-
>>> ml.focus = 2
|
|
224
|
+
>>> ml.focus = 2
|
|
225
|
+
... ml.focus
|
|
225
226
|
2
|
|
226
|
-
>>> ml.focus = 0
|
|
227
|
+
>>> ml.focus = 0
|
|
228
|
+
... ml.focus
|
|
227
229
|
0
|
|
228
230
|
>>> ml.focus = -2
|
|
229
231
|
Traceback (most recent call last):
|
|
@@ -274,7 +276,7 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
274
276
|
new_focus -- new focus index
|
|
275
277
|
|
|
276
278
|
>>> import sys
|
|
277
|
-
>>> ml = MonitoredFocusList([1,2,3], focus=1)
|
|
279
|
+
>>> ml = MonitoredFocusList([1, 2, 3], focus=1)
|
|
278
280
|
>>> ml.set_focus_changed_callback(lambda f: sys.stdout.write("focus: %d\\n" % (f,)))
|
|
279
281
|
>>> ml
|
|
280
282
|
MonitoredFocusList([1, 2, 3], focus=1)
|
|
@@ -359,28 +361,38 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
359
361
|
|
|
360
362
|
def __delitem__(self, y: int | slice) -> None:
|
|
361
363
|
"""
|
|
362
|
-
>>> ml = MonitoredFocusList([0,1,2,3,4], focus=2)
|
|
363
|
-
>>> del ml[3]
|
|
364
|
+
>>> ml = MonitoredFocusList([0, 1, 2, 3, 4], focus=2)
|
|
365
|
+
>>> del ml[3]
|
|
366
|
+
>>> ml
|
|
364
367
|
MonitoredFocusList([0, 1, 2, 4], focus=2)
|
|
365
|
-
>>> del ml[-1]
|
|
368
|
+
>>> del ml[-1]
|
|
369
|
+
>>> ml
|
|
366
370
|
MonitoredFocusList([0, 1, 2], focus=2)
|
|
367
|
-
>>> del ml[0]
|
|
371
|
+
>>> del ml[0]
|
|
372
|
+
>>> ml
|
|
368
373
|
MonitoredFocusList([1, 2], focus=1)
|
|
369
|
-
>>> del ml[1]
|
|
374
|
+
>>> del ml[1]
|
|
375
|
+
>>> ml
|
|
370
376
|
MonitoredFocusList([1], focus=0)
|
|
371
|
-
>>> del ml[0]
|
|
377
|
+
>>> del ml[0]
|
|
378
|
+
>>> ml
|
|
372
379
|
MonitoredFocusList([], focus=None)
|
|
373
|
-
>>> ml = MonitoredFocusList([5,4,6,4,5,4,6,4,5], focus=4)
|
|
374
|
-
>>> del ml[1::2]
|
|
380
|
+
>>> ml = MonitoredFocusList([5, 4, 6, 4, 5, 4, 6, 4, 5], focus=4)
|
|
381
|
+
>>> del ml[1::2]
|
|
382
|
+
>>> ml
|
|
375
383
|
MonitoredFocusList([5, 6, 5, 6, 5], focus=2)
|
|
376
|
-
>>> del ml[::2]
|
|
384
|
+
>>> del ml[::2]
|
|
385
|
+
>>> ml
|
|
377
386
|
MonitoredFocusList([6, 6], focus=1)
|
|
378
|
-
>>> ml = MonitoredFocusList([0,1,2,3,4,6,7], focus=2)
|
|
379
|
-
>>> del ml[-2:]
|
|
387
|
+
>>> ml = MonitoredFocusList([0, 1, 2, 3, 4, 6, 7], focus=2)
|
|
388
|
+
>>> del ml[-2:]
|
|
389
|
+
>>> ml
|
|
380
390
|
MonitoredFocusList([0, 1, 2, 3, 4], focus=2)
|
|
381
|
-
>>> del ml[-4:-2]
|
|
391
|
+
>>> del ml[-4:-2]
|
|
392
|
+
>>> ml
|
|
382
393
|
MonitoredFocusList([0, 3, 4], focus=1)
|
|
383
|
-
>>> del ml[:]
|
|
394
|
+
>>> del ml[:]
|
|
395
|
+
>>> ml
|
|
384
396
|
MonitoredFocusList([], focus=None)
|
|
385
397
|
"""
|
|
386
398
|
if isinstance(y, slice):
|
|
@@ -399,8 +411,8 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
399
411
|
def __setitem__(self, i: int | slice, y: _T | Collection[_T]) -> None:
|
|
400
412
|
"""
|
|
401
413
|
>>> def modified(indices, new_items):
|
|
402
|
-
... print(f"range{indices!r} <- {new_items!r}"
|
|
403
|
-
>>> ml = MonitoredFocusList([0,1,2,3], focus=2)
|
|
414
|
+
... print(f"range{indices!r} <- {new_items!r}")
|
|
415
|
+
>>> ml = MonitoredFocusList([0, 1, 2, 3], focus=2)
|
|
404
416
|
>>> ml.set_validate_contents_modified(modified)
|
|
405
417
|
>>> ml[0] = 9
|
|
406
418
|
range(0, 1, 1) <- [9]
|
|
@@ -435,8 +447,8 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
435
447
|
def __imul__(self, n: int):
|
|
436
448
|
"""
|
|
437
449
|
>>> def modified(indices, new_items):
|
|
438
|
-
... print(f"range{indices!r} <- {list(new_items)!r}"
|
|
439
|
-
>>> ml = MonitoredFocusList([0,1,2], focus=2)
|
|
450
|
+
... print(f"range{indices!r} <- {list(new_items)!r}")
|
|
451
|
+
>>> ml = MonitoredFocusList([0, 1, 2], focus=2)
|
|
440
452
|
>>> ml.set_validate_contents_modified(modified)
|
|
441
453
|
>>> ml *= 3
|
|
442
454
|
range(3, 3, 1) <- [0, 1, 2, 0, 1, 2]
|
|
@@ -458,8 +470,8 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
458
470
|
def append(self, item: _T) -> None:
|
|
459
471
|
"""
|
|
460
472
|
>>> def modified(indices, new_items):
|
|
461
|
-
... print(f"range{indices!r} <- {new_items!r}"
|
|
462
|
-
>>> ml = MonitoredFocusList([0,1,2], focus=2)
|
|
473
|
+
... print(f"range{indices!r} <- {new_items!r}")
|
|
474
|
+
>>> ml = MonitoredFocusList([0, 1, 2], focus=2)
|
|
463
475
|
>>> ml.set_validate_contents_modified(modified)
|
|
464
476
|
>>> ml.append(6)
|
|
465
477
|
range(3, 3, 1) <- [6]
|
|
@@ -471,10 +483,10 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
471
483
|
def extend(self, items: Collection[_T]) -> None:
|
|
472
484
|
"""
|
|
473
485
|
>>> def modified(indices, new_items):
|
|
474
|
-
... print(f"range{indices!r} <- {list(new_items)!r}"
|
|
475
|
-
>>> ml = MonitoredFocusList([0,1,2], focus=2)
|
|
486
|
+
... print(f"range{indices!r} <- {list(new_items)!r}")
|
|
487
|
+
>>> ml = MonitoredFocusList([0, 1, 2], focus=2)
|
|
476
488
|
>>> ml.set_validate_contents_modified(modified)
|
|
477
|
-
>>> ml.extend((6,7,8))
|
|
489
|
+
>>> ml.extend((6, 7, 8))
|
|
478
490
|
range(3, 3, 1) <- [6, 7, 8]
|
|
479
491
|
"""
|
|
480
492
|
focus = self._adjust_focus_on_contents_modified(slice(len(self), len(self)), items)
|
|
@@ -483,12 +495,15 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
483
495
|
|
|
484
496
|
def insert(self, index: int, item: _T) -> None:
|
|
485
497
|
"""
|
|
486
|
-
>>> ml = MonitoredFocusList([0,1,2,3], focus=2)
|
|
487
|
-
>>> ml.insert(-1, -1)
|
|
498
|
+
>>> ml = MonitoredFocusList([0, 1, 2, 3], focus=2)
|
|
499
|
+
>>> ml.insert(-1, -1)
|
|
500
|
+
>>> ml
|
|
488
501
|
MonitoredFocusList([0, 1, 2, -1, 3], focus=2)
|
|
489
|
-
>>> ml.insert(0, -2)
|
|
502
|
+
>>> ml.insert(0, -2)
|
|
503
|
+
>>> ml
|
|
490
504
|
MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3)
|
|
491
|
-
>>> ml.insert(3, -3)
|
|
505
|
+
>>> ml.insert(3, -3)
|
|
506
|
+
>>> ml
|
|
492
507
|
MonitoredFocusList([-2, 0, 1, -3, 2, -1, 3], focus=4)
|
|
493
508
|
"""
|
|
494
509
|
focus = self._adjust_focus_on_contents_modified(slice(index, index), [item])
|
|
@@ -497,18 +512,22 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
497
512
|
|
|
498
513
|
def pop(self, index: int = -1) -> _T:
|
|
499
514
|
"""
|
|
500
|
-
>>> ml = MonitoredFocusList([-2,0,1
|
|
501
|
-
>>> ml.pop(3)
|
|
515
|
+
>>> ml = MonitoredFocusList([-2, 0, 1, -3, 2, 3], focus=4)
|
|
516
|
+
>>> ml.pop(3)
|
|
502
517
|
-3
|
|
518
|
+
>>> ml
|
|
503
519
|
MonitoredFocusList([-2, 0, 1, 2, 3], focus=3)
|
|
504
|
-
>>> ml.pop(0)
|
|
520
|
+
>>> ml.pop(0)
|
|
505
521
|
-2
|
|
522
|
+
>>> ml
|
|
506
523
|
MonitoredFocusList([0, 1, 2, 3], focus=2)
|
|
507
|
-
>>> ml.pop(-1)
|
|
524
|
+
>>> ml.pop(-1)
|
|
508
525
|
3
|
|
526
|
+
>>> ml
|
|
509
527
|
MonitoredFocusList([0, 1, 2], focus=2)
|
|
510
|
-
>>> ml.pop(2)
|
|
528
|
+
>>> ml.pop(2)
|
|
511
529
|
2
|
|
530
|
+
>>> ml
|
|
512
531
|
MonitoredFocusList([0, 1], focus=1)
|
|
513
532
|
"""
|
|
514
533
|
focus = self._adjust_focus_on_contents_modified(slice(index, index + 1 or None))
|
|
@@ -518,12 +537,15 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
518
537
|
|
|
519
538
|
def remove(self, value: _T) -> None:
|
|
520
539
|
"""
|
|
521
|
-
>>> ml = MonitoredFocusList([-2,0,1
|
|
522
|
-
>>> ml.remove(-3)
|
|
540
|
+
>>> ml = MonitoredFocusList([-2, 0, 1, -3, 2, -1, 3], focus=4)
|
|
541
|
+
>>> ml.remove(-3)
|
|
542
|
+
>>> ml
|
|
523
543
|
MonitoredFocusList([-2, 0, 1, 2, -1, 3], focus=3)
|
|
524
|
-
>>> ml.remove(-2)
|
|
544
|
+
>>> ml.remove(-2)
|
|
545
|
+
>>> ml
|
|
525
546
|
MonitoredFocusList([0, 1, 2, -1, 3], focus=2)
|
|
526
|
-
>>> ml.remove(3)
|
|
547
|
+
>>> ml.remove(3)
|
|
548
|
+
>>> ml
|
|
527
549
|
MonitoredFocusList([0, 1, 2, -1], focus=2)
|
|
528
550
|
"""
|
|
529
551
|
index = self.index(value)
|
|
@@ -533,8 +555,9 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
533
555
|
|
|
534
556
|
def reverse(self) -> None:
|
|
535
557
|
"""
|
|
536
|
-
>>> ml = MonitoredFocusList([0,1,2,3,4], focus=1)
|
|
537
|
-
>>> ml.reverse()
|
|
558
|
+
>>> ml = MonitoredFocusList([0, 1, 2, 3, 4], focus=1)
|
|
559
|
+
>>> ml.reverse()
|
|
560
|
+
>>> ml
|
|
538
561
|
MonitoredFocusList([4, 3, 2, 1, 0], focus=3)
|
|
539
562
|
"""
|
|
540
563
|
rval = super().reverse()
|
|
@@ -543,8 +566,9 @@ class MonitoredFocusList(MonitoredList[_T], typing.Generic[_T]):
|
|
|
543
566
|
|
|
544
567
|
def sort(self, **kwargs) -> None:
|
|
545
568
|
"""
|
|
546
|
-
>>> ml = MonitoredFocusList([-2,0,1
|
|
547
|
-
>>> ml.sort()
|
|
569
|
+
>>> ml = MonitoredFocusList([-2, 0, 1, -3, 2, -1, 3], focus=4)
|
|
570
|
+
>>> ml.sort()
|
|
571
|
+
>>> ml
|
|
548
572
|
MonitoredFocusList([-3, -2, -1, 0, 1, 2, 3], focus=5)
|
|
549
573
|
"""
|
|
550
574
|
if not self:
|
urwid/widget/padding.py
CHANGED
|
@@ -100,27 +100,27 @@ class Padding(WidgetDecoration[WrappedWidget], typing.Generic[WrappedWidget]):
|
|
|
100
100
|
>>> def pr(w):
|
|
101
101
|
... with set_temporary_encoding("utf-8"):
|
|
102
102
|
... for t in w.render(size).text:
|
|
103
|
-
... print(f"|{t.decode('utf-8')}|"
|
|
104
|
-
>>> pr(Padding(Text(
|
|
103
|
+
... print(f"|{t.decode('utf-8')}|")
|
|
104
|
+
>>> pr(Padding(Text("Head"), ("relative", 20), "pack"))
|
|
105
105
|
| Head |
|
|
106
|
-
>>> pr(Padding(Divider(
|
|
106
|
+
>>> pr(Padding(Divider("-"), left=2, right=1))
|
|
107
107
|
| ---- |
|
|
108
|
-
>>> pr(Padding(Divider(
|
|
108
|
+
>>> pr(Padding(Divider("*"), "center", 3))
|
|
109
109
|
| *** |
|
|
110
|
-
>>> p=Padding(Text(
|
|
110
|
+
>>> p = Padding(Text("1234"), "left", 2, None, 1, 1)
|
|
111
111
|
>>> p
|
|
112
112
|
<Padding fixed/flow widget <Text fixed/flow widget '1234'> left=1 right=1 width=2>
|
|
113
|
-
>>> pr(p)
|
|
113
|
+
>>> pr(p) # align against left
|
|
114
114
|
| 12 |
|
|
115
115
|
| 34 |
|
|
116
|
-
>>> p.align =
|
|
117
|
-
>>> pr(p)
|
|
116
|
+
>>> p.align = "right"
|
|
117
|
+
>>> pr(p) # align against right
|
|
118
118
|
| 12 |
|
|
119
119
|
| 34 |
|
|
120
|
-
>>> pr(Padding(Text(
|
|
120
|
+
>>> pr(Padding(Text("hi\\nthere"), "right", "pack")) # pack text first
|
|
121
121
|
| hi |
|
|
122
122
|
| there|
|
|
123
|
-
>>> pr(Padding(BigText("1,2,3", FontRegistry[
|
|
123
|
+
>>> pr(Padding(BigText("1,2,3", FontRegistry["Thin 3x3"]()), width="clip"))
|
|
124
124
|
| ┐ ┌─┐|
|
|
125
125
|
| │ ┌─┘|
|
|
126
126
|
| ┴ ,└─ |
|
|
@@ -521,25 +521,25 @@ def calculate_left_right_padding(
|
|
|
521
521
|
right -- a fixed number of columns to pad on the right
|
|
522
522
|
|
|
523
523
|
>>> clrp = calculate_left_right_padding
|
|
524
|
-
>>> clrp(15,
|
|
524
|
+
>>> clrp(15, "left", 0, "given", 10, None, 2, 0)
|
|
525
525
|
(2, 3)
|
|
526
|
-
>>> clrp(15,
|
|
526
|
+
>>> clrp(15, "relative", 0, "given", 10, None, 2, 0)
|
|
527
527
|
(2, 3)
|
|
528
|
-
>>> clrp(15,
|
|
528
|
+
>>> clrp(15, "relative", 100, "given", 10, None, 2, 0)
|
|
529
529
|
(5, 0)
|
|
530
|
-
>>> clrp(15,
|
|
530
|
+
>>> clrp(15, "center", 0, "given", 4, None, 2, 0)
|
|
531
531
|
(6, 5)
|
|
532
|
-
>>> clrp(15,
|
|
532
|
+
>>> clrp(15, "left", 0, "clip", 18, None, 0, 0)
|
|
533
533
|
(0, -3)
|
|
534
|
-
>>> clrp(15,
|
|
534
|
+
>>> clrp(15, "right", 0, "clip", 18, None, 0, -1)
|
|
535
535
|
(-2, -1)
|
|
536
|
-
>>> clrp(15,
|
|
536
|
+
>>> clrp(15, "center", 0, "given", 18, None, 2, 0)
|
|
537
537
|
(0, 0)
|
|
538
|
-
>>> clrp(20,
|
|
538
|
+
>>> clrp(20, "left", 0, "relative", 60, None, 0, 0)
|
|
539
539
|
(0, 8)
|
|
540
|
-
>>> clrp(20,
|
|
540
|
+
>>> clrp(20, "relative", 30, "relative", 60, None, 0, 0)
|
|
541
541
|
(2, 6)
|
|
542
|
-
>>> clrp(20,
|
|
542
|
+
>>> clrp(20, "relative", 30, "relative", 60, 14, 0, 0)
|
|
543
543
|
(2, 4)
|
|
544
544
|
"""
|
|
545
545
|
if width_type == WHSettings.RELATIVE:
|