Skip to content

Commit

Permalink
Add dbus support for widget screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Nov 23, 2024
1 parent 30d80ea commit a9571d7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
15 changes: 14 additions & 1 deletion test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

from qtile_extras.popup.toolkit import PopupRelativeLayout, PopupText

ICON = Path(__file__).parent / "resources" / "qtile.rgba"

# the sizes for outputs
WIDTH = 800
HEIGHT = 600
Expand Down Expand Up @@ -575,6 +577,17 @@ def __init__(self, popup, name, *args):
self.popup = popup
self.servicename = name

with open(ICON, "rb") as f:
self.icon = f.read()

arr = bytearray(self.icon)
for i in range(0, len(arr), 4):
r, g, b, a = arr[i : i + 4]
arr[i] = a
arr[i + 1 : i + 4] = bytearray([r, g, b])

self.icon = bytes(arr)

@method()
def Activate(self, x: "i", y: "i"): # noqa: F821, N802
self.popup.update_controls(textbox="Activated")
Expand All @@ -585,7 +598,7 @@ def IconName(self) -> "s": # noqa: F821, N802

@dbus_property(PropertyAccess.READ)
def IconPixmap(self) -> "a(iiay)": # noqa: F821, N802
return [[32, 32, bytes([100] * (32 * 32 * 4))]]
return [[32, 32, self.icon]]

@dbus_property(PropertyAccess.READ)
def AttentionIconPixmap(self) -> "a(iiay)": # noqa: F821, N802
Expand Down
1 change: 1 addition & 0 deletions test/resources/qtile.rgba
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������T���*���)���)���)���)���0���e�������������������������������������������������������������������������������������������>���)���)���)���)���)���)���)���)���)���)���U�������������������������������������������������������������������������������)���)���)���)���)���)���)���)���)���)���)���)���)���3�����������������������������������������������������������������������)���)���)���)���0���r�������������������a���*���)���)���)���,���������������������������������������������������������������*���)���)���)���o�����������������������������������O���)���)���)���2�������������������������������������������������������?���)���)���)�����������������������������������������������_���)���)���)���e���������������������������������������������������)���)���)���n���������������������������������������������������B���)���)���)�����������������������������������������������V���)���)���/�����������������������������������������������������������)���)���)�����������������������������������������������+���)���)���m�����������������������������������������������������������;���)���)���M�������������������������������������������)���)���)�������������������������������d���E���������������������������j���)���)���-�������������������������������������������)���)���)���������������������������e���)���)���>���������������������������)���)���)�������������������������������������������)���)���)���������������������������F���)���)���)���>�����������������������)���)���)�������������������������������������������)���)���)�������������������������������>���)���)���)���>�������������������)���)���5�������������������������������������������0���)���)���[�������������������������������>���)���)���)���>�������������������������������������������������������������������g���)���)���)�����������������������������������?���)���)���)���<�������������������������������������������������������������������)���)���)���L�����������������������������������>���)���)���)���>���������������������������������������������������������������V���)���)���)���_�����������������������������������>���)���)���)���>���������������������������������������������������������������3���)���)���)���@�����������������������������������=���)���)���)���U���������������������������������������������������������������,���)���)���)���)���5���`������z�������������������=���)���)�����������������������������������������������������������������������3���)���)���)���)���)���)���)���)�������������������U�������������������������������������������������������������������������������i���)���)���)���)���)���)���)���������������������������������������������������������������������������������������������������������������S���0���)���)���:���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
53 changes: 51 additions & 2 deletions test/widget/docs_screenshots/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import pytest
from libqtile.bar import Bar
from libqtile.command.base import expose_command
from libqtile.config import Group, Screen
from libqtile.config import Group, Key, Screen
from libqtile.lazy import lazy

from qtile_extras.popup.toolkit import _PopupLayout
from test.helpers import DBusPopup, Retry


@pytest.fixture(scope="function")
Expand All @@ -40,6 +42,22 @@ def vertical(request):
vertical_bar = pytest.mark.parametrize("vertical", [True], indirect=True)


@pytest.fixture(scope="function")
def sni(request):
yield getattr(request, "param", False)


statusnotifier = pytest.mark.parametrize("sni", [True], indirect=True)


@pytest.fixture(scope="function")
def gm(request):
yield getattr(request, "param", False)


globalmenu = pytest.mark.parametrize("gm", [True], indirect=True)


@pytest.fixture(scope="session")
def target():
folder = Path(__file__).parent / "screenshots"
Expand Down Expand Up @@ -106,7 +124,9 @@ def get_file_name(w_name, config):


@pytest.fixture
def screenshot_manager(widget, request, manager_nospawn, minimal_conf_noscreen, target, vertical):
def screenshot_manager(
widget, request, manager_nospawn, minimal_conf_noscreen, target, vertical, sni, gm
):
"""
Create a manager instance for the screenshots. Individual "tests" should only call
`screenshot_manager.take_screenshot()` but the destination path is also available in
Expand Down Expand Up @@ -258,9 +278,38 @@ def filename(caption=None):
Screen(**bar1, x=0, y=0, width=300, height=300),
Screen(**bar2, x=0, y=300, width=300, height=300),
]
minimal_conf_noscreen.enable_sni = sni
minimal_conf_noscreen.enable_global_menu = gm

if sni or gm:

def start_dbus(qtile):
dbus_window = DBusPopup(
qtile=qtile,
width=1,
height=1,
x=-1,
y=-1,
# controls=[PopupText(text="Started", x=0, y=0, width=1, height=0.2, name="textbox")],
)

dbus_window.show()

minimal_conf_noscreen.keys = [Key(["mod4"], "m", lazy.function(start_dbus))]

request.getfixturevalue("dbus") # Start dbus

manager_nospawn.start(minimal_conf_noscreen)

if sni or gm:
manager_nospawn.c.simulate_keypress(["mod4"], "m")

@Retry(ignore_exceptions=(AssertionError,))
def wait_for_popup():
assert len(manager_nospawn.c.internal_windows()) == 3

wait_for_popup()

# Add some convenience attributes for taking screenshots
manager_nospawn.target = filename
ss_widget = manager_nospawn.c.widget[name]
Expand Down

0 comments on commit a9571d7

Please sign in to comment.