Skip to content

Commit

Permalink
rules: allow sub-second delays in Later
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Mar 14, 2024
1 parent 4e4275c commit 154dd70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/logitech_receiver/diversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions lib/solaar/ui/diversion_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 154dd70

Please sign in to comment.