def on_custom_image_select(self, _widget, image_type): dialog = Gtk.FileChooserDialog( "Please choose a custom image", self, Gtk.FileChooserAction.OPEN, ( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK, ), ) image_filter = Gtk.FileFilter() image_filter.set_name("Images") image_filter.add_pixbuf_formats() dialog.add_filter(image_filter) response = dialog.run() if response == Gtk.ResponseType.OK: image_path = dialog.get_filename() if image_type == "banner": self.game.has_custom_banner = True dest_path = resources.get_banner_path(self.game.slug) size = BANNER_SIZE file_format = "jpeg" else: self.game.has_custom_icon = True dest_path = resources.get_icon_path(self.game.slug) size = ICON_SIZE file_format = "png" pixbuf = get_pixbuf(image_path, size) pixbuf.savev(dest_path, file_format, [], []) self._set_image(image_type) if image_type == "icon": resources.update_desktop_icons() dialog.destroy()
def download_icons(self, downloads, media_type): """Download a list of media files concurrently. Limits the number of simultaneous downloads to avoid API throttling and UI being overloaded with signals. """ if not downloads: return with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: future_downloads = { executor.submit(download_media, url, dest_path): slug for slug, url, dest_path in downloads } for future in concurrent.futures.as_completed(future_downloads): slug = future_downloads[future] try: future.result() except Exception as ex: # pylint: disable=broad-except logger.exception('%r failed: %s', slug, ex) else: self.emit("icon-loaded", slug, media_type) if media_type == "icon": update_desktop_icons()
def on_custom_image_select(self, _widget, image_type): dialog = Gtk.FileChooserDialog( _("Please choose a custom image"), self, Gtk.FileChooserAction.OPEN, ( Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK, ), ) image_filter = Gtk.FileFilter() image_filter.set_name(_("Images")) image_filter.add_pixbuf_formats() dialog.add_filter(image_filter) try: main_file_path = self.game.runner.get_main_file() except AttributeError: main_file_path = None path_type = PATH_TYPE.UNKNOWN if ImageType.banner & image_type: path_type = PATH_TYPE.BANNER if ImageType.icon & image_type: path_type = PATH_TYPE.ICON def_path = default_path_handler.get( # unfortuantely the original path is not stored entry=None, # No default for images default=None, main_file_path=main_file_path, install_path=self.lutris_config.game_config.get("game_path"), path_type=path_type) if os.path.isfile(def_path): if self.action != Gtk.FileChooserAction.SELECT_FOLDER: dialog.set_filename(os.path.basename(def_path)) def_path = os.path.dirname(def_path) dialog.set_current_folder(def_path) response = dialog.run() if response == Gtk.ResponseType.OK: image_path = dialog.get_filename() default_path_handler.set_selected(image_path, image_type) file_format = "" dest_path = "" size = None if ImageType.banner & image_type: self.game.has_custom_banner = True dest_path = resources.get_banner_path(self.game.slug) size = BANNER_SIZE file_format = "jpeg" if ImageType.icon & image_type: self.game.has_custom_icon = True dest_path = resources.get_icon_path(self.game.slug) size = ICON_SIZE file_format = "png" pixbuf = get_pixbuf(image_path, size) pixbuf.savev(dest_path, file_format, [], []) self._set_image(image_type) if ImageType.icon & image_type: resources.update_desktop_icons() dialog.destroy()