Skip to content

Commit 1d45262

Browse files
authored
Merge pull request #1 from cibere/v0.0.2
V0.0.2
2 parents 594fbbd + 79ac9d5 commit 1d45262

File tree

10 files changed

+92
-35
lines changed

10 files changed

+92
-35
lines changed

assets/error.png

14.6 KB
Loading

main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
sys.path.append(parent_folder_path)
66
sys.path.append(os.path.join(parent_folder_path, "lib"))
77
sys.path.append(os.path.join(parent_folder_path, "venv", "lib", "site-packages"))
8-
sys.path.append(os.path.join(parent_folder_path, "venv", "lib", "site-packages", "win32", "lib"))
9-
sys.path.append(os.path.join(parent_folder_path, "venv", "lib", "site-packages", "win32"))
8+
sys.path.append(
9+
os.path.join(parent_folder_path, "venv", "lib", "site-packages", "win32", "lib")
10+
)
11+
sys.path.append(
12+
os.path.join(parent_folder_path, "venv", "lib", "site-packages", "win32")
13+
)
1014
sys.path.append(os.path.join(parent_folder_path, "lib", "win32", "lib"))
1115
sys.path.append(os.path.join(parent_folder_path, "lib", "win32"))
1216

1317
from plugin.plugin import ScreenBrightnessPlugin
1418

1519
if __name__ == "__main__":
16-
ScreenBrightnessPlugin().run()
20+
ScreenBrightnessPlugin().run()

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "ScreenBrightness",
55
"Description": "Control the brightness of your monitors within flow",
66
"Author": "cibere",
7-
"Version": "0.0.1",
7+
"Version": "0.0.2",
88
"Language": "python_v2",
99
"Website": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness",
1010
"IcoPath": "assets/app.png",

plugin/conds.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from flogin._types import SearchHandlerCondition
21
from flogin import Query
2+
from flogin._types import SearchHandlerCondition
3+
34

45
class MultiAnyCondition:
56
r"""A builtin search condition to check for multiple conditions.
@@ -23,4 +24,4 @@ def __call__(self, query: Query) -> bool:
2324
query.condition_data = condition
2425
return True
2526

26-
return False
27+
return False

plugin/handlers/get.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from flogin import Query, Result, SearchHandler, PlainTextCondition, ProgressBar
3+
from flogin import PlainTextCondition, ProgressBar, Query, Result, SearchHandler
44

55
from ..plugin import ScreenBrightnessPlugin
66

@@ -13,4 +13,9 @@ async def callback(self, query: Query):
1313
assert self.plugin
1414

1515
for value, monitor in self.plugin.get_brightnesses():
16-
yield Result("", sub=f"Monitor: {monitor} | Brightness: {value}%", icon="assets/app.png", progress_bar=ProgressBar(value, "#f7f309"))
16+
yield Result(
17+
"",
18+
sub=f"Monitor: {monitor} | Brightness: {value}%",
19+
icon="assets/app.png",
20+
progress_bar=ProgressBar(value, "#f7f309"),
21+
)

plugin/handlers/invalid.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

3-
from flogin import Query, Result, SearchHandler, ExecuteResponse, RegexCondition
4-
from flogin.jsonrpc.results import ResultConstructorArgs
5-
from typing import Unpack
6-
from ..plugin import ScreenBrightnessPlugin
73
import re
4+
from flogin import Query, Result, SearchHandler
5+
6+
from ..plugin import ScreenBrightnessPlugin
7+
88

99
class InvalidSetBrightnessHandler(SearchHandler[ScreenBrightnessPlugin]):
1010
async def callback(self, query: Query[re.Match]):
11-
return Result("Invalid Brightness Value. Brightness value must be a valid whole number from 0 to 100.", icon="assets/app.png")
11+
return Result(
12+
"Invalid Brightness Value. Brightness value must be a valid whole number from 0 to 100.",
13+
icon="assets/error.png",
14+
)

plugin/handlers/set.py

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,53 @@
11
from __future__ import annotations
22

3-
from flogin import Query, Result, SearchHandler, ExecuteResponse, PlainTextCondition, MultiCondition
4-
from flogin.jsonrpc.results import ResultConstructorArgs
5-
from typing import Unpack
6-
from ..plugin import ScreenBrightnessPlugin
73
import re
4+
from typing import Unpack
5+
6+
import screen_brightness_control as sbc
7+
from flogin import (
8+
ExecuteResponse,
9+
PlainTextCondition,
10+
Query,
11+
Result,
12+
SearchHandler,
13+
)
14+
from flogin.jsonrpc.results import ResultConstructorArgs
15+
816
from ..conds import MultiAnyCondition
17+
from ..plugin import ScreenBrightnessPlugin
18+
919

1020
class SetBrightnessResult(Result[ScreenBrightnessPlugin]):
11-
def __init__(self, value: int, kw: str, **kwargs: Unpack[ResultConstructorArgs]):
21+
def __init__(
22+
self,
23+
value: int,
24+
monitor: str | None,
25+
kw: str,
26+
**kwargs: Unpack[ResultConstructorArgs],
27+
):
1228
super().__init__(**kwargs)
1329

1430
self.value = value
1531
self.kw = kw
32+
self.monitor = monitor
1633

1734
async def callback(self):
1835
assert self.plugin
1936

20-
self.plugin.set_brightness(self.value)
21-
await self.plugin.api.show_notification("ScreenBrightness", f"Successfully set screen brightness to {self.value}%.")
37+
self.plugin.set_brightness(self.value, monitor=self.monitor)
38+
await self.plugin.api.show_notification(
39+
"ScreenBrightness",
40+
(
41+
f"Successfully set the brightness of your {self.monitor} display to {self.value}%."
42+
if self.monitor
43+
else f"Successfully set the brightness of all of your displays to {self.value}%."
44+
),
45+
)
2246
await self.plugin.api.change_query(f"{self.kw} ")
23-
47+
2448
return ExecuteResponse(False)
2549

50+
2651
class SetBrightnessHandler(SearchHandler[ScreenBrightnessPlugin]):
2752
def __init__(self):
2853
cond = MultiAnyCondition(*[PlainTextCondition(str(i + 1)) for i in range(100)])
@@ -33,5 +58,21 @@ async def callback(self, query: Query[re.Match]):
3358
assert self.plugin
3459

3560
value = int(query.text.strip())
36-
37-
return SetBrightnessResult(value, title=f"Set brightness to {value}%?", icon="assets/app.png", kw=query.keyword)
61+
62+
yield SetBrightnessResult(
63+
value,
64+
None,
65+
title=f"Set brightness to {value}% for all of your displays?",
66+
icon="assets/app.png",
67+
kw=query.keyword,
68+
score=10,
69+
)
70+
71+
for monitor in sbc.list_monitors():
72+
yield SetBrightnessResult(
73+
value,
74+
monitor,
75+
title=f"Set brightness to {value}% for {monitor}?",
76+
icon="assets/app.png",
77+
kw=query.keyword,
78+
)

plugin/plugin.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from typing import Iterable
2+
3+
import screen_brightness_control as sbc
14
from flogin import Plugin
25

36
from .settings import ScreenBrightnessSettings
4-
from typing import Iterable
5-
import screen_brightness_control as sbc
7+
68

79
class ScreenBrightnessPlugin(Plugin[ScreenBrightnessSettings]):
810
def __init__(self) -> None:
@@ -11,11 +13,15 @@ def __init__(self) -> None:
1113
from .handlers.get import GetBrightnessHandler
1214
from .handlers.invalid import InvalidSetBrightnessHandler
1315
from .handlers.set import SetBrightnessHandler
14-
15-
self.register_search_handlers(SetBrightnessHandler(), GetBrightnessHandler(), InvalidSetBrightnessHandler())
16-
16+
17+
self.register_search_handlers(
18+
SetBrightnessHandler(),
19+
GetBrightnessHandler(),
20+
InvalidSetBrightnessHandler(),
21+
)
22+
1723
def get_brightnesses(self) -> Iterable[tuple[int, str]]:
1824
return zip(sbc.get_brightness(), sbc.list_monitors())
19-
20-
def set_brightness(self, value: int) -> None:
21-
sbc.set_brightness(value)
25+
26+
def set_brightness(self, value: int, monitor: int | str | None = None) -> None:
27+
sbc.set_brightness(value, display=monitor)

plugin/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from flogin import Settings
22

33

4-
class ScreenBrightnessSettings(Settings):
5-
...
4+
class ScreenBrightnessSettings(Settings): ...

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Flow.Launcher.Plugin.ScreenBrightness
22
Lets you easily and quickly the brightness of all of your monitors
33

4-
**Coming Soon**: Setting the brightness of individual monitors. I am hung up on the design, so it will come eventually.
5-
64
## Useage
75

86
An empty query will get you the current brightness levels. From there, type in the new value, and click on the option.

0 commit comments

Comments
 (0)