refactor(brightness-osd): switch to BlockProgressBar and fix initial percent fallback
This commit is contained in:
1 file changed
+16
-7
@@ -1,12 +1,11 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from fabric.utils import logger
|
from fabric.utils import logger
|
||||||
from fabric.widgets.scale import ScaleMark
|
|
||||||
|
|
||||||
from services.brightness import Brightness
|
from services.brightness import Brightness
|
||||||
|
from shared.widgets.block_progress_bar import BlockProgressBar
|
||||||
from utils.gtk_utils import svg_file
|
from utils.gtk_utils import svg_file
|
||||||
|
|
||||||
from .animated_scale import AnimatedScale
|
|
||||||
from .base import BaseOSDContainer
|
from .base import BaseOSDContainer
|
||||||
|
|
||||||
|
|
||||||
@@ -28,13 +27,17 @@ class BrightnessOSDContainer(BaseOSDContainer):
|
|||||||
h_expand=True,
|
h_expand=True,
|
||||||
v_expand=True,
|
v_expand=True,
|
||||||
)
|
)
|
||||||
self.scale = AnimatedScale(
|
self.scale = BlockProgressBar(
|
||||||
marks=(ScaleMark(value=i) for i in range(0, 101, 10)),
|
|
||||||
value=70,
|
value=70,
|
||||||
min_value=0,
|
min_value=0,
|
||||||
max_value=100,
|
max_value=100,
|
||||||
increments=(1, 1),
|
block_count=20,
|
||||||
orientation="h",
|
block_spacing=2.0,
|
||||||
|
block_height=10.0,
|
||||||
|
block_radius=0.0,
|
||||||
|
orientation="horizontal",
|
||||||
|
name="osd-block-bar",
|
||||||
|
h_expand=True,
|
||||||
)
|
)
|
||||||
self.add(self.osd_window_image)
|
self.add(self.osd_window_image)
|
||||||
self.add(self.scale)
|
self.add(self.scale)
|
||||||
@@ -55,7 +58,13 @@ class BrightnessOSDContainer(BaseOSDContainer):
|
|||||||
self._update_display()
|
self._update_display()
|
||||||
|
|
||||||
def _update_display(self):
|
def _update_display(self):
|
||||||
percent = self._last_percent if self._last_percent is not None else 0
|
if self._last_percent is None:
|
||||||
|
raw = self.brightness_service.screen_brightness
|
||||||
|
max_br = self.brightness_service.max_screen
|
||||||
|
self._last_percent = (
|
||||||
|
int((raw / max_br) * 100) if max_br > 0 and raw >= 0 else 0
|
||||||
|
)
|
||||||
|
percent = self._last_percent
|
||||||
level = 0 if percent == 0 else min(math.ceil(percent / 33), 3)
|
level = 0 if percent == 0 else min(math.ceil(percent / 33), 3)
|
||||||
|
|
||||||
self.osd_window_image.set_from_file(f"brightness/brightness-{level}.svg")
|
self.osd_window_image.set_from_file(f"brightness/brightness-{level}.svg")
|
||||||
|
|||||||
Reference in new issue
Block a user