diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index 88b0e34756..06bc1f7f47 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -1355,9 +1355,9 @@ def __init__(self, args, warn=True): if not (isinstance(args, list) and len(args) >= 1): if warn: logger.warning("rule Later argument not list with minimum length 1: %s", args) - elif not (isinstance(args[0], int)) or not 0 < args[0] < 101: + elif not (isinstance(args[0], (int, float))) or not 0.01 <= args[0] <= 100: if warn: - logger.warning("rule Later argument delay not integer between 1 and 100: %s", args) + logger.warning("rule Later delay not between 0.01 and 100: %s", args) else: self.delay = args[0] self.rule = Rule(args[1:], warn=warn) @@ -1368,7 +1368,10 @@ def __str__(self): def evaluate(self, feature, notification, device, last_result): if self.delay and self.rule: - GLib.timeout_add_seconds(self.delay, Rule.once, self.rule, feature, notification, device, last_result) + if self.delay >= 1: + GLib.timeout_add_seconds(int(self.delay), Rule.once, self.rule, feature, notification, device, last_result) + else: + GLib.timeout_add(int(self.delay * 1000), Rule.once, self.rule, feature, notification, device, last_result) return None def data(self): diff --git a/lib/solaar/ui/diversion_rules.py b/lib/solaar/ui/diversion_rules.py index 4d77f195a7..54765e51ae 100644 --- a/lib/solaar/ui/diversion_rules.py +++ b/lib/solaar/ui/diversion_rules.py @@ -1131,20 +1131,21 @@ def left_label(cls, component): class LaterUI(RuleComponentUI): CLASS = _DIV.Later - MIN_VALUE = 1 + MIN_VALUE = 0.01 MAX_VALUE = 100 def create_widgets(self): self.widgets = {} self.label = Gtk.Label(valign=Gtk.Align.CENTER, hexpand=True) - self.label.set_text(_("Number of seconds to delay.")) + self.label.set_text(_("Number of seconds to delay. Delay between 0 and 1 is done with higher precision.")) self.widgets[self.label] = (0, 0, 1, 1) self.field = Gtk.SpinButton.new_with_range(self.MIN_VALUE, self.MAX_VALUE, 1) + self.field.set_digits(3) self.field.set_halign(Gtk.Align.CENTER) self.field.set_valign(Gtk.Align.CENTER) self.field.set_hexpand(True) # self.field.set_vexpand(True) - self.field.connect("changed", self._on_update) + self.field.connect("value-changed", self._on_update) self.widgets[self.field] = (0, 1, 1, 1) def show(self, component, editable): @@ -1153,7 +1154,7 @@ def show(self, component, editable): self.field.set_value(component.delay) def collect_value(self): - return [int(self.field.get_value())] + self.component.components + return [float(int((self.field.get_value() + 0.0001) * 1000)) / 1000] + self.component.components @classmethod def left_label(cls, component):