def cmd_set_profile(argv0, argv): """ Sets controller profile Usage: scc set-profile [controller_id] "profile name" """ from scc.tools import find_profile if len(argv) < 1: show_help(command="set_profile", out=sys.stderr) return 1 s = connect_to_daemon() if s is None: return -1 if len(argv) >= 2: profile = find_profile(argv[1]) if profile is None: print >> sys.stderr, "Unknown profile:", argv[1] return 1 print >> s, "Controller: %s" % (argv[0], ) if not check_error(s): return 1 print >> s, "Profile: %s" % (profile, ) if not check_error(s): return 1 else: profile = find_profile(argv[0]) if profile is None: print >> sys.stderr, "Unknown profile:", argv[0] return 1 print >> s, "Profile: %s" % (profile, ) if not check_error(s): return 1 return 0
def cmd_set_profile(argv0, argv): """ Sets controller profile Usage: scc set-profile [controller_id] "profile name" """ from scc.tools import find_profile if len(argv) < 1: show_help(command = "set_profile", out=sys.stderr) return 1 s = connect_to_daemon() if s is None: return -1 if len(argv) >= 2: profile = find_profile(argv[1]) if profile is None: print >>sys.stderr, "Unknown profile:", argv[1] return 1 print >>s, "Controller: %s" % (argv[0],) if not check_error(s): return 1 print >>s, "Profile: %s" % (profile,) if not check_error(s): return 1 else: profile = find_profile(argv[0]) if profile is None: print >>sys.stderr, "Unknown profile:", argv[0] return 1 print >>s, "Profile: %s" % (profile,) if not check_error(s): return 1 return 0
def set_profile(self, name, create=False): """ Selects specified profile in UI. Returns True on success or False if profile is not in combobox. If 'create' is set to True, creates new combobox item if needed. """ if name is None: return if name.endswith(".mod"): name = name[0:-4] if name.endswith(".sccprofile"): name = name[0:-11] if "/" in name : name = os.path.split(name)[-1] self._current = name active = self._combo.get_active_iter() giofile = None for row in self._model: if self._model.get_value(row.iter, 1) is not None: if name == self._model.get_value(row.iter, 0): giofile = self._model.get_value(row.iter, 1) if active == row.iter: # Already selected break self._combo.set_active_iter(row.iter) break if giofile is None and create: path = find_profile(name) if path: giofile = Gio.File.new_for_path(path) self._model.insert(0, (name, giofile, None)) self._combo.set_active(0) return giofile != None
def refresh_profile_path(self, name): """ Called from main window after profile file is deleted. May either change path to profile in default_profiles directory, or remove entry entirely. """ prev = None new_path = find_profile(name) # Find row with named profile for row in self._model: if row[0] == name: active = self._combo.get_active_iter() if new_path is None: # Profile was completly removed if self._model.get_value(active, 0) == name: # If removed profile happends to be active one (what's # almost always), switch to previous profile in list self._model.remove(row.iter) if prev is None: # ... unless removed profile was 1st in list. Switch # to next in that case self._combo.set_active_iter(self._model[0].iter) else: self._combo.set_active_iter(prev.iter) else: self._model.remove(row.iter) else: giofile = Gio.File.new_for_path(new_path) self._model.set_value(row.iter, 1, giofile) if self._model.get_value(active, 0) == name: # Active profile was changed self.emit('changed', name, giofile) return prev = row
def load_osk(self): cbStickAction = self.builder.get_object("cbStickAction") cbTriggersAction = self.builder.get_object("cbTriggersAction") profile = Profile(GuiActionParser()) profile.load(find_profile(OSDKeyboard.OSK_PROF_NAME)) self._recursing = True # Load triggers triggers = "%s|%s" % ( profile.triggers[LEFT].to_string(), profile.triggers[RIGHT].to_string() ) if not self.set_cb(cbTriggersAction, triggers, keyindex=1): self.add_custom(cbTriggersAction, triggers) # Load stick if not self.set_cb(cbStickAction, profile.stick.to_string(), keyindex=1): self.add_custom(cbStickAction, profile.stick.to_string()) # Load sensitivity s = profile.pads[LEFT].compress().speed self.builder.get_object("sclSensX").set_value(s[0]) self.builder.get_object("sclSensY").set_value(s[1]) self._recursing = False
def refresh_profile_path(self, name): """ Called from main window after profile file is deleted. May either change path to profile in default_profiles directory, or remove entry altogether. """ prev = None new_path = find_profile(name) # Find row with named profile for row in self._model: if row[0] == name: active = self._combo.get_active_iter() if new_path is None: # Profile was completly removed if self._model.get_value(active, 0) == name: # If removed profile happends to be active one (what's # almost always), switch to previous profile in list self._model.remove(row.iter) if prev is None: # ... unless removed profile was 1st in list. Switch # to next in that case self._combo.set_active_iter(self._model[0].iter) else: self._combo.set_active_iter(prev.iter) else: self._model.remove(row.iter) else: giofile = Gio.File.new_for_path(new_path) self._model.set_value(row.iter, 1, giofile) if self._model.get_value(active, 0) == name: # Active profile was changed self.emit('changed', name, giofile) return prev = row
def show(self, *a): OSDWindow.show(self, *a) self.profile.load(find_profile(".scc-osd.keyboard")).compress() self.mapper = SlaveMapper(self.profile, keyboard=b"SCC OSD Keyboard") self.mapper.set_special_actions_handler(self) self.set_cursor_position(0, 0, self.cursors[LEFT], self.limits[LEFT]) self.set_cursor_position(0, 0, self.cursors[RIGHT], self.limits[RIGHT])
def enable_osd_mode(self): # TODO: Support for multiple controllers here self.osd_mode_controller = 0 osd_mode_profile = Profile(GuiActionParser()) osd_mode_profile.load(find_profile(App.OSD_MODE_PROF_NAME)) try: c = self.dm.get_controllers()[self.osd_mode_controller] except IndexError: log.error("osd_mode: Controller not connected") self.quit() return def on_lock_failed(*a): log.error("osd_mode: Locking failed") self.quit() def on_lock_success(*a): log.debug("osd_mode: Locked everything") from scc.gui.osd_mode_mapper import OSDModeMapper self.osd_mode_mapper = OSDModeMapper(osd_mode_profile) self.osd_mode_mapper.set_target_window(self.window.get_window()) GLib.timeout_add(10, self.osd_mode_mapper.run_scheduled) # Locks everything but pads. Pads are emulating mouse and this is # better left in daemon - involving socket in mouse controls # adds too much lags. c.lock(on_lock_success, on_lock_failed, 'A', 'B', 'X', 'Y', 'START', 'BACK', 'LB', 'RB', 'C', 'LPAD', 'RPAD', 'STICK', 'LGRIP', 'RGRIP', 'LT', 'RT', 'STICKPRESS') # Ask daemon to temporaly reconfigure pads for mouse emulation c.replace(DaemonManager.nocallback, on_lock_failed, LEFT, osd_mode_profile.pads[LEFT]) c.replace(DaemonManager.nocallback, on_lock_failed, RIGHT, osd_mode_profile.pads[RIGHT])
def set_profile(self, name, create=False): """ Selects specified profile in UI. Returns True on success or False if profile is not in combobox. If 'create' is set to True, creates new combobox item if needed. """ if name is None: return if name.endswith(".mod"): name = name[0:-4] if name.endswith(".sccprofile"): name = name[0:-11] if "/" in name: name = os.path.split(name)[-1] self._current = name active = self._combo.get_active_iter() giofile = None for row in self._model: if self._model.get_value(row.iter, 1) is not None: if name == self._model.get_value(row.iter, 0): giofile = self._model.get_value(row.iter, 1) if active == row.iter: # Already selected break self._combo.set_active_iter(row.iter) break if giofile is None and create: path = find_profile(name) if path: giofile = Gio.File.new_for_path(path) self._model.insert(0, (name, giofile, None)) self._combo.set_active(0) return giofile != None
def __init__(self, app): BindingEditor.__init__(self, app) self.app = app self.gladepath = app.gladepath self.imagepath = app.imagepath self.current = Profile(GuiActionParser()) self.current.load(find_profile(OSDKeyboard.OSK_PROF_NAME)) self.setup_widgets()
def _load_osk_profile(self): """ Loads and returns on-screen keyboard profile. Used by methods that are changing it. """ profile = Profile(GuiActionParser()) profile.load(find_profile(OSDKeyboard.OSK_PROF_NAME)) return profile
def load_profile(self): self.profile.load(find_profile(Keyboard.OSK_PROF_NAME)).compress() if not self.profile.pads[CPAD]: # Backwards compatibility; Originally, there was # no default mapping for CPDAD self.profile.pads[CPAD] = scc.osd.osk_actions.OSKCursorAction(CPAD) self.profile.pads[CPAD].speed = [1.0, 1.0] self.set_help()
def check_name(name): if len(name.strip()) <= 0: return False if "/" in name: return False if find_profile(name): # Profile already exists if profile_is_default(name) and not profile_is_override(name): # Existing profile is default and has no override yet return True return False return True
def generate(self, menuhandler): rv = [] for p in menuhandler.config['recent_profiles']: filename = find_profile(p) if filename: menuitem = MenuItem("generated", p) menuitem.filename = filename menuitem.callback = ProfileListMenuGenerator.callback rv.append(menuitem) if len(rv) >= self.rows: break return rv
def _parse_action(self, model, action, used): """ Common part of _add_refereced_profile and _add_refereced_menu """ if isinstance(action, ChangeProfileAction): if action.profile not in used: filename = find_profile(action.profile) used.add(action.profile) if filename: model.append((not profile_is_default(action.profile), _("Profile"), action.profile, filename, True, self.TP_PROFILE)) self._add_refereced_profile(model, Gio.File.new_for_path(filename), used) else: model.append((False, _("Profile"), _("%s (not found)") % (action.profile,), "", False, self.TP_PROFILE)) elif isinstance(action, MenuAction): self._add_refereced_menu(model, action.menu_id, used)
def _parse_action(self, model, action, used): """ Common part of _add_refereced_profile and _add_refereced_menu """ if isinstance(action, ChangeProfileAction): if action.profile not in used: filename = find_profile(action.profile) used.add(action.profile) if filename: model.append( (not profile_is_default(action.profile), _("Profile"), action.profile, filename, True, self.TP_PROFILE)) self._add_refereced_profile( model, Gio.File.new_for_path(filename), used) else: model.append((False, _("Profile"), _("%s (not found)") % (action.profile, ), "", False, self.TP_PROFILE)) elif isinstance(action, MenuAction): self._add_refereced_menu(model, action.menu_id, used)
def load_profile(self): self.profile.load(find_profile(Keyboard.OSK_PROF_NAME)).compress() self.set_help()
def on_txRename_changed(self, tx): name = tx.get_text() btRenameProfile = self.builder.get_object("btRenameProfile") btRenameProfile.set_sensitive(find_profile(name) is None)