Skip to content

Conversation

@vyagh
Copy link

@vyagh vyagh commented Jan 21, 2026

Fixes #8

Summary

This PR replaces all 11 usages of the deprecated Gtk.Widget.get_allocation() with valid GTK4 alternatives.

Approach

Per the documentation, i've used two replacement patterns depending on the use case:

Widget dimensions only: get_width() / get_height()
Position relative to another widget: compute_bounds(target)

issue mentioned compute_bounds, but the docs had the simpler get_width()/get_height() when only dimensions are needed, which was the case for 9 of the 11 usages

Changes

activity.py – preview generation uses canvas/widget dimensions
tray.py – Scroll calculations now use viewport dimensions directly, scroll_to_item uses compute_bounds for item position relative to traybar
palettewindow.py – Removed an unused allocation fetch because the value was never read
toolbarbox.pycompute_bounds gets button position for drawing highlight lines, with fallback if bounds computation fails

Testing

11 failed, 335 passed, 28 warnings

The 11 failures are pre-existing issues in test_combobox.py and test_icon.py
These are unrelated to this change, they're attribute errors from GTK4 API differences.
No new failures or warnings introduced.

Copy link
Member

@chimosky chimosky left a comment

Choose a reason for hiding this comment

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

Edit your commit message and remove "Files modified", that's what the diff is for.

return

allocation = self.parent.get_allocation()
# Removed unused get_allocation() call (deprecated in GTK 4.12)
Copy link
Member

Choose a reason for hiding this comment

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

Redundant comment, please remove.

Gtk.Widget.do_snapshot(self, snapshot)

button_alloc = self._toolbar_button.get_allocation()
# Get button bounds relative to self for drawing highlight lines
Copy link
Member

Choose a reason for hiding this comment

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

Another redundant comment.


# Get the item's allocation
allocation = item.get_allocation()
# Get item bounds relative to traybar for scroll calculation
Copy link
Member

Choose a reason for hiding this comment

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

Redundant comment.

@vyagh vyagh force-pushed the fix/replace-get-allocation branch from 992fcf8 to 85e5b67 Compare January 21, 2026 18:16
@vyagh
Copy link
Author

vyagh commented Jan 21, 2026

removed the redundant comments and cleaned up the commit message

Copy link
Member

@chimosky chimosky left a comment

Choose a reason for hiding this comment

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

Just to be clear, your earlier commit message was better, except the part where you mentioned the files you modified, which is why I asked you to remove that part, I'm shocked you changed it to this, it's way more scanty and can be better.

Also don't include issue numbers in commit messages, see making commits.

# GTK4 approach to getting preview
allocation = self.canvas.get_allocation()
if allocation.width <= 0 or allocation.height <= 0:
# Get canvas dimensions for preview
Copy link
Member

Choose a reason for hiding this comment

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

You said you removed these, but they're still here.

widget_allocation.width,
widget_allocation.height,
)
# Get drawable widget dimensions for preview surface
Copy link
Member

Choose a reason for hiding this comment

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

This too.

Replace deprecated Gtk.Widget.get_allocation() with modern GTK4 APIs:
- compute_bounds() for relative widget positions
- get_width()/get_height() for widget dimensions

According to GTK4 documentation, get_width()/get_height() is the recommended
replacement when only dimensions are needed. compute_bounds() is used
when relative positioning between widgets is required.
@vyagh vyagh force-pushed the fix/replace-get-allocation branch from 85e5b67 to c148dec Compare January 22, 2026 05:27
@vyagh
Copy link
Author

vyagh commented Jan 22, 2026

Totally Misunderstood on the comments, i thought you only wanted the ones you directly pointed out to be removed, missed that you meant all the explanatory ones. fixed now along with the commit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace use of get_allocation

2 participants