Example #1
0
    def __init__(self, parent):
        fsui.Group.__init__(self, parent)
        self.layout = fsui.VerticalLayout()

        heading_label = fsui.HeadingLabel(self, gettext("ROM & RAM"))
        self.layout.add(heading_label, margin=10)
        self.layout.add_spacer(0)

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

        label = fsui.Label(self, gettext("Kickstart ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)

        kickstart_types = [
            gettext("Default"),
            gettext("Custom"),
            gettext("Internal")
        ]
        self.kickstart_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.kickstart_type_choice, margin=10)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin=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_button)
        hori_layout.add(self.browse_button, margin=10)

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

        label = fsui.Label(self, gettext("Extended ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)
        # self.layout.add_spacer(0)

        kickstart_types = [gettext("Default"), gettext("Custom")]
        self.ext_rom_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.ext_rom_type_choice, margin_right=10)

        self.ext_text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.ext_text_field, expand=True, margin_right=10)

        self.ext_browse_button = IconButton(self, "browse_file_16.png")
        self.ext_browse_button.set_tooltip(gettext("Browse for File"))
        self.ext_browse_button.activated.connect(self.on_ext_browse_button)
        hori_layout.add(self.ext_browse_button, margin_right=10)

        self.initialize_from_config()
        self.set_config_handlers()
Example #2
0
    def __init__(self, parent):
        fsui.Panel.__init__(self, parent)
        AmigaEnableBehavior(self)
        self.layout = fsui.VerticalLayout()

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

        label = fsui.Label(self, gettext("Kickstart ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)

        kickstart_types = [
            gettext("Default"),
            gettext("Custom"),
            gettext("Internal"),
        ]
        self.kickstart_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.kickstart_type_choice, margin=10)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin=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_button)
        hori_layout.add(self.browse_button, margin=10)

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

        label = fsui.Label(self, gettext("Extended ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)
        # self.layout.add_spacer(0)

        kickstart_types = [gettext("Default"), gettext("Custom")]
        self.ext_rom_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.ext_rom_type_choice, margin_right=10)

        self.ext_text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.ext_text_field, expand=True, margin_right=10)

        self.ext_browse_button = IconButton(self, "browse_file_16.png")
        self.ext_browse_button.set_tooltip(gettext("Browse for File"))
        self.ext_browse_button.activated.connect(self.on_ext_browse_button)
        hori_layout.add(self.ext_browse_button, margin_right=10)

        self.initialize_from_config()
        self.set_config_handlers()
    def __init__(self, parent, *, path, placeholder=""):
        super().__init__(parent)
        self.layout = HorizontalLayout()

        self.text_field = TextField(self,
                                    text=path,
                                    placeholder=placeholder,
                                    clearbutton=True)
        self.text_field.changed.connect(self.__on_text_field_changed)
        self.layout.add(self.text_field, expand=True)

        self.browse_button = IconButton(self, "browse_folder_16.png")
        self.browse_button.set_tooltip(gettext("Browse for File"))
        self.browse_button.activated.connect(self.__on_browse_button)
        # FIXME: Scale 5 here
        self.layout.add(self.browse_button, fill=True, margin_left=5)
class FilePickerField(Group):
    changed = Signal()

    def __init__(self, parent, *, path, placeholder=""):
        super().__init__(parent)
        self.layout = HorizontalLayout()

        self.text_field = TextField(self,
                                    text=path,
                                    placeholder=placeholder,
                                    clearbutton=True)
        self.text_field.changed.connect(self.__on_text_field_changed)
        self.layout.add(self.text_field, expand=True)

        self.browse_button = IconButton(self, "browse_folder_16.png")
        self.browse_button.set_tooltip(gettext("Browse for File"))
        self.browse_button.activated.connect(self.__on_browse_button)
        # FIXME: Scale 5 here
        self.layout.add(self.browse_button, fill=True, margin_left=5)

    def path(self):
        return self.text_field.text()

    def __on_text_field_changed(self):
        self.changed.emit()

    def __on_browse_button(self):
        # FIXME: Show file picker dialog
        # dialog = FileDialog()
        # dialog.show()

        # FIXME: Choose initial directory based on directory of existing path,
        # if any

        dialog = LauncherFilePicker(
            get_window(self),
            # FIXME
            gettext("Select file"),
            # FIXME
            "floppy",
        )
        if not dialog.show_modal():
            print("dialog.show returned false")
            return
        print("dialog.show returned true")
        path = dialog.get_path()
        self.text_field.set_text(path)
Example #5
0
    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()
Example #6
0
class Launcher2SidePanel(Panel):
    def __init__(self, parent):
        super().__init__(parent)
        self.set_background_color(Color(Launcher2Colors.SIDE_PANEL_COLOR))
        # self.set_min_width(300)
        self.set_min_width(252 + 20 * 2)

        hori_layout = HorizontalLayout()
        self.layout.add(
            hori_layout,
            fill=True,
            margin_top=10,
            margin_right=20,
            margin_left=20,
            margin_bottom=0,
        )

        self.choice = Choice(
            self,
            [
                "Game front cover",
            ],
        )
        hori_layout.add(self.choice, expand=True)
        self.choice.disable()  # Currently not implemented

        # FIXME: Only enable button if screen is big enough for expanded
        # window?
        self.add_button = IconButton(self, "add_button.png")
        hori_layout.add(self.add_button, margin_left=10)
        self.add_button.disable()  # Currently not implemented

        self.book = Book(self)
        self.layout.add(self.book, expand=True, fill=True)
        self.pages = []
        self.pages.append(GameFrontCoverPanel(self.book))
        for page in self.pages:
            self.book.add_page(page)
        self.book.set_page(self.pages[0])
    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.text_field = fsui.TextField(self, "", read_only=True)

        self.browse_button = IconButton(self, "browse_folder_16.png")
        self.browse_button.set_tooltip(gettext("Browse for file"))
        self.browse_button.activated.connect(self.on_browse)

        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.layout = fsui.HorizontalLayout()
        self.layout.add(self.text_field, expand=True)
        self.layout.add_spacer(5)
        self.layout.add(self.eject_button, fill=True)
        self.layout.add_spacer(5)
        self.layout.add(self.browse_button, fill=True)

        # 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)
        get_config(self).attach(self.__on_config)
        self.on_config(Option.PLATFORM, fsgs.config.get(Option.PLATFORM))
        self.update_config_key()
Example #8
0
    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)
Example #9
0
    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()
Example #10
0
    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)
Example #11
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))
Example #12
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)
Example #13
0
    def __init__(self, parent, fsgc):
        self.fsgc = fsgc
        super().__init__(parent)
        self.layout = fsui.VerticalLayout()

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, fill=True)
        heading_label = fsui.HeadingLabel(self, gettext("Settings"))
        hori_layout.add(heading_label, margin=10)
        hori_layout.add_spacer(0, expand=True)
        settings_button = IconButton(self, "16x16/more.png")
        settings_button.activated.connect(self.on_settings_button)
        hori_layout.add(settings_button, margin_right=10)
        self.layout.add_spacer(0)

        # button = fsui.Button(self, "Platform Settings")
        # button.activated.connect(self.on_platform_settings_button)
        # self.layout.add(button, margin=10, fill=True)

        # self.add_option(Option.KEEP_ASPECT, text=gettext("Keep Aspect"),
        #                 platforms=AMIGA_PLATFORMS)
        self.add_option(Option.SCALE, text=None, enable=SCALING)
        self.add_option(Option.STRETCH, text=None, enable=STRETCHING)
        self.add_option(Option.BEZEL, text=None, enable=BEZEL)

        self.add_option(Option.EFFECT, text=None, enable=EFFECTS)

        self.add_option(Option.ZOOM, text=None, platforms=AMIGA_PLATFORMS)
        self.add_option(Option.BORDER, text=None, platforms=BORDER)

        # self.add_option(Option.SMOOTHING, text=None, platforms=SMOOTHING)

        # self.add_option(Option.CROP, text=None, platforms=CROPPING)

        # if fsgc.settings[Option.DEVELOPER_MODE] == "1":
        #     pass
        #     # self.add_option(Option.ZXS_DRIVER, [Platform.ZXS])
        #     # self.add_option(Option.DOS_EMULATOR, [Platform.DOS])
        # self.add_option(Option.NES_EMULATOR, [Platform.NES])

        self.add_option(Option.AUTO_LOAD, [Platform.DOS, Platform.ZXS])
        self.add_option(Option.AUTO_QUIT, [Platform.DOS])
        self.add_option(Option.TURBO_LOAD, [Platform.ZXS])

        # self.add_option(Option.FRAME, text=None, platforms=BEZEL)
        # self.add_option(Option.BEZEL, text=None, platforms=BEZEL)

        # self.add_option(Option.CHEATS, platforms=CHEATS)

        quick_settings = fsgc.settings[Option.QUICK_SETTINGS_OPTIONS]
        for option in quick_settings.split(","):
            option = option.strip().lower()
            if "[" in option:
                # For future use of e.g.:
                # option1[platform1,platform2],option2[platform,...]
                option, platforms = option.split("[", 1)
            else:
                platforms = []
            if option in options:
                try:
                    self.add_option(option)
                except Exception:
                    print("Error adding quick setting")
                    traceback.print_exc()

        self.layout.add_spacer(expand=True)

        hori_layout = fsui.HorizontalLayout()
        hori_layout.add_spacer(expand=True)
        self.platform_settings_button = fsui.Button(self, "Platform Settings")
        self.platform_settings_button.activated.connect(
            self.on_platform_settings_button)
        hori_layout.add(self.platform_settings_button, margin=10)
        self.layout.add(hori_layout, fill=True)

        hori_layout = fsui.HorizontalLayout()
        hori_layout.add_spacer(expand=True)
        self.video_sync_checkbox = VideoSyncCheckBox(self)
        hori_layout.add(self.video_sync_checkbox, margin_right=10)
        self.layout.add(hori_layout, fill=True)
        self.monitor_button = MonitorButton(self)
        hori_layout.add(self.monitor_button, fill=True, margin_right=10)
        self.fullscreen_mode_button = FullscreenModeButton(self)
        hori_layout.add(self.fullscreen_mode_button, fill=True, margin_right=10)
        self.layout.add_spacer(10)

        ConfigBehavior(self, [Option.PLATFORM])
        SettingsBehavior(self, [Option.G_SYNC])
    def __init__(self, parent, cd_mode):
        fsui.Group.__init__(self, parent)
        self.layout = fsui.VerticalLayout()

        self.cd_mode = cd_mode
        if self.cd_mode:
            self.file_key_prefix = "cdrom_image_"
            self.file_key = "cdrom_image_{0}"
            self.sha1_key = "x_cdrom_image_{0}_sha1"
        else:
            self.file_key_prefix = "floppy_image_"
            self.file_key = "floppy_image_{0}"
            self.sha1_key = "x_floppy_image_{0}_sha1"

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, expand=False, fill=True)
        self.heading_label = fsui.HeadingLabel(self,
                                               gettext("Media Swap List"))
        hori_layout.add(self.heading_label,
                        margin=10,
                        margin_top=20,
                        margin_bottom=20)
        hori_layout.add_spacer(0, expand=True)
        if not self.cd_mode:
            # hori_layout.add(ConfigWidgetFactory().create(
            #     self, Option.SAVE_DISK), margin_right=20)
            hori_layout.add(SaveDiskCheckBox(self), margin_right=20)
        clear_button = IconButton(self, "clear_button.png")
        clear_button.set_tooltip(gettext("Clear List"))
        clear_button.activated.connect(self.on_clear_list)
        hori_layout.add(clear_button, margin_right=10)
        remove_button = IconButton(self, "remove_button.png")
        remove_button.set_tooltip(gettext("Remove Selected Files"))
        remove_button.activated.connect(self.on_remove_button)
        hori_layout.add(remove_button, margin_right=10)
        add_button = IconButton(self, "add_button.png")
        add_button.set_tooltip(gettext("Add Files to List"))
        add_button.activated.connect(self.on_add_button)
        hori_layout.add(add_button, margin_right=10)

        # hori_layout = fsui.HorizontalLayout()
        # self.layout.add(hori_layout, expand=True, fill=True)
        self.list_view = fsui.ListView(self)
        self.list_view.on_activate_item = self.on_activate_item
        if self.cd_mode:
            self.default_icon = fsui.Image("launcher:res/cdrom_16.png")
        else:
            self.default_icon = fsui.Image("launcher:res/floppy_16.png")
        # hori_layout.add(self.list_view, expand=True, fill=True, margin=10)
        self.layout.add(self.list_view,
                        expand=True,
                        fill=True,
                        margin=10,
                        margin_top=0)

        # vert_layout = fsui.VerticalLayout()
        # hori_layout.add(vert_layout, fill=True)

        # add_button = IconButton(self, "add_button.png")
        # add_button.set_tooltip(gettext("Add Files to List"))
        # add_button.activated.connect(self.on_add_button)
        # vert_layout.add(add_button, margin=10)
        #
        # remove_button = IconButton(self, "remove_button.png")
        # remove_button.set_tooltip(gettext("Remove Selected Files"))
        # remove_button.activated.connect(self.on_remove_button)
        # vert_layout.add(remove_button, margin=10)
        #
        # clear_button = IconButton(self, "clear_button.png")
        # clear_button.set_tooltip(gettext("Clear List"))
        # clear_button.activated.connect(self.on_clear_list)
        # vert_layout.add(clear_button, margin=10)

        self.update_list()
        LauncherConfig.add_listener(self)
    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()
class InputSelector(fsui.Panel):
    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()

    def rebuild_device_list(self):
        self.joystick_values = ["", "none"]
        devices = ["", gettext("No Host Device")]
        for i, name in enumerate(DeviceManager.get_joystick_names()):
            devices.append(fix_device_name(name))
            self.joystick_values.append(DeviceManager.device_ids[i])
        self.device_choice.set_items(devices)

    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 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 on_destroy(self):
        print("InputSelector.on_destroy")
        get_config(self).remove_listener(self)
        LauncherSignal.remove_listener("settings_updated", self)
        LauncherSignal.remove_listener("device_list_updated", self)
        super().on_destroy()

    def on_mode_changed(self):
        if self.mode_choice is not None:
            index = self.mode_choice.index()
            value = self.joystick_mode_values[index]
            self.set_value_or_default(value)

    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 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 on_autofire_button(self):
        if get_config(self).get(self.autofire_mode_option_key) == "1":
            get_config(self).set(self.autofire_mode_option_key, "")
        else:
            get_config(self).set(self.autofire_mode_option_key, "1")

    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()

    def on_device_list_updated_signal(self):
        # print(self.device_choice.index())
        had_default = self.device_choice.index() == 0
        self.rebuild_device_list()
        self.update_default_device(had_default=had_default)

    def on_settings_updated_signal(self):
        self.update_default_device()

    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)
Example #17
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))
Example #18
0
    def __init__(self, parent, cd_mode):
        fsui.Group.__init__(self, parent)
        self.layout = fsui.VerticalLayout()

        self.cd_mode = cd_mode
        if self.cd_mode:
            self.file_key_prefix = "cdrom_image_"
            self.file_key = "cdrom_image_{0}"
            self.sha1_key = "x_cdrom_image_{0}_sha1"
            platforms = AMIGA_PLATFORMS
        else:
            self.file_key_prefix = "floppy_image_"
            self.file_key = "floppy_image_{0}"
            self.sha1_key = "x_floppy_image_{0}_sha1"
            platforms = AMIGA_PLATFORMS

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, expand=False, fill=True)
        self.heading_label = fsui.HeadingLabel(
            self, gettext("Media Swap List")
        )
        hori_layout.add(
            self.heading_label, margin=10, margin_top=20, margin_bottom=20
        )
        hori_layout.add_spacer(0, expand=True)

        if not self.cd_mode:
            save_disk_check_box = SaveDiskCheckBox(self)
            hori_layout.add(save_disk_check_box, margin_right=20)
            PlatformEnableBehavior(save_disk_check_box, platforms=platforms)

        clear_button = IconButton(self, "clear_button.png")
        clear_button.set_tooltip(gettext("Clear List"))
        clear_button.activated.connect(self.on_clear_list)
        PlatformEnableBehavior(clear_button, platforms=platforms)
        hori_layout.add(clear_button, margin_right=10)
        remove_button = IconButton(self, "remove_button.png")
        remove_button.set_tooltip(gettext("Remove Selected Files"))
        remove_button.activated.connect(self.on_remove_button)
        PlatformEnableBehavior(remove_button, platforms=platforms)
        hori_layout.add(remove_button, margin_right=10)
        add_button = IconButton(self, "add_button.png")
        add_button.set_tooltip(gettext("Add Files to List"))
        add_button.activated.connect(self.on_add_button)
        PlatformEnableBehavior(add_button, platforms=platforms)
        hori_layout.add(add_button, margin_right=10)

        # hori_layout = fsui.HorizontalLayout()
        # self.layout.add(hori_layout, expand=True, fill=True)
        self.list_view = fsui.ListView(self)
        PlatformEnableBehavior(self.list_view, platforms=platforms)
        self.list_view.on_activate_item = self.on_activate_item
        if self.cd_mode:
            self.default_icon = fsui.Image("launcher:res/cdrom_16.png")
        else:
            self.default_icon = fsui.Image("launcher:res/floppy_16.png")
        # hori_layout.add(self.list_view, expand=True, fill=True, margin=10)
        self.layout.add(
            self.list_view, expand=True, fill=True, margin=10, margin_top=0
        )

        # vert_layout = fsui.VerticalLayout()
        # hori_layout.add(vert_layout, fill=True)

        # add_button = IconButton(self, "add_button.png")
        # add_button.set_tooltip(gettext("Add Files to List"))
        # add_button.activated.connect(self.on_add_button)
        # vert_layout.add(add_button, margin=10)
        #
        # remove_button = IconButton(self, "remove_button.png")
        # remove_button.set_tooltip(gettext("Remove Selected Files"))
        # remove_button.activated.connect(self.on_remove_button)
        # vert_layout.add(remove_button, margin=10)
        #
        # clear_button = IconButton(self, "clear_button.png")
        # clear_button.set_tooltip(gettext("Clear List"))
        # clear_button.activated.connect(self.on_clear_list)
        # vert_layout.add(clear_button, margin=10)

        self.update_list()
        LauncherConfig.add_listener(self)
    def __init__(self, parent, cd_mode):
        super().__init__(parent)
        self.layout = fsui.VerticalLayout()

        self.cd_mode = cd_mode
        if self.cd_mode:
            self.file_key_prefix = "cdrom_image_"
            self.file_key = "cdrom_image_{0}"
            self.sha1_key = "x_cdrom_image_{0}_sha1"
            platforms = AMIGA_PLATFORMS
        else:
            self.file_key_prefix = "floppy_image_"
            self.file_key = "floppy_image_{0}"
            self.sha1_key = "x_floppy_image_{0}_sha1"
            platforms = AMIGA_PLATFORMS

        hori_layout = fsui.HorizontalLayout()
        self.layout.add(hori_layout, expand=False, fill=True)
        self.heading_label = fsui.HeadingLabel(self,
                                               gettext("Media Swap List"))
        hori_layout.add(self.heading_label,
                        margin=10,
                        margin_top=20,
                        margin_bottom=20)
        hori_layout.add_spacer(0, expand=True)

        if not self.cd_mode:
            save_disk_check_box = SaveDiskCheckBox(self)
            hori_layout.add(save_disk_check_box, margin_right=20)
            PlatformEnableBehavior(save_disk_check_box, platforms=platforms)

        clear_button = IconButton(self, "clear_button.png")
        clear_button.set_tooltip(gettext("Clear List"))
        clear_button.activated.connect(self.on_clear_list)
        PlatformEnableBehavior(clear_button, platforms=platforms)
        hori_layout.add(clear_button, margin_right=10)
        remove_button = IconButton(self, "remove_button.png")
        remove_button.set_tooltip(gettext("Remove Selected Files"))
        remove_button.activated.connect(self.on_remove_button)
        PlatformEnableBehavior(remove_button, platforms=platforms)
        hori_layout.add(remove_button, margin_right=10)
        add_button = IconButton(self, "add_button.png")
        add_button.set_tooltip(gettext("Add Files to List"))
        add_button.activated.connect(self.on_add_button)
        PlatformEnableBehavior(add_button, platforms=platforms)
        hori_layout.add(add_button, margin_right=10)

        # hori_layout = fsui.HorizontalLayout()
        # self.layout.add(hori_layout, expand=True, fill=True)
        self.list_view = fsui.ListView(self)
        PlatformEnableBehavior(self.list_view, platforms=platforms)
        self.list_view.on_activate_item = self.on_activate_item
        if self.cd_mode:
            self.default_icon = fsui.Image("launcher:/data/cdrom_16.png")
        else:
            self.default_icon = fsui.Image("launcher:/data/floppy_16.png")
        # hori_layout.add(self.list_view, expand=True, fill=True, margin=10)
        self.layout.add(self.list_view,
                        expand=True,
                        fill=True,
                        margin=10,
                        margin_top=0)

        # vert_layout = fsui.VerticalLayout()
        # hori_layout.add(vert_layout, fill=True)

        # add_button = IconButton(self, "add_button.png")
        # add_button.set_tooltip(gettext("Add Files to List"))
        # add_button.activated.connect(self.on_add_button)
        # vert_layout.add(add_button, margin=10)
        #
        # remove_button = IconButton(self, "remove_button.png")
        # remove_button.set_tooltip(gettext("Remove Selected Files"))
        # remove_button.activated.connect(self.on_remove_button)
        # vert_layout.add(remove_button, margin=10)
        #
        # clear_button = IconButton(self, "clear_button.png")
        # clear_button.set_tooltip(gettext("Clear List"))
        # clear_button.activated.connect(self.on_clear_list)
        # vert_layout.add(clear_button, margin=10)

        self.update_list()
        config = get_config(self)
        config.add_listener(self)
Example #20
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)
Example #21
0
class KickstartGroup(fsui.Panel):
    def __init__(self, parent):
        fsui.Panel.__init__(self, parent)
        AmigaEnableBehavior(self)
        self.layout = fsui.VerticalLayout()

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

        label = fsui.Label(self, gettext("Kickstart ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)

        kickstart_types = [
            gettext("Default"),
            gettext("Custom"),
            gettext("Internal"),
        ]
        self.kickstart_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.kickstart_type_choice, margin=10)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin=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_button)
        hori_layout.add(self.browse_button, margin=10)

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

        label = fsui.Label(self, gettext("Extended ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)
        # self.layout.add_spacer(0)

        kickstart_types = [gettext("Default"), gettext("Custom")]
        self.ext_rom_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.ext_rom_type_choice, margin_right=10)

        self.ext_text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.ext_text_field, expand=True, margin_right=10)

        self.ext_browse_button = IconButton(self, "browse_file_16.png")
        self.ext_browse_button.set_tooltip(gettext("Browse for File"))
        self.ext_browse_button.activated.connect(self.on_ext_browse_button)
        hori_layout.add(self.ext_browse_button, margin_right=10)

        self.initialize_from_config()
        self.set_config_handlers()

    def initialize_from_config(self):
        self.on_config("kickstart_file", LauncherConfig.get("kickstart_file"))
        self.on_config("kickstart_ext_file",
                       LauncherConfig.get("kickstart_ext_file"))

    def set_config_handlers(self):
        self.kickstart_type_choice.on_changed = self.on_kickstart_type_changed
        self.ext_rom_type_choice.on_changed = self.on_ext_rom_type_changed
        LauncherConfig.add_listener(self)

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

    def on_kickstart_type_changed(self):
        index = self.kickstart_type_choice.get_index()
        if index == 0:
            if LauncherConfig.get("kickstart_file") == "":
                return
            LauncherConfig.set("kickstart_file", "")
        elif index == 2:
            if LauncherConfig.get("kickstart_file") == "internal":
                return
            LauncherConfig.set("kickstart_file", "internal")
        else:
            LauncherConfig.set("kickstart_file",
                               LauncherConfig.get("x_kickstart_file"))
        LauncherConfig.update_kickstart()

    def on_ext_rom_type_changed(self):
        index = self.ext_rom_type_choice.get_index()
        if index == 0:
            if LauncherConfig.get("kickstart_ext_file") == "":
                return
            LauncherConfig.set("kickstart_ext_file", "")
        else:
            LauncherConfig.set(
                "kickstart_ext_file",
                LauncherConfig.get("x_kickstart_ext_file"),
            )
        LauncherConfig.update_kickstart()

    def on_browse_button(self, extended=False):
        default_dir = FSGSDirectories.get_kickstarts_dir()
        if extended:
            title = gettext("Choose Extended ROM")
            key = "kickstart_ext_file"
        else:
            title = gettext("Choose Kickstart ROM")
            key = "kickstart_file"
        dialog = LauncherFilePicker(self.get_window(), title, "rom",
                                    LauncherConfig.get(key))
        if not dialog.show_modal():
            return
        path = dialog.get_path()

        checksum_tool = ChecksumTool(self.get_window())
        sha1 = checksum_tool.checksum_rom(path)

        dir_path, file = os.path.split(path)
        if extended:
            self.ext_text_field.set_text(file)
        else:
            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

        if extended:
            LauncherConfig.set_multiple([
                ("kickstart_ext_file", path),
                ("x_kickstart_ext_file", path),
                ("x_kickstart_ext_file_sha1", sha1),
            ])
        else:
            LauncherConfig.set_multiple([
                ("kickstart_file", path),
                ("x_kickstart_file", path),
                ("x_kickstart_file_sha1", sha1),
            ])

    def on_ext_browse_button(self):
        return self.on_browse_button(extended=True)

    def on_config(self, key, value):
        if key == "kickstart_file":
            if value == "internal":
                self.text_field.set_text("")
                self.kickstart_type_choice.set_index(2)
            elif value:
                _, file = os.path.split(value)
                self.text_field.set_text(file)
                self.kickstart_type_choice.set_index(1)
            else:
                self.text_field.set_text("")
                self.kickstart_type_choice.set_index(0)
        elif key == "kickstart_ext_file":
            if value:
                _, file = os.path.split(value)
                self.ext_text_field.set_text(file)
                self.ext_rom_type_choice.set_index(1)
            else:
                self.ext_text_field.set_text("")
                self.ext_rom_type_choice.set_index(0)
Example #22
0
class KickstartGroup(fsui.Panel):
    def __init__(self, parent):
        fsui.Panel.__init__(self, parent)
        AmigaEnableBehavior(self)
        self.layout = fsui.VerticalLayout()

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

        label = fsui.Label(self, gettext("Kickstart ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)

        kickstart_types = [
            gettext("Default"),
            gettext("Custom"),
            gettext("Internal"),
        ]
        self.kickstart_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.kickstart_type_choice, margin=10)

        self.text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.text_field, expand=True, margin=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_button)
        hori_layout.add(self.browse_button, margin=10)

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

        label = fsui.Label(self, gettext("Extended ROM") + ":")
        hori_layout.add(label, margin_left=10, margin_right=10)
        # self.layout.add_spacer(0)

        kickstart_types = [gettext("Default"), gettext("Custom")]
        self.ext_rom_type_choice = fsui.Choice(self, kickstart_types)
        hori_layout.add(self.ext_rom_type_choice, margin_right=10)

        self.ext_text_field = fsui.TextField(self, "", read_only=True)
        hori_layout.add(self.ext_text_field, expand=True, margin_right=10)

        self.ext_browse_button = IconButton(self, "browse_file_16.png")
        self.ext_browse_button.set_tooltip(gettext("Browse for File"))
        self.ext_browse_button.activated.connect(self.on_ext_browse_button)
        hori_layout.add(self.ext_browse_button, margin_right=10)

        self.initialize_from_config()
        self.set_config_handlers()

    def initialize_from_config(self):
        self.on_config("kickstart_file", LauncherConfig.get("kickstart_file"))
        self.on_config(
            "kickstart_ext_file", LauncherConfig.get("kickstart_ext_file")
        )

    def set_config_handlers(self):
        self.kickstart_type_choice.on_changed = self.on_kickstart_type_changed
        self.ext_rom_type_choice.on_changed = self.on_ext_rom_type_changed
        LauncherConfig.add_listener(self)

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

    def on_kickstart_type_changed(self):
        index = self.kickstart_type_choice.get_index()
        if index == 0:
            if LauncherConfig.get("kickstart_file") == "":
                return
            LauncherConfig.set("kickstart_file", "")
        elif index == 2:
            if LauncherConfig.get("kickstart_file") == "internal":
                return
            LauncherConfig.set("kickstart_file", "internal")
        else:
            LauncherConfig.set(
                "kickstart_file", LauncherConfig.get("x_kickstart_file")
            )
        LauncherConfig.update_kickstart()

    def on_ext_rom_type_changed(self):
        index = self.ext_rom_type_choice.get_index()
        if index == 0:
            if LauncherConfig.get("kickstart_ext_file") == "":
                return
            LauncherConfig.set("kickstart_ext_file", "")
        else:
            LauncherConfig.set(
                "kickstart_ext_file",
                LauncherConfig.get("x_kickstart_ext_file"),
            )
        LauncherConfig.update_kickstart()

    def on_browse_button(self, extended=False):
        default_dir = FSGSDirectories.get_kickstarts_dir()
        if extended:
            title = gettext("Choose Extended ROM")
            key = "kickstart_ext_file"
        else:
            title = gettext("Choose Kickstart ROM")
            key = "kickstart_file"
        dialog = LauncherFilePicker(
            self.get_window(), title, "rom", LauncherConfig.get(key)
        )
        if not dialog.show_modal():
            return
        path = dialog.get_path()

        checksum_tool = ChecksumTool(self.get_window())
        sha1 = checksum_tool.checksum_rom(path)

        dir_path, file = os.path.split(path)
        if extended:
            self.ext_text_field.set_text(file)
        else:
            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

        if extended:
            LauncherConfig.set_multiple(
                [
                    ("kickstart_ext_file", path),
                    ("x_kickstart_ext_file", path),
                    ("x_kickstart_ext_file_sha1", sha1),
                ]
            )
        else:
            LauncherConfig.set_multiple(
                [
                    ("kickstart_file", path),
                    ("x_kickstart_file", path),
                    ("x_kickstart_file_sha1", sha1),
                ]
            )

    def on_ext_browse_button(self):
        return self.on_browse_button(extended=True)

    def on_config(self, key, value):
        if key == "kickstart_file":
            if value == "internal":
                self.text_field.set_text("")
                self.kickstart_type_choice.set_index(2)
            elif value:
                _, file = os.path.split(value)
                self.text_field.set_text(file)
                self.kickstart_type_choice.set_index(1)
            else:
                self.text_field.set_text("")
                self.kickstart_type_choice.set_index(0)
        elif key == "kickstart_ext_file":
            if value:
                _, file = os.path.split(value)
                self.ext_text_field.set_text(file)
                self.ext_rom_type_choice.set_index(1)
            else:
                self.ext_text_field.set_text("")
                self.ext_rom_type_choice.set_index(0)