Skip to content
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

Some little fixes + screenshots #397

Merged
merged 5 commits into from
Nov 18, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2024-11-18: [BUGFIX] Fix square border for `AnalogueClock`
2024-11-14: [FEATURE] Enable support for vertical bars for `GroupBox2`
2024-11-03: [FEATURE] Add `ImageDecoration` for widgets
2024-10-19: [RELEASE] v0.29.0 release - compatible with qtile 0.29.0
Expand Down
Binary file removed docs/_static/images/analogue_clock1.png
Binary file not shown.
Binary file removed docs/_static/images/analogue_clock2.png
Binary file not shown.
Binary file removed docs/_static/images/github_notifications.png
Binary file not shown.
Binary file removed docs/_static/images/snapcast.png
Binary file not shown.
23 changes: 10 additions & 13 deletions qtile_extras/widget/analogueclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,19 @@ class AnalogueClock(base._Widget):
("adjust_y", 0, "Adjust the y position of the widget"),
]

_screenshots = [
("analogue_clock1.png", "Default config"),
("analogue_clock2.png", "With square clock face"),
]

def __init__(self, **config):
base._Widget.__init__(self, 0, **config)
self.add_defaults(AnalogueClock.defaults)
self.hours = self.minutes = self.seconds = 0
self.clock_size = 0
self.clock_string = ""
self.previous_clock = ""

def _configure(self, qtile, bar):
base._Widget._configure(self, qtile, bar)
self.drawer.ctx.set_antialias(cairocffi.ANTIALIAS_NONE)
self.length = self.bar.size + 2 * (self.padding - self.margin)
self.clock_size = self.bar.size - 2 * self.margin
self.length = self.clock_size + 2 * (self.padding + self.margin)

if self.face_shape not in ["square", "circle", None]:
logger.warning("Unknown clock face shape. Setting to None.")
Expand All @@ -101,28 +98,28 @@ def update(self):
def _draw_hand(self, angle, thickness, length, colour):
self.drawer.ctx.save()
self.drawer.ctx.translate(
self.bar.size // 2 + self.padding + self.adjust_x - self.margin,
self.clock_size // 2 + self.padding + self.adjust_x + self.margin,
self.bar.size // 2 + thickness // 2 + self.adjust_y,
)
self.drawer.ctx.rotate(angle)
self.drawer.set_source_rgb(colour)
self.drawer.ctx.set_line_width(thickness)
self.drawer.ctx.move_to(0, 0)
self.drawer.ctx.line_to((self.bar.size // 2 - self.margin) * length, 0)
self.drawer.ctx.line_to((self.clock_size // 2) * length, 0)
self.drawer.ctx.stroke()
self.drawer.ctx.restore()

def draw_face(self):
if self.face_shape == "square":
self.drawer.ctx.rectangle(
self.padding + self.margin + self.adjust_x,
self.margin + self.adjust_y,
self.bar.size - 2 * self.margin,
self.bar.size - 2 * self.margin,
self.padding + self.margin + self.adjust_x - self.face_border_width // 2,
self.margin + self.adjust_y - self.face_border_width // 2,
self.clock_size,
self.clock_size,
)
else:
self.drawer.ctx.arc(
self.bar.size // 2 + self.padding + self.adjust_x - self.margin,
self.clock_size // 2 + self.padding + self.margin + self.adjust_x,
self.bar.size // 2 + self.adjust_y,
self.bar.size // 2 - self.margin - self.face_border_width,
0,
Expand Down
2 changes: 0 additions & 2 deletions qtile_extras/widget/githubnotifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class GithubNotifications(base._Widget):
("update_interval", 150, "Number of seconds before checking status."),
]

_screenshots = [("github_notifications.png", "")]

_dependencies = ["requests"]

_hooks = [h.name for h in hook.githubnotifications_hooks]
Expand Down
4 changes: 1 addition & 3 deletions qtile_extras/widget/snapcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class SnapCast(base._Widget):
),
]

_screenshots = [("snapcast.png", "Snapclient active running in background")]

_dependencies = ["requests"]

def __init__(self, **config):
Expand Down Expand Up @@ -188,7 +186,7 @@ def draw(self):
self.drawer.clear(self.background or self.bar.background)

offsety = (self.bar.height - self.img.height) // 2
self.img.draw(colour=self.status_colour, y=offsety)
self.img.draw(colour=self.status_colour, x=self.padding, y=offsety)
self.drawer.draw(offsetx=self.offsetx, offsety=self.offsety, width=self.length)

def finalize(self):
Expand Down
23 changes: 20 additions & 3 deletions test/widget/docs_screenshots/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
from libqtile.config import Group, Screen


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


vertical_bar = pytest.mark.parametrize("vertical", [True], indirect=True)


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


@pytest.fixture
def screenshot_manager(widget, request, manager_nospawn, minimal_conf_noscreen, target):
def screenshot_manager(widget, request, manager_nospawn, minimal_conf_noscreen, target, vertical):
"""
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 @@ -189,11 +197,16 @@ def take_screenshot(self, target, x=0, y=0, width=None, height=None):
def filename():
return target(name, config)

# define bars
position = "left" if vertical else "top"
bar1 = {position: ScreenshotBar([wdgt], 32)}
bar2 = {position: ScreenshotBar([], 32)}

# Add the widget to our config
minimal_conf_noscreen.groups = [Group(i) for i in "123456789"]
minimal_conf_noscreen.fake_screens = [
Screen(top=ScreenshotBar([wdgt], 32), x=0, y=0, width=300, height=300),
Screen(top=ScreenshotBar([], 32), x=0, y=300, width=300, height=300),
Screen(**bar1, x=0, y=0, width=300, height=300),
Screen(**bar2, x=0, y=300, width=300, height=300),
]

manager_nospawn.start(minimal_conf_noscreen)
Expand All @@ -204,3 +217,7 @@ def filename():
manager_nospawn.take_screenshot = lambda f=filename: ss_widget.take_screenshot(f())

yield manager_nospawn


def widget_config(params):
return pytest.mark.parametrize("screenshot_manager", params, indirect=True)
34 changes: 34 additions & 0 deletions test/widget/docs_screenshots/ss_analogue_clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2024 elParaguayo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest

from qtile_extras.widget.analogueclock import AnalogueClock
from test.widget.docs_screenshots.conftest import widget_config


@pytest.fixture
def widget():
yield AnalogueClock


@widget_config([{}, {"face_shape": "circle"}, {"face_shape": "square"}])
def ss_analogueclock(screenshot_manager):
screenshot_manager.c.widget["analogueclock"].eval("self.update()")
screenshot_manager.take_screenshot()
31 changes: 31 additions & 0 deletions test/widget/docs_screenshots/ss_githubnotifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2024 elParaguayo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest

from qtile_extras.widget.githubnotifications import GithubNotifications


@pytest.fixture
def widget():
yield GithubNotifications


def ss_githubnotifications(screenshot_manager):
screenshot_manager.take_screenshot()
33 changes: 29 additions & 4 deletions test/widget/docs_screenshots/ss_groupbox2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest

from qtile_extras.widget.groupbox2 import GroupBox2, GroupBoxRule
from test.widget.docs_screenshots.conftest import vertical_bar, widget_config


@pytest.fixture
Expand Down Expand Up @@ -55,8 +56,7 @@ def set_label(rule, box):
return True


@pytest.mark.parametrize(
"screenshot_manager",
@widget_config(
[
{},
{"visible_groups": ["1", "2", "3", "4"]},
Expand Down Expand Up @@ -97,10 +97,35 @@ def set_label(rule, box):
GroupBoxRule(text_colour="999999"),
],
},
],
indirect=True,
]
)
def ss_groupbox2(screenshot_manager):
screenshot_manager.test_window("one")
screenshot_manager.c.window.togroup("3")
screenshot_manager.take_screenshot()


@widget_config(
[
{
"padding_y": 5,
"rules": [
GroupBoxRule(
line_colour="00ffff",
line_position=GroupBoxRule.LINE_RIGHT,
).when(screen=GroupBoxRule.SCREEN_THIS),
GroupBoxRule(
line_colour="009999",
line_position=GroupBoxRule.LINE_LEFT,
).when(screen=GroupBoxRule.SCREEN_OTHER),
GroupBoxRule(text_colour="ffffff").when(occupied=True),
GroupBoxRule(text_colour="999999").when(occupied=False),
],
},
]
)
@vertical_bar
def ss_groupbox2_vertical(screenshot_manager):
screenshot_manager.test_window("one")
screenshot_manager.c.window.togroup("3")
screenshot_manager.take_screenshot()
31 changes: 31 additions & 0 deletions test/widget/docs_screenshots/ss_snapcast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2024 elParaguayo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest

from qtile_extras.widget.snapcast import SnapCast


@pytest.fixture
def widget():
yield SnapCast


def ss_snapcast(screenshot_manager):
screenshot_manager.take_screenshot()
Loading