示例#1
0
class HardDriveGroup(fsui.Panel):

    def __init__(self, parent, index):
        fsui.Panel.__init__(self, parent)
        AmigaEnableBehavior(self)
        self.layout = fsui.VerticalLayout()

        self.index = index
        self.config_key = "hard_drive_{0}".format(index)
        self.config_key_sha1 = "x_hard_drive_{0}_sha1".format(index)

        # if index == 0:
        #     # heading_label = fsui.HeadingLabel(self,
        #     #         _("Hard Drive {0}").format(index + 1))
        #     heading_label = fsui.HeadingLabel(self, gettext("Hard Drives"))
        #     self.layout.add(heading_label, margin_bottom=20)
        #     self.layout.add_spacer(0)

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, fill=True)

        self.eject_button = IconButton(self, "eject_button.png")
        self.eject_button.set_tooltip(gettext("Eject"))
        self.eject_button.activated.connect(self.on_eject_button)
        hori_layout.add(self.eject_button)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin_left=10)

        self.browse_button = IconButton(self, "browse_folder_16.png")
        self.browse_button.set_tooltip(gettext("Browse for Folder"))
        self.browse_button.activated.connect(self.on_browse_folder_button)
        hori_layout.add(self.browse_button, margin_left=10)

        self.browse_button = IconButton(self, "browse_file_16.png")
        self.browse_button.set_tooltip(gettext("Browse for File"))
        self.browse_button.activated.connect(self.on_browse_file_button)
        hori_layout.add(self.browse_button, margin_left=10)

        self.initialize_from_config()
        self.set_config_handlers()

    def initialize_from_config(self):
        self.on_config(self.config_key, LauncherConfig.get(self.config_key))

    def set_config_handlers(self):
        LauncherConfig.add_listener(self)

    def on_destroy(self):
        LauncherConfig.remove_listener(self)

    def on_config(self, key, value):
        if key != self.config_key:
            return
        dir_path, name = os.path.split(value)
        if dir_path:
            path = "{0} ({1})".format(name, dir_path)
        else:
            path = name
        self.text_field.set_text(path)
        self.text_field.set_cursor_position(0)
        self.eject_button.enable(bool(value))

    def on_eject_button(self):
        LauncherConfig.set_multiple([(self.config_key, ""),
                                     (self.config_key_sha1, "")])

    def on_browse_folder_button(self):
        self.browse(dir_mode=True)

    def on_browse_file_button(self):
        self.browse(dir_mode=False)

    def browse(self, dir_mode):
        default_dir = FSGSDirectories.get_hard_drives_dir()
        dialog = LauncherFilePicker(
            self.get_window(), gettext("Choose Hard Drive"), "hd",
            LauncherConfig.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())
        LauncherConfig.set_multiple(values)
示例#2
0
class FloppySelector(fsui.Panel):
    FLOPPY_MODE = 0
    CD_MODE = 1
    TAPE_MODE = 2
    CARTRIDGE_MODE = 3

    def __init__(self, parent, drive, show_path=True):
        fsui.Panel.__init__(self, parent)
        self.mode = FloppySelector.FLOPPY_MODE
        self.show_path = show_path
        self.drive = drive
        self.config_key = ""
        self.config_key_sha1 = ""
        self.config_key_implicit = ""
        self.config_value_implicit = ""
        self.__platform = ""

        self.eject_button = IconButton(self, "eject_button.png")
        # AmigaEnableBehavior(self.eject_button)
        self.eject_button.set_tooltip(gettext("Eject"))
        self.eject_button.activated.connect(self.on_eject)

        self.text_field = fsui.TextField(self, "", read_only=True)

        self.browse_button = IconButton(self, "browse_file_16.png")
        self.browse_button.set_tooltip(gettext("Browse for File"))
        self.browse_button.activated.connect(self.on_browse)
        # AmigaEnableBehavior(self.browse_button)

        self.layout = fsui.HorizontalLayout()
        self.layout.add(self.eject_button)
        self.layout.add_spacer(10)
        self.layout.add(self.text_field, expand=True)
        self.layout.add_spacer(10)
        self.layout.add(self.browse_button)

        # Config.add_listener(self)
        #  fsgs.signal.connect(self.on_config,
        #          "fsgs:config:floppy_drive_{0}".format(self.drive),
        #          "fsgs:config:cdrom_drive_{0}".format(self.drive))
        fsgs.signal.connect("config", self.on_config)
        self.on_config(Option.PLATFORM, fsgs.config.get(Option.PLATFORM))
        self.update_config_key()

    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)

    # def enable(self, enable=True):
    #     self.text_field.enable(enable)
    #     self.browse_button.enable(enable)
    #     self.eject_button.enable(enable)

    def on_config(self, key, value):
        if key == self.config_key:
            dir_path, name = os.path.split(value)
            if dir_path:
                if self.show_path:
                    path = "{0} ({1})".format(name, dir_path)
                else:
                    path = name
            else:
                path = name
            self.text_field.set_text(path)
            self.text_field.set_cursor_position(0)
            self.eject_button.enable(bool(value))
        elif key == self.config_key_implicit:
            self.config_value_implicit = value
            self.update_enable()
        elif key == Option.PLATFORM:
            self.__platform = value
            self.update_enable()

    def update_enable(self):
        if self.__platform in AMIGA_PLATFORMS:
            if self.mode == self.CD_MODE:
                self.text_field.enable(self.config_value_implicit != "0")
            elif self.mode == self.CARTRIDGE_MODE:
                pass
            else:
                self.text_field.enable(self.config_value_implicit != "-1")
        else:
            if self.__platform == PLATFORM_ATARI and \
                            self.mode == self.FLOPPY_MODE:
                self.text_field.enable(self.drive < 2)
            else:
                self.text_field.enable(self.drive == 0)

    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)
        self.on_config(self.config_key, LauncherConfig.get(self.config_key))
        self.on_config(self.config_key_implicit,
                       LauncherConfig.get(self.config_key_implicit))

    def set_mode(self, mode):
        self.mode = mode
        self.update_config_key()

    def on_eject(self):
        if self.mode == self.CD_MODE:
            CDManager.eject(self.drive)
        elif self.mode == self.FLOPPY_MODE:
            FloppyManager.eject(self.drive)
        else:
            fsgs.config.set(self.config_key, "")

    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, LauncherConfig.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))
示例#3
0
class ScanPathsGroup(fsui.Group):
    def __init__(self, parent):
        fsui.Group.__init__(self, parent)
        self.layout = fsui.HorizontalLayout()

        self.layout2 = fsui.VerticalLayout()
        self.layout.add(self.layout2, fill=True, expand=True)

        layout3 = fsui.HorizontalLayout()
        self.layout2.add(layout3, fill=True, expand=True)

        self.list_view = fsui.ListView(self)
        self.list_view.set_min_height(130)
        self.default_icon = fsui.Image("launcher:res/folder_16.png")
        layout3.add(self.list_view, expand=True, fill=True)
        layout3.add_spacer(10)

        vlayout = fsui.VerticalLayout()
        layout3.add(vlayout, fill=True)

        add_button = IconButton(self, "add_button.png")
        add_button.set_tooltip(gettext("Add Directory to Search Path"))
        # add_button.disable()
        add_button.activated.connect(self.on_add_button)
        vlayout.add(add_button)
        vlayout.add_spacer(10)

        self.remove_button = IconButton(self, "remove_button.png")
        self.remove_button.set_tooltip(
            gettext("Remove Directory from Search Path"))
        self.remove_button.disable()
        self.remove_button.activated.connect(self.on_remove_button)
        vlayout.add(self.remove_button)

        # self.list_view.set_items(self.get_search_path())
        self.repopulate_list()
        self.list_view.on_select_item = self.on_select_item
        LauncherSettings.add_listener(self)

    def on_destroy(self):
        LauncherSettings.remove_listener(self)

    def on_setting(self, key, value):
        unused(value)
        if key == "search_path":
            self.repopulate_list()

    def on_select_item(self, index):
        unused(index)
        self.remove_button.enable()

    def repopulate_list(self):
        self.list_view.clear()
        for item in self.get_search_path():
            self.list_view.add_item(item, self.default_icon)

    @classmethod
    def get_search_path(cls):
        paths = FSGSDirectories.get_default_search_path()
        search_path = LauncherSettings.get("search_path")
        for p in search_path.split(";"):
            p = p.strip()
            if not p:
                continue
            elif p[0] == "-":
                p = p[1:]
                if p in paths:
                    paths.remove(p)
            else:
                if p not in paths:
                    paths.append(p)
        # The Configurations dir is always scanned on startup (whenever
        # modification time has changed). If we don't include it here too
        # always, the result will be that the configs sometimes appear (on
        # startup) and disappear (on scan).
        if not FSGSDirectories.get_configurations_dir() in paths:
            paths.append(FSGSDirectories.get_configurations_dir())
        # Likewise, we force the Kickstarts directory to always be scanned.
        if not FSGSDirectories.get_kickstarts_dir() in paths:
            paths.append(FSGSDirectories.get_kickstarts_dir())
        return paths

    def on_add_button(self):
        search_path = LauncherSettings.get("search_path")
        search_path = [x.strip() for x in search_path.split(";") if x.strip()]
        path = fsui.pick_directory(parent=self.get_window())
        if path:
            for i in range(len(search_path)):
                if search_path[i].startswith("-"):
                    if path == search_path[i][1:]:
                        search_path.remove(search_path[i])
                        break
                else:
                    if search_path[i] == path:
                        # Already added.
                        break
            else:
                default_paths = FSGSDirectories.get_default_search_path()
                if path not in default_paths:
                    search_path.append(path)
            LauncherSettings.set("search_path", ";".join(search_path))

    def on_remove_button(self):
        path = self.list_view.get_item(self.list_view.get_index())
        search_path = LauncherSettings.get("search_path")
        search_path = [x.strip() for x in search_path.split(";") if x.strip()]
        for i in range(len(search_path)):
            if search_path[i].startswith("-"):
                if path == search_path[i][1:]:
                    # Already removed.
                    break
            else:
                if search_path[i] == path:
                    search_path.remove(search_path[i])
                    break
        default_paths = FSGSDirectories.get_default_search_path()
        if path in default_paths:
            search_path.append("-" + path)
        LauncherSettings.set("search_path", ";".join(search_path))
示例#4
0
class HardDriveGroup(fsui.Panel):
    def __init__(self, parent, index):
        fsui.Panel.__init__(self, parent)
        AmigaEnableBehavior(self)
        self.layout = fsui.VerticalLayout()

        self.index = index
        self.config_key = "hard_drive_{0}".format(index)
        self.config_key_sha1 = "x_hard_drive_{0}_sha1".format(index)

        # if index == 0:
        #     # heading_label = fsui.HeadingLabel(self,
        #     #         _("Hard Drive {0}").format(index + 1))
        #     heading_label = fsui.HeadingLabel(self, gettext("Hard Drives"))
        #     self.layout.add(heading_label, margin_bottom=20)
        #     self.layout.add_spacer(0)

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, fill=True)

        self.eject_button = IconButton(self, "eject_button.png")
        self.eject_button.set_tooltip(gettext("Eject"))
        self.eject_button.activated.connect(self.on_eject_button)
        hori_layout.add(self.eject_button)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin_left=10)

        self.browse_button = IconButton(self, "browse_folder_16.png")
        self.browse_button.set_tooltip(gettext("Browse for Folder"))
        self.browse_button.activated.connect(self.on_browse_folder_button)
        hori_layout.add(self.browse_button, margin_left=10)

        self.browse_button = IconButton(self, "browse_file_16.png")
        self.browse_button.set_tooltip(gettext("Browse for File"))
        self.browse_button.activated.connect(self.on_browse_file_button)
        hori_layout.add(self.browse_button, margin_left=10)

        self.initialize_from_config()
        self.set_config_handlers()

    def initialize_from_config(self):
        self.on_config(self.config_key, LauncherConfig.get(self.config_key))

    def set_config_handlers(self):
        LauncherConfig.add_listener(self)

    def on_destroy(self):
        LauncherConfig.remove_listener(self)

    def on_config(self, key, value):
        if key != self.config_key:
            return
        dir_path, name = os.path.split(value)
        if dir_path:
            path = "{0} ({1})".format(name, dir_path)
        else:
            path = name
        self.text_field.set_text(path)
        self.text_field.set_cursor_position(0)
        self.eject_button.enable(bool(value))

    def on_eject_button(self):
        LauncherConfig.set_multiple(
            [(self.config_key, ""), (self.config_key_sha1, "")]
        )

    def on_browse_folder_button(self):
        self.browse(dir_mode=True)

    def on_browse_file_button(self):
        self.browse(dir_mode=False)

    def browse(self, dir_mode):
        default_dir = FSGSDirectories.get_hard_drives_dir()
        dialog = LauncherFilePicker(
            self.get_window(),
            gettext("Choose Hard Drive"),
            "hd",
            LauncherConfig.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()
            )
        LauncherConfig.set_multiple(values)