mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
mechanic: emit bar signals if significant changes
This commit is contained in:
+7
-1
@@ -1,6 +1,7 @@
|
||||
import datetime
|
||||
import itertools
|
||||
import logging
|
||||
import math
|
||||
import typing as T
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
@@ -45,6 +46,9 @@ class Bar(SignalMixin):
|
||||
self.emit("change")
|
||||
|
||||
def reset(self, new_max: int, position: float = 0.0) -> None:
|
||||
if not math.isclose(new_max, self._max) or not math.isclose(
|
||||
position, self._position
|
||||
):
|
||||
self._max = new_max
|
||||
self._position = position
|
||||
self.emit("change")
|
||||
@@ -65,7 +69,9 @@ class Bar(SignalMixin):
|
||||
return self._position >= self.max_
|
||||
|
||||
def reposition(self, new_pos: float) -> None:
|
||||
self._position = float(min(new_pos, self._max))
|
||||
new_pos = float(min(new_pos, self._max))
|
||||
if not math.isclose(new_pos, self._position):
|
||||
self._position = new_pos
|
||||
self.emit("change")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user