def get_user_info_box(self): user_box = Gtk.Box(spacing=6, visible=True) user_box.set_size_request(254, 64) if not system.path_exists(api.USER_INFO_FILE_PATH): return user_box if system.path_exists(api.USER_ICON_FILE_PATH): user_icon = Gtk.Image(visible=True) user_icon.set_from_pixbuf(get_pixbuf(api.USER_ICON_FILE_PATH, (56, 56))) icon_align = Gtk.Alignment(visible=True) icon_align.set(1, 0, 0, 0) icon_align.add(user_icon) user_box.pack_end(icon_align, False, False, 0) with open(api.USER_INFO_FILE_PATH) as user_info_file: user_info = json.load(user_info_file) user_info_box = Gtk.VBox(spacing=6, visible=True) user_label = Gtk.Label(visible=True) user_label.set_markup("<b>%s</b>" % user_info.get("username")) user_label.set_justify(Gtk.Justification.RIGHT) user_label.set_ellipsize(Pango.EllipsizeMode.END) user_label.set_alignment(1, 0.5) user_info_box.pack_start(user_label, False, False, 0) if user_info.get("steamid"): steam_button = Gtk.Button(visible=True) steam_button.set_image(Gtk.Image.new_from_icon_name("steam-symbolic", Gtk.IconSize.MENU)) steam_button.connect( "clicked", lambda *x: open_uri("https://steamcommunity.com/profiles/%s" % user_info["steamid"]), ) button_align = Gtk.Alignment(visible=True) button_align.set(1, 0, 0, 0) button_align.add(steam_button) user_info_box.pack_start(button_align, False, False, 0) user_box.pack_end(user_info_box, True, True, 0) return user_box
def on_custom_image_select(self, _widget, image_type): dialog = Gtk.FileChooserNative.new( _("Please choose a custom image"), self, Gtk.FileChooserAction.OPEN, None, None, ) 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.ACCEPT: image_path = dialog.get_filename() if image_type == "banner": self.game.has_custom_banner = True dest_path = os.path.join(settings.BANNER_PATH, "%s.jpg" % 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": system.update_desktop_icons() dialog.destroy()
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 = datapath.get_banner_path(self.game.slug) size = BANNER_SIZE file_format = 'jpeg' else: self.game.has_custom_icon = True dest_path = datapath.get_icon_path(self.game.slug) size = ICON_SIZE file_format = 'png' pixbuf = get_pixbuf(image_path, None, size) pixbuf.savev(dest_path, file_format, [], []) self._set_image(image_type) if image_type == 'icon': resources.udpate_desktop_icons() dialog.destroy()
def on_icon_loaded(self, media_loader, appid, _path, width, heigth): row = self.get_row_by_id(appid) if not row: return if width != self.service_media.size[0]: return installed = appid in self.installed_game_slugs row[COL_ICON] = get_pixbuf(_path, (width, heigth), is_installed=installed)
def update_icons(self, icon_updates): """Updates the store with new icon paths keyed by slug""" for slug in icon_updates: row = self.get_row_by_slug(slug) if not row: continue installed = slug in self.installed_game_slugs row[COL_ICON] = get_pixbuf(icon_updates[slug], self.service_media.size, is_installed=installed)
def get_pixbuf(self): """Pixbuf varying on icon type""" if self._game_data.get("icon"): image_path = self._game_data["icon"] else: image_path = self.service_media.get_absolute_path(self.slug or self.id) if system.path_exists(image_path): return get_pixbuf(image_path, self.service_media.size) return get_pixbuf_for_game(self._game_data["slug"], self._game_data["image_size"], self.installed)
def update_icons(self): """Updates the store with newly updated icons""" icon_updates = copy(self._icon_updates) self._icon_updates = {} logger.debug("Updating %s icons", len(icon_updates)) for rowid in icon_updates: row = self.get_row_by_id(rowid) if not row: continue path = icon_updates[rowid] installed = rowid in self.installed_game_slugs row[COL_ICON] = get_pixbuf(path, self.service_media.size, is_installed=installed) return False
def get_store(self): """Return a ListStore for the games to import""" liststore = Gtk.ListStore( bool, # import str, # appid str, # name Pixbuf, # icon str, # details ) for game in sorted(self.games or [], key=lambda x: x.name): liststore.append([ False, game.appid, game.name, get_pixbuf(game.icon, (32, 32)) if game.icon else None, str(game.details), ]) return liststore
def get_store(self): """Return a ListStore for the games to import""" liststore = Gtk.ListStore( bool, # import str, # appid str, # name Pixbuf, # icon str, # details ) for game in sorted(self.games, key=lambda x: x.name): liststore.append( [ False, game.appid, game.name, get_pixbuf(game.icon, (32, 32)), str(game.details), ] ) return liststore
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_icon_path(self.game.slug, icon_type=image_type) size = BANNER_SIZE file_format = "jpeg" else: self.game.has_custom_icon = True dest_path = resources.get_icon_path(self.game.slug, icon_type="icon") 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": system.update_desktop_icons() dialog.destroy()
def get_user_info_box(self): user_box = Gtk.Box(spacing=6, visible=True) user_box.set_size_request(254, 64) if not system.path_exists(api.USER_INFO_FILE_PATH): return user_box if system.path_exists(api.USER_ICON_FILE_PATH): user_icon = Gtk.Image(visible=True) user_icon.set_from_pixbuf(get_pixbuf(api.USER_ICON_FILE_PATH, (56, 56))) icon_align = Gtk.Alignment(visible=True) icon_align.set(1, 0, 0, 0) icon_align.add(user_icon) user_box.pack_end(icon_align, False, False, 0) with open(api.USER_INFO_FILE_PATH) as user_info_file: user_info = json.load(user_info_file) user_info_box = Gtk.VBox(spacing=6, visible=True) user_label = Gtk.Label(visible=True) user_label.set_markup("<b>%s</b>" % user_info.get("username")) user_label.set_justify(Gtk.Justification.RIGHT) user_label.set_ellipsize(Pango.EllipsizeMode.END) user_label.set_alignment(1, 0.5) user_info_box.pack_start(user_label, False, False, 0) if user_info.get("steamid"): steam_button = Gtk.Button(visible=True) steam_button.set_image( Gtk.Image.new_from_icon_name("steam-symbolic", Gtk.IconSize.MENU) ) steam_button.connect( "clicked", lambda *x: open_uri( "https://steamcommunity.com/profiles/%s" % user_info["steamid"] ), ) button_align = Gtk.Alignment(visible=True) button_align.set(1, 0, 0, 0) button_align.add(steam_button) user_info_box.pack_start(button_align, False, False, 0) user_box.pack_end(user_info_box, True, True, 0) return user_box
def get_pixbuf(self): """Pixbuf varying on icon type""" if self._game_data.get("icon"): image_path = self._game_data["icon"] else: image_path = self.service_media.get_absolute_path(self.slug) if not system.path_exists(image_path): service = self._game_data.get("service") appid = self._game_data.get("service_id") if appid: service_game = ServiceGameCollection.get_game( service, appid) else: service_game = None if service_game: image_path = self.service_media.get_absolute_path( service_game["slug"]) if system.path_exists(image_path): return get_pixbuf(image_path, self.service_media.size, is_installed=self.installed) return self.service_media.get_pixbuf_for_game(self._game_data["slug"], self.installed)
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()
def get_pixbuf_for_game(self, slug, is_installed=True): image_abspath = self.get_absolute_path(slug) return get_pixbuf(image_abspath, self.size, fallback=get_default_icon(self.size), is_installed=is_installed)