-
Notifications
You must be signed in to change notification settings - Fork 12
fix: replace deprecated get_allocation with GTK4 alternatives #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
chimosky
left a comment
There was a problem hiding this 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.
src/sugar4/graphics/palettewindow.py
Outdated
| return | ||
|
|
||
| allocation = self.parent.get_allocation() | ||
| # Removed unused get_allocation() call (deprecated in GTK 4.12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant comment, please remove.
src/sugar4/graphics/toolbarbox.py
Outdated
| Gtk.Widget.do_snapshot(self, snapshot) | ||
|
|
||
| button_alloc = self._toolbar_button.get_allocation() | ||
| # Get button bounds relative to self for drawing highlight lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another redundant comment.
src/sugar4/graphics/tray.py
Outdated
|
|
||
| # Get the item's allocation | ||
| allocation = item.get_allocation() | ||
| # Get item bounds relative to traybar for scroll calculation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant comment.
992fcf8 to
85e5b67
Compare
|
removed the redundant comments and cleaned up the commit message |
chimosky
left a comment
There was a problem hiding this 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.
src/sugar4/activity/activity.py
Outdated
| # GTK4 approach to getting preview | ||
| allocation = self.canvas.get_allocation() | ||
| if allocation.width <= 0 or allocation.height <= 0: | ||
| # Get canvas dimensions for preview |
There was a problem hiding this comment.
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.
src/sugar4/activity/activity.py
Outdated
| widget_allocation.width, | ||
| widget_allocation.height, | ||
| ) | ||
| # Get drawable widget dimensions for preview surface |
There was a problem hiding this comment.
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.
85e5b67 to
c148dec
Compare
|
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. |
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 simplerget_width()/get_height()when only dimensions are needed, which was the case for 9 of the 11 usagesChanges
activity.py – preview generation uses canvas/widget dimensions
tray.py – Scroll calculations now use viewport dimensions directly, scroll_to_item uses
compute_boundsfor item position relative to traybarpalettewindow.py – Removed an unused allocation fetch because the value was never read
toolbarbox.py –
compute_boundsgets button position for drawing highlight lines, with fallback if bounds computation failsTesting
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.