Exemplo n.º 1
0
    def create_group(cls,
                     parent,
                     name,
                     description=None,
                     help_button=True,
                     thin=False):
        group = fsui.Group(parent)
        group.layout = fsui.HorizontalLayout()
        if thin:
            thin_layout = fsui.VerticalLayout()
            thin_layout.add(group.layout, fill=True)
        option = Option.get(name)
        if description == "":
            description = gettext(option["description"])
        if description:
            group.label = fsui.Label(group, description + ":")
            group.layout.add(group.label, margin_right=10)
            group.layout.add(OverrideWarning(group, name), margin_right=10)

        if thin:
            group.layout = fsui.HorizontalLayout()
            if description:
                thin_layout.add(group.layout, fill=True, margin_top=6)
            else:
                thin_layout.add(group.layout, fill=True, margin_top=0)

        choice_values = []

        if description:
            default_tmpl = "{0} (*)"
            # default_tmpl = "Default - {0}"
        else:
            default_tmpl = "{0} (*)"
            # default_tmpl = "Default - {0}"

        if option["type"].lower() == "boolean":
            if option["default"] == "1":
                default_desc = gettext(default_tmpl).format(gettext("On"))
            elif option["default"] == "0":
                default_desc = gettext(default_tmpl).format(gettext("Off"))
            else:
                default_desc = gettext("Default")
            choice_values.append(("", default_desc))
            choice_values.append(("1", gettext("On")))
            choice_values.append(("0", gettext("Off")))

        elif option["type"].lower() == "choice":
            for i, value in enumerate(option["values"]):
                if option["default"] == value[0]:
                    default_desc = gettext(default_tmpl).format(
                        gettext(value[1]))
                    break
            else:
                default_desc = gettext("Default")
            choice_values.append(("", default_desc))
            for option in option["values"]:
                choice_values.append((option[0], gettext(option[1])))

        elif option["type"].lower() == "string":

            def on_changed():
                val = text_field.get_text()
                LauncherSettings.set(name, val.strip())

            text_field = fsui.TextField(group)
            # text_field.set_min_width(400)
            text_field.set_text(LauncherSettings.get(name))
            text_field.on_changed = on_changed
            group.layout.add(text_field, expand=True)

        elif (option["type"].lower() == "integer" and "min" in option
              and "max" in option):
            current = LauncherSettings.get(name)

            if name == Option.LAUNCHER_FONT_SIZE:
                font = app.qapplication.font()
                Option.get(
                    Option.LAUNCHER_FONT_SIZE)["default"] = font.pointSize()

            current_int = int(option["default"])
            if current:
                try:
                    current_int = int(current)
                except ValueError:
                    pass
            current_int = max(option["min"], min(option["max"], current_int))
            check_box = fsui.CheckBox(group, gettext("Default"))
            spin_ctrl = fsui.SpinCtrl(group, option["min"], option["max"],
                                      current_int)
            if current == "":
                check_box.check()
                spin_ctrl.disable()

            def on_checkbox():
                if check_box.is_checked():
                    spin_ctrl.set_value(int(option["default"]))
                    spin_ctrl.disable()
                    LauncherSettings.set(name, "")
                else:
                    spin_ctrl.enable()

            check_box.on_changed = on_checkbox

            def on_spin():
                val = spin_ctrl.get_value()
                val = max(option["min"], min(option["max"], val))
                LauncherSettings.set(name, str(val))

            spin_ctrl.on_changed = on_spin
            group.layout.add_spacer(0, expand=True)
            group.layout.add(check_box)
            group.layout.add(spin_ctrl, margin_left=10)

        if choice_values:

            def on_changed():
                index = choice.get_index()
                LauncherSettings.set(name, choice_values[index][0])

            choice_labels = [x[1] for x in choice_values]
            choice = fsui.Choice(group, choice_labels)
            current = LauncherSettings.get(name)
            for i, value in enumerate(choice_values):
                if current == value[0]:
                    choice.set_index(i)
                    break
            choice.on_changed = on_changed
            if thin:
                group.layout.add(choice, expand=True)
            else:
                group.layout.add_spacer(0, expand=True)
                group.layout.add(choice)
            group.widget = choice

        if help_button:
            option_url = "https://fs-uae.net/docs/options/" + name.replace(
                "_", "-")
            group.help_button = HelpButton(parent, option_url)
            group.layout.add(group.help_button, margin_left=10)

        if thin:
            group.layout = thin_layout
        return group
    def __init__(self, parent, port, autofire_button=True):
        self.port = port
        self.device_option_key = "joystick_port_{0}".format(port)
        self.mode_option_key = "joystick_port_{0}_mode".format(port)
        self.autofire_mode_option_key = "joystick_port_{0}_autofire".format(
            port)

        super().__init__(parent)
        self.layout = fsui.HorizontalLayout()

        if port == 1:
            non_amiga_port_gui_index = 0
        elif port == 0:
            non_amiga_port_gui_index = 1
        else:
            non_amiga_port_gui_index = port
        self.layout.add(InputPortTypeChoice(self, non_amiga_port_gui_index))

        self.joystick_mode_values = [
            "nothing",
            "joystick",
        ]
        self.joystick_mode_titles = [
            gettext("No Amiga Device"),
            gettext("Amiga Joystick"),
        ]

        if port < 2:
            self.joystick_mode_values.extend([
                "mouse",
                "cd32 gamepad",
            ])
            self.joystick_mode_titles.extend([
                gettext("Amiga Mouse"),
                gettext("CD32 Pad"),
            ])

        self.mode_choice = fsui.Choice(self, self.joystick_mode_titles)
        self.mode_choice.set_min_width(MIN_TYPE_CHOICE_WIDTH)
        # AmigaEnableBehavior(self.mode_choice)
        AmigaShowBehavior(self.mode_choice)

        self.layout.add(self.mode_choice)
        self.layout.add_spacer(10)
        # else:
        #     self.mode_choice = None
        if port >= 4:
            self.mode_choice.set_enabled(False)

        # devices = ["", _("No Host Device"), _("Mouse"),
        #         _("Cursor Keys and Right Ctrl/Alt")]
        # for i, name in enumerate(DeviceManager.get_joystick_names()):
        #     devices.append(name)
        #     if not self.joystick_values_initialized:
        #         self.joystick_values.append(DeviceManager.device_ids[i])
        # self.joystick_values_initialized = True

        self.device_choice = fsui.ComboBox(self, [""], read_only=True)
        # AmigaEnableBehavior(self.device_choice)
        self.joystick_values = []
        self.rebuild_device_list()
        self.device_choice.set_index(0)
        # print(self.device_choice.index())
        AmigaShowBehavior(self.device_choice)
        self.layout.add(self.device_choice, expand=True)

        self.layout.add(
            InputPortDeviceChoice(self, non_amiga_port_gui_index),
            expand=True,
        )

        if port < 4 and autofire_button:
            self.autofire_button = IconButton(self, "16x16/lightning_off.png")
            self.autofire_button.activated.connect(self.on_autofire_button)
            self.layout.add(self.autofire_button, margin_left=10)
            AmigaShowBehavior(self.autofire_button)
        else:
            self.autofire_button = None

        if port == 4:
            self.help_button = HelpButton(
                self, "https://fs-uae.net/custom-joystick-port")
            self.layout.add(self.help_button, margin_left=10)

        self.initialize_from_config()
        self.set_config_handlers()
Exemplo n.º 3
0
def create_option_group(parent,
                        options,
                        option,
                        key,
                        option_type,
                        option_text,
                        use_checkbox,
                        use_help_button,
                        label_spacing,
                        platforms=None,
                        use_label=True):
    # group = fsui.Group(parent)
    group = OptionPanel(parent, platforms)
    group.layout = fsui.HorizontalLayout()

    if use_checkbox:
        group.layout.add(OptionCheckBox(group, option_text + ":", options,
                                        key),
                         margin_right=label_spacing)
    elif use_label:
        group.layout.add(fsui.Label(group, option_text + ":"),
                         margin_right=label_spacing)

    choice_values = []

    if option_type == "boolean":
        group.layout.add_spacer(0, expand=True)
        group.layout.add(
            BooleanChoiceControl(group,
                                 options,
                                 key,
                                 use_checkbox=use_checkbox))

    elif option_type == "choice":
        group.layout.add_spacer(0, expand=True)
        choices = option["values"]
        # if use_checkbox:
        #     choices,insert(("", gettext("Auto")))
        group.layout.add(
            ChoiceControl(group,
                          options,
                          key,
                          choices,
                          use_checkbox=use_checkbox))

    elif option_type == "string":

        def on_changed():
            val = text_field.get_text()
            LauncherConfig.set(key, val.strip())

        text_field = fsui.TextField(group)
        # text_field.set_min_width(400)
        text_field.set_text(LauncherConfig.get(key))
        text_field.on_changed = on_changed
        group.layout.add(text_field, expand=True)

    elif option["type"].lower() == "integer" and "min" in option \
            and "max" in option:
        assert use_checkbox

        spin_ctrl = SpinValueControl(group, options, key, option["min"],
                                     option["max"])

        # current = LauncherConfig.get(key)
        # current_int = int(option["default"])
        # if current:
        #     try:
        #         current_int = int(current)
        #     except ValueError:
        #         pass
        # current_int = max(option["min"], min(option["max"], current_int))
        # check_box = fsui.CheckBox(group, gettext("Default"))
        # spin_ctrl = fsui.SpinCtrl(group, option["min"],
        #                           option["max"], current_int)
        # if current == "":
        #     check_box.check()
        #     spin_ctrl.disable()

        # def on_checkbox():
        #     if check_box.is_checked():
        #         spin_ctrl.set_value(int(option["default"]))
        #         spin_ctrl.disable()
        #         LauncherConfig.set(key, "")
        #     else:
        #         spin_ctrl.enable()
        #
        # check_box.on_changed = on_checkbox
        #
        # def on_spin():
        #     val = spin_ctrl.get_value()
        #     val = max(option["min"], min(option["max"], val))
        #     LauncherConfig.set(key, str(val))

        # spin_ctrl.on_changed = on_spin
        # group.layout.add(check_box)
        group.layout.add_spacer(0, expand=True)
        group.layout.add(spin_ctrl, margin_left=10)

    if choice_values:

        def on_changed():
            index = choice.get_index()
            LauncherConfig.set(key, choice_values[index][0])

        choice_labels = [x[1] for x in choice_values]
        choice = fsui.Choice(group, choice_labels)
        current = LauncherConfig.get(key)
        for i, value in enumerate(choice_values):
            if current == value[0]:
                choice.set_index(i)
                break
        choice.on_changed = on_changed
        group.layout.add_spacer(0, expand=True)
        group.layout.add(choice)
        group.widget = choice

    if use_help_button:
        help_button = HelpButton(parent, "https://fs-uae.net/options#" + key)
        group.layout.add(help_button, margin_left=10)

    return group