def on_destroy(self):
     # fsgs.signal.disconnect(
     #     "fsgs:config:floppy_drive_{0}".format(self.drive),
     #     self.on_config_floppy_drive)
     # fsgs.signal.disconnect("config", self.on_config)
     get_config(self).detach(self.__on_config)
     super().on_destroy()
 def set_config_handlers(self):
     if self.mode_choice is not None:
         self.mode_choice.on_changed = self.on_mode_changed
     self.device_choice.on_changed = self.on_device_changed
     get_config(self).add_listener(self)
     LauncherSignal.add_listener("settings_updated", self)
     LauncherSignal.add_listener("device_list_updated", self)
    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 update_default_device(self, had_default=None):
        config = {"platform": self._platform}
        for port in range(1, 4 + 1):
            key = "{}_port_{}".format(self._platform, port)
            if self.port == port:
                config[key] = ""
            else:
                config[key] = get_config(self).get(key)
            key = "{}_port_{}_type".format(self._platform, port)
            config[key] = get_config(self).get(key)
            # config[key] = DeviceManager.get_calculated_port_mode(
            #     get_config(self), port)

        device = DeviceManager.get_non_amiga_device_for_port(config, self.port)

        default_description = "{} (*)".format(fix_device_name(device.name))
        # print("default_description = ", default_description)

        if had_default is None:
            had_default = self.index() == 0
        # print("had default", had_default, self.index())
        self.set_item_text(0, default_description)
        # print("had_default", had_default)
        if had_default:
            # print("set text for", self.port, default_description)
            # self.set_index(1)
            self.set_text(default_description)
            self.set_index(0)
 def initialize_from_config(self):
     self.on_config(
         self.device_option_key,
         get_config(self).get(self.device_option_key),
     )
     self.on_config(self.mode_option_key,
                    get_config(self).get(self.mode_option_key))
     self.on_config(
         self.autofire_mode_option_key,
         get_config(self).get(self.autofire_mode_option_key),
     )
 def on_changed(self):
     index = self.index()
     value = self.device_values[index]
     if value != "none":
         # Reset to default device for other ports using the same device.
         for port in range(1, 4 + 1):
             if self.port == port:
                 continue
             key = "{}_port_{}".format(self._platform, port)
             if get_config(self).get(key) == value:
                 get_config(self).set(key, "")
     get_config(self).set(self.device_option_key, value)
    def on_device_changed(self):
        index = self.device_choice.index()

        value = self.joystick_values[index]
        if value != "none":
            # Reset to default device for other ports using the same device.
            for port in range(4):
                if self.port == port:
                    continue
                key = "joystick_port_{0}".format(port)
                if get_config(self).get(key) == value:
                    get_config(self).set(key, "")
        get_config(self).set(self.device_option_key, value)
    def load_configuration(self, item):
        if item[str("uuid")]:
            # This triggers the variant browser to load variants for the game.
            # FIXME: This needs to be moved to config, somehow.
            get_config(self).set(PARENT_UUID, item["uuid"])

            # FIXME: REMOVE
            # LauncherSettings.set(PARENT_UUID, item["uuid"])

        else:
            config_path = Database.get_instance().decode_path(
                item[str("path")])
            print("load config from", config_path)
            ConfigLoader(get_config(self)).load_config_file(config_path)
Пример #9
0
    def browse(self, dir_mode):
        default_dir = FSGSDirectories.get_hard_drives_dir()
        dialog = LauncherFilePicker(
            self.get_window(),
            gettext("Choose Hard Drive"),
            "hd",
            get_config(self).get(self.config_key),
            dir_mode=dir_mode,
        )
        if not dialog.show_modal():
            dialog.destroy()
            return
        path = dialog.get_path()
        dialog.destroy()

        checksum_tool = ChecksumTool(self.get_window())
        sha1 = ""
        if dir_mode:
            print("not calculating HD checksums for directories")
        else:
            size = os.path.getsize(path)
            if size < 64 * 1024 * 1024:
                sha1 = checksum_tool.checksum(path)
            else:
                print("not calculating HD checksums HD files > 64MB")
        full_path = path

        # FIXME: use contract function
        dir_path, file = os.path.split(path)
        self.text_field.set_text(file)
        if os.path.normcase(os.path.normpath(dir_path)) == os.path.normcase(
                os.path.normpath(default_dir)):
            path = file

        self.text_field.set_text(path)
        values = [(self.config_key, path), (self.config_key_sha1, sha1)]
        if self.index == 0:
            # whdload_args = ""
            # dummy, ext = os.path.splitext(path)
            # if not dir_mode and ext.lower() in Archive.extensions:
            #     try:
            #         whdload_args = self.calculate_whdload_args(full_path)
            #     except Exception:
            #         traceback.print_exc()
            # values.append(("x_whdload_args", whdload_args))
            values.extend(
                whdload.generate_config_for_archive(
                    full_path, model_config=False).items())
        get_config(self).set_multiple(values)
Пример #10
0
 def __init__(self, parent, names):
     parent.__config_enable_behavior = self
     self._parent = weakref.ref(parent)
     self._names = set(names)
     get_config(parent).add_listener(self)
     try:
         parent.destroyed.connect(self.on_parent_destroyed)
     except AttributeError:
         print(
             "WARNING: ConfigBehavior without remove_listener "
             "implementation"
         )
     for name in names:
         # Broadcast initial value
         self.on_config(name, get_config(parent).get(name))
Пример #11
0
 def on_accuracy_changed(self):
     index = self.accuracy_choice.index()
     config = get_config(self)
     if index == 0:
         config.set("accuracy", "")
     else:
         config.set("accuracy", str(1 - index))
Пример #12
0
    def update_sub_models(self, model_id, sub_model_id):
        sub_model_index = 0
        model_id_s = model_id + "/"
        self.sub_model_ids.clear()
        self.sub_model_titles.clear()

        for config in Amiga.models:
            if config["id"] == model_id:
                self.sub_model_ids.append("")
                self.sub_model_titles.append(config["subtitle"])
            elif config["id"].startswith(model_id_s):
                self.sub_model_ids.append(config["id"].split("/", 1)[1])
                self.sub_model_titles.append(config["subtitle"])
            else:
                continue
            if sub_model_id == self.sub_model_ids[-1]:
                sub_model_index = len(self.sub_model_ids) - 1

        self.sub_model_choice.clear()
        config = get_config(self)
        for title in self.sub_model_titles:
            self.sub_model_choice.add_item(title)
        self.sub_model_choice.set_enabled(
            config.get(Option.PLATFORM) in AMIGA_PLATFORMS
            and len(self.sub_model_ids) > 1)
        return sub_model_index
 def on_variant_rating_config(self, event):
     variant_uuid = get_config(self).get(VARIANT_UUID__)
     for item in self.items:
         if item["uuid"] == variant_uuid:
             item["personal_rating"] = int(event.value or 0)
             self.update()
             break
    def on_browse(self):
        if self.mode == self.CD_MODE:
            title = gettext("Choose CD-ROM Image")
            # default_dir = FSGSDirectories.get_cdroms_dir()
            media_type = "cd"
        elif self.mode == self.TAPE_MODE:
            title = gettext("Choose Tape Image")
            media_type = "tape"
        elif self.mode == self.CARTRIDGE_MODE:
            title = gettext("Choose Cartridge Image")
            media_type = "cartridge"
        else:
            title = gettext("Choose Floppy Image")
            # default_dir = FSGSDirectories.get_floppies_dir()
            media_type = "floppy"
        dialog = LauncherFilePicker(
            self.window,
            title,
            media_type,
            get_config(self).get(self.config_key),
        )

        if not dialog.show_modal():
            return
        path = dialog.get_path()

        if self.mode == self.CD_MODE:
            fsgs.amiga.insert_cd(self.drive, path)
        elif self.mode == self.FLOPPY_MODE:
            fsgs.amiga.insert_floppy(self.drive, path)
        else:
            fsgs.config.set(self.config_key, Paths.contract_path(path))
    def __init__(self, parent, port_gui_index):
        super().__init__(parent, [""], read_only=True)
        self.port_gui_index = port_gui_index
        self.port = self.port_gui_index + 1
        self._platform = ""
        self._config_key = ""
        self.device_option_key = ""

        # AmigaEnableBehavior(self.device_choice)
        self.device_values = []
        self.rebuild_device_list()

        config = get_config(self)
        # Must check platform before device option key
        self.on_config(Option.PLATFORM, config.get(Option.PLATFORM))
        self.on_config(
            self.device_option_key,
            config.get(self.device_option_key),
        )
        # self.changed.connect(self.__changed)
        self.set_index(0)

        config.add_listener(self)
        LauncherSignal.add_listener("settings_updated", self)
        LauncherSignal.add_listener("device_list_updated", self)
 def set_value_or_default(self, value):
     if self.port == 0:
         if value == "mouse":
             value = ""
     elif self.port == 1:
         if get_config(self).get("amiga_model").startswith("CD32"):
             default = "cd32 gamepad"
         else:
             default = "joystick"
         if value == default:
             value = ""
     else:
         if value == "nothing":
             value = ""
     if get_config(self).get(self.mode_option_key) != value:
         get_config(self).set(self.mode_option_key, value)
 def update_config_key(self):
     if self.mode == self.CD_MODE:
         self.config_key = "cdrom_drive_{}".format(self.drive)
         self.config_key_sha1 = "x_cdrom_drive_{}_sha1".format(self.drive)
         self.config_key_implicit = "__implicit_cdrom_drive_count"
     elif self.mode == self.TAPE_MODE:
         self.config_key = "tape_drive_{}".format(self.drive)
         self.config_key_sha1 = "x_tape_drive_{}_sha1".format(self.drive)
         self.config_key_implicit = "__implicit_tape_drive_count"
     elif self.mode == self.CARTRIDGE_MODE:
         if self.drive == 0:
             self.config_key = Option.CARTRIDGE_SLOT
             self.config_key_sha1 = "x_cartridge_slot_sha1"
         else:
             self.config_key = "cartridge_drive_{}".format(self.drive)
             self.config_key_sha1 = "x_cartridge_drive_{}_sha1".format(
                 self.drive)
         self.config_key_implicit = "__implicit_cartridge_drive_count"
     else:
         self.config_key = "floppy_drive_{}".format(self.drive)
         self.config_key_sha1 = "x_floppy_drive_{}_sha1".format(self.drive)
         self.config_key_implicit = "__implicit_uae_floppy{}type".format(
             self.drive)
     config = get_config(self)
     self.on_config(self.config_key, config.get(self.config_key))
     self.on_config(
         self.config_key_implicit,
         config.get(self.config_key_implicit),
     )
 def on_amiga_model_config(self, value):
     config = get_config(self)
     config.update_kickstart()
     if value != self.amiga_model:
         self.amiga_model = value
         self.amiga_model_calculated = value.split("/")[0]
         self.rebuild_warnings_and_refresh()
 def on_activate_item(self, item):
     config = get_config(self)
     path = config.get(self.file_key.format(item))
     sha1 = config.get(self.sha1_key.format(item))
     if self.cd_mode:
         pass
     else:
         fsgs.amiga.insert_floppy_in_free_drive(path, sha1=sha1)
    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()
Пример #21
0
 def get_url(self):
     config = get_config(self)
     variant_uuid = config.get("variant_uuid", "")
     if not variant_uuid:
         return
     return "{0}/game/{1}/edit#{1}".format(
         openretro_url_prefix(), variant_uuid
     )
 def on_eject(self):
     config = get_config(self)
     if self.mode == self.CD_MODE:
         CDManager.eject(self.drive, config=config)
     elif self.mode == self.FLOPPY_MODE:
         FloppyManager.eject(self.drive, config=config)
     else:
         fsgs.config.set(self.config_key, "")
Пример #23
0
 def function():
     if progress == "__run__":
         self.cancel_button.set_enabled(False)
         # Hide dialog after 1.5 seconds. The reason for delaying it
         # is to avoid "confusing" flickering if/when the dialog is
         # only shown for a split second.
         if self.visible():
             fsui.call_later(1500, hide_function)
         get_config(self).set("__progress",
                              gettext("Running: Emulator"))
     else:
         if self.no_gui:
             print("[PROGRESS]", progress)
         else:
             self.sub_title_label.set_text(progress)
         get_config(self).set("__progress",
                              "Preparing: {}".format(progress))
Пример #24
0
 def set_rating_for_variant(self, variant_uuid, rating):
     # FIXME: Do asynchronously, add to queue
     client = OGDClient()
     result = client.rate_variant(variant_uuid, like=rating)
     like_rating = result.get("like", 0)
     work_rating = result.get("work", 0)
     database = Database.instance()
     cursor = database.cursor()
     cursor.execute("DELETE FROM rating WHERE game_uuid = ?",
                    (variant_uuid, ))
     cursor.execute(
         "INSERT INTO rating (game_uuid, work_rating, like_rating) "
         "VALUES (?, ?, ?)",
         (variant_uuid, work_rating, like_rating),
     )
     database.commit()
     # LauncherSettings.set("__variant_rating", str(like_rating))
     get_config(self).set(VARIANT_RATING__, str(like_rating))
 def __init__(self, parent, platforms):
     self._widget = parent
     self.platforms = set(platforms)
     # self._parent = weakref.ref(parent)
     parent.__platform_behavior = self
     config = get_config(self.widget())
     self.on_config("platform", config.get("platform"))
     config.add_listener(self)
     parent.destroyed.connect(self.__on_parent_destroy)
Пример #26
0
 def on_model_changed(self):
     print("ModelGroup.on_model_change\n")
     index = self.model_choice.index()
     model = self.model_ids[index]
     if model == "A500":
         # The default model (A500) can be specified with the empty string
         model = ""
     config = get_config(self)
     config.set("amiga_model", model)
Пример #27
0
 def on_left_down(self):
     config = get_config(self)
     if len(self.have) == 0:
         return
     menu = Menu()
     for key, description in url_descriptions:
         value = config.get(key, "")
         if value:
             menu.add_item(description, create_open_url_function(value))
     self.popup_menu(menu)
Пример #28
0
 def __init__(self, parent, icon=None):
     if icon is not None:
         self.icon = icon
     else:
         self.icon = Image("launcher:/data/16x16/world.png")
     Panel.__init__(self, parent, paintable=True)
     # self.set_tooltip(tooltip)
     config = get_config(self)
     config.add_listener(self)
     self.on_config("variant_uuid", "")
    def update_media_type(self):
        if self.__platform in AMIGA_PLATFORMS:
            self.set_cd_mode(Amiga.is_cd_based(get_config(self)))
        elif self.__platform in [Platform.C64]:
            if self._c64_model == C64_MODEL_C64C_1541_II:
                self.set_mode(self.FLOPPY_MODE)
            else:
                self.set_mode(self.TAPE_MODE)
        elif self.__platform in [Platform.CPC]:
            if self._cpc_model == CPC_MODEL_464:
                self.set_mode(self.TAPE_MODE)
            else:
                self.set_mode(self.FLOPPY_MODE)
        elif self.__platform in [Platform.DOS]:
            self.set_mode(self.FLOPPY_MODE)
        elif self.__platform in [Platform.PSX]:
            self.set_mode(self.CD_MODE)
        elif self.__platform in [Platform.ST]:
            self.set_mode(self.FLOPPY_MODE)
        elif self.__platform in [Platform.SPECTRUM]:
            if self._spectrum_model == SPECTRUM_MODEL_PLUS3:
                self.set_mode(self.FLOPPY_MODE)
            else:
                self.set_mode(self.TAPE_MODE)
        else:
            self.set_mode(self.CARTRIDGE_MODE)

        if self._main:
            if self.__platform == Platform.A7800:
                self.selectors[1].hide()
                self._a78_header_widget.show()
                self._command_widget.hide()
                self._ines_header_widget.hide()
            elif self.__platform in [
                    Platform.CPC,
                    Platform.DOS,
                    Platform.SPECTRUM,
            ]:
                self.selectors[1].hide()
                self._a78_header_widget.hide()
                self._command_widget.show()
                self._ines_header_widget.hide()
            elif self.__platform == Platform.NES:
                # if self.selectors[1].is_visible():
                self.selectors[1].hide()
                self._a78_header_widget.hide()
                self._command_widget.hide()
                self._ines_header_widget.show()
            else:
                # if not self.selectors[1].is_visible():
                self.selectors[1].show()
                self._command_widget.hide()
                self._a78_header_widget.hide()
                self._ines_header_widget.hide()
            self.layout.update()
Пример #30
0
    def __init__(self, parent):
        StatusElement.__init__(self, parent)
        self.icon = Image("launcher:/data/16x16/user.png")
        self.text = gettext("N/A")
        self.active = False

        self.players = ""

        config = get_config(self)
        config.add_listener(self)
        self.on_config("players", config.get("players"))