Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/sugar4/activity/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,9 @@ def get_preview(self):
return None

try:
# GTK4 approach to getting preview
allocation = self.canvas.get_allocation()
if allocation.width <= 0 or allocation.height <= 0:
canvas_width = self.canvas.get_width()
canvas_height = self.canvas.get_height()
if canvas_width <= 0 or canvas_height <= 0:
return None

# For GTK4, we need to use a different approach since snapshot()
Expand All @@ -918,12 +918,9 @@ def get_preview(self):
drawing_widget = self._find_drawable_widget(self.canvas)

if drawing_widget and hasattr(drawing_widget, "snapshot"):
# Use the drawable widget for preview
widget_allocation = drawing_widget.get_allocation()
canvas_width, canvas_height = (
widget_allocation.width,
widget_allocation.height,
)
widget_width = drawing_widget.get_width()
widget_height = drawing_widget.get_height()
canvas_width, canvas_height = widget_width, widget_height

# Create Cairo surface for the widget
screenshot_surface = cairo.ImageSurface(
Expand All @@ -937,9 +934,7 @@ def get_preview(self):
# Try to render the widget
try:
snapshot = Gtk.Snapshot()
drawing_widget.snapshot(
snapshot, widget_allocation.width, widget_allocation.height
)
drawing_widget.snapshot(snapshot, widget_width, widget_height)

# Convert snapshot to cairo surface
# For now, we'll create a basic preview
Expand Down
1 change: 0 additions & 1 deletion src/sugar4/graphics/palettewindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,6 @@ def draw_rectangle(self, cr, palette):
if not self.parent:
return

allocation = self.parent.get_allocation()
context = self.parent.get_style_context()
context.add_class("toolitem")
context.add_class("palette-down")
Expand Down
18 changes: 12 additions & 6 deletions src/sugar4/graphics/toolbarbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,17 @@ def do_snapshot(self, snapshot):
"""Render palette using snapshot drawing."""
Gtk.Widget.do_snapshot(self, snapshot)

button_alloc = self._toolbar_button.get_allocation()
success, bounds = self._toolbar_button.compute_bounds(self)
if success:
button_x = bounds.get_x()
button_width = bounds.get_width()
else:
button_x = 0
button_width = self._toolbar_button.get_width()

my_width = self.get_width()

if my_width > 0:
if my_width > 0 and button_width > 0:
color = Gdk.RGBA()
color.red = 0.7
color.green = 0.7
Expand All @@ -451,15 +458,14 @@ def do_snapshot(self, snapshot):
line_width = style.FOCUS_LINE_WIDTH * 2

rect1 = Graphene.Rect()
rect1.init(0, 0, button_alloc.x + style.FOCUS_LINE_WIDTH, line_width)
rect1.init(0, 0, button_x + style.FOCUS_LINE_WIDTH, line_width)
snapshot.append_color(color, rect1)

rect2 = Graphene.Rect()
rect2.init(
button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH,
button_x + button_width - style.FOCUS_LINE_WIDTH,
0,
my_width
- (button_alloc.x + button_alloc.width - style.FOCUS_LINE_WIDTH),
my_width - (button_x + button_width - style.FOCUS_LINE_WIDTH),
line_width,
)
snapshot.append_color(color, rect2)
Expand Down
41 changes: 23 additions & 18 deletions src/sugar4/graphics/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ def scroll_to_item(self, item):
logging.warning("Item not found in tray children")
return

# Get the item's allocation
allocation = item.get_allocation()
success, bounds = item.compute_bounds(self.traybar)
if not success:
return

if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment()
start = allocation.x
stop = allocation.x + allocation.width
start = bounds.get_x()
stop = bounds.get_x() + bounds.get_width()
else:
adj = self.get_vadjustment()
start = allocation.y
stop = allocation.y + allocation.height
start = bounds.get_y()
stop = bounds.get_y() + bounds.get_height()

# Scroll if needed
if start < adj.get_value():
Expand All @@ -116,26 +118,28 @@ def scroll_to_item(self, item):

def _scroll_next(self):
"""Scroll to next page."""
allocation = self.get_allocation()
if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment()
new_value = adj.get_value() + allocation.width
adj.set_value(min(new_value, adj.get_upper() - allocation.width))
width = self.get_width()
new_value = adj.get_value() + width
adj.set_value(min(new_value, adj.get_upper() - width))
else:
adj = self.get_vadjustment()
new_value = adj.get_value() + allocation.height
adj.set_value(min(new_value, adj.get_upper() - allocation.height))
height = self.get_height()
new_value = adj.get_value() + height
adj.set_value(min(new_value, adj.get_upper() - height))

def _scroll_previous(self):
"""Scroll to previous page."""
allocation = self.get_allocation()
if self.orientation == Gtk.Orientation.HORIZONTAL:
adj = self.get_hadjustment()
new_value = adj.get_value() - allocation.width
width = self.get_width()
new_value = adj.get_value() - width
adj.set_value(max(adj.get_lower(), new_value))
else:
adj = self.get_vadjustment()
new_value = adj.get_value() - allocation.height
height = self.get_height()
new_value = adj.get_value() - height
adj.set_value(max(adj.get_lower(), new_value))

def do_get_preferred_width(self):
Expand Down Expand Up @@ -164,16 +168,17 @@ def _size_changed_cb(self, widget, pspec):
self._update_scrollable_state()

def _update_scrollable_state(self):
allocation = self.get_allocation()
if allocation.width <= 1 and allocation.height <= 1:
width = self.get_width()
height = self.get_height()
if width <= 1 and height <= 1:
return

traybar_min, traybar_nat = self.traybar.get_preferred_size()

if self.orientation == Gtk.Orientation.HORIZONTAL:
scrollable = traybar_nat.width > allocation.width
scrollable = traybar_nat.width > width
else:
scrollable = traybar_nat.height > allocation.height
scrollable = traybar_nat.height > height

if scrollable != self._scrollable:
self._scrollable = scrollable
Expand Down