def _make_action(self): """ Generates and returns Action instance """ cbMode = self.builder.get_object("cbMode") key = cbMode.get_model().get_value(cbMode.get_active_iter(), 0) if key == "inner": return MultiAction( self.actions[1], RingAction(self.radius, self.actions[0], NoAction())) elif key == "outer": return MultiAction( self.actions[0], RingAction(self.radius, NoAction(), self.actions[1])) else: return RingAction(self.radius, *self.actions)
def on_key_grabbed(self, keys): """ Handles selecting key using "Grab the Key" dialog """ action = ButtonAction(keys[0]) if len(keys) > 1: actions = [ButtonAction(k) for k in keys] action = MultiAction(*actions) self.editor.set_action(action)
def send(self, *a): if self._recursing: return cbGyroButton = self.builder.get_object("cbGyroButton") button = cbGyroButton.get_model().get_value( cbGyroButton.get_active_iter(), 0) normal, n_set = [None, None, None], False absolute, a_set = [None, None, None], False for i in xrange(0, 3): if self.axes[i] is not None: if self.cbs[i].get_active(): absolute[i] = self.axes[i] a_set = True else: normal[i] = self.axes[i] n_set = True if n_set and a_set: action = MultiAction(GyroAction(*normal), GyroAbsAction(*absolute)) elif n_set: action = GyroAction(*normal) elif a_set: action = GyroAbsAction(*absolute) else: action = NoAction() if button and action: action = ModeModifier(getattr(SCButtons, button), action) self.editor.set_action(action)
def apply_keys(self): """ Common part of on_*key_grabbed """ keys = list(self.keys) action = ButtonAction(keys[0]) if len(keys) > 1: actions = [ButtonAction(k) for k in keys] action = MultiAction(*actions) self.editor.set_action(action)
def apply_keys(self, *a): """ Common part of on_*key_grabbed """ cbToggle = self.builder.get_object("cbToggle") keys = list(sorted(self.keys, key=ButtonsComponent.modifiers_first)) action = ButtonAction(keys[0]) if len(keys) > 1: actions = [ButtonAction(k) for k in keys] action = MultiAction(*actions) if cbToggle.get_active(): action = Cycle(PressAction(action), ReleaseAction(action)) self.editor.set_action(action)
def make_circular_action(self): """ Constructs Circular Modifier """ if self.circular_axis and any(self.circular_buttons): return CircularModifier( MultiAction(self.circular_axis, ButtonAction(*self.circular_buttons))) elif any(self.circular_buttons): return CircularModifier(ButtonAction(*self.circular_buttons)) else: return CircularModifier(self.circular_axis)
def send(self, *a): if self._recursing: return rvSoftLevel = self.builder.get_object("rvSoftLevel") sclSoftLevel = self.builder.get_object("sclSoftLevel") cbGyroButton = self.builder.get_object("cbGyroButton") cbInvertGyro = self.builder.get_object("cbInvertGyro") item = cbGyroButton.get_model().get_value( cbGyroButton.get_active_iter(), 0) rvSoftLevel.set_reveal_child(item in TRIGGERS) normal, n_set = [None, None, None], False absolute, a_set = [None, None, None], False for i in xrange(0, 3): if self.axes[i] is not None: if self.cbs[i].get_active(): absolute[i] = self.axes[i] a_set = True else: normal[i] = self.axes[i] n_set = True if n_set and a_set: action = MultiAction(GyroAction(*normal), GyroAbsAction(*absolute)) elif n_set: action = GyroAction(*normal) elif a_set: action = GyroAbsAction(*absolute) else: action = NoAction() if item and action: what = getattr(SCButtons, item) if item in TRIGGERS: what = RangeOP(what, ">=", sclSoftLevel.get_value()) if cbInvertGyro.get_active(): action = ModeModifier(what, NoAction(), action) else: action = ModeModifier(what, action) self.editor.set_action(action)
def area_action_selected(self, area, action): if area: self.set_active_area(area) if self.full: action = MultiAction(ButtonAction(None, self.full), action) self.editor.set_action(action)
def _convert(self, from_version): """ Performs conversion from older profile version """ if from_version < 1: from scc.modifiers import ModeModifier # Add 'display Default.menu if center button is held' for old profiles c = self.buttons[SCButtons.C] if not c: # Nothing set to C button self.buttons[SCButtons.C] = HoldModifier( MenuAction("Default.menu"), normalaction=MenuAction("Default.menu")) elif hasattr(c, "holdaction") and c.holdaction: # Already set to something, don't overwrite it pass elif c.to_string().startswith("OSK."): # Special case, don't touch this either pass else: self.buttons[SCButtons.C] = HoldModifier( MenuAction("Default.menu"), normalaction=self.buttons[SCButtons.C]) if from_version < 1.1: # Convert old scrolling wheel to new representation from scc.modifiers import FeedbackModifier, BallModifier from scc.actions import MouseAction, XYAction from scc.uinput import Rels iswheelaction = ( lambda x: isinstance(x, MouseAction) and x.parameters[0] in (Rels.REL_HWHEEL, Rels.REL_WHEEL)) for p in (Profile.LEFT, Profile.RIGHT): a, feedback = self.pads[p], None if isinstance(a, FeedbackModifier): feedback = a.haptic.get_position() a = a.action if isinstance(a, XYAction): if iswheelaction(a.x) or iswheelaction(a.y): n = BallModifier(XYAction(a.x, a.y)) if feedback is not None: n = FeedbackModifier(feedback, 4096, 16, n) self.pads[p] = n log.info("Converted %s to %s", a.to_string(), n.to_string()) if from_version < 1.2: # Convert old trigger settings that were done with ButtonAction # to new TriggerAction from scc.constants import TRIGGER_HALF, TRIGGER_MAX, TRIGGER_CLICK from scc.actions import ButtonAction, TriggerAction, MultiAction from scc.uinput import Keys for p in (Profile.LEFT, Profile.RIGHT): if isinstance(self.triggers[p], ButtonAction): buttons, numbers = [], [] n = None # There were one or two keys and zero to two numeric # 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
def _parse_action(self, frm=Action.ALL): """ Parses one action, that is one of: - something(params) - something() - something """ # Check if next token is TokenType.NAME and grab action name from it t = self._next_token() if t.type != TokenType.NAME: raise ParseError("Expected action name, got '%s'" % (t.value, )) if t.value not in frm: raise ParseError("Unknown action '%s'" % (t.value, )) action_name = t.value action_class = frm[action_name] # Check if there are any tokens left - return action without parameters # if not if not self._tokens_left(): return self._create_action(action_class) # Check if token after action name is parenthesis and if yes, parse # parameters from it t = self._peek_token() parameters = [] if t.type == TokenType.OP and t.value == '.': # ACTION dict can have nested dicts; SOMETHING.action if type(action_class) == dict: self._next_token() return self._parse_action(action_class) else: raise ParseError("Unexpected '.' after '%s'" % (action_name, )) if t.type == TokenType.OP and t.value == '(': parameters = self._parse_parameters() if not self._tokens_left(): return self._create_action(action_class, *parameters) t = self._peek_token() # ... or, if it is one of ';', 'and' or 'or' and if yes, parse next action if t.type == TokenType.NAME and t.value == 'and': # Two (or more) actions joined by 'and' self._next_token() if not self._tokens_left(): raise ParseError("Expected action after 'and'") action1 = self._create_action(action_class, *parameters) action2 = self._parse_action() return MultiAction(action1, action2) if t.type == TokenType.NEWLINE or t.value == "\n": # Newline can be used to join actions instead of 'and' self._next_token() if not self._tokens_left(): # Newline at end of string is not error return self._create_action(action_class, *parameters) t = self._peek_token() if t.type == TokenType.OP and t.value in (')', ','): # ')' starts next line return self._create_action(action_class, *parameters) action1 = self._create_action(action_class, *parameters) action2 = self._parse_action() return MultiAction(action1, action2) if t.type == TokenType.OP and t.value == ';': # Two (or more) actions joined by ';' self._next_token() while self._tokens_left() and self._peek_token( ).type == TokenType.NEWLINE: self._next_token() if not self._tokens_left(): # Having ';' at end of string is not actually error return self._create_action(action_class, *parameters) action1 = self._create_action(action_class, *parameters) action2 = self._parse_action() return Macro(action1, action2) return self._create_action(action_class, *parameters)