Skip to content

Fix handling of WEIGHT selectable items in the Pile#1006

Merged
penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:bug_scrollable_no_size
Apr 22, 2025
Merged

Fix handling of WEIGHT selectable items in the Pile#1006
penguinolog merged 1 commit into
urwid:masterfrom
penguinolog:bug_scrollable_no_size

Conversation

@penguinolog
Copy link
Copy Markdown
Collaborator

In the case of not enough rows for full render,
focused widget should receive priority
and need to be rendered in the price of dropping other widgets.

For the optimization purposes and better code organization, protected _get_flow_rows_sizes was detached from the get_rows_sizes. It should not be called manually.

Fix #1005

Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment
  • I've included docstrings and/or documentation and/or examples for my code (if this is a new feature)

Comment thread urwid/widget/columns.py
return col

def rows(self, size: tuple[int] | tuple[int, int], focus: bool = False) -> int:
def rows(self, size: tuple[int], focus: bool = False) -> int:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix type annotation. While not officially tuple[int, int] is accepted, it's incorrect behaviour.

Comment thread urwid/widget/pile.py
"""
Return a size appropriate for passing to self.contents[i][0].render
"""
warnings.warn(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it maybe questionable, but method is not used and not covered by tests.

Comment thread urwid/widget/pile.py
heights: dict[int, int] = {}
weighted: dict[int, int] = {}
w_h_args: dict[int, tuple[int, int] | tuple[int] | tuple[()]] = {}
focus_position = self.focus_position
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-cache, asking self.focus on each iteration is expensive

@penguinolog penguinolog force-pushed the bug_scrollable_no_size branch from e4416dc to f582c0a Compare April 15, 2025 18:52
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 15, 2025

Pull Request Test Coverage Report for Build 14477399840

Details

  • 85 of 90 (94.44%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.05%) to 74.869%

Changes Missing Coverage Covered Lines Changed/Added Lines %
urwid/widget/pile.py 83 88 94.32%
Files with Coverage Reduction New Missed Lines %
urwid/widget/padding.py 1 86.82%
Totals Coverage Status
Change from base Build 14463996647: 0.05%
Covered Lines: 9303
Relevant Lines: 12472

💛 - Coveralls

In the case of not enough rows for full render,
focused widget should receive priority
and need to be rendered in the price of dropping other widgets.

For the optimization purposes and better code organization,
protected `_get_flow_rows_sizes` was detached from the `get_rows_sizes`.
It should not be called manually.

Fix urwid#1005
@penguinolog penguinolog force-pushed the bug_scrollable_no_size branch from f582c0a to d2b008b Compare April 15, 2025 19:06
Comment thread urwid/widget/pile.py
for i, (w, (f, height)) in enumerate(self.contents):
if isinstance(w, Widget):
w_sizing = w.sizing()
else:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope to kill this warning in the next major release.
Following documentation for 2.0, all widgets have to subclass Widget, but some users not adopted code due to no warnings from the urwid side

Comment thread urwid/widget/pile.py
tuple(w_h_args[idx] for idx in range(len(w_h_args))),
)

def _get_flow_rows_sizes(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while code of this method is close to the get_rows_sizes, dedicated "semi copy-paste" should work faster and easier to debug

@penguinolog penguinolog merged commit 0b3d8d3 into urwid:master Apr 22, 2025
29 checks passed
@penguinolog penguinolog deleted the bug_scrollable_no_size branch April 22, 2025 09:39
@penguinolog penguinolog changed the title Fix handling of WEIGHT selectable items in the Pile Fix handling of WEIGHT selectable items in the Pile Apr 22, 2025
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request May 11, 2025
Urwid 3.0.2
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Bugfix: Corner case: Scrollbar render for only 1 row height by @penguinolog in urwid/urwid#1021

Urwid 3.0.1
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Packaging: drop setup.py and adjust requirements by @penguinolog in urwid/urwid#1018
  Not updated `setup.py` lead to wrong metadata and mark of release 3.0.0 as Python 3.7 compatible.
  Since urwid is distribluted in the pre-packaged format (wheel),
  missing `setup.py` will not affect old toolchain users except special cases (manually enforced sdist usage).
* Python 3.14 compatibility: adjust `AsyncioEventLoop` by @penguinolog in urwid/urwid#1019

Urwid 3.0.0
===========

2025-05-06

Breaking Changes ⚠
++++++++++++++++++
* Drop deprecated `__super` property by @penguinolog in urwid/urwid#956
* Drop deprecated `FlowWidget`, `BoxWidget` and `FixedWidget` widgets by @penguinolog in urwid/urwid#955
* Remove deprecated protected getter methods from the `Canvas` and `AttrSpec` by @penguinolog in urwid/urwid#958
* Remove support for the `bytes` based fonts by @penguinolog in urwid/urwid#961
* Remove deprecated `TermScroller` by @penguinolog in urwid/urwid#960
* Remove deprecated protected getter methods from the decoration widgets by @penguinolog in urwid/urwid#959
* Remove deprecated protected getter methods from the container widgets by @penguinolog in urwid/urwid#957
* Remove deprecated protected setters in the decoration widgets by @penguinolog in urwid/urwid#968
* Remove deprecated protected methods from the container widgets by @penguinolog in urwid/urwid#970
* Remove deprecated protected method `_set_done` from the `ProgressBar` by @penguinolog in urwid/urwid#971

New features 🗹
+++++++++++++++
* API Extension: make `CommandMap` `MutableMapping` by @penguinolog in urwid/urwid#969
* Make sizing computation much faster for nested containers by @ogayot in urwid/urwid#991
* `MetaSignals` subclass `ABCMeta` by @penguinolog in urwid/urwid#962

Deprecations ⚡
+++++++++++++++
* `MetaSuper` should be the last base for classes by @penguinolog in urwid/urwid#972
* Announce deprecated API removal versions by @penguinolog in urwid/urwid#999

Bug fixes 🕷
++++++++++++
* Fix handling of WEIGHT selectable items in the `Pile` by @penguinolog in urwid/urwid#1006

Refactoring 🛠
++++++++++++++
* Refactoring: micro optimizations of iterable items reconstruction by @penguinolog in urwid/urwid#1009

New Contributors
++++++++++++++++
* @ogayot made their first contribution in urwid/urwid#991
msk pushed a commit to msk/pkgsrc that referenced this pull request May 11, 2026
Urwid 3.0.2
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Bugfix: Corner case: Scrollbar render for only 1 row height by @penguinolog in urwid/urwid#1021

Urwid 3.0.1
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Packaging: drop setup.py and adjust requirements by @penguinolog in urwid/urwid#1018
  Not updated `setup.py` lead to wrong metadata and mark of release 3.0.0 as Python 3.7 compatible.
  Since urwid is distribluted in the pre-packaged format (wheel),
  missing `setup.py` will not affect old toolchain users except special cases (manually enforced sdist usage).
* Python 3.14 compatibility: adjust `AsyncioEventLoop` by @penguinolog in urwid/urwid#1019

Urwid 3.0.0
===========

2025-05-06

Breaking Changes ⚠
++++++++++++++++++
* Drop deprecated `__super` property by @penguinolog in urwid/urwid#956
* Drop deprecated `FlowWidget`, `BoxWidget` and `FixedWidget` widgets by @penguinolog in urwid/urwid#955
* Remove deprecated protected getter methods from the `Canvas` and `AttrSpec` by @penguinolog in urwid/urwid#958
* Remove support for the `bytes` based fonts by @penguinolog in urwid/urwid#961
* Remove deprecated `TermScroller` by @penguinolog in urwid/urwid#960
* Remove deprecated protected getter methods from the decoration widgets by @penguinolog in urwid/urwid#959
* Remove deprecated protected getter methods from the container widgets by @penguinolog in urwid/urwid#957
* Remove deprecated protected setters in the decoration widgets by @penguinolog in urwid/urwid#968
* Remove deprecated protected methods from the container widgets by @penguinolog in urwid/urwid#970
* Remove deprecated protected method `_set_done` from the `ProgressBar` by @penguinolog in urwid/urwid#971

New features 🗹
+++++++++++++++
* API Extension: make `CommandMap` `MutableMapping` by @penguinolog in urwid/urwid#969
* Make sizing computation much faster for nested containers by @ogayot in urwid/urwid#991
* `MetaSignals` subclass `ABCMeta` by @penguinolog in urwid/urwid#962

Deprecations ⚡
+++++++++++++++
* `MetaSuper` should be the last base for classes by @penguinolog in urwid/urwid#972
* Announce deprecated API removal versions by @penguinolog in urwid/urwid#999

Bug fixes 🕷
++++++++++++
* Fix handling of WEIGHT selectable items in the `Pile` by @penguinolog in urwid/urwid#1006

Refactoring 🛠
++++++++++++++
* Refactoring: micro optimizations of iterable items reconstruction by @penguinolog in urwid/urwid#1009

New Contributors
++++++++++++++++
* @ogayot made their first contribution in urwid/urwid#991
jperkin pushed a commit to TritonDataCenter/pkgsrc that referenced this pull request May 14, 2026
Urwid 3.0.2
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Bugfix: Corner case: Scrollbar render for only 1 row height by @penguinolog in urwid/urwid#1021

Urwid 3.0.1
===========

2025-05-07

Bug fixes 🕷
++++++++++++
* Packaging: drop setup.py and adjust requirements by @penguinolog in urwid/urwid#1018
  Not updated `setup.py` lead to wrong metadata and mark of release 3.0.0 as Python 3.7 compatible.
  Since urwid is distribluted in the pre-packaged format (wheel),
  missing `setup.py` will not affect old toolchain users except special cases (manually enforced sdist usage).
* Python 3.14 compatibility: adjust `AsyncioEventLoop` by @penguinolog in urwid/urwid#1019

Urwid 3.0.0
===========

2025-05-06

Breaking Changes ⚠
++++++++++++++++++
* Drop deprecated `__super` property by @penguinolog in urwid/urwid#956
* Drop deprecated `FlowWidget`, `BoxWidget` and `FixedWidget` widgets by @penguinolog in urwid/urwid#955
* Remove deprecated protected getter methods from the `Canvas` and `AttrSpec` by @penguinolog in urwid/urwid#958
* Remove support for the `bytes` based fonts by @penguinolog in urwid/urwid#961
* Remove deprecated `TermScroller` by @penguinolog in urwid/urwid#960
* Remove deprecated protected getter methods from the decoration widgets by @penguinolog in urwid/urwid#959
* Remove deprecated protected getter methods from the container widgets by @penguinolog in urwid/urwid#957
* Remove deprecated protected setters in the decoration widgets by @penguinolog in urwid/urwid#968
* Remove deprecated protected methods from the container widgets by @penguinolog in urwid/urwid#970
* Remove deprecated protected method `_set_done` from the `ProgressBar` by @penguinolog in urwid/urwid#971

New features 🗹
+++++++++++++++
* API Extension: make `CommandMap` `MutableMapping` by @penguinolog in urwid/urwid#969
* Make sizing computation much faster for nested containers by @ogayot in urwid/urwid#991
* `MetaSignals` subclass `ABCMeta` by @penguinolog in urwid/urwid#962

Deprecations ⚡
+++++++++++++++
* `MetaSuper` should be the last base for classes by @penguinolog in urwid/urwid#972
* Announce deprecated API removal versions by @penguinolog in urwid/urwid#999

Bug fixes 🕷
++++++++++++
* Fix handling of WEIGHT selectable items in the `Pile` by @penguinolog in urwid/urwid#1006

Refactoring 🛠
++++++++++++++
* Refactoring: micro optimizations of iterable items reconstruction by @penguinolog in urwid/urwid#1009

New Contributors
++++++++++++++++
* @ogayot made their first contribution in urwid/urwid#991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Pile incorrectly arrange item sizes in the case of SELECTABLE focused widget not fit in maxrow

2 participants