Skip to content
Merged
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: 15 additions & 4 deletions anura/widgets/welcome_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def __init__(self, **kwargs: object) -> None:
self.connect_tracked(self.drop_button, "clicked", self._on_drop_button_clicked)
self._setup_drop_target()

# Initialize drop_button's accessibility expanded state to False
if self.drop_button:
self.drop_button.update_state([Gtk.AccessibleState.EXPANDED], [False])

def _setup_drop_target(self) -> None:
"""Configure drop target with DropTargetAsync and explicit text/uri-list.

Expand Down Expand Up @@ -84,16 +88,21 @@ def _setup_drop_target(self) -> None:

self.add_controller(self._drop_target)

def _on_drop_button_clicked(self, _: Gtk.Button) -> None:
def _on_drop_button_clicked(self, _button: Gtk.Button) -> None:
"""Toggle the visibility of the dedicated drop area."""
try:
is_revealed = self.drop_revealer.get_reveal_child()
self.drop_revealer.set_reveal_child(not is_revealed)
if not is_revealed:
new_revealed = not is_revealed
self.drop_revealer.set_reveal_child(new_revealed)
if new_revealed:
self.drop_button.add_css_class("suggested-action")
self.drop_button.set_tooltip_text(_("Hide drop area"))
self.drop_button.update_state([Gtk.AccessibleState.EXPANDED], [True])
else:
self.drop_button.remove_css_class("suggested-action")
except (AttributeError, RuntimeError) as e:
self.drop_button.set_tooltip_text(_("Drop image here"))
self.drop_button.update_state([Gtk.AccessibleState.EXPANDED], [False])
except Exception as e:
logger.exception(f"Anura: Failed to handle drop button click: {e}")

def _on_dnd_enter(self, target: Gtk.DropTargetAsync, drop: Gdk.Drop, x: float, y: float) -> Gdk.DragAction:
Expand Down Expand Up @@ -269,6 +278,8 @@ def reset_drop_area_state(self) -> None:
self.hide_spinner()
self.drop_revealer.set_reveal_child(False)
self.drop_button.remove_css_class("suggested-action")
self.drop_button.set_tooltip_text(_("Drop image here"))
self.drop_button.update_state([Gtk.AccessibleState.EXPANDED], [False])
self.welcome.set_description(_("Extract text from anywhere"))

def set_status(self, status_msg: str) -> None:
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ def pytest_sessionfinish(session, exitstatus):
try:
tr = session.config.pluginmanager.get_plugin("terminalreporter")
if tr is not None:
# Verbose printing of test failure tracebacks since os._exit() suppresses standard reporting
failed_reports = tr.stats.get('failed', [])
for rep in failed_reports:
print("\n" + "="*80)
print(f"FAILURE IN {rep.nodeid}:")
print("="*80)
print(rep.longrepr)
# Also print captured stdout/stderr
for secname, secdata in rep.sections:
print(f"--- {secname} ---")
print(secdata)
print("="*80 + "\n")
tr.summary_stats()
sys.stdout.flush()
sys.stderr.flush()
Expand Down
29 changes: 29 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

pytest.importorskip("gi")

from gettext import gettext as _
from unittest.mock import MagicMock, patch

import gi
Expand Down Expand Up @@ -146,16 +147,40 @@ def test_spinner_state(self, widget):
@pytest.mark.gtk
def test_drop_button_toggle(self, widget):
"""Test that the drop area visibility is toggled by the button."""
import sys
initial_revealed = widget.drop_revealer.get_reveal_child()
print(f"\n[DEBUG] initial_revealed = {initial_revealed}")
print(f"[DEBUG] initial tooltip = '{widget.drop_button.get_tooltip_text()}'")
sys.stdout.flush()

# In GTK4, we use activate() or emit("clicked")
widget.drop_button.emit("clicked")

tooltip_1 = widget.drop_button.get_tooltip_text() or ""
print(f"[DEBUG] after first click, revealed = {widget.drop_revealer.get_reveal_child()}")
print(f"[DEBUG] after first click, has suggested-action = {widget.drop_button.has_css_class('suggested-action')}")
print(f"[DEBUG] after first click, tooltip = '{tooltip_1}'")
sys.stdout.flush()

assert widget.drop_revealer.get_reveal_child() == (not initial_revealed)
assert widget.drop_button.has_css_class("suggested-action")

# Robust assertion for tooltip text to support localized environments smoothly
assert "Hide" in tooltip_1 or tooltip_1 == _("Hide drop area")

widget.drop_button.emit("clicked")

tooltip_2 = widget.drop_button.get_tooltip_text() or ""
print(f"[DEBUG] after second click, revealed = {widget.drop_revealer.get_reveal_child()}")
print(f"[DEBUG] after second click, has suggested-action = {widget.drop_button.has_css_class('suggested-action')}")
print(f"[DEBUG] after second click, tooltip = '{tooltip_2}'")
sys.stdout.flush()

assert widget.drop_revealer.get_reveal_child() == initial_revealed
assert not widget.drop_button.has_css_class("suggested-action")

assert "Drop" in tooltip_2 or "Trascina" in tooltip_2 or tooltip_2 == _("Drop image here")

@pytest.mark.gtk
def test_language_changed_signal(self, widget):
"""Test that language change updates the UI and settings."""
Expand All @@ -180,6 +205,10 @@ def test_reset_drop_area_state(self, widget):
assert widget.spinner.get_visible() is False
assert not widget.drop_button.has_css_class("suggested-action")

# Robust assertion for tooltip text to support localized environments smoothly
tooltip = widget.drop_button.get_tooltip_text() or ""
assert "Drop" in tooltip or "Trascina" in tooltip or tooltip == _("Drop image here")


class TestLanguagePopoverEnterprise:
"""
Expand Down
Loading