mirror of
https://github.com/lutris/lutris
synced 2024-10-06 07:50:16 +00:00
Add icon type switching
This commit is contained in:
parent
aca6280a5f
commit
3c9d204c98
|
@ -150,6 +150,62 @@
|
|||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="icon_type_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Icon style</property>
|
||||
<property name="use_underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu" id="menu1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="banner_small_menuitem">
|
||||
<property name="name">banner_small</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Small banner</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<signal name="activate" handler="on_icon_type_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="banner_menuitem">
|
||||
<property name="name">banner</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Banner</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">banner_small_menuitem</property>
|
||||
<signal name="activate" handler="on_icon_type_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioMenuItem" id="icon_menuitem">
|
||||
<property name="name">icon</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Icon</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="draw_as_radio">True</property>
|
||||
<property name="group">banner_small_menuitem</property>
|
||||
<signal name="activate" handler="on_icon_type_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem" id="separatormenuitem2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckMenuItem" id="filter_installed">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
@ -28,7 +28,7 @@ from gi.repository import Gio
|
|||
from lutris import pga
|
||||
from lutris.util.log import logger
|
||||
from lutris.util.strings import slugify
|
||||
from lutris.settings import PGA_DB, CONFIG_DIR, DATA_DIR, CACHE_DIR
|
||||
from lutris.settings import PGA_DB, CONFIG_DIR, DATA_DIR, CACHE_DIR, ICON_PATH
|
||||
|
||||
|
||||
def register_handler():
|
||||
|
@ -55,7 +55,7 @@ def check_config(force_wipe=False):
|
|||
join(CONFIG_DIR, "games"),
|
||||
DATA_DIR,
|
||||
join(DATA_DIR, "covers"),
|
||||
join(DATA_DIR, "icons"),
|
||||
ICON_PATH,
|
||||
join(DATA_DIR, "banners"),
|
||||
join(DATA_DIR, "runners"),
|
||||
join(DATA_DIR, "lib"),
|
||||
|
|
|
@ -29,13 +29,17 @@ from lutris.gui.widgets import (
|
|||
)
|
||||
|
||||
GAME_VIEW = 'icon'
|
||||
ICON_TYPE = 'banner'
|
||||
|
||||
|
||||
def switch_to_view(view=GAME_VIEW, games=[], filter_text=None):
|
||||
def switch_to_view(view=GAME_VIEW, games=[], filter_text=None,
|
||||
icon_type=ICON_TYPE):
|
||||
if view == 'icon':
|
||||
view = GameIconView(games, filter_text=filter_text)
|
||||
view = GameIconView(games, filter_text=filter_text,
|
||||
icon_type=icon_type)
|
||||
elif view == 'list':
|
||||
view = GameTreeView(games, filter_text=filter_text)
|
||||
view = GameTreeView(games, filter_text=filter_text,
|
||||
icon_type=icon_type)
|
||||
return view
|
||||
|
||||
|
||||
|
@ -57,6 +61,7 @@ class LutrisWindow(object):
|
|||
height = int(settings.read_setting('height') or 600)
|
||||
self.window_size = (width, height)
|
||||
view_type = settings.read_setting('view_type') or 'icon'
|
||||
self.icon_type = settings.read_setting('icon_type') or 'banner'
|
||||
filter_installed_setting = settings.read_setting(
|
||||
'filter_installed'
|
||||
) or 'false'
|
||||
|
@ -68,25 +73,36 @@ class LutrisWindow(object):
|
|||
logger.debug("Getting game list")
|
||||
game_list = get_game_list(self.filter_installed)
|
||||
logger.debug("Switching view")
|
||||
self.view = switch_to_view(view_type, game_list)
|
||||
self.view = switch_to_view(view_type, game_list,
|
||||
icon_type=self.icon_type)
|
||||
logger.debug("Connecting signals")
|
||||
self.main_box = self.builder.get_object('main_box')
|
||||
self.splash_box = self.builder.get_object('splash_box')
|
||||
# View menu
|
||||
self.icon_view_menuitem = self.builder.get_object("iconview_menuitem")
|
||||
self.icon_view_menuitem.set_active(view_type == 'icon')
|
||||
self.list_view_menuitem = self.builder.get_object("listview_menuitem")
|
||||
self.list_view_menuitem.set_active(view_type == 'list')
|
||||
# View buttons
|
||||
self.icon_view_btn = self.builder.get_object('switch_grid_view_btn')
|
||||
self.icon_view_btn.set_active(view_type == 'icon')
|
||||
self.list_view_btn = self.builder.get_object('switch_list_view_btn')
|
||||
self.list_view_btn.set_active(view_type == 'list')
|
||||
# Icon type menu
|
||||
self.banner_small_menuitem = \
|
||||
self.builder.get_object('banner_small_menuitem')
|
||||
self.banner_small_menuitem.set_active(self.icon_type == 'banner_small')
|
||||
self.banner_menuitem = self.builder.get_object('banner_menuitem')
|
||||
self.banner_menuitem.set_active(self.icon_type == 'banner')
|
||||
self.icon_menuitem = self.builder.get_object('icon_menuitem')
|
||||
self.icon_menuitem.set_active(self.icon_type == 'icon')
|
||||
|
||||
self.search_entry = self.builder.get_object('search_entry')
|
||||
|
||||
# Scroll window
|
||||
self.games_scrollwindow = self.builder.get_object('games_scrollwindow')
|
||||
self.games_scrollwindow.add(self.view)
|
||||
#Status bar
|
||||
# Status bar
|
||||
self.status_label = self.builder.get_object('status_label')
|
||||
self.joystick_icons = []
|
||||
# Buttons
|
||||
|
@ -146,8 +162,7 @@ class LutrisWindow(object):
|
|||
def sync_icons(self):
|
||||
game_list = pga.get_games()
|
||||
resources.fetch_icons([game_info['slug'] for game_info in game_list],
|
||||
callback=self.on_image_downloaded)
|
||||
self.view.queue_draw()
|
||||
callback=self.on_image_downloaded)
|
||||
|
||||
def connect_signals(self):
|
||||
"""Connects signals from the view with the main window.
|
||||
|
@ -214,6 +229,7 @@ class LutrisWindow(object):
|
|||
"""Signal for window close"""
|
||||
view_type = 'icon' if 'IconView' in str(type(self.view)) else 'list'
|
||||
settings.write_setting('view_type', view_type)
|
||||
settings.write_setting('icon_type', self.icon_type)
|
||||
width, height = self.window_size
|
||||
settings.write_setting('width', width)
|
||||
settings.write_setting('height', height)
|
||||
|
@ -344,7 +360,8 @@ class LutrisWindow(object):
|
|||
self.view = switch_to_view(
|
||||
view_type,
|
||||
get_game_list(filter_installed=self.filter_installed),
|
||||
filter_text=self.search_entry.get_text()
|
||||
filter_text=self.search_entry.get_text(),
|
||||
icon_type=self.icon_type
|
||||
)
|
||||
self.view.contextual_menu = self.menu
|
||||
self.connect_signals()
|
||||
|
@ -352,6 +369,13 @@ class LutrisWindow(object):
|
|||
self.view.show_all()
|
||||
self.view.check_resize()
|
||||
|
||||
def on_icon_type_activate(self, menuitem):
|
||||
icon_type = menuitem.get_name()
|
||||
if icon_type == self.view.icon_type:
|
||||
return
|
||||
self.icon_type = icon_type
|
||||
self.do_view_switch(self.current_view_type)
|
||||
|
||||
def create_menu_shortcut(self, *args):
|
||||
"""Adds the game to the system's Games menu"""
|
||||
game_slug = slugify(self.view.selected_game)
|
||||
|
|
|
@ -51,14 +51,14 @@ def filter_view(model, _iter, user_data):
|
|||
return False
|
||||
|
||||
|
||||
def get_pixbuf_for_game(game_slug, size=BANNER_SIZE, is_installed=True):
|
||||
width = size[0]
|
||||
height = size[1]
|
||||
if size in (BANNER_SIZE, BANNER_SMALL_SIZE):
|
||||
def get_pixbuf_for_game(game_slug, icon_type="banner", is_installed=True):
|
||||
if icon_type in ("banner", "banner_small"):
|
||||
size = BANNER_SIZE if icon_type == "banner" else BANNER_SMALL_SIZE
|
||||
default_icon = DEFAULT_BANNER
|
||||
icon_path = os.path.join(settings.BANNER_PATH,
|
||||
"%s.jpg" % game_slug)
|
||||
elif size == ICON_SIZE:
|
||||
elif icon_type == "icon":
|
||||
size = ICON_SIZE
|
||||
default_icon = DEFAULT_ICON
|
||||
icon_path = os.path.join(settings.ICON_PATH,
|
||||
"%s.png" % game_slug)
|
||||
|
@ -66,17 +66,17 @@ def get_pixbuf_for_game(game_slug, size=BANNER_SIZE, is_installed=True):
|
|||
if not os.path.exists(icon_path):
|
||||
icon_path = default_icon
|
||||
try:
|
||||
pixbuf = Pixbuf.new_from_file_at_size(icon_path, width, height)
|
||||
pixbuf = Pixbuf.new_from_file_at_size(icon_path, size[0], size[1])
|
||||
except GLib.GError:
|
||||
pixbuf = Pixbuf.new_from_file_at_size(default_icon, width, height)
|
||||
pixbuf = Pixbuf.new_from_file_at_size(default_icon, size[0], size[1])
|
||||
if not is_installed:
|
||||
transparent_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
|
||||
UNAVAILABLE_GAME_OVERLAY, width, height
|
||||
UNAVAILABLE_GAME_OVERLAY, size[0], size[1]
|
||||
)
|
||||
transparent_pixbuf = transparent_pixbuf.scale_simple(
|
||||
width, height, GdkPixbuf.InterpType.NEAREST
|
||||
size[0], size[1], GdkPixbuf.InterpType.NEAREST
|
||||
)
|
||||
pixbuf.composite(transparent_pixbuf, 0, 0, width, height,
|
||||
pixbuf.composite(transparent_pixbuf, 0, 0, size[0], size[1],
|
||||
0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 100)
|
||||
return transparent_pixbuf
|
||||
return pixbuf
|
||||
|
@ -136,9 +136,9 @@ class IconViewCellRenderer(Gtk.CellRendererText):
|
|||
|
||||
class GameStore(object):
|
||||
|
||||
def __init__(self, games, icon_size=BANNER_SIZE, filter_text=None):
|
||||
def __init__(self, games, filter_text=None, icon_type=None):
|
||||
self.filter_text = filter_text
|
||||
self.icon_size = icon_size
|
||||
self.icon_type = icon_type
|
||||
self.store = Gtk.ListStore(str, str, Pixbuf, str, str, bool)
|
||||
self.store.set_default_sort_func(sort_func)
|
||||
self.store.set_sort_column_id(-1, Gtk.SortType.ASCENDING)
|
||||
|
@ -156,7 +156,7 @@ class GameStore(object):
|
|||
"""Adds a game into the store """
|
||||
if not game.name:
|
||||
return
|
||||
pixbuf = get_pixbuf_for_game(game.slug, self.icon_size,
|
||||
pixbuf = get_pixbuf_for_game(game.slug, self.icon_type,
|
||||
is_installed=game.is_installed)
|
||||
name = game.name.replace('&', "&")
|
||||
self.store.append(
|
||||
|
@ -212,7 +212,7 @@ class GameView(object):
|
|||
def update_image(self, game_slug, is_installed=False):
|
||||
row = self.get_row_by_slug(game_slug)
|
||||
if row:
|
||||
game_pixpuf = get_pixbuf_for_game(game_slug, self.icon_size,
|
||||
game_pixpuf = get_pixbuf_for_game(game_slug, self.icon_type,
|
||||
is_installed=is_installed)
|
||||
row[COL_ICON] = game_pixpuf
|
||||
row[COL_INSTALLED] = is_installed
|
||||
|
@ -237,10 +237,10 @@ class GameTreeView(Gtk.TreeView, GameView):
|
|||
"""Show the main list of games"""
|
||||
__gsignals__ = GameView.__gsignals__
|
||||
|
||||
def __init__(self, games, filter_text=""):
|
||||
def __init__(self, games, filter_text="", icon_type="icon"):
|
||||
self.filter_text = filter_text
|
||||
self.icon_size = ICON_SIZE
|
||||
self.game_store = GameStore(games, icon_size=self.icon_size,
|
||||
self.icon_type = icon_type
|
||||
self.game_store = GameStore(games, icon_type=icon_type,
|
||||
filter_text=self.filter_text)
|
||||
self.model = self.game_store.modelfilter.sort_new_with_model()
|
||||
super(GameTreeView, self).__init__(self.model)
|
||||
|
@ -301,10 +301,10 @@ class GameIconView(Gtk.IconView, GameView):
|
|||
icon_width = BANNER_SIZE[0]
|
||||
icon_padding = 1
|
||||
|
||||
def __init__(self, games, filter_text=""):
|
||||
def __init__(self, games, filter_text="", icon_type="banner"):
|
||||
self.filter_text = filter_text
|
||||
self.icon_size = BANNER_SIZE
|
||||
self.game_store = GameStore(games, icon_size=self.icon_size,
|
||||
self.icon_type = icon_type
|
||||
self.game_store = GameStore(games, icon_type=icon_type,
|
||||
filter_text=self.filter_text)
|
||||
self.model = self.game_store.modelfilter
|
||||
super(GameIconView, self).__init__(model=self.model)
|
||||
|
|
|
@ -19,7 +19,8 @@ CACHE_DIR = os.path.join(BaseDirectory.xdg_cache_home, 'lutris')
|
|||
|
||||
TMP_PATH = os.path.join(CACHE_DIR, 'tmp')
|
||||
BANNER_PATH = os.path.join(DATA_DIR, 'banners')
|
||||
ICON_PATH = os.path.join(BaseDirectory.xdg_data_home, 'icons/hicolor/32x32/apps')
|
||||
ICON_PATH = os.path.join(BaseDirectory.xdg_data_home,
|
||||
'icons/hicolor/32x32/apps')
|
||||
|
||||
sio = SettingsIO(CONFIG_FILE)
|
||||
PGA_DB = sio.read_setting('pga_path') or os.path.join(DATA_DIR, 'pga.db')
|
||||
|
|
Loading…
Reference in a new issue