Skip to content

Commit

Permalink
Do not use deprecated positioning in the code and examples
Browse files Browse the repository at this point in the history
Deprecated, but still supported:
* "fixed left"
* "fixed right"
* "fixed top"
* "fixed bottom"
  • Loading branch information
Aleksei Stepanov committed Apr 10, 2024
1 parent cd3ead5 commit aaecefb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/dialog.py
Expand Up @@ -68,8 +68,8 @@ def __init__(self, text, height: int | str, width: int | str, body=None) -> None
w = self.frame

# pad area around listbox
w = urwid.Padding(w, ("fixed left", 2), ("fixed right", 2))
w = urwid.Filler(w, ("fixed top", 1), ("fixed bottom", 1))
w = urwid.Padding(w, urwid.LEFT, left=2, right=2)
w = urwid.Filler(w, urwid.TOP, urwid.RELATIVE_100, top=1, bottom=1)
w = urwid.AttrMap(w, "body")

# "shadow" effect
Expand Down
30 changes: 26 additions & 4 deletions examples/graph.py
Expand Up @@ -209,8 +209,30 @@ def main_shadow(self, w):
bg = urwid.AttrMap(urwid.SolidFill("▒"), "screen edge")
shadow = urwid.AttrMap(urwid.SolidFill(" "), "main shadow")

bg = urwid.Overlay(shadow, bg, ("fixed left", 3), ("fixed right", 1), ("fixed top", 2), ("fixed bottom", 1))
w = urwid.Overlay(w, bg, ("fixed left", 2), ("fixed right", 3), ("fixed top", 1), ("fixed bottom", 2))
bg = urwid.Overlay(
shadow,
bg,
urwid.LEFT,
urwid.RELATIVE_100,
urwid.TOP,
urwid.RELATIVE_100,
left=3,
right=1,
top=2,
bottom=1,
)
w = urwid.Overlay(
w,
bg,
urwid.LEFT,
urwid.RELATIVE_100,
urwid.TOP,
urwid.RELATIVE_100,
left=2,
right=3,
top=1,
bottom=2,
)
return w

def bar_graph(self, smooth=False):
Expand Down Expand Up @@ -288,10 +310,10 @@ def graph_controls(self):
def main_window(self):
self.graph = self.bar_graph()
self.graph_wrap = urwid.WidgetWrap(self.graph)
vline = urwid.AttrMap(urwid.SolidFill("\u2502"), "line")
vline = urwid.AttrMap(urwid.SolidFill(""), "line")
c = self.graph_controls()
w = urwid.Columns([(urwid.WEIGHT, 2, self.graph_wrap), (1, vline), c], dividechars=1, focus_column=2)
w = urwid.Padding(w, ("fixed left", 1), ("fixed right", 0))
w = urwid.Padding(w, urwid.LEFT, left=1)
w = urwid.AttrMap(w, "body")
w = urwid.LineBox(w)
w = urwid.AttrMap(w, "line")
Expand Down
6 changes: 4 additions & 2 deletions urwid/widget/padding.py
Expand Up @@ -40,12 +40,14 @@ def __init__(
self,
w: WrappedWidget,
align: (
Literal["left", "center", "right"] | Align | tuple[Literal["relative", WHSettings.RELATIVE], int]
Literal["left", "center", "right"]
| Align
| tuple[Literal["relative", WHSettings.RELATIVE, "fixed left", "fixed right"], int]
) = Align.LEFT,
width: (
int
| Literal["pack", "clip", WHSettings.PACK, WHSettings.CLIP]
| tuple[Literal["relative", WHSettings.RELATIVE], int]
| tuple[Literal["relative", WHSettings.RELATIVE, "fixed left", "fixed right"], int]
) = RELATIVE_100,
min_width: int | None = None,
left: int = 0,
Expand Down
29 changes: 16 additions & 13 deletions urwid/widget/popup.py
Expand Up @@ -24,7 +24,7 @@

from urwid.canvas import CompositeCanvas

from .constants import Sizing
from .constants import Align, Sizing, VAlign
from .overlay import Overlay
from .widget import delegate_to_widget_mixin
from .widget_decoration import WidgetDecoration
Expand Down Expand Up @@ -86,8 +86,7 @@ def render(self, size, focus: bool = False) -> CompositeCanvas | Canvas:


class PopUpTarget(WidgetDecoration[WrappedWidget]):
# FIXME: this whole class is a terrible hack and must be fixed
# when layout and rendering are separated
# FIXME: this whole class is a terrible hack and must be fixed when layout and rendering are separated
_sizing = frozenset((Sizing.BOX,))
_selectable = True

Expand All @@ -105,19 +104,23 @@ def _update_overlay(self, size: tuple[int, int], focus: bool) -> None:
if self._pop_up != w:
self._pop_up = w
self._current_widget = Overlay(
w,
self._original_widget,
("fixed left", left),
overlay_width,
("fixed top", top),
overlay_height,
top_w=w,
bottom_w=self._original_widget,
align=Align.LEFT,
width=overlay_width,
valign=VAlign.TOP,
height=overlay_height,
left=left,
top=top,
)
else:
self._current_widget.set_overlay_parameters(
("fixed left", left),
overlay_width,
("fixed top", top),
overlay_height,
align=Align.LEFT,
width=overlay_width,
valign=VAlign.TOP,
height=overlay_height,
left=left,
top=top,
)
else:
self._pop_up = None
Expand Down

0 comments on commit aaecefb

Please sign in to comment.