def __init__(self, *parameters): if len(parameters) < 2: raise TypeError("Not enought parameters") self.action = parameters[-1] self.haptic = HapticData(*parameters[:-1]) self.action.set_haptic(self.haptic) Modifier.__init__(self, self.action) self.parameters = parameters
class FeedbackModifier(Modifier): COMMAND = "feedback" def __init__(self, *parameters): if len(parameters) < 2: raise TypeError("Not enought parameters") self.action = parameters[-1] self.haptic = HapticData(*parameters[:-1]) self.action.set_haptic(self.haptic) Modifier.__init__(self, self.action) self.parameters = parameters def describe(self, context): if self.name: return self.name return self.action.describe(context) def to_string(self, multiline=False, pad=0): # Convert all but last parameters to string, using int() for amplitude and period pars = list(self.parameters[0:-1]) if len(pars) >= 1: pars[0] = str(pars[0]) # Side if len(pars) >= 2: pars[1] = str(int(pars[1])) # Amplitude if len(pars) >= 3: pars[2] = str(pars[2]) # Frequency if len(pars) >= 4: pars[3] = str(int(pars[3])) # period if multiline: childstr = self.action.to_string(True, pad + 2) if "\n" in childstr: return ((" " * pad) + "feedback(" + ", ".join(pars) + ",\n" + childstr + "\n" + (" " * pad) + ")") return ("feedback(" + ", ".join(pars) + ", " + self.action.to_string(False) + ")") def __str__(self): return "<with Feedback %s>" % (self.action,) def encode(self): rv = Modifier.encode(self) rv['feedback'] = list(self.parameters[0:-1]) if self.haptic.get_position() == HapticPos.LEFT: rv['feedback'][0] = "LEFT" elif self.haptic.get_position() == HapticPos.RIGHT: rv['feedback'][0] = "RIGHT" else: rv['feedback'][0] = "BOTH" return rv def strip(self): return self.action.strip() def compress(self): return self.action.compress()
class FeedbackModifier(Modifier): COMMAND = "feedback" def __init__(self, *parameters): if len(parameters) < 2: raise TypeError("Not enought parameters") self.action = parameters[-1] self.haptic = HapticData(*parameters[:-1]) self.action.set_haptic(self.haptic) Modifier.__init__(self, self.action) self.parameters = parameters def describe(self, context): if self.name: return self.name return self.action.describe(context) def to_string(self, multiline=False, pad=0): # Convert all but last parameters to string, using int() for amplitude and period pars = list(self.parameters[0:-1]) if len(pars) >= 1: pars[0] = str(pars[0]) # Side if len(pars) >= 2: pars[1] = str(int(pars[1])) # Amplitude if len(pars) >= 3: pars[2] = str(pars[2]) # Frequency if len(pars) >= 4: pars[3] = str(int(pars[3])) # period if multiline: childstr = self.action.to_string(True, pad + 2) if "\n" in childstr: return ((" " * pad) + "feedback(" + ", ".join(pars) + ",\n" + childstr + "\n" + (" " * pad) + ")") return ("feedback(" + ", ".join(pars) + ", " + self.action.to_string(False) + ")") def __str__(self): return "<with Feedback %s>" % (self.action, ) def encode(self): rv = Modifier.encode(self) rv['feedback'] = list(self.parameters[0:-1]) if self.haptic.get_position() == HapticPos.LEFT: rv['feedback'][0] = "LEFT" elif self.haptic.get_position() == HapticPos.RIGHT: rv['feedback'][0] = "RIGHT" else: rv['feedback'][0] = "BOTH" return rv def strip(self): return self.action.strip() def compress(self): return self.action.compress()
def _rumble_ready(self, fd, event): ef = self.gamepad.ff_read() if ef: # tale of... self.send_feedback( HapticData(HapticPos.BOTH, period=32760, amplitude=ef.level, count=min(0x7FFF, ef.duration * ef.repetitions / 30)))
def _mod_init(self, position, amplitude=512, frequency=4, period=1024, count=1): self.haptic = HapticData(position, amplitude, frequency, period, count) if self.action: a = self.action while a: if hasattr(a, "set_haptic"): a.set_haptic(self.haptic) break if hasattr(a, "action"): a = a.action else: break
def set_action(self, action): """ Updates Action field(s) on bottom and recolors apropriate image area, if such area exists. """ entAction = self.builder.get_object("entAction") entActionY = self.builder.get_object("entActionY") btOK = self.builder.get_object("btOK") # Load modifiers and update UI if needed action = self.load_modifiers(action) # Check for InvalidAction and display error message if found if isinstance(action, InvalidAction): btOK.set_sensitive(False) entAction.set_name("error") entAction.set_text(str(action.error)) self._set_y_field_visible(False) else: # Check for XYAction and treat it specialy entAction.set_name("entAction") btOK.set_sensitive(True) self._action = action if isinstance(action, XYAction): entAction.set_text( self.generate_modifiers(action.x).to_string()) if not action.y: entActionY.set_text("") else: entActionY.set_text( self.generate_modifiers(action.y).to_string()) self._set_y_field_visible(True) action = self.generate_modifiers(action) else: action = self.generate_modifiers(action) if hasattr(action, 'string') and "\n" not in action.string: # Stuff generated by my special parser entAction.set_text(action.string) else: # Actions generated elsewhere entAction.set_text(action.to_string()) self._set_y_field_visible(False) # Check if action supports feedback if action.set_haptic(HapticData(HapticPos.LEFT)): self.set_feedback_settings_enabled(True) else: self.set_feedback_settings_enabled(False) # Send changed action into selected component if self._selected_component is None: self._selected_component = None for component in reversed( sorted(self.components, key=lambda a: a.PRIORITY)): if component.CTXS == Action.AC_ALL or self._mode in component.CTXS: if component.handles(self._mode, action.strip()): self._selected_component = component break if self._selected_component: if self._selected_component in self.c_buttons: self.c_buttons[self._selected_component].set_active(True) if isinstance(action, InvalidAction): self._selected_component.set_action(self._mode, action) elif not self._selected_component.handles(self._mode, action.strip()): log.warning("selected_component no longer handles edited action") log.warning(self._selected_component) log.warning(action.to_string())