rules: add Later action
This commit is contained in:
parent
7031f5338f
commit
619223e8be
|
@ -216,6 +216,10 @@ For settings that use gestures as an argument the internal name of the gesture i
|
|||
which can be found in the GESTURE2_GESTURES_LABELS structure in lib/logitech_receiver/settings_templates.
|
||||
All settings are supported.
|
||||
|
||||
A `Sleep` action executes rule components later.
|
||||
`Set` actions take an integer delay between 1 and 100 followed by a list of rule components that will be executed later.
|
||||
Processing of the rest of the rule continues immediately.
|
||||
|
||||
Solaar has several built-in rules, which are run after user-created rules and so can be overridden by user-created rules.
|
||||
One rule turns
|
||||
`Brightness Down` key press notifications into `XF86_MonBrightnessDown` key taps
|
||||
|
|
|
@ -1092,6 +1092,38 @@ class Execute(Action):
|
|||
return {'Execute': self.args[:]}
|
||||
|
||||
|
||||
class Later(Action):
|
||||
def __init__(self, args, warn=True):
|
||||
self.delay = 0
|
||||
self.rule = Rule([])
|
||||
self.components = []
|
||||
if not (isinstance(args, list)):
|
||||
args = [args]
|
||||
if not (isinstance(args, list) and len(args) >= 1):
|
||||
if warn:
|
||||
_log.warn('rule Later argument not list with minimum length 1: %s', args)
|
||||
elif not (isinstance(args[0], int)) or not 0 < args[0] < 101:
|
||||
if warn:
|
||||
_log.warn('rule Later argument delay not integer between 1 and 100: %s', args)
|
||||
else:
|
||||
self.delay = args[0]
|
||||
self.rule = Rule(args[1:], warn=warn)
|
||||
self.components = self.rule.components
|
||||
|
||||
def __str__(self):
|
||||
return 'Later: [' + str(self.delay) + ', ' + ', '.join(str(c) for c in self.components) + ']'
|
||||
|
||||
def evaluate(self, feature, notification, device, status, last_result):
|
||||
if self.delay and self.rule:
|
||||
GLib.timeout_add_seconds(self.delay, Rule.evaluate, self.rule, feature, notification, device, status, last_result)
|
||||
return None
|
||||
|
||||
def data(self):
|
||||
data = [c.data() for c in self.components]
|
||||
data.insert(0, self.delay)
|
||||
return {'Later': data}
|
||||
|
||||
|
||||
COMPONENTS = {
|
||||
'Rule': Rule,
|
||||
'Not': Not,
|
||||
|
@ -1113,6 +1145,7 @@ COMPONENTS = {
|
|||
'MouseClick': MouseClick,
|
||||
'Set': Set,
|
||||
'Execute': Execute,
|
||||
'Later': Later,
|
||||
}
|
||||
|
||||
built_in_rules = Rule([])
|
||||
|
|
Loading…
Reference in New Issue