Add Platform icons

This commit is contained in:
Rob Loach 2017-06-09 14:17:05 -04:00
parent 3ea77dac94
commit a1f0270072
No known key found for this signature in database
GPG key ID: 627C60834A74A21A
8 changed files with 23 additions and 12 deletions

View file

@ -59,7 +59,7 @@ class GogWindow(Gtk.Window):
for platform in game['worksOn']:
if game['worksOn'][platform]:
icon_path = os.path.join(datapath.get(), 'media/platforms/{}.png'.format(platform.lower()))
icon_path = os.path.join(datapath.get(), 'media/platform_icons/{}.png'.format(platform.lower()))
icon_box.pack_start(Gtk.Image.new_from_file(icon_path), False, False, 2)
install_button = Gtk.Button.new_from_icon_name("browser-download", Gtk.IconSize.BUTTON)

View file

@ -3,7 +3,7 @@ from gi.repository import Gtk, GObject, Gdk
from lutris import runners
from lutris import settings
from lutris.gui.widgets.utils import get_runner_icon
from lutris.gui.widgets.utils import get_icon
from lutris.gui.dialogs import ErrorDialog
from lutris.gui.config_dialogs import RunnerConfigDialog
from lutris.gui.runnerinstalldialog import RunnerInstallDialog
@ -81,7 +81,7 @@ class RunnersDialog(Gtk.Dialog):
hbox = Gtk.Box()
hbox.show()
# Icon
icon = get_runner_icon(runner_name)
icon = get_icon(runner_name)
icon.show()
icon.set_alignment(0.5, 0.1)
hbox.pack_start(icon, False, False, 10)

View file

@ -6,7 +6,9 @@ from lutris import pga
from lutris.gui.runnerinstalldialog import RunnerInstallDialog
from lutris.gui.config_dialogs import RunnerConfigDialog
from lutris.gui.runnersdialog import RunnersDialog
from lutris.gui.widgets.utils import get_runner_icon
from lutris.gui.widgets.utils import get_icon
from pprint import pprint
TYPE = 0
SLUG = 1
@ -116,13 +118,14 @@ class SidebarListBox(Gtk.ListBox):
self.add(all_row)
self.select_row(all_row)
for runner in self.runners:
icon = get_runner_icon(runner, format='pixbuf', size=(16, 16))
icon = get_icon(runner, format='pixbuf', size=(16, 16))
name = runners.import_runner(runner).human_name
self.add(SidebarRow(runner, 'runner', name, icon))
self.add(SidebarRow(None, 'platform', 'All', None))
for platform in self.platforms:
self.add(SidebarRow(platform, 'platform', platform, None))
icon = get_icon(platform, format='pixbuf', size=(16, 16), icon_type='platform')
self.add(SidebarRow(platform, 'platform', platform, icon))
self.set_filter_func(self._filter_func)
self.set_header_func(self._header_func)

View file

@ -1,5 +1,5 @@
from gi.repository import Gtk, GLib, Gio
from lutris.gui.widgets.utils import get_runner_icon
from lutris.gui.widgets.utils import get_icon
from lutris.gui.dialogs import NoticeDialog
from lutris.services import get_services
from lutris.settings import read_setting, write_setting
@ -15,7 +15,7 @@ class ServiceSyncRow(Gtk.Box):
self.identifier = service.__name__.split('.')[-1]
name = service.NAME
icon = get_runner_icon(self.identifier)
icon = get_icon(self.identifier)
self.pack_start(icon, False, False, 0)
label = Gtk.Label(xalign=0)

View file

@ -39,11 +39,19 @@ def get_pixbuf(image, size, fallback=None):
return pixbuf
def get_runner_icon(runner_name, format='image', size=None):
icon_path = os.path.join(datapath.get(), 'media/runner_icons',
runner_name + '.png')
def get_icon(icon_name, format='image', size=None, icon_type='runner'):
"""Return an icon based on the given name, format, size and type.
Keyword arguments:
icon_name -- The name of the icon to retrieve
format -- The format of the icon, which should be either 'image' or 'pixbuf' (default 'image')
size -- The size for the desired image (default None)
icon_type -- Retrieve either a 'runner' or 'platform' icon (default 'runner')
"""
filename = icon_name.lower().replace(' ', '') + '.png'
icon_path = os.path.join(datapath.get(), 'media/' + icon_type + '_icons', filename)
if not os.path.exists(icon_path):
logger.error("Unable to find icon '%s'", icon_path)
# The icon doesn't exist, so return nothing.
return
if format == 'image':
icon = Gtk.Image()

View file

Before

Width:  |  Height:  |  Size: 715 B

After

Width:  |  Height:  |  Size: 715 B

View file

Before

Width:  |  Height:  |  Size: 361 B

After

Width:  |  Height:  |  Size: 361 B

View file

Before

Width:  |  Height:  |  Size: 499 B

After

Width:  |  Height:  |  Size: 499 B