def find_joystick(id_or_name): nr = js_count() # Anzahl der vorhandenen Joysticks if isinstance(id_or_name, str): # Substring-Suche for i in xrange(nr): j = js_Joystick(i) if id_or_name.lower() in j.get_name().lower(): return j elif isinstance(id_or_name, int) \ and (0 <= id_or_name < nr): # Id-Suche return js_Joystick(id_or_name) raise JoystickNotFound(id_or_name)
def detect_joystick(cmdr): # TODO beruecksichtige Praeferenzen for id in xrange(js_count()): try: js = get_joystick_profile(id, cmdr) except KeyError: # KeyError passiert entweder beim Nachschlagen in der # profile_map oder erst beim Nachschlagen in den profiles # der Joystick-Klasse. continue else: print "Benutze `%s' als Joystick." % js.name() return js # Falls keine Joystick gefunden wurde: raise NoMatchingProfile