def parse_group(self, group, side): """ Parses output (group) from vdf profile. Returns Action. """ if not "mode" in group: raise ParseError("Group without mode") mode = group["mode"] inputs = VDFProfile.get_inputs(group) settings = group["settings"] if "settings" in group else {} for o in ("output_trigger", "output_joystick"): if o in settings: if int(settings[o]) <= 1: side = Profile.LEFT else: side = Profile.RIGHT if mode == "dpad": keys = [] for k in ("dpad_north", "dpad_south", "dpad_east", "dpad_west"): if k in inputs: keys.append(self.parse_button(inputs[k])) else: keys.append(NoAction()) action = DPadAction(*keys) elif mode == "four_buttons": keys = [] for k in ("button_y", "button_a", "button_x", "button_b"): if k in inputs: keys.append(self.parse_button(inputs[k])) else: keys.append(NoAction()) action = DPadAction(*keys) elif mode == "joystick_move": if side == Profile.LEFT: # Left action = XYAction(AxisAction(Axes.ABS_X), AxisAction(Axes.ABS_Y)) else: # Right action = XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY)) elif mode == "joystick_camera": output_joystick = 0 if 'output_joystick' in settings: output_joystick = int(settings['output_joystick']) if output_joystick == 0: action = BallModifier( XYAction(AxisAction(Axes.ABS_X), AxisAction(Axes.ABS_Y))) elif output_joystick == 1: action = BallModifier( XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY))) else: # TODO: Absolute mouse? Doesn't seems to do anything in Steam action = BallModifier( SensitivityModifier(0.1, 0.1, MouseAction())) elif mode == "mouse_joystick": action = BallModifier( XYAction(AxisAction(Axes.ABS_RX), AxisAction(Axes.ABS_RY))) elif mode == "scrollwheel": action = BallModifier( XYAction(MouseAction(Rels.REL_HWHEEL), MouseAction(Rels.REL_WHEEL))) elif mode == "touch_menu": # Touch menu is converted to GridMenu items = [] next_item_id = 1 for k in inputs: action = self.parse_button(inputs[k]) items.append( MenuItem("item_%s" % (next_item_id, ), action.describe(Action.AC_BUTTON), action)) next_item_id += 1 # Menu is stored in profile, with generated ID menu_id = "menu_%s" % (self.next_menu_id, ) self.next_menu_id += 1 self.menus[menu_id] = MenuData(*items) action = GridMenuAction( menu_id, 'LEFT' if side == Profile.LEFT else 'RIGHT', SCButtons.LPAD if side == Profile.LEFT else SCButtons.RPAD) elif mode == "absolute_mouse": if "click" in inputs: if side == Profile.LEFT: self.add_by_binding(SCButtons.LPAD, self.parse_button(inputs["click"])) else: self.add_by_binding(SCButtons.RPAD, self.parse_button(inputs["click"])) if "gyro_axis" in settings: if int(settings["gyro_axis"]) == 1: action = MouseAction(ROLL) else: action = MouseAction(YAW) else: action = MouseAction() elif mode == "mouse_wheel": action = BallModifier( XYAction(MouseAction(Rels.REL_HWHEEL), ouseAction(Rels.REL_WHEEL))) elif mode == "trigger": actions = [] if "click" in inputs: actions.append( TriggerAction(TRIGGER_CLICK, self.parse_button(inputs["click"]))) if side == Profile.LEFT: actions.append(AxisAction(Axes.ABS_Z)) else: actions.append(AxisAction(Axes.ABS_RZ)) action = MultiAction.make(*actions) elif mode == "mouse_region": # Read value and assume dafaults scale = float(settings["scale"]) if "scale" in settings else 100.0 x = float( settings["position_x"]) if "position_x" in settings else 50.0 y = float( settings["position_y"]) if "position_y" in settings else 50.0 w = float(settings["sensitivity_horiz_scale"] ) if "sensitivity_horiz_scale" in settings else 100.0 h = float(settings["sensitivity_vert_scale"] ) if "sensitivity_vert_scale" in settings else 100.0 # Apply scale w = w * scale / 100.0 h = h * scale / 100.0 # Convert to (0, 1) range x, y = x / 100.0, 1.0 - (y / 100.0) w, h = w / 100.0, h / 100.0 # Convert to rectangle x1 = max(0.0, x - (w * VDFProfile.REGION_IMPORT_FACTOR)) x2 = min(1.0, x + (w * VDFProfile.REGION_IMPORT_FACTOR)) y1 = max(0.0, y - (h * VDFProfile.REGION_IMPORT_FACTOR)) y2 = min(1.0, y + (h * VDFProfile.REGION_IMPORT_FACTOR)) action = RelAreaAction(x1, y1, x2, y2) else: raise ParseError("Unknown mode: '%s'" % (group["mode"], )) action = VDFProfile.parse_modifiers(group, action, side) return action
def on_cbMenus_changed(self, *a): """ Called when user changes any menu settings """ if self._recursing: return cbMenuAutoConfirm = self.builder.get_object("cbMenuAutoConfirm") cbConfirmWith = self.builder.get_object("cbConfirmWith") cbCancelWith = self.builder.get_object("cbCancelWith") if cbMenuAutoConfirm and cbConfirmWith: # Control Options block exists in UI lblConfirmWith = self.builder.get_object("lblConfirmWith") lblConfirmWith.set_sensitive(not cbMenuAutoConfirm.get_active()) cbConfirmWith.set_sensitive(not cbMenuAutoConfirm.get_active()) name = self.get_selected_menu() if name == "": # 'New menu' selected self.load_menu_list() log.debug("Creating editor for new menu") me = MenuEditor(self.app, self.on_menu_changed) me.set_new_menu() me.allow_menus(self.allow_globals, self.allow_in_profile) me.show(self.editor.window) return if name: # There is some menu choosen cbControlWith = self.builder.get_object("cbControlWith") self.builder.get_object("btEditMenu").set_sensitive( name not in MenuEditor.OPEN) params = [name] if cbControlWith: params += [ cbControlWith.get_model().get_value( cbControlWith.get_active_iter(), 1), getattr( SCButtons, cbConfirmWith.get_model().get_value( cbConfirmWith.get_active_iter(), 1)), getattr( SCButtons, cbCancelWith.get_model().get_value( cbCancelWith.get_active_iter(), 1)) ] if self.confirm_with_same_active(): params[2] = SAME elif self.confirm_with_same_active(): params += [STICK, SAME] cbm = self.builder.get_object("cbMenuType") # Hide / apply and display 'Items per row' selector if it exists in UI if self.builder.get_object("rvMaxSize"): rvMaxSize = self.builder.get_object("rvMaxSize") spMaxSize = self.builder.get_object("spMaxSize") visible = cbm.get_model().get_value(cbm.get_active_iter(), 1) == "gridmenu" rvMaxSize.set_reveal_child(visible) if visible: max_size = int(spMaxSize.get_adjustment().get_value()) if max_size > 0: # max_size is 2nd parameter params = [params[0], max_size] + params[1:] # Grab menu type and choose apropriate action action = NoAction() if cbm and cbm.get_model().get_value(cbm.get_active_iter(), 1) == "gridmenu": # Grid menu action = GridMenuAction(*params) elif cbm and cbm.get_model().get_value(cbm.get_active_iter(), 1) == "radialmenu": # Circular menu action = RadialMenuAction(*params) elif cbm and cbm.get_model().get_value(cbm.get_active_iter(), 1) == "hmenu": # Horizontal menu action = HorizontalMenuAction(*params) else: # Normal menu action = MenuAction(*params) # Apply Menu Position options, if such block exists in UI if self.builder.get_object("spMenuPosX"): cbMenuPosX = self.builder.get_object("cbMenuPosX") cbMenuPosY = self.builder.get_object("cbMenuPosY") x = int(self.builder.get_object("spMenuPosX").get_value()) y = int(self.builder.get_object("spMenuPosY").get_value()) x *= cbMenuPosX.get_model().get_value( cbMenuPosX.get_active_iter(), 0) y *= cbMenuPosY.get_model().get_value( cbMenuPosY.get_active_iter(), 0) if (x, y) != MenuAction.DEFAULT_POSITION: action = PositionModifier(x, y, action) self.editor.set_action(action)
def on_cbMenus_changed(self, *a): """ Called when user changes any menu settings """ if self._recursing: return cbMenuConfirmWithClick = self.builder.get_object( "cbMenuConfirmWithClick") cbMenuAutoConfirm = self.builder.get_object("cbMenuAutoConfirm") cbMenuAutoCancel = self.builder.get_object("cbMenuAutoCancel") lblControlWith = self.builder.get_object("lblControlWith") cbControlWith = self.builder.get_object("cbControlWith") lblConfirmWith = self.builder.get_object("lblConfirmWith") cbConfirmWith = self.builder.get_object("cbConfirmWith") lblCancelWith = self.builder.get_object("lblCancelWith") cbCancelWith = self.builder.get_object("cbCancelWith") cbm = self.builder.get_object("cbMenuType") menu_type = cbm.get_model().get_value(cbm.get_active_iter(), 1) if cbControlWith: sensitive = True if menu_type == "quickmenu": sensitive = False lblControlWith.set_sensitive(sensitive) cbControlWith.set_sensitive(sensitive) if cbConfirmWith: sensitive = True if cbMenuAutoConfirm and cbMenuAutoConfirm.get_active(): sensitive = False if cbMenuConfirmWithClick and cbMenuConfirmWithClick.get_active(): sensitive = False if menu_type == "quickmenu": sensitive = False lblConfirmWith.set_sensitive(sensitive) cbConfirmWith.set_sensitive(sensitive) if cbCancelWith: sensitive = True if cbMenuAutoCancel and cbMenuAutoCancel.get_active(): sensitive = False if menu_type == "quickmenu": sensitive = False lblCancelWith.set_sensitive(sensitive) cbCancelWith.set_sensitive(sensitive) if cbMenuAutoConfirm: sensitive = True if menu_type == "quickmenu": sensitive = False cbMenuAutoConfirm.set_sensitive(sensitive) name = self.get_selected_menu() if name == "": return self.on_new_menu_selected() if name: # There is some menu choosen self.builder.get_object("btEditMenu").set_sensitive( name not in MenuEditor.OPEN) params = [name] cow = SAME if cbMenuAutoConfirm and cbMenuAutoConfirm.get_active(): cow = SAME elif cbMenuConfirmWithClick and cbMenuConfirmWithClick.get_active( ): cow = DEFAULT elif cbConfirmWith: cow = cbConfirmWith.get_model().get_value( cbConfirmWith.get_active_iter(), 1) if cow != DEFAULT: cow = getattr(SCButtons, cow) caw = DEFAULT if cbMenuAutoCancel and cbMenuAutoCancel.get_active(): caw = DEFAULT elif cbCancelWith: caw = cbCancelWith.get_model().get_value( cbCancelWith.get_active_iter(), 1) if caw != DEFAULT: caw = getattr(SCButtons, caw) params += [self.get_control_with(), cow, caw] # Hide / apply and display 'Items per row' selector if it exists in UI if self.builder.get_object("rvMenuSize"): spMenuSize = self.builder.get_object("spMenuSize") menu_type = cbm.get_model().get_value(cbm.get_active_iter(), 1) if menu_type == "gridmenu": self.update_size_display(GridMenuAction("dummy")) size = int(spMenuSize.get_adjustment().get_value()) if size > 0: # size is 2nd parameter params += [False, size] elif menu_type == "radialmenu": self.update_size_display(RadialMenuAction("dummy")) size = int(spMenuSize.get_adjustment().get_value()) if size > 0 and size < 100: # Both 0 and 100 means default here # size is 2nd parameter params += [False, size] elif menu_type == "hmenu": self.update_size_display(HorizontalMenuAction("dummy")) size = int(spMenuSize.get_adjustment().get_value()) if size > 1: # Size 0 and 1 means default here # size is 2nd parameter params += [False, size] else: # , "radialmenu"): self.update_size_display(None) # Grab menu type and choose apropriate action action = NoAction() if cbm and menu_type == "gridmenu": # Grid menu action = GridMenuAction(*params) elif cbm and menu_type == "radialmenu": # Circular menu action = RadialMenuAction(*params) elif cbm and menu_type == "hmenu": # Horizontal menu action = HorizontalMenuAction(*params) elif cbm and menu_type == "quickmenu": # Horizontal menu action = QuickMenuAction(name) else: # Normal menu action = MenuAction(*params) # Apply Menu Position options, if such block exists in UI if self.builder.get_object("spMenuPosX"): cbMenuPosX = self.builder.get_object("cbMenuPosX") cbMenuPosY = self.builder.get_object("cbMenuPosY") x = int(self.builder.get_object("spMenuPosX").get_value()) y = int(self.builder.get_object("spMenuPosY").get_value()) x *= cbMenuPosX.get_model().get_value( cbMenuPosX.get_active_iter(), 0) y *= cbMenuPosY.get_model().get_value( cbMenuPosY.get_active_iter(), 0) if (x, y) != MenuAction.DEFAULT_POSITION: action = PositionModifier(x, y, action) self.editor.set_action(action)