def get_pixbuf_for_game(game_slug, icon_type, is_installed=True): if icon_type.startswith("banner"): default_icon_path = os.path.join(datapath.get(), "media/default_banner.png") icon_path = resources.get_banner_path(game_slug) elif icon_type.startswith("icon"): default_icon_path = os.path.join(datapath.get(), "media/default_icon.png") icon_path = resources.get_icon_path(game_slug) else: logger.error("Invalid icon type '%s'", icon_type) return None size = IMAGE_SIZES[icon_type] pixbuf = get_pixbuf(icon_path, size, fallback=default_icon_path) if not is_installed: unavailable_game_overlay = os.path.join(datapath.get(), "media/unavailable.png") transparent_pixbuf = get_overlay(unavailable_game_overlay, size).copy() pixbuf.composite( transparent_pixbuf, 0, 0, size[0], size[1], 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 100, ) return transparent_pixbuf return pixbuf
def on_custom_image_reset_clicked(self, _widget, image_type): dest_path = "" if ImageType.banner & image_type: self.game.has_custom_banner = False dest_path = resources.get_banner_path(self.game.slug) if ImageType.icon & image_type: self.game.has_custom_icon = False dest_path = resources.get_icon_path(self.game.slug) os.remove(dest_path) self._set_image(image_type)
def on_custom_image_reset_clicked(self, _widget, image_type): if image_type == "banner": self.game.has_custom_banner = False dest_path = resources.get_banner_path(self.game.slug) elif image_type == "icon": self.game.has_custom_icon = False dest_path = resources.get_icon_path(self.game.slug) else: raise ValueError("Unsupported image type %s" % image_type) os.remove(dest_path) self._set_image(image_type)
def sync_game_details(remote_library): """Update local game details, :return: A set of ids of the updated games. """ if not remote_library: return set() updated = set() for remote_game in remote_library: slug = remote_game["slug"] sync_required = False local_game = pga.get_game_by_field(slug, "slug") if not local_game: continue if local_game["updated"] and remote_game["updated"] > local_game["updated"]: # The remote game's info is more recent than the local game sync_required = True if not sync_required: continue logger.debug("Syncing details for %s", slug) game_id = pga.add_or_update( id=local_game["id"], name=local_game["name"], runner=local_game["runner"], slug=slug, year=remote_game["year"], updated=remote_game["updated"], steamid=remote_game["steamid"], ) updated.add(game_id) if not local_game.get("has_custom_banner") and remote_game["banner_url"]: path = resources.get_banner_path(slug) resources.download_media(remote_game["banner_url"], path, overwrite=True) if not local_game.get("has_custom_icon") and remote_game["icon_url"]: path = resources.get_icon_path(slug) resources.download_media(remote_game["icon_url"], path, overwrite=True) if updated: logger.debug("%d games updated", len(updated)) return updated
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 get_pixbuf_for_game(game_slug, image_type, is_installed=True): icon_path = "" default_icon_path = "" if ImageType.banner & image_type: default_icon_path = os.path.join(datapath.get(), "media/default_banner.png") icon_path = resources.get_banner_path(game_slug) if ImageType.icon == image_type: default_icon_path = os.path.join(datapath.get(), "media/default_icon.png") icon_path = resources.get_icon_path(game_slug) size = IMAGE_SIZES[image_type] pixbuf = get_pixbuf(icon_path, size, fallback=default_icon_path) if not is_installed: unavailable_game_overlay = os.path.join(datapath.get(), "media/unavailable.png") transparent_pixbuf = get_overlay(unavailable_game_overlay, size).copy() pixbuf.composite( transparent_pixbuf, 0, 0, size[0], size[1], 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 100, ) return transparent_pixbuf return pixbuf
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()