示例#1
0
    def on_import_icon_clicked(self, *args):
        dialog = FileChooserNative.new(
            _("Import game icon from PNG..."),
            SkyTempleMainController.window(),
            FileChooserAction.OPEN,
            None, None
        )

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == ResponseType.ACCEPT:
            try:
                self.icon_banner.icon.from_pil(Image.open(fn))
            except Exception as err:
                display_error(
                    sys.exc_info(),
                    _('Failed importing game icon:\n') + str(err),
                    _("Could not import.")
                )
            self.icon_surface = pil_to_cairo_surface(self.icon_banner.icon.to_pil().convert('RGBA'))
            self.builder.get_object('draw_icon').queue_draw()
            # Mark as modified
            self.module.mark_as_modified()
    def _destination_file_chooser_response_cb(
        self,
        native: Gtk.FileChooserNative,
        response: int,
        button: Gtk.Button,
    ):
        if response == Gtk.ResponseType.ACCEPT:
            file: Gio.File = native.get_file()
            filename: str = file.get_path()
            if (filename and os.path.isdir(filename)
                    and os.access(filename, os.W_OK)):
                label: Gtk.Label = button.get_child()
                label.set_text(filename)
                self._destination = filename
            else:
                self._destination = None
            self._update_buttons()

        native.destroy()
示例#3
0
    def on_export_icon_clicked(self, *args):
        dialog = FileChooserNative.new(_("Export game icon as PNG..."),
                                       SkyTempleMainController.window(),
                                       FileChooserAction.SAVE, None, None)

        add_dialog_png_filter(dialog)

        response = dialog.run()
        fn = dialog.get_filename()
        dialog.destroy()

        if response == ResponseType.ACCEPT:
            fn = add_extension_if_missing(fn, 'png')
            self.icon_banner.icon.to_pil().save(fn)
示例#4
0
 def _add_zip_filter_to_dialog(self, dialog: Gtk.FileChooserNative):
     filter_zip = Gtk.FileFilter()
     filter_zip.set_name("Zip archives")
     filter_zip.add_pattern("*.zip")
     dialog.add_filter(filter_zip)
     dialog.set_current_name("spritesheet.zip")