def update_default_device(self, had_default=None):
        config = {}
        for port in range(4):
            key = "joystick_port_{0}".format(port)
            if self.port == port:
                config[key] = ""
            else:
                config[key] = get_config(self).get(key)
            key = "joystick_port_{0}_mode".format(port)
            config[key] = DeviceManager.get_calculated_port_mode(
                get_config(self), port)
        device = DeviceManager.get_device_for_port(config, self.port)
        default_description = gettext("Default ({0})").format(
            fix_device_name(device.name))
        # print("default_description = ", default_description)

        if had_default is None:
            had_default = self.device_choice.index() == 0
        # print("had default", had_default, self.device_choice.index())
        self.device_choice.set_item_text(0, default_description)
        # print("had_default", had_default)
        if had_default:
            # print("set text for", self.port, default_description)
            # self.device_choice.set_index(1)
            self.device_choice.set_text(default_description)
            self.device_choice.set_index(0)
    def on_config(self, key, value):
        if key == "platform":
            self.layout.update()
            return

        if key == "amiga_model":
            value = get_config(self).get("joystick_port_{0}_mode".format(
                self.port))
            self.set_value_or_default(value)

        if key == self.mode_option_key or key == "amiga_model":
            value = DeviceManager.get_calculated_port_mode(
                get_config(self), self.port)
            for i, config in enumerate(self.joystick_mode_values):
                if config == value:
                    if self.mode_choice is not None:
                        self.mode_choice.set_index(i)
                        if self.port >= 4:
                            self.device_choice.set_enabled(i != 0)
                    break
            else:
                print("FIXME: could not set mode")
        elif key == self.device_option_key or key == "amiga_model":
            # print(self.joystick_values)
            value_lower = value.lower()
            for i, name in enumerate(self.joystick_values):
                if value_lower == name.lower():
                    self.device_choice.set_index(i)
                    break
        elif key == self.autofire_mode_option_key:
            if self.autofire_button is not None:
                if value == "1":
                    self.autofire_button.set_tooltip(
                        gettext("Auto-Fire is On"))
                    self.autofire_button.set_icon_name(
                        "16x16/lightning_red.png")
                else:
                    self.autofire_button.set_tooltip(
                        gettext("Auto-Fire is Off"))
                    self.autofire_button.set_icon_name(
                        "16x16/lightning_off.png")

        # this is intended to catch all config changes for all ports (both
        # mode and device) to update the defaults
        if key.startswith("joystick_port_") or key == "amiga_model":
            self.update_default_device()