コード例 #1
0
ファイル: vdf.py プロジェクト: miniskipper/sc-controller
    def load_data(self, data):
        if 'controller_mappings' not in data:
            raise ValueError("Invalid profile file")
        data = data['controller_mappings']
        if 'title' in data:
            name = data['title'].strip()
            if name:
                self.name = name
        presets = ensure_list(data['preset'])
        for p in presets:
            id = int(p["id"])
            if id == 0:
                # Default profile
                VDFProfile._load_preset(data, self, p)
            else:
                aset = VDFProfile(VDFProfile._get_preset_name(data, p))
                aset.action_set_id = id
                aset.action_set_switches = self.action_set_switches
                self.action_sets[aset.name] = aset
                VDFProfile._load_preset(data, aset, p)

        for aset in self.action_sets.values():
            aset.buttons[SCButtons.C] = HoldModifier(
                MenuAction("Default.menu"), MenuAction("Default.menu"))

        return self
コード例 #2
0
ファイル: profile.py プロジェクト: wiltonlazary/sc-controller
 def clear(self):
     """ Clears all actions and adds default menu action on center button """
     self.buttons = {x: NoAction() for x in SCButtons}
     self.buttons[SCButtons.C] = HoldModifier(
         MenuAction("Default.menu"),
         normalaction=MenuAction("Default.menu"))
     self.menus = {}
     self.stick = NoAction()
     self.is_template = False
     self.triggers = {Profile.LEFT: NoAction(), Profile.RIGHT: NoAction()}
     self.pads = {Profile.LEFT: NoAction(), Profile.RIGHT: NoAction()}
     self.gyro = NoAction()
コード例 #3
0
ファイル: profile.py プロジェクト: wiltonlazary/sc-controller
    def _convert(self, from_version):
        """ Performs conversion from older profile version """
        if from_version < 1:
            from scc.modifiers import ModeModifier
            # Add 'display Default.menu if center button is held' for old profiles
            c = self.buttons[SCButtons.C]
            if not c:
                # Nothing set to C button
                self.buttons[SCButtons.C] = HoldModifier(
                    MenuAction("Default.menu"),
                    normalaction=MenuAction("Default.menu"))
            elif hasattr(c, "holdaction") and c.holdaction:
                # Already set to something, don't overwrite it
                pass
            elif c.to_string().startswith("OSK."):
                # Special case, don't touch this either
                pass
            else:
                self.buttons[SCButtons.C] = HoldModifier(
                    MenuAction("Default.menu"),
                    normalaction=self.buttons[SCButtons.C])
        if from_version < 1.1:
            # Convert old scrolling wheel to new representation
            from scc.modifiers import FeedbackModifier, BallModifier
            from scc.actions import MouseAction, XYAction
            from scc.uinput import Rels
            iswheelaction = (
                lambda x: isinstance(x, MouseAction) and x.parameters[0] in
                (Rels.REL_HWHEEL, Rels.REL_WHEEL))
            for p in (Profile.LEFT, Profile.RIGHT):
                a, feedback = self.pads[p], None
                if isinstance(a, FeedbackModifier):
                    feedback = a.haptic.get_position()
                    a = a.action
                if isinstance(a, XYAction):
                    if iswheelaction(a.x) or iswheelaction(a.y):
                        n = BallModifier(XYAction(a.x, a.y))
                        if feedback is not None:
                            n = FeedbackModifier(feedback, 4096, 16, n)
                        self.pads[p] = n
                        log.info("Converted %s to %s", a.to_string(),
                                 n.to_string())
        if from_version < 1.2:
            # Convert old trigger settings that were done with ButtonAction
            # to new TriggerAction
            from scc.constants import TRIGGER_HALF, TRIGGER_MAX, TRIGGER_CLICK
            from scc.actions import ButtonAction, TriggerAction, MultiAction
            from scc.uinput import Keys
            for p in (Profile.LEFT, Profile.RIGHT):
                if isinstance(self.triggers[p], ButtonAction):
                    buttons, numbers = [], []
                    n = None
                    # There were one or two keys and zero to two numeric
                    # parameters for old button action
                    for param in self.triggers[p].parameters:
                        if param in Keys:
                            buttons.append(param)
                        elif type(param) in (int, float):
                            numbers.append(int(param))
                    if len(numbers) == 0:
                        # Trigger range was not specified, assume defaults
                        numbers = (TRIGGER_HALF, TRIGGER_CLICK)
                    elif len(numbers) == 1:
                        # Only lower range was specified, add default upper range
                        numbers.append(TRIGGER_CLICK)
                    if len(buttons) == 1:
                        # If only one button was set, trigger should work like
                        # one big button
                        n = TriggerAction(numbers[0], ButtonAction(buttons[0]))
                    elif len(buttons) == 2:
                        # Both buttons were set
                        n = MultiAction(
                            TriggerAction(numbers[0], numbers[1],
                                          ButtonAction(buttons[0])),
                            TriggerAction(numbers[1], TRIGGER_MAX,
                                          ButtonAction(buttons[1])))

                    if n:
                        log.info("Converted %s to %s",
                                 self.triggers[p].to_string(), n.to_string())
                        self.triggers[p] = n
コード例 #4
0
    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)
コード例 #5
0
 def on_menu_changed(self, new_id):
     self._current_menu = new_id
     self.editor.set_action(MenuAction(new_id))
     self.load_menu_list()
コード例 #6
0
    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)