Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _strip_trigger(action):
"""
If passed action is TriggerAction, returns its child action.
Returns passed action otherwise.
"""
if isinstance(action, TriggerAction):
return action.child
return action
elif type(param) in (int, float):
numbers.append(int(param))
if len(numbers) == 0:
# Trigger range was not specified, assume defaults
numbers = ( TRIGGER_HALF, TRIGGER_CLICK )
elif len(numbers) == 1:
# Only lower range was specified, add default upper range
numbers.append(TRIGGER_CLICK)
if len(buttons) == 1:
# If only one button was set, trigger should work like
# one big button
n = TriggerAction(numbers[0], ButtonAction(buttons[0]))
elif len(buttons) == 2:
# Both buttons were set
n = MultiAction(
TriggerAction(numbers[0], numbers[1], ButtonAction(buttons[0])),
TriggerAction(numbers[1], TRIGGER_MAX, ButtonAction(buttons[1]))
)
if n:
log.info("Converted %s to %s",
self.triggers[p].to_string(), n.to_string())
self.triggers[p] = n
if from_version < 1.3:
# Action format completly changed in v0.4, but profile foramt is same.
pass
def _strip_trigger(action):
"""
If passed action is TriggerAction, returns its child action.
Returns passed action otherwise.
"""
if isinstance(action, TriggerAction):
return action.action
return action
def send(self):
actions = []
half_level = int(self.builder.get_object("sclPartialLevel").get_value())
full_level = int(self.builder.get_object("sclFullLevel").get_value())
release = self.builder.get_object("cbReleasePartially").get_active()
if self.half:
if self.full and release:
actions.append(TriggerAction(half_level, full_level, self.half))
else:
actions.append(TriggerAction(half_level, TRIGGER_MAX, self.half))
if self.full:
actions.append(TriggerAction(full_level, TRIGGER_MAX, self.full))
if self.analog:
analog_start = int(self.builder.get_object("sclARangeStart").get_value())
analog_end = int(self.builder.get_object("sclARangeEnd").get_value())
if analog_start == TRIGGER_MIN and analog_end == TRIGGER_MAX:
actions.append(self.analog)
else:
actions.append(TriggerAction(analog_start, analog_end, self.analog))
self.editor.set_action(MultiAction.make(*actions))
def cb(action):
action = TriggerAction(254, 255, action)
self.set_action(action, from_custom=True)
self.force_page("trigger")
b = SimpleChooser(self.app, "buttons", cb)
# parameters for old button action
for param in self.triggers[p].parameters:
if param in Keys:
buttons.append(param)
elif type(param) in (int, float):
numbers.append(int(param))
if len(numbers) == 0:
# Trigger range was not specified, assume defaults
numbers = ( TRIGGER_HALF, TRIGGER_CLICK )
elif len(numbers) == 1:
# Only lower range was specified, add default upper range
numbers.append(TRIGGER_CLICK)
if len(buttons) == 1:
# If only one button was set, trigger should work like
# one big button
n = TriggerAction(numbers[0], ButtonAction(buttons[0]))
elif len(buttons) == 2:
# Both buttons were set
n = MultiAction(
TriggerAction(numbers[0], numbers[1], ButtonAction(buttons[0])),
TriggerAction(numbers[1], TRIGGER_MAX, ButtonAction(buttons[1]))
)
if n:
log.info("Converted %s to %s",
self.triggers[p].to_string(), n.to_string())
self.triggers[p] = n
if from_version < 1.3:
# Action format completly changed in v0.4, but profile foramat is same.
pass
def send(self):
actions = []
half_level = int(self.builder.get_object("sclPartialLevel").get_value())
full_level = int(self.builder.get_object("sclFullLevel").get_value())
release = self.builder.get_object("cbReleasePartially").get_active()
if self.half:
if self.full and release:
actions.append(TriggerAction(half_level, full_level, self.half))
else:
actions.append(TriggerAction(half_level, TRIGGER_MAX, self.half))
if self.full:
actions.append(TriggerAction(full_level, TRIGGER_MAX, self.full))
if self.analog:
analog_start = int(self.builder.get_object("sclARangeStart").get_value())
analog_end = int(self.builder.get_object("sclARangeEnd").get_value())
if analog_start == TRIGGER_MIN and analog_end == TRIGGER_MAX:
actions.append(self.analog)
else:
actions.append(TriggerAction(analog_start, analog_end, self.analog))
self.editor.set_action(MultiAction.make(*actions))
def send(self):
actions = []
half_level = int(self.builder.get_object("sclPartialLevel").get_value())
full_level = int(self.builder.get_object("sclFullLevel").get_value())
release = self.builder.get_object("cbReleasePartially").get_active()
if self.half:
if self.full and release:
actions.append(TriggerAction(half_level, full_level, self.half))
else:
actions.append(TriggerAction(half_level, TRIGGER_MAX, self.half))
if self.full:
actions.append(TriggerAction(full_level, TRIGGER_MAX, self.full))
if self.analog:
analog_start = int(self.builder.get_object("sclARangeStart").get_value())
analog_end = int(self.builder.get_object("sclARangeEnd").get_value())
if analog_start == TRIGGER_MIN and analog_end == TRIGGER_MAX:
actions.append(self.analog)
else:
actions.append(TriggerAction(analog_start, analog_end, self.analog))
self.editor.set_action(MultiAction.make(*actions))
def decode(data, a, parser, *b):
""" Called when decoding profile from json """
press_level, release_level = data[TriggerAction.PROFILE_KEYS[0]]
return TriggerAction(press_level, release_level, a)
numbers.append(int(param))
if len(numbers) == 0:
# Trigger range was not specified, assume defaults
numbers = ( TRIGGER_HALF, TRIGGER_CLICK )
elif len(numbers) == 1:
# Only lower range was specified, add default upper range
numbers.append(TRIGGER_CLICK)
if len(buttons) == 1:
# If only one button was set, trigger should work like
# one big button
n = TriggerAction(numbers[0], ButtonAction(buttons[0]))
elif len(buttons) == 2:
# Both buttons were set
n = MultiAction(
TriggerAction(numbers[0], numbers[1], ButtonAction(buttons[0])),
TriggerAction(numbers[1], TRIGGER_MAX, ButtonAction(buttons[1]))
)
if n:
log.info("Converted %s to %s",
self.triggers[p].to_string(), n.to_string())
self.triggers[p] = n
if from_version < 1.3:
# Action format completly changed in v0.4, but profile foramt is same.
pass