Skip to content

Commit

Permalink
invert rules
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Nov 13, 2024
1 parent efba65d commit 2f7eb2a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions qtile_extras/widget/groupbox2.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ def __repr__(self) -> str:
)
return f"<GroupBoxRule format({output}) when({when})>"

def __invert__(self) -> InvertedGroupBoxRule:
igbr = InvertedGroupBoxRule()
igbr.__dict__ = self.__dict__.copy()
return igbr


class InvertedGroupBoxRule(GroupBoxRule):
def match(self, box: Box) -> bool:
return not super().match(box)

def __repr__(self) -> str:
"""Short representation of rule instance."""
output = describe_attributes(self, GroupBoxRule.attrs, lambda x: x is not SENTINEL)
when = describe_attributes(
self, ["screen", "focused", "occupied", "urgent", "group_name", "func"], filter_attrs
)
return f"<GroupBoxRule format({output}) NOT when({when})>"


class Box:
# Attributes loaded dynamically from widget
Expand Down Expand Up @@ -640,6 +658,10 @@ class GroupBox2(base._Widget, base.MarginMixin, base.PaddingMixin):
* Whether the group name matches a given string
* Whether a user-defined function returns True
Rules can be inverted by using the ``~`` operator. For example, to apply to rule when the group is not
on the current screen, you can write ``~GroupBoxRule(text_colour="888").when(screen=GroupBoxRule.SCREEN_THIS)``.
This is expected to be of limited use but may provide finer control in some circumstances.
Rules are only rechecked when there a change to one of the following properties of the groups:
* Whether the group is focused
Expand Down

0 comments on commit 2f7eb2a

Please sign in to comment.