def create_gamepad(self, enabled, poller): """ Parses gamepad configuration and creates apropriate unput device """ if not enabled or "SCC_NOGAMEPAD" in os.environ: # Completly undocumented and for debuging purposes only. # If set, no gamepad is emulated self.gamepad = Dummy() return cfg = Config() keys = ALL_BUTTONS[0:cfg["output"]["buttons"]] vendor = int(cfg["output"]["vendor"], 16) product = int(cfg["output"]["product"], 16) version = int(cfg["output"]["version"], 16) name = cfg["output"]["name"] rumble = cfg["output"]["rumble"] and poller != None axes = [] i = 0 for min, max in cfg["output"]["axes"]: fuzz, flat = 0, 0 if abs(max - min) > 32768: fuzz, flat = 16, 128 try: axes.append(( ALL_AXES[i], min, max, fuzz, flat )) except IndexError: # Out of axes break i += 1 ui = UInput(vendor=vendor, product=product, version=version, name=name, keys=keys, axes=axes, rels=[], rumble=rumble) if poller and rumble: poller.register(ui.getDescriptor(), poller.POLLIN, self._rumble_ready) return ui
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): print "failed to parse args" return False if not self.parse_menu(): print "failed to parse menu" return False if not self.config: self.config = Config() self._cancel_with = self.args.cancel_with self._timeout = self.args.timeout # Create buttons that are displayed on screen items = self.items.generate(self) self.items = [] self._button_index = 0 for item in items: item.widget = self.generate_widget(item) if item.widget is not None: self.items.append(item) self.pack_items(self.parent, self.items) if len(self.items) == 0: print >> sys.stderr, '%s: error: no items in menu' % (sys.argv[0]) return False return True
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.config: self.config = Config() try: self.items = MenuData.from_args(self.args.items) self._menuid = None except ValueError: print >> sys.stderr, '%s: error: invalid number of arguments' % ( sys.argv[0]) return False self._text.set_label(self.args.text) if self.args.feedback_amplitude: side = "LEFT" self.feedback = side, int(self.args.feedback_amplitude) # Create buttons that are displayed on screen items = self.items.generate(self) self.items = [] for item in items: item.widget = self.generate_widget(item) if item.widget is not None: self.items.append(item) self.pack_items(self.parent, self.items) if len(self.items) == 0: print >> sys.stderr, '%s: error: no items in menu' % (sys.argv[0]) return False return True
def on_daemon_connected(self, *a): def success(*a): log.error("Sucessfully locked input") if not self.config: self.config = Config() self.controller = self.choose_controller(self.daemon) if self.controller is None or not self.controller.is_connected(): # There is no controller connected to daemon self.on_failed_to_lock("Controller not connected") return ccfg = self.config.get_controller_config(self.controller.get_id()) self._confirm_with = ccfg[ "menu_confirm"] if self.args.confirm_with == DEFAULT else self.args.confirm_with self._cancel_with = ccfg[ "menu_cancel"] if self.args.cancel_with == DEFAULT else self.args.cancel_with self._eh_ids += [ (self.controller, self.controller.connect('event', self.on_event)), (self.controller, self.controller.connect('lost', self.on_controller_lost)), ] locks = [ LEFT, RIGHT, STICK, "LPAD", "RPAD", "LB", self._confirm_with, self._cancel_with ] self.controller.lock(success, self.on_failed_to_lock, *locks)
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.parse_menu(): return False if not self.config: self.config = Config() # Parse simpler arguments self._size = self.args.size # Create buttons that are displayed on screen items = self.items.generate(self) self.items = [] for item in items: item.widget = self.generate_widget(item) if item.widget is not None: self.items.append(item) self.pack_items(self.parent, self.items) if len(self.items) == 0: print >> sys.stderr, '%s: error: no items in menu' % (sys.argv[0]) return False if self.args.print_items: max_id_len = max(*[len(x.id) for x in self.items]) row_format = "{:>%s}:\t{}" % (max_id_len, ) for item in self.items: print row_format.format(item.id, item.label) return True
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.config: self.config = Config() if self.args.from_profile: try: self._menuid = self.args.items[0] self.items = MenuData.from_profile(self.args.from_profile, self._menuid) except IOError: print >> sys.stderr, '%s: error: profile file not found' % ( sys.argv[0]) return False except ValueError: print >> sys.stderr, '%s: error: menu not found' % ( sys.argv[0]) return False elif self.args.from_file: #try: data = json.loads(open(self.args.from_file, "r").read()) self._menuid = self.args.from_file self.items = MenuData.from_json_data(data) #except: # print >>sys.stderr, '%s: error: failed to load menu file' % (sys.argv[0]) # return False else: try: self.items = MenuData.from_args(self.args.items) self._menuid = None except ValueError: print >> sys.stderr, '%s: error: invalid number of arguments' % ( sys.argv[0]) return False # Parse simpler arguments self._control_with = self.args.control_with self._confirm_with = self.args.confirm_with self._cancel_with = self.args.cancel_with if self.args.use_cursor: self.enable_cursor() # Create buttons that are displayed on screen self.items = self.items.generate(self) for item in self.items: item.widget = self.generate_widget(item) self.pack_items(self.parent, self.items) if len(self.items) == 0: print >> sys.stderr, '%s: error: no items in menu' % (sys.argv[0]) return False if self.args.print_items: max_id_len = max(*[len(x.id) for x in self.items]) row_format = "{:>%s}:\t{}" % (max_id_len, ) for item in self.items: print row_format.format(item.id, item.label) return True
def on_daemon_connected(self, *a): def success(*a): log.error("Sucessfully locked input") pass if not self.config: self.config = Config() locks = [self._control_with, self._confirm_with, self._cancel_with] self.daemon.lock(success, self.on_failed_to_lock, *locks)
def run(self): self.daemon = DaemonManager() self.config = Config() self.daemon.connect('alive', self.on_daemon_connected) self.daemon.connect('dead', self.on_daemon_died) self.daemon.connect('profile-changed', self.on_profile_changed) self.daemon.connect('reconfigured', self.on_daemon_reconfigured) self.daemon.connect('unknown-msg', self.on_unknown_message) self.mainloop.run()
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.config: self.use_config(Config()) # Parse simpler arguments self._control_with = self.args.control_with return True
def __init__(self, config=None): OSDWindow.__init__(self, "osd-gesture") self.daemon = None self._left_detector = GestureDetector(0, self._on_gesture_finished) # self._right_detector = GestureDetector(0, self._on_gesture_finished) self._control_with = LEFT self._eh_ids = [] self._gesture = None self.setup_widgets() self.use_config(config or Config())
def on_daemon_connected(self, *a): if not self.config: self.config = Config() self.controller = self.choose_controller(self.daemon) if self.controller is None or not self.controller.is_connected(): # There is no controller connected to daemon self.on_failed_to_lock("Controller not connected") return self._eh_ids += [ (self.controller, self.controller.connect('event', self.on_event)) ] self.lock_inputs()
def recolor(self): config = Config() source_colors = {} try: # Try to read json file and bail out if it fails desc = os.path.join(get_share_path(), "images", 'radial-menu.svg.json') source_colors = json.loads(open(desc, "r").read())['colors'] except Exception, e: log.warning("Failed to load keyboard description") log.warning(e) return
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.config: self.config = Config() if self.args.feedback_amplitude: side = "LEFT" self.feedback = side, int(self.args.feedback_amplitude) # Create buttons that are displayed on screen return True
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.parse_menu(): return False if not self.config: self.config = Config() # Parse simpler arguments self._control_with = self.args.control_with self._confirm_with = self.args.confirm_with self._cancel_with = self.args.cancel_with self._size = self.args.size if self.args.use_cursor: self.enable_cursor() if self.args.feedback_amplitude: side = "LEFT" if self._control_with == "RIGHT": side = "RIGHT" elif self._control_with == "STICK": side = "BOTH" self.feedback = side, int(self.args.feedback_amplitude) if self._confirm_with == SAME: if self._control_with == RIGHT: self._confirm_with = SCButtons.RPADTOUCH.name else: self._confirm_with = SCButtons.LPADTOUCH.name # Create buttons that are displayed on screen items = self.items.generate(self) self.items = [] for item in items: item.widget = self.generate_widget(item) if item.widget is not None: self.items.append(item) self.pack_items(self.parent, self.items) if len(self.items) == 0: print >>sys.stderr, '%s: error: no items in menu' % (sys.argv[0]) return False if self.args.print_items: max_id_len = max(*[ len(x.id) for x in self.items ]) row_format ="{:>%s}:\t{}" % (max_id_len,) for item in self.items: print row_format.format(item.id, item.label) return True
def run(self): on_wayland = "WAYLAND_DISPLAY" in os.environ or not isinstance(Gdk.Display.get_default(), GdkX11.X11Display) if on_wayland: log.error("Cannot run on Wayland") self.exit_code = 8 return self.daemon = DaemonManager() self.config = Config() self._check_colorconfig_change() self.daemon.connect('alive', self.on_daemon_connected) self.daemon.connect('dead', self.on_daemon_died) self.daemon.connect('profile-changed', self.on_profile_changed) self.daemon.connect('reconfigured', self.on_daemon_reconfigured) self.daemon.connect('unknown-msg', self.on_unknown_message) self.mainloop.run()
def on_daemon_connected(self, *a): def success(*a): log.error("Sucessfully locked input") if not self.config: self.config = Config() locks = [self._control_with, self._confirm_with, self._cancel_with] c = self.choose_controller(self.daemon) if c is None or not c.is_connected(): # There is no controller connected to daemon self.on_failed_to_lock("Controller not connected") return self._eh_ids += [(c, c.connect('event', self.on_event))] c.lock(success, self.on_failed_to_lock, *locks)
def on_daemon_connected(self, *a): def success(*a): log.error("Sucessfully locked %s pad", self._control_with) self._left_detector.enable() # self._right_detector.enable() if not self.config: self.config = Config() locks = [self._control_with] c = self.choose_controller(self.daemon) if c is None or not c.is_connected(): # There is no controller connected to daemon self.on_failed_to_lock("Controller not connected") return self._eh_ids += [(c, c.connect('event', self.on_event))] c.lock(success, self.on_failed_to_lock, *locks)
def on_daemon_connected(self, *a): def success(*a): log.error("Sucessfully locked input") if not self.config: self.config = Config() locks = [ LEFT, RIGHT, STICK, "LPAD", "RPAD", "LB", self._confirm_with, self._cancel_with ] self.controller = self.choose_controller(self.daemon) if self.controller is None or not self.controller.is_connected(): # There is no controller connected to daemon self.on_failed_to_lock("Controller not connected") return self._eh_ids += [ (self.controller, self.controller.connect('event', self.on_event)) ] self.controller.lock(success, self.on_failed_to_lock, *locks)
def parse_argumets(self, argv): if not OSDWindow.parse_argumets(self, argv): return False if not self.config: self.config = Config() # Parse simpler arguments self._confirm_with = self.args.confirm_with self._cancel_with = self.args.cancel_with if self.args.feedback_amplitude: side = "LEFT" self.feedback = side, int(self.args.feedback_amplitude) # Create buttons that are displayed on screen return True
def __init__(self, config=None): self.bdisplay = os.path.join(get_config_path(), 'binding-display.svg') if not os.path.exists(self.bdisplay): # Prefer image in ~/.config/scc, but load default one as fallback self.bdisplay = os.path.join(get_share_path(), "images", 'binding-display.svg') OSDWindow.__init__(self, "osd-keyboard") self.daemon = None self.config = config or Config() self.group = None self.limits = {} self.background = None self._eh_ids = [] self._stick = 0, 0 self.c = Gtk.Box() self.c.set_name("osd-keyboard-container")
def __init__(self, wmclass): Gtk.Window.__init__(self) OSDWindow._apply_css(Config()) self.argparser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, epilog=self.EPILOG) self._add_arguments() self.exit_code = -1 self.position = (20, -20) self.mainloop = None self.set_name(wmclass) self.set_wmclass(wmclass, wmclass) self.set_decorated(False) self.stick() self.set_skip_taskbar_hint(True) self.set_skip_pager_hint(True) self.set_keep_above(True) self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION)
def __init__(self, config=None): self.kbimage = os.path.join(get_config_path(), 'keyboard.svg') if not os.path.exists(self.kbimage): # Prefer image in ~/.config/scc, but load default one as fallback self.kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg') TimerManager.__init__(self) OSDWindow.__init__(self, "osd-keyboard") self.daemon = None self.mapper = None self.keymap = Gdk.Keymap.get_default() self.keymap.connect('state-changed', self.on_keymap_state_changed) Action.register_all(sys.modules['scc.osd.osk_actions'], prefix="OSK") self.profile = Profile(TalkingActionParser()) self.config = config or Config() self.dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) self.group = None self.limits = {} self.background = None cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = {} self.cursors[LEFT] = Gtk.Image.new_from_file(cursor) self.cursors[LEFT].set_name("osd-keyboard-cursor") self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor) self.cursors[RIGHT].set_name("osd-keyboard-cursor") self.cursors[CPAD] = Gtk.Image.new_from_file(cursor) self.cursors[CPAD].set_name("osd-keyboard-cursor") self._eh_ids = [] self._controller = None self._stick = 0, 0 self._hovers = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self._pressed = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self._pressed_areas = {} self.c = Gtk.Box() self.c.set_name("osd-keyboard-container") self.f = Gtk.Fixed()
def __init__(self, gladepath="/usr/share/scc", imagepath="/usr/share/scc/images"): Gtk.Application.__init__(self, application_id="me.kozec.scc", flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE | Gio.ApplicationFlags.NON_UNIQUE ) UserDataManager.__init__(self) BindingEditor.__init__(self, self) # Setup Gtk.Application self.setup_commandline() # Setup DaemonManager self.dm = DaemonManager() self.dm.connect("alive", self.on_daemon_alive) self.dm.connect("controller-count-changed", self.on_daemon_ccunt_changed) self.dm.connect("dead", self.on_daemon_dead) self.dm.connect("error", self.on_daemon_error) self.dm.connect('reconfigured', self.on_daemon_reconfigured), self.dm.connect("version", self.on_daemon_version) # Set variables self.config = Config() self.gladepath = gladepath self.imagepath = imagepath self.builder = None self.recursing = False self.statusicon = None self.status = "unknown" self.context_menu_for = None self.daemon_changed_profile = False self.osd_mode = False # In OSD mode, only active profile can be editted self.osd_mode_mapper = None self.background = None self.outdated_version = None self.profile_switchers = [] self.current_file = None # Currently edited file self.controller_count = 0 self.current = Profile(GuiActionParser()) self.just_started = True self.button_widgets = {} self.hilights = { App.HILIGHT_COLOR : set(), App.OBSERVE_COLOR : set() } self.undo = [] self.redo = []
def read_serial(self): """ Requests and reads serial number from controller """ if Config()["ignore_serials"]: # Special exception for cases when controller drops instead of # sending serial number. See issue #103 self.generate_serial() self.on_serial_got() return def cb(rawserial): size, serial = struct.unpack(">xBx12s49x", rawserial) if size > 1: serial = serial.strip(" \x00") self._serial = serial self.on_serial_got() else: self._driver._no_serial.append(self) self._driver.make_request( self._ccidx, cb, struct.pack('>BBB61x', SCPacketType.GET_SERIAL, SCPacketLength.GET_SERIAL, 0x01))
def disconnected(self): # If ignore_serials config option is enabled, fake serial used by this # controller is stored away and reused when next controller is connected if Config()["ignore_serials"]: self._driver._available_serials.add(self._serial)