Coverage for lutris.gui.widgets : 40%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding:Utf-8 -*-
'media/unavailable.png') COL_ID, COL_NAME, COL_ICON, COL_RUNNER, COL_INSTALLED, ) = range(5)
"""Default sort function""" a_name = store.get(a_iter, COL_NAME)
if a_name > b_name: return -1 else:
"""Filter the game list""" return True name = model.get(_iter, COL_NAME)[0] if filter_text.lower() in name.lower(): return True else: return False
width = size[0] height = size[1] "%s.jpg" % game_slug) if not os.path.exists(icon_path): icon_path = MISSING_ICON try: pixbuf = Pixbuf.new_from_file_at_size(icon_path, width, height) except GLib.GError: pixbuf = Pixbuf.new_from_file_at_size(MISSING_ICON, width, height) if not is_installed: transparent_pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size( UNAVAILABLE_GAME_OVERLAY, width, height ) width, height, GdkPixbuf.InterpType.NEAREST ) pixbuf.composite(transparent_pixbuf, 0, 0, width, height, 0, 0, 1, 1, GdkPixbuf.InterpType.NEAREST, 100) return transparent_pixbuf return pixbuf
'play': "Play", 'install': "Install", 'add': "Add manually", 'configure': "Configure", 'desktop-shortcut': "Create desktop shortcut", 'menu-shortcut': "Create application menu shortcut", 'uninstall': "Uninstall", }
super(ContextualMenu, self).__init__() for callback in callbacks: name = callback[0] label = self.menu_labels[name] action = Gtk.Action(name=name, label=label, tooltip=None, stock_id=None) action.connect('activate', callback[1]) menuitem = action.create_menu_item() menuitem.action_id = name self.append(menuitem) self.show_all()
is_installed = game_row[COL_INSTALLED] hide_when_installed = ('install', 'add') hide_when_not_installed = ('play', 'configure')
action = menuitem.action_id if is_installed: menuitem.set_visible(action not in hide_when_installed) else: menuitem.set_visible(action not in hide_when_not_installed)
super(ContextualMenu, self).popup(None, None, None, None, event.button, event.time)
self.props.alignment = Pango.Alignment.CENTER self.props.wrap_mode = Pango.WrapMode.WORD self.props.xalign = 0.5 self.props.yalign = 0 self.props.width = ICON_SIZE[0] self.props.wrap_width = ICON_SIZE[0]
self.filter_text = filter_text self.icon_size = icon_size self.store = Gtk.ListStore(str, str, Pixbuf, str, bool) self.store.set_default_sort_func(sort_func) self.fill_store(games) self.modelfilter = self.store.filter_new() self.modelfilter.set_visible_func(filter_view, lambda x: self.filter_text)
self.store.clear() for game in games:
"""Adds a game into the store """ return is_installed=game.is_installed) (game.slug, name, pixbuf, game.runner_name, game.is_installed) )
"game-selected": (GObject.SIGNAL_RUN_FIRST, None, ()), "game-activated": (GObject.SIGNAL_RUN_FIRST, None, ()), "game-installed": (GObject.SIGNAL_RUN_FIRST, None, (str,)), "filter-updated": (GObject.SIGNAL_RUN_FIRST, None, (str,)), }
def n_games(self): return len(self.game_store.store)
game_row = None if model_row[COL_ID] == game_slug: return game_row
self.game_store.add_game(game) self.queue_draw()
row = self.get_row_by_slug(removed_id) if row: self.remove_row(row.iter)
"""Remove a game from the treeview.""" store = self.game_store.store store.remove(model_iter)
self.filter_text = data self.filter_view()
if row: game_pixpuf = get_pixbuf_for_game(game_slug, is_installed=is_installed) row[COL_ICON] = game_pixpuf row[COL_INSTALLED] = is_installed self.queue_draw()
"""Contextual menu""" if event.button != 3: return try: view.current_path = view.get_path_at_pos(event.x, event.y) if type(view) is GameIconView and view.current_path: view.current_path = path game_row = self.get_row_by_slug(self.selected_game) self.contextual_menu.popup(event, game_row)
"""Show the main list of games"""
self.filter_text = filter_text self.game_store = GameStore(games, filter_text=self.filter_text) super(GameTreeView, self).__init__(self.game_store.modelfilter) self.set_rules_hint(True)
# Icon column image_cell = Gtk.CellRendererPixbuf() column = Gtk.TreeViewColumn("", image_cell, pixbuf=COL_ICON) column.set_reorderable(True) self.append_column(column)
column = self.setup_text_column("Name", COL_NAME) self.append_column(column) self.append_column(column)
self.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
self.connect('cursor-changed', self.get_selected_game, False) self.connect('filter-updated', self.update_filter) self.connect('button-press-event', self.popup_contextual_menu)
text_cell = Gtk.CellRendererText() text_cell.set_padding(4, 10) text_cell.set_property("width-chars", 40)
column = Gtk.TreeViewColumn(header, text_cell, markup=column_id) column.set_sort_indicator(True) column.set_resizable(True) column.set_reorderable(True) return column
"""Remove a game from the treeview.""" model = self.get_model() model.remove(model_iter)
"""Sort the game list.""" Gtk.TreeModel.sort_new_with_model(model)
selection = self.get_selection() if launch: else: self.emit("game-selected")
self.filter_text = filter_text self.game_store = GameStore(games, icon_size=ICON_SIZE, filter_text=self.filter_text) super(GameIconView, self).__init__(model=self.game_store.modelfilter) self.set_columns(1) self.set_column_spacing(1) self.pack_end(iconview_cell_renderer, False) self.add_attribute(iconview_cell_renderer, 'markup', COL_NAME)
self.connect('item-activated', self.on_item_activated) self.connect('filter-updated', self.update_filter) self.connect('button-press-event', self.popup_contextual_menu) self.connect('size-allocate', self.on_size_allocate)
icon_width = self.icon_width + self.icon_padding * 2 self.set_columns(nb_columns)
""" Recalculate the colum spacing based on total widget width """ width = self.get_parent().get_allocated_width() self.set_fluid_columns(width - 20)
self.get_selected_game(True)
self.get_selected_game(False)
COL_ID)[0] self.emit("game-activated") else:
"""Progress bar used to monitor a file download.""" 'complete': (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT,)), 'cancelrequested': (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT,)) }
super(DownloadProgressBox, self).__init__()
self.progress_box = Gtk.VBox()
self.progressbar = Gtk.ProgressBar() self.progress_box.pack_start(self.progressbar, True, True, 10) self.progress_label = Gtk.Label() self.progress_box.pack_start(self.progress_label, True, True, 10) self.pack_start(self.progress_box, True, True, 10)
if cancelable: self.cancel_button.show() self.cancel_button.set_sensitive(False) self.cancel_button.connect('clicked', self.cancel) self.pack_end(self.cancel_button, False, False, 10)
self.url = params['url'] self.dest = params['dest']
"""Start downloading a file.""" self.downloader = Downloader(self.url, self.dest) timer_id = GLib.timeout_add(100, self.progress) self.cancel_button.set_sensitive(True) self.downloader.start() return timer_id
"""Show download progress.""" progress = min(self.downloader.progress, 1) if self.downloader.cancelled: self.progressbar.set_fraction(0) self.progress_label.set_text("Download canceled") self.emit('cancelrequested', {}) "%0.2fMb out of %0.2fMb (%0.2fMb/s), %d seconds remaining" % ( float(self.downloader.downloaded_bytes) / megabytes, float(self.downloader.total_bytes) / megabytes, float(self.downloader.speed) / megabytes, self.downloader.time_remaining ) ) self.progress_label.set_text(progress_text) self.progressbar.set_fraction(progress) if progress >= 1.0: return True
"""Cancel the current download.""" if self.downloader: self.downloader.cancel() self.cancel_button.set_sensitive(False)
default=None): super(FileChooserEntry, self).__init__()
self.entry = Gtk.Entry() self.entry.set_text(default) self.pack_start(self.entry, True, True, 0)
self.path_completion = Gtk.ListStore(str) completion = Gtk.EntryCompletion() completion.set_model(self.path_completion) completion.set_text_column(0) self.entry.connect("changed", self.entry_changed)
title="Select folder", transient_for=None, action=action )
self.file_chooser_dlg.add_buttons( Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE, Gtk.STOCK_OPEN, Gtk.ResponseType.OK ) if default: self.file_chooser_dlg.set_current_folder(default)
button = Gtk.Button() button.set_label("Browse...") button.connect('clicked', self.open_filechooser) self.add(button)
self.file_chooser_dlg.connect('response', self.select_file) self.file_chooser_dlg.run()
current_path = widget.get_text() if not current_path: current_path = "/" if not os.path.exists(current_path): current_path, filefilter = os.path.split(current_path) else: for filename in sorted(os.listdir(current_path)): if filename.startswith("."): continue if filefilter is not None \ and not filename.startswith(filefilter): continue self.path_completion.append( [os.path.join(current_path, filename)] ) index += 1 if index > 15: break
if response == Gtk.ResponseType.OK: target_path = dialog.get_filename() self.file_chooser_dlg.set_current_folder(target_path) self.entry.set_text(target_path) dialog.hide()
return self.entry.get_text() |