| 1 |
# Copyright (C) 2010 Adam Olsen |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 2, or (at your option) |
| 6 |
# any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 |
# |
| 17 |
# |
| 18 |
# The developers of the Exaile media player hereby grant permission |
| 19 |
# for non-GPL compatible GStreamer and Exaile plugins to be used and |
| 20 |
# distributed together with GStreamer and Exaile. This permission is |
| 21 |
# above and beyond the permissions granted by the GPL license by which |
| 22 |
# Exaile is covered. If you modify this code, you may extend this |
| 23 |
# exception to your version of the code, but you are not obligated to |
| 24 |
# do so. If you do not wish to do so, delete this exception statement |
| 25 |
# from your version. |
| 26 |
|
| 27 |
from gi.repository import Gdk |
| 28 |
from gi.repository import GdkPixbuf |
| 29 |
from gi.repository import GLib |
| 30 |
from gi.repository import GObject |
| 31 |
from gi.repository import Gtk |
| 32 |
from gi.repository import Pango |
| 33 |
|
| 34 |
import logging |
| 35 |
import sys |
| 36 |
|
| 37 |
from xl.nls import gettext as _ |
| 38 |
from xl.playlist import Playlist, is_valid_playlist, import_playlist |
| 39 |
from xl import common, event, main, player, providers, settings, trax, xdg |
| 40 |
|
| 41 |
from xlgui.widgets.common import AutoScrollTreeView |
| 42 |
from xlgui.widgets.notebook import NotebookPage |
| 43 |
from xlgui.widgets import dialogs, menu, menuitems, playlist_columns |
| 44 |
from xlgui import guiutil, icons |
| 45 |
|
| 46 |
logger = logging.getLogger(__name__) |
| 47 |
|
| 48 |
|
| 49 |
def default_get_playlist_func(parent, context): |
| 50 |
return player.QUEUE.current_playlist |
| 51 |
|
| 52 |
|
| 53 |
class ModesMenuItem(menu.MenuItem): |
| 54 |
""" |
| 55 |
A menu item having a submenu containing entries for shuffle modes. |
| 56 |
|
| 57 |
Defaults to adjusting the currently-playing playlist. |
| 58 |
""" |
| 59 |
|
| 60 |
modetype = '' |
| 61 |
display_name = "" |
| 62 |
|
| 63 |
def __init__(self, name, after, get_playlist_func=default_get_playlist_func): |
| 64 |
menu.MenuItem.__init__(self, name, None, after) |
| 65 |
self.get_playlist_func = get_playlist_func |
| 66 |
|
| 67 |
def factory(self, menu, parent, context): |
| 68 |
item = Gtk.ImageMenuItem.new_with_mnemonic(self.display_name) |
| 69 |
image = Gtk.Image.new_from_icon_name( |
| 70 |
'media-playlist-' + self.modetype, size=Gtk.IconSize.MENU |
| 71 |
) |
| 72 |
item.set_image(image) |
| 73 |
submenu = self.create_mode_submenu(item) |
| 74 |
item.set_submenu(submenu) |
| 75 |
pl = self.get_playlist_func(parent, context) |
| 76 |
item.set_sensitive(pl is not None) |
| 77 |
return item |
| 78 |
|
| 79 |
def create_mode_submenu(self, parent_item): |
| 80 |
names = getattr(Playlist, "%s_modes" % self.modetype) |
| 81 |
displays = getattr(Playlist, "%s_mode_names" % self.modetype) |
| 82 |
items = [] |
| 83 |
previous = None |
| 84 |
for name, display in zip(names, displays): |
| 85 |
after = [previous] if previous else [] |
| 86 |
item = menu.radio_menu_item( |
| 87 |
name, |
| 88 |
after, |
| 89 |
display, |
| 90 |
'%s_modes' % self.modetype, |
| 91 |
self.mode_is_selected, |
| 92 |
self.on_mode_activated, |
| 93 |
) |
| 94 |
items.append(item) |
| 95 |
if previous is None: |
| 96 |
items.append(menu.simple_separator("sep", [items[-1].name])) |
| 97 |
previous = items[-1].name |
| 98 |
m = menu.Menu(parent_item) |
| 99 |
for item in items: |
| 100 |
m.add_item(item) |
| 101 |
return m |
| 102 |
|
| 103 |
def mode_is_selected(self, name, parent, context): |
| 104 |
pl = self.get_playlist_func(parent, context) |
| 105 |
if pl is None: |
| 106 |
return False |
| 107 |
return getattr(pl, "%s_mode" % self.modetype) == name |
| 108 |
|
| 109 |
def on_mode_activated(self, widget, name, parent, context): |
| 110 |
pl = self.get_playlist_func(parent, context) |
| 111 |
if pl is None: |
| 112 |
return False |
| 113 |
setattr(pl, "%s_mode" % self.modetype, name) |
| 114 |
|
| 115 |
|
| 116 |
class ShuffleModesMenuItem(ModesMenuItem): |
| 117 |
modetype = 'shuffle' |
| 118 |
display_name = _("S_huffle") |
| 119 |
|
| 120 |
|
| 121 |
class RepeatModesMenuItem(ModesMenuItem): |
| 122 |
modetype = 'repeat' |
| 123 |
display_name = _("R_epeat") |
| 124 |
|
| 125 |
|
| 126 |
class DynamicModesMenuItem(ModesMenuItem): |
| 127 |
modetype = 'dynamic' |
| 128 |
display_name = _("_Dynamic") |
| 129 |
|
| 130 |
|
| 131 |
class RemoveCurrentMenuItem(menu.MenuItem): |
| 132 |
""" |
| 133 |
Allows for removing the currently playing |
| 134 |
track from the current playlist |
| 135 |
""" |
| 136 |
|
| 137 |
def __init__(self, after, get_playlist_func=default_get_playlist_func): |
| 138 |
menu.MenuItem.__init__(self, 'remove-current', None, after) |
| 139 |
self.get_playlist_func = get_playlist_func |
| 140 |
|
| 141 |
def factory(self, menu, parent, context): |
| 142 |
""" |
| 143 |
Sets up the menu item |
| 144 |
""" |
| 145 |
item = Gtk.ImageMenuItem.new_with_mnemonic( |
| 146 |
_('Remove _Current Track From Playlist') |
| 147 |
) |
| 148 |
item.set_image(Gtk.Image.new_from_icon_name('list-remove', Gtk.IconSize.MENU)) |
| 149 |
item.connect('activate', self.on_activate, parent, context) |
| 150 |
|
| 151 |
if player.PLAYER.is_stopped(): |
| 152 |
item.set_sensitive(False) |
| 153 |
|
| 154 |
return item |
| 155 |
|
| 156 |
def on_activate(self, menuitem, parent, context): |
| 157 |
""" |
| 158 |
Removes the currently playing track from the current playlist |
| 159 |
""" |
| 160 |
playlist = self.get_playlist_func(parent, context) |
| 161 |
|
| 162 |
if playlist and playlist.current == player.PLAYER.current: |
| 163 |
del playlist[playlist.current_position] |
| 164 |
|
| 165 |
|
| 166 |
class RandomizeMenuItem(menu.MenuItem): |
| 167 |
""" |
| 168 |
A menu item which randomizes the full |
| 169 |
playlist or the current selection |
| 170 |
""" |
| 171 |
|
| 172 |
def __init__(self, after): |
| 173 |
menu.MenuItem.__init__(self, 'randomize', None, after) |
| 174 |
|
| 175 |
def factory(self, menu, parent, context): |
| 176 |
""" |
| 177 |
Sets up the menu item |
| 178 |
""" |
| 179 |
label = _('R_andomize Playlist') |
| 180 |
|
| 181 |
if not context['selection-empty']: |
| 182 |
label = _('R_andomize Selection') |
| 183 |
|
| 184 |
item = Gtk.MenuItem.new_with_mnemonic(label) |
| 185 |
item.connect('activate', self.on_activate, parent, context) |
| 186 |
|
| 187 |
return item |
| 188 |
|
| 189 |
def on_activate(self, menuitem, parent, context): |
| 190 |
""" |
| 191 |
Randomizes the playlist or the selection |
| 192 |
""" |
| 193 |
positions = [path[0] for path in context['selected-paths']] |
| 194 |
# Randomize the full playlist if only one track was selected |
| 195 |
positions = positions if len(positions) > 1 else [] |
| 196 |
|
| 197 |
# If you don't unselect before randomizing, a large number of selected will |
| 198 |
# kill performance |
| 199 |
parent.get_selection().unselect_all() |
| 200 |
with parent.handler_block(parent._cursor_changed): |
| 201 |
context['playlist'].randomize(positions) |
| 202 |
|
| 203 |
|
| 204 |
# do this in a function to avoid polluting the global namespace |
| 205 |
def __create_playlist_tab_context_menu(): |
| 206 |
smi = menu.simple_menu_item |
| 207 |
sep = menu.simple_separator |
| 208 |
items = [] |
| 209 |
items.append( |
| 210 |
smi( |
| 211 |
'new-tab', |
| 212 |
[], |
| 213 |
_("_New Playlist"), |
| 214 |
'tab-new', |
| 215 |
lambda w, n, o, c: o.tab.notebook.create_new_playlist(), |
| 216 |
) |
| 217 |
) |
| 218 |
items.append(sep('new-tab-sep', ['new-tab'])) |
| 219 |
|
| 220 |
items.append( |
| 221 |
smi( |
| 222 |
'save', |
| 223 |
['new-tab-sep'], |
| 224 |
_("_Save"), |
| 225 |
'document-save', |
| 226 |
callback=lambda w, n, p, c: p.on_save(), |
| 227 |
condition_fn=lambda n, p, c: ( |
| 228 |
p.can_save() |
| 229 |
and main.exaile().playlists.has_playlist_name(p.playlist.name) |
| 230 |
), |
| 231 |
) |
| 232 |
) |
| 233 |
items.append( |
| 234 |
smi( |
| 235 |
'saveas', |
| 236 |
['save'], |
| 237 |
_("Save _As"), |
| 238 |
'document-save-as', |
| 239 |
callback=lambda w, n, p, c: p.on_saveas(), |
| 240 |
condition_fn=lambda n, p, c: p.can_saveas(), |
| 241 |
) |
| 242 |
) |
| 243 |
items.append( |
| 244 |
smi( |
| 245 |
'rename', |
| 246 |
['saveas'], |
| 247 |
_("_Rename"), |
| 248 |
None, |
| 249 |
callback=lambda w, n, p, c: p.tab.start_rename(), |
| 250 |
condition_fn=lambda n, p, c: p.tab.can_rename(), |
| 251 |
) |
| 252 |
) |
| 253 |
items.append( |
| 254 |
smi( |
| 255 |
'clear', |
| 256 |
['rename'], |
| 257 |
_("_Clear"), |
| 258 |
'edit-clear-all', |
| 259 |
lambda w, n, o, c: o.playlist.clear(), |
| 260 |
) |
| 261 |
) |
| 262 |
items.append(sep('tab-close-sep', ['clear'])) |
| 263 |
|
| 264 |
def _get_pl_func(o, c): |
| 265 |
return o.playlist |
| 266 |
|
| 267 |
items.append( |
| 268 |
menuitems.ExportPlaylistMenuItem('export', ['tab-close-sep'], _get_pl_func) |
| 269 |
) |
| 270 |
items.append( |
| 271 |
menuitems.ExportPlaylistFilesMenuItem('export-files', ['export'], _get_pl_func) |
| 272 |
) |
| 273 |
items.append(sep('tab-export-sep', ['export'])) |
| 274 |
items.append( |
| 275 |
smi( |
| 276 |
'tab-close', |
| 277 |
['tab-export-sep'], |
| 278 |
_("Close _Tab"), |
| 279 |
'window-close', |
| 280 |
lambda w, n, o, c: o.tab.close(), |
| 281 |
) |
| 282 |
) |
| 283 |
for item in items: |
| 284 |
providers.register('playlist-tab-context-menu', item) |
| 285 |
|
| 286 |
|
| 287 |
__create_playlist_tab_context_menu() |
| 288 |
|
| 289 |
|
| 290 |
class PlaylistContextMenu(menu.ProviderMenu): |
| 291 |
def __init__(self, page): |
| 292 |
""" |
| 293 |
:param page: The :class:`PlaylistPage` this menu is |
| 294 |
associated with. |
| 295 |
""" |
| 296 |
menu.ProviderMenu.__init__(self, 'playlist-context-menu', page) |
| 297 |
self.attach_to_widget(page, None) |
| 298 |
|
| 299 |
def get_context(self): |
| 300 |
context = common.LazyDict(self._parent) |
| 301 |
context['playlist'] = lambda name, parent: parent.playlist |
| 302 |
context['selection-empty'] = ( |
| 303 |
lambda name, parent: parent.get_selection_count() == 0 |
| 304 |
) |
| 305 |
context['selected-paths'] = lambda name, parent: parent.get_selected_paths() |
| 306 |
context['selected-items'] = lambda name, parent: parent.get_selected_items() |
| 307 |
context['selected-tracks'] = lambda name, parent: parent.get_selected_tracks() |
| 308 |
context['selection-count'] = lambda name, parent: parent.get_selection_count() |
| 309 |
return context |
| 310 |
|
| 311 |
|
| 312 |
class SPATMenuItem(menu.MenuItem): |
| 313 |
""" |
| 314 |
Menu item allowing for toggling playback |
| 315 |
stop after the selected track (SPAT) |
| 316 |
""" |
| 317 |
|
| 318 |
def __init__(self, name, after): |
| 319 |
menu.MenuItem.__init__(self, name, None, after) |
| 320 |
|
| 321 |
def factory(self, menu, parent, context): |
| 322 |
""" |
| 323 |
Generates the menu item |
| 324 |
""" |
| 325 |
display_name = _('_Stop Playback After This Track') |
| 326 |
icon_name = 'media-playback-stop' |
| 327 |
|
| 328 |
if context['selected-items']: |
| 329 |
selection_position = context['selected-items'][0][0] |
| 330 |
|
| 331 |
if selection_position == parent.playlist.spat_position: |
| 332 |
display_name = _('_Continue Playback After This Track') |
| 333 |
icon_name = 'media-playback-start' |
| 334 |
|
| 335 |
menuitem = Gtk.ImageMenuItem.new_with_mnemonic(display_name) |
| 336 |
menuitem.set_image(Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU)) |
| 337 |
menuitem.connect('activate', self.on_menuitem_activate, parent, context) |
| 338 |
|
| 339 |
return menuitem |
| 340 |
|
| 341 |
def on_menuitem_activate(self, menuitem, parent, context): |
| 342 |
""" |
| 343 |
Toggles the SPAT state |
| 344 |
""" |
| 345 |
selection_position = context['selected-items'][0][0] |
| 346 |
|
| 347 |
if selection_position == parent.playlist.spat_position: |
| 348 |
parent.playlist.spat_position = -1 |
| 349 |
else: |
| 350 |
parent.playlist.spat_position = selection_position |
| 351 |
|
| 352 |
|
| 353 |
def __create_playlist_context_menu(): |
| 354 |
smi = menu.simple_menu_item |
| 355 |
sep = menu.simple_separator |
| 356 |
items = [] |
| 357 |
|
| 358 |
items.append(menuitems.EnqueueMenuItem('enqueue', [])) |
| 359 |
|
| 360 |
items.append(SPATMenuItem('toggle-spat', [items[-1].name])) |
| 361 |
|
| 362 |
def rating_get_tracks_func(menuobj, parent, context): |
| 363 |
return [row[1] for row in context['selected-items']] |
| 364 |
|
| 365 |
items.append(menuitems.RatingMenuItem('rating', [items[-1].name])) |
| 366 |
|
| 367 |
# TODO: custom playlist item here |
| 368 |
items.append(sep('sep1', [items[-1].name])) |
| 369 |
|
| 370 |
def remove_tracks_cb(widget, name, playlistpage, context): |
| 371 |
tracks = context['selected-items'] |
| 372 |
playlist = playlistpage.playlist |
| 373 |
# If it's all one block, just delete it in one chunk for |
| 374 |
# maximum speed. |
| 375 |
positions = [t[0] for t in tracks] |
| 376 |
if positions == list(range(positions[0], positions[0] + len(positions))): |
| 377 |
del playlist[positions[0] : positions[0] + len(positions)] |
| 378 |
else: |
| 379 |
for position, track in tracks[::-1]: |
| 380 |
del playlist[position] |
| 381 |
|
| 382 |
items.append( |
| 383 |
smi( |
| 384 |
'remove', |
| 385 |
[items[-1].name], |
| 386 |
_("_Remove from Playlist"), |
| 387 |
'list-remove', |
| 388 |
remove_tracks_cb, |
| 389 |
) |
| 390 |
) |
| 391 |
|
| 392 |
items.append(RandomizeMenuItem([items[-1].name])) |
| 393 |
|
| 394 |
def playlist_menu_condition(name, parent, context): |
| 395 |
""" |
| 396 |
Returns True if the containing notebook's tab bar is hidden |
| 397 |
""" |
| 398 |
scrolledwindow = parent.get_parent() |
| 399 |
page = scrolledwindow.get_parent() |
| 400 |
return not page.tab.notebook.get_show_tabs() |
| 401 |
|
| 402 |
items.append( |
| 403 |
smi( |
| 404 |
'playlist-menu', |
| 405 |
[items[-1].name], |
| 406 |
_('Playlist'), |
| 407 |
submenu=menu.ProviderMenu('playlist-tab-context-menu', None), |
| 408 |
condition_fn=playlist_menu_condition, |
| 409 |
) |
| 410 |
) |
| 411 |
|
| 412 |
items.append(sep('sep2', [items[-1].name])) |
| 413 |
|
| 414 |
items.append( |
| 415 |
smi( |
| 416 |
'properties', |
| 417 |
[items[-1].name], |
| 418 |
_("_Track Properties"), |
| 419 |
'document-properties', |
| 420 |
lambda w, n, o, c: o.show_properties_dialog(), |
| 421 |
) |
| 422 |
) |
| 423 |
|
| 424 |
for item in items: |
| 425 |
providers.register('playlist-context-menu', item) |
| 426 |
|
| 427 |
|
| 428 |
__create_playlist_context_menu() |
| 429 |
|
| 430 |
|
| 431 |
class PlaylistPageBase(NotebookPage): |
| 432 |
""" |
| 433 |
Base class for playlist pages. Subclasses can indicate that |
| 434 |
they support the following operations: |
| 435 |
|
| 436 |
save: |
| 437 |
- Define a function called 'on_save' |
| 438 |
|
| 439 |
save as: |
| 440 |
- Define a function called 'on_saveas' |
| 441 |
""" |
| 442 |
|
| 443 |
menu_provider_name = 'playlist-tab-context-menu' |
| 444 |
|
| 445 |
def __init__(self, playlist, player): |
| 446 |
NotebookPage.__init__(self) |
| 447 |
|
| 448 |
self.player = player |
| 449 |
self.playlist = playlist |
| 450 |
|
| 451 |
self.play_pixbuf = icons.MANAGER.pixbuf_from_icon_name( |
| 452 |
'media-playback-start', size=Gtk.IconSize.MENU |
| 453 |
) |
| 454 |
self.pause_pixbuf = icons.MANAGER.pixbuf_from_icon_name( |
| 455 |
'media-playback-pause', size=Gtk.IconSize.MENU |
| 456 |
) |
| 457 |
|
| 458 |
event.add_ui_callback( |
| 459 |
self.on_playback_state_change, |
| 460 |
"playback_track_start", |
| 461 |
player, |
| 462 |
destroy_with=self, |
| 463 |
) |
| 464 |
event.add_ui_callback( |
| 465 |
self.on_playback_state_change, |
| 466 |
"playback_track_end", |
| 467 |
player, |
| 468 |
destroy_with=self, |
| 469 |
) |
| 470 |
event.add_ui_callback( |
| 471 |
self.on_playback_state_change, |
| 472 |
"playback_player_pause", |
| 473 |
player, |
| 474 |
destroy_with=self, |
| 475 |
) |
| 476 |
event.add_ui_callback( |
| 477 |
self.on_playback_state_change, |
| 478 |
"playback_player_resume", |
| 479 |
player, |
| 480 |
destroy_with=self, |
| 481 |
) |
| 482 |
|
| 483 |
def on_playback_state_change(self, typ, player, track): |
| 484 |
""" |
| 485 |
Sets the tab icon to reflect the playback status |
| 486 |
""" |
| 487 |
if player.queue.current_playlist != self.playlist: |
| 488 |
self.tab.set_icon(None) |
| 489 |
elif typ in ('playback_player_end', 'playback_track_end'): |
| 490 |
self.tab.set_icon(None) |
| 491 |
elif typ in ('playback_track_start', 'playback_player_resume'): |
| 492 |
self.tab.set_icon(self.play_pixbuf) |
| 493 |
elif typ == 'playback_player_pause': |
| 494 |
self.tab.set_icon(self.pause_pixbuf) |
| 495 |
|
| 496 |
def can_save(self): |
| 497 |
return hasattr(self, 'on_save') |
| 498 |
|
| 499 |
def can_saveas(self): |
| 500 |
return hasattr(self, 'on_saveas') |
| 501 |
|
| 502 |
|
| 503 |
class PlaylistPage(PlaylistPageBase): |
| 504 |
""" |
| 505 |
Displays a playlist and associated controls. |
| 506 |
""" |
| 507 |
|
| 508 |
def __init__(self, playlist, player): |
| 509 |
""" |
| 510 |
:param playlist: The :class:`xl.playlist.Playlist` to display |
| 511 |
in this page. |
| 512 |
:param player: The :class:`xl.player._base.ExailePlayer` that |
| 513 |
this page is associated with |
| 514 |
:param queue: |
| 515 |
""" |
| 516 |
PlaylistPageBase.__init__(self, playlist, player) |
| 517 |
NotebookPage.__init__(self) |
| 518 |
|
| 519 |
self.icon = None |
| 520 |
|
| 521 |
self.loading = None |
| 522 |
self.loading_timer = None |
| 523 |
|
| 524 |
uifile = xdg.get_data_path("ui", "playlist.ui") |
| 525 |
|
| 526 |
self.builder = guiutil.get_builder(uifile) |
| 527 |
playlist_page = self.builder.get_object("playlist_page") |
| 528 |
|
| 529 |
for child in playlist_page.get_children(): |
| 530 |
packing = playlist_page.query_child_packing(child) |
| 531 |
playlist_page.remove(child) |
| 532 |
self.add(child) |
| 533 |
self.set_child_packing(child, *packing) |
| 534 |
|
| 535 |
self.shuffle_button = self.builder.get_object("shuffle_button") |
| 536 |
self.repeat_button = self.builder.get_object("repeat_button") |
| 537 |
self.dynamic_button = self.builder.get_object("dynamic_button") |
| 538 |
self.search_entry = guiutil.SearchEntry(self.builder.get_object("search_entry")) |
| 539 |
|
| 540 |
self.builder.connect_signals(self) |
| 541 |
|
| 542 |
self.playlist_window = self.builder.get_object("playlist_window") |
| 543 |
self.playlist_utilities_bar = self.builder.get_object('playlist_utilities_bar') |
| 544 |
|
| 545 |
self.view = PlaylistView(playlist, player) |
| 546 |
self.view.set_search_entry(self.search_entry.entry) |
| 547 |
self.view.connect( |
| 548 |
'start-interactive-search', lambda *a: self.search_entry.entry.grab_focus() |
| 549 |
) |
| 550 |
|
| 551 |
self.playlist_window.add(self.view) |
| 552 |
|
| 553 |
event.add_ui_callback( |
| 554 |
self.on_mode_changed, |
| 555 |
'playlist_shuffle_mode_changed', |
| 556 |
self.playlist, |
| 557 |
self.shuffle_button, |
| 558 |
destroy_with=self, |
| 559 |
) |
| 560 |
event.add_ui_callback( |
| 561 |
self.on_mode_changed, |
| 562 |
'playlist_repeat_mode_changed', |
| 563 |
self.playlist, |
| 564 |
self.repeat_button, |
| 565 |
destroy_with=self, |
| 566 |
) |
| 567 |
event.add_ui_callback( |
| 568 |
self.on_mode_changed, |
| 569 |
'playlist_dynamic_mode_changed', |
| 570 |
self.playlist, |
| 571 |
self.dynamic_button, |
| 572 |
destroy_with=self, |
| 573 |
) |
| 574 |
event.add_ui_callback( |
| 575 |
self.on_dynamic_playlists_provider_changed, |
| 576 |
'dynamic_playlists_provider_added', |
| 577 |
destroy_with=self, |
| 578 |
) |
| 579 |
event.add_ui_callback( |
| 580 |
self.on_dynamic_playlists_provider_changed, |
| 581 |
'dynamic_playlists_provider_removed', |
| 582 |
destroy_with=self, |
| 583 |
) |
| 584 |
event.add_ui_callback(self.on_option_set, 'gui_option_set', destroy_with=self) |
| 585 |
|
| 586 |
self.on_mode_changed( |
| 587 |
None, None, self.playlist.shuffle_mode, self.shuffle_button |
| 588 |
) |
| 589 |
self.on_mode_changed(None, None, self.playlist.repeat_mode, self.repeat_button) |
| 590 |
self.on_mode_changed( |
| 591 |
None, None, self.playlist.dynamic_mode, self.dynamic_button |
| 592 |
) |
| 593 |
self.on_dynamic_playlists_provider_changed(None, None, None) |
| 594 |
self.on_option_set( |
| 595 |
'gui_option_set', settings, 'gui/playlist_utilities_bar_visible' |
| 596 |
) |
| 597 |
self.view.connect('button-press-event', self.on_view_button_press_event) |
| 598 |
self.view.model.connect('data-loading', self.on_data_loading) |
| 599 |
|
| 600 |
if self.view.model.data_loading: |
| 601 |
self.on_data_loading(None, True) |
| 602 |
|
| 603 |
self.show_all() |
| 604 |
|
| 605 |
## NotebookPage API ## |
| 606 |
|
| 607 |
def focus(self): |
| 608 |
self.view.grab_focus() |
| 609 |
|
| 610 |
def get_page_name(self): |
| 611 |
return self.playlist.name |
| 612 |
|
| 613 |
def set_page_name(self, name): |
| 614 |
self.playlist.name = name |
| 615 |
self.name_changed() |
| 616 |
|
| 617 |
def get_search_entry(self): |
| 618 |
return self.search_entry |
| 619 |
|
| 620 |
## End NotebookPage ## |
| 621 |
|
| 622 |
## PlaylistPageBase API ## |
| 623 |
|
| 624 |
# TODO: These two probably shouldn't reach back to main.. |
| 625 |
def on_save(self): |
| 626 |
main.exaile().playlists.save_playlist(self.playlist, overwrite=True) |
| 627 |
|
| 628 |
def on_saveas(self): |
| 629 |
exaile = main.exaile() |
| 630 |
playlists = exaile.playlists |
| 631 |
name = dialogs.ask_for_playlist_name( |
| 632 |
exaile.gui.main.window, playlists, self.playlist.name |
| 633 |
) |
| 634 |
if name is not None: |
| 635 |
self.set_page_name(name) |
| 636 |
playlists.save_playlist(self.playlist) |
| 637 |
|
| 638 |
## End PlaylistPageBase API ## |
| 639 |
|
| 640 |
def on_shuffle_button_press_event(self, widget, event): |
| 641 |
self.__show_toggle_menu( |
| 642 |
Playlist.shuffle_modes, |
| 643 |
Playlist.shuffle_mode_names, |
| 644 |
self.on_shuffle_mode_set, |
| 645 |
'shuffle_mode', |
| 646 |
widget, |
| 647 |
event, |
| 648 |
) |
| 649 |
|
| 650 |
def on_shuffle_button_popup_menu(self, widget): |
| 651 |
self.__show_toggle_menu( |
| 652 |
Playlist.shuffle_modes, |
| 653 |
Playlist.shuffle_mode_names, |
| 654 |
self.on_shuffle_mode_set, |
| 655 |
'shuffle_mode', |
| 656 |
widget, |
| 657 |
None, |
| 658 |
) |
| 659 |
return True |
| 660 |
|
| 661 |
def on_repeat_button_press_event(self, widget, event): |
| 662 |
self.__show_toggle_menu( |
| 663 |
Playlist.repeat_modes, |
| 664 |
Playlist.repeat_mode_names, |
| 665 |
self.on_repeat_mode_set, |
| 666 |
'repeat_mode', |
| 667 |
widget, |
| 668 |
event, |
| 669 |
) |
| 670 |
|
| 671 |
def on_repeat_button_popup_menu(self, widget): |
| 672 |
self.__show_toggle_menu( |
| 673 |
Playlist.repeat_modes, |
| 674 |
Playlist.repeat_mode_names, |
| 675 |
self.on_repeat_mode_set, |
| 676 |
'repeat_mode', |
| 677 |
widget, |
| 678 |
None, |
| 679 |
) |
| 680 |
return True |
| 681 |
|
| 682 |
def on_dynamic_button_toggled(self, widget): |
| 683 |
if widget.get_active(): |
| 684 |
self.playlist.dynamic_mode = self.playlist.dynamic_modes[1] |
| 685 |
else: |
| 686 |
self.playlist.dynamic_mode = self.playlist.dynamic_modes[0] |
| 687 |
|
| 688 |
def on_search_entry_activate(self, entry): |
| 689 |
filter_string = entry.get_text() |
| 690 |
self.view.filter_tracks(filter_string or None) |
| 691 |
|
| 692 |
def __show_toggle_menu(self, names, display_names, callback, attr, widget, event): |
| 693 |
""" |
| 694 |
Display the menu on the shuffle/repeat toggle buttons |
| 695 |
|
| 696 |
:param names: The list of names of the menu entries |
| 697 |
:param display_names: The list of names to display on |
| 698 |
each menu entry. |
| 699 |
:param callback: The function to call when a menu item is |
| 700 |
activated. It will be passed the name of the activated item. |
| 701 |
:param attr: The attribute of self.playlist to look at to |
| 702 |
determine the currently-selected item. |
| 703 |
:param widget: The ToggleButton to display the menu on |
| 704 |
:param event: The gtk event that triggered the menu display |
| 705 |
""" |
| 706 |
widget.set_active(True) |
| 707 |
menu = Gtk.Menu() |
| 708 |
menu.connect('deactivate', self._mode_menu_set_toggle, widget, attr) |
| 709 |
prev = None |
| 710 |
mode = getattr(self.playlist, attr) |
| 711 |
for name, disp in zip(names, display_names): |
| 712 |
group = None if prev is None else prev.get_group() |
| 713 |
item = Gtk.RadioMenuItem.new_with_mnemonic(group, disp) |
| 714 |
if name == mode: |
| 715 |
item.set_active(True) |
| 716 |
item.connect('activate', callback, name) |
| 717 |
menu.append(item) |
| 718 |
if prev is None: |
| 719 |
menu.append(Gtk.SeparatorMenuItem()) |
| 720 |
prev = item |
| 721 |
menu.attach_to_widget(widget) |
| 722 |
menu.show_all() |
| 723 |
if event is not None: |
| 724 |
menu.popup( |
| 725 |
None, None, guiutil.position_menu, widget, event.button, event.time |
| 726 |
) |
| 727 |
else: |
| 728 |
menu.popup(None, None, guiutil.position_menu, widget, 0, 0) |
| 729 |
menu.reposition() |
| 730 |
|
| 731 |
def _mode_menu_set_toggle(self, menu, button, name): |
| 732 |
mode = getattr(self.playlist, name) |
| 733 |
self.on_mode_changed(None, None, mode, button) |
| 734 |
|
| 735 |
def on_shuffle_mode_set(self, widget, mode): |
| 736 |
""" |
| 737 |
Callback for the Shuffle mode menu |
| 738 |
""" |
| 739 |
if widget.get_active(): |
| 740 |
self.playlist.shuffle_mode = mode |
| 741 |
|
| 742 |
def on_repeat_mode_set(self, widget, mode): |
| 743 |
""" |
| 744 |
Callback for the Repeat mode menu |
| 745 |
""" |
| 746 |
if widget.get_active(): |
| 747 |
self.playlist.repeat_mode = mode |
| 748 |
|
| 749 |
def on_mode_changed(self, evtype, playlist, mode, button): |
| 750 |
button.set_active(mode != 'disabled') |
| 751 |
|
| 752 |
def on_dynamic_playlists_provider_changed(self, evtype, manager, provider): |
| 753 |
""" |
| 754 |
Updates the dynamic button on provider changes |
| 755 |
""" |
| 756 |
providers_available = len(providers.get('dynamic_playlists')) > 0 |
| 757 |
sensitive = False |
| 758 |
tooltip_text = _('Requires plugins providing dynamic playlists') |
| 759 |
|
| 760 |
if providers_available: |
| 761 |
sensitive = True |
| 762 |
tooltip_text = _('Dynamically add similar tracks to the playlist') |
| 763 |
|
| 764 |
self.dynamic_button.set_sensitive(sensitive) |
| 765 |
self.dynamic_button.set_tooltip_text(tooltip_text) |
| 766 |
|
| 767 |
def on_option_set(self, evtype, settings, option): |
| 768 |
""" |
| 769 |
Handles option changes |
| 770 |
""" |
| 771 |
if option == 'gui/playlist_utilities_bar_visible': |
| 772 |
visible = settings.get_option(option, True) |
| 773 |
self.playlist_utilities_bar.set_visible(visible) |
| 774 |
self.playlist_utilities_bar.set_sensitive(visible) |
| 775 |
self.playlist_utilities_bar.set_no_show_all(not visible) |
| 776 |
|
| 777 |
def on_data_loading(self, model, loading): |
| 778 |
'''Called when tracks are being loaded into the model''' |
| 779 |
if loading: |
| 780 |
if self.loading is None and self.loading_timer is None: |
| 781 |
self.view.set_model(None) |
| 782 |
self.loading_timer = GLib.timeout_add(500, self.on_data_loading_timer) |
| 783 |
else: |
| 784 |
if self.loading_timer is not None: |
| 785 |
GLib.source_remove(self.loading_timer) |
| 786 |
self.loading_timer = None |
| 787 |
|
| 788 |
self.view.set_model(self.view.modelfilter) |
| 789 |
|
| 790 |
if self.loading is not None: |
| 791 |
guiutil.gtk_widget_replace(self.loading, self.playlist_window) |
| 792 |
self.loading.destroy() |
| 793 |
self.loading = None |
| 794 |
|
| 795 |
def on_data_loading_timer(self): |
| 796 |
if self.loading_timer is None: |
| 797 |
return |
| 798 |
|
| 799 |
self.loading_timer = None |
| 800 |
|
| 801 |
grid = Gtk.Grid() |
| 802 |
sp = Gtk.Spinner() |
| 803 |
sp.start() |
| 804 |
lbl = Gtk.Label.new(_('Loading')) |
| 805 |
|
| 806 |
grid.attach(sp, 0, 0, 1, 1) |
| 807 |
grid.attach(lbl, 1, 0, 1, 1) |
| 808 |
|
| 809 |
grid.set_halign(Gtk.Align.CENTER) |
| 810 |
grid.set_valign(Gtk.Align.CENTER) |
| 811 |
|
| 812 |
self.loading = grid |
| 813 |
|
| 814 |
guiutil.gtk_widget_replace(self.playlist_window, self.loading) |
| 815 |
self.loading.show_all() |
| 816 |
|
| 817 |
def on_view_button_press_event(self, view, e): |
| 818 |
""" |
| 819 |
Displays the tab context menu upon |
| 820 |
clicks in the contained view |
| 821 |
""" |
| 822 |
path = view.get_path_at_pos(int(e.x), int(e.y)) |
| 823 |
# We only need the tree path if present |
| 824 |
path = path[0] if path else None |
| 825 |
|
| 826 |
if ( |
| 827 |
not path |
| 828 |
and e.type == Gdk.EventType.BUTTON_PRESS |
| 829 |
and e.triggers_context_menu() |
| 830 |
): |
| 831 |
self.tab_menu.popup(None, None, None, None, e.button, e.time) |
| 832 |
|
| 833 |
|
| 834 |
class PlaylistView(AutoScrollTreeView, providers.ProviderHandler): |
| 835 |
__gsignals__ = {} |
| 836 |
|
| 837 |
def __init__(self, playlist, player): |
| 838 |
AutoScrollTreeView.__init__(self) |
| 839 |
providers.ProviderHandler.__init__(self, 'playlist-columns') |
| 840 |
|
| 841 |
self.playlist = playlist |
| 842 |
self.player = player |
| 843 |
|
| 844 |
self._current_vertical_scroll = 0 |
| 845 |
self._insert_row = -1 |
| 846 |
self._insert_count = 0 |
| 847 |
|
| 848 |
self.menu = PlaylistContextMenu(self) |
| 849 |
self.header_menu = menu.ProviderMenu('playlist-columns-menu', self) |
| 850 |
self.header_menu.set_context_func(self.get_header_context) |
| 851 |
self.header_menu.attach_to_widget(self) |
| 852 |
|
| 853 |
self.dragging = False |
| 854 |
self.pending_event = None |
| 855 |
|
| 856 |
self.pending_edit_id = None # Timeout to ensure a double-click didn't occur |
| 857 |
self.pending_edit_data = None # (path, col) or None |
| 858 |
self.pending_edit_ok = False # Set to True by release or timeout |
| 859 |
|
| 860 |
self._insert_focusing = False |
| 861 |
|
| 862 |
self._hack_is_osx = sys.platform == 'darwin' |
| 863 |
self._hack_osx_control_mask = False |
| 864 |
|
| 865 |
# Set to true if you only want things to be copied here, not moved |
| 866 |
self.dragdrop_copyonly = False |
| 867 |
|
| 868 |
self.set_fixed_height_mode(True) # MASSIVE speedup - don't disable this! |
| 869 |
self.set_enable_search(True) |
| 870 |
self.selection = self.get_selection() |
| 871 |
self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) |
| 872 |
|
| 873 |
self._filter_matcher = None |
| 874 |
|
| 875 |
self._sort_columns = list(common.BASE_SORT_TAGS) # Column sort order |
| 876 |
|
| 877 |
self._setup_models() |
| 878 |
self._setup_columns() |
| 879 |
self.columns_changed_id = self.connect( |
| 880 |
"columns-changed", self.on_columns_changed |
| 881 |
) |
| 882 |
|
| 883 |
self.targets = [ |
| 884 |
Gtk.TargetEntry.new("exaile-index-list", Gtk.TargetFlags.SAME_APP, 0), |
| 885 |
Gtk.TargetEntry.new("text/uri-list", 0, 0), |
| 886 |
] |
| 887 |
self.drag_source_set( |
| 888 |
Gdk.ModifierType.BUTTON1_MASK, |
| 889 |
self.targets, |
| 890 |
Gdk.DragAction.COPY | Gdk.DragAction.MOVE, |
| 891 |
) |
| 892 |
self.drag_dest_set( |
| 893 |
Gtk.DestDefaults.ALL, |
| 894 |
self.targets, |
| 895 |
Gdk.DragAction.COPY | Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE, |
| 896 |
) |
| 897 |
|
| 898 |
event.add_ui_callback(self.on_option_set, "gui_option_set", destroy_with=self) |
| 899 |
event.add_ui_callback( |
| 900 |
self.on_playback_start, |
| 901 |
"playback_track_start", |
| 902 |
self.player, |
| 903 |
destroy_with=self, |
| 904 |
) |
| 905 |
event.add_ui_callback( |
| 906 |
self.on_playback_start, |
| 907 |
"playlist_track_next", |
| 908 |
self.player, |
| 909 |
destroy_with=self, |
| 910 |
) |
| 911 |
self._cursor_changed = self.connect("cursor-changed", self.on_cursor_changed) |
| 912 |
self.connect("row-activated", self.on_row_activated) |
| 913 |
self.connect("key-press-event", self.on_key_press_event) |
| 914 |
|
| 915 |
self.connect("drag-begin", self.on_drag_begin) |
| 916 |
self.connect("drag-drop", self.on_drag_drop) |
| 917 |
self.connect("drag-data-get", self.on_drag_data_get) |
| 918 |
self.connect("drag-data-received", self.on_drag_data_received) |
| 919 |
self.connect("drag-data-delete", self.on_drag_data_delete) |
| 920 |
self.connect("drag-end", self.on_drag_end) |
| 921 |
self.connect("drag-motion", self.on_drag_motion) |
| 922 |
self.connect("size-allocate", self.on_size_allocate) |
| 923 |
|
| 924 |
def do_destroy(self): |
| 925 |
# if this isn't disconnected, then the columns are emptied out and |
| 926 |
# the user's settings are overwritten with an empty list |
| 927 |
self.disconnect(self.columns_changed_id) |
| 928 |
AutoScrollTreeView.do_destroy(self) |
| 929 |
|
| 930 |
def _refilter(self): |
| 931 |
with guiutil.without_model(self): |
| 932 |
self.modelfilter.refilter() |
| 933 |
|
| 934 |
def filter_tracks(self, filter_string): |
| 935 |
""" |
| 936 |
Only show tracks that match the filter. If filter is None, then |
| 937 |
clear any existing filters. |
| 938 |
|
| 939 |
The filter will search any currently enabled columns AND the |
| 940 |
default columns. |
| 941 |
""" |
| 942 |
|
| 943 |
if filter_string is None: |
| 944 |
self._filter_matcher = None |
| 945 |
self._refilter() |
| 946 |
else: |
| 947 |
# Merge default columns and currently enabled columns |
| 948 |
keyword_tags = set( |
| 949 |
playlist_columns.DEFAULT_COLUMNS |
| 950 |
+ [c.name for c in self.get_columns()[1:]] |
| 951 |
) |
| 952 |
self._filter_matcher = trax.TracksMatcher( |
| 953 |
filter_string, case_sensitive=False, keyword_tags=keyword_tags |
| 954 |
) |
| 955 |
logger.debug( |
| 956 |
"Filtering playlist %r by %r.", self.playlist.name, filter_string |
| 957 |
) |
| 958 |
self._refilter() |
| 959 |
logger.debug( |
| 960 |
"Filtering playlist %r by %r completed.", |
| 961 |
self.playlist.name, |
| 962 |
filter_string, |
| 963 |
) |
| 964 |
|
| 965 |
def get_selection_count(self): |
| 966 |
""" |
| 967 |
Returns the number of items currently selected in the |
| 968 |
playlist. Prefer this to len(get_selected_tracks()) et al |
| 969 |
if you will discard the actual track list |
| 970 |
""" |
| 971 |
return self.get_selection().count_selected_rows() |
| 972 |
|
| 973 |
def get_selected_tracks(self): |
| 974 |
""" |
| 975 |
Returns a list of :class:`xl.trax.Track` |
| 976 |
which are currently selected in the playlist. |
| 977 |
""" |
| 978 |
return [x[1] for x in self.get_selected_items()] |
| 979 |
|
| 980 |
def get_selected_paths(self): |
| 981 |
""" |
| 982 |
Returns a list of pairs of treepaths which are currently |
| 983 |
selected in the playlist. |
| 984 |
|
| 985 |
The treepaths are returned for the base model, so they are |
| 986 |
indices that can be used with the playlist currently |
| 987 |
associated with this view. |
| 988 |
""" |
| 989 |
selection = self.get_selection() |
| 990 |
model, paths = selection.get_selected_rows() |
| 991 |
|
| 992 |
if isinstance(model, Gtk.TreeModelFilter): |
| 993 |
paths = [model.convert_path_to_child_path(path) for path in paths] |
| 994 |
|
| 995 |
return paths |
| 996 |
|
| 997 |
def get_selected_items(self): |
| 998 |
""" |
| 999 |
Returns a list of pairs of indices and :class:`xl.trax.Track` |
| 1000 |
which are currently selected in the playlist. |
| 1001 |
|
| 1002 |
The indices can be used with the playlist currently associated |
| 1003 |
with this view. |
| 1004 |
""" |
| 1005 |
selection = self.get_selection() |
| 1006 |
model, paths = selection.get_selected_rows() |
| 1007 |
try: |
| 1008 |
if isinstance(model, Gtk.TreeModelFilter): |
| 1009 |
tracks = [ |
| 1010 |
( |
| 1011 |
model.convert_path_to_child_path(path)[0], |
| 1012 |
model.get_value(model.get_iter(path), 0), |
| 1013 |
) |
| 1014 |
for path in paths |
| 1015 |
] |
| 1016 |
else: |
| 1017 |
tracks = [ |
| 1018 |
(path[0], model.get_value(model.get_iter(path), 0)) |
| 1019 |
for path in paths |
| 1020 |
] |
| 1021 |
except TypeError: # one of the paths was invalid |
| 1022 |
return [] |
| 1023 |
return tracks |
| 1024 |
|
| 1025 |
def get_sort_column(self): |
| 1026 |
for col in self.get_columns(): |
| 1027 |
if col.get_sort_indicator(): |
| 1028 |
return col |
| 1029 |
return None |
| 1030 |
|
| 1031 |
def get_sort_by(self): |
| 1032 |
sortcol = self.get_sort_column() |
| 1033 |
if sortcol: |
| 1034 |
reverse = sortcol.get_sort_order() == Gtk.SortType.DESCENDING |
| 1035 |
else: |
| 1036 |
reverse = False |
| 1037 |
return (self._sort_columns, reverse) |
| 1038 |
|
| 1039 |
def play_track_at(self, position, track): |
| 1040 |
""" |
| 1041 |
When called, this will begin playback of a track at a given |
| 1042 |
position in the internal playlist |
| 1043 |
""" |
| 1044 |
self._play_track_at(position, track) |
| 1045 |
|
| 1046 |
def _play_track_at( |
| 1047 |
self, position, track, on_activated=False, restart_if_playing=False |
| 1048 |
): |
| 1049 |
'''Internal API''' |
| 1050 |
if not settings.get_option('playlist/enqueue_by_default', False) or ( |
| 1051 |
self.playlist is self.player.queue and on_activated |
| 1052 |
): |
| 1053 |
# If track is already playing, then: |
| 1054 |
# a) if restart_if_playing flag is set, restart the track |
| 1055 |
# b) otherwise, pause/resume it instead of starting over |
| 1056 |
if ( |
| 1057 |
on_activated |
| 1058 |
and not self.player.is_stopped() |
| 1059 |
and self.player.queue.current_playlist is self.playlist |
| 1060 |
and self.playlist.get_current_position() == position |
| 1061 |
and not (restart_if_playing and self.player.is_playing()) |
| 1062 |
): |
| 1063 |
self.player.toggle_pause() |
| 1064 |
|
| 1065 |
elif self.player.queue.is_play_enabled(): |
| 1066 |
self.playlist.set_current_position(position) |
| 1067 |
self.player.queue.set_current_playlist(self.playlist) |
| 1068 |
self.player.queue.play(track=track) |
| 1069 |
elif self.playlist is not self.player.queue: |
| 1070 |
self.player.queue.append(track) |
| 1071 |
|
| 1072 |
def _setup_columns(self): |
| 1073 |
columns = settings.get_option('gui/columns', playlist_columns.DEFAULT_COLUMNS) |
| 1074 |
provider_names = [p.name for p in providers.get('playlist-columns')] |
| 1075 |
columns = [name for name in columns if name in provider_names] |
| 1076 |
|
| 1077 |
if not columns: |
| 1078 |
columns = playlist_columns.DEFAULT_COLUMNS |
| 1079 |
|
| 1080 |
self.model._set_columns(columns) |
| 1081 |
|
| 1082 |
font, ratio = self._compute_font() |
| 1083 |
|
| 1084 |
# create a fixed column for the playlist icon |
| 1085 |
self._setup_fixed_column(ratio) |
| 1086 |
|
| 1087 |
for column in columns: |
| 1088 |
playlist_column = providers.get_provider('playlist-columns', column)( |
| 1089 |
self, self.player, font, ratio |
| 1090 |
) |
| 1091 |
playlist_column.connect('clicked', self.on_column_clicked) |
| 1092 |
|
| 1093 |
if isinstance(playlist_column.cellrenderer, Gtk.CellRendererText): |
| 1094 |
playlist_column.set_attributes( |
| 1095 |
playlist_column.cellrenderer, |
| 1096 |
sensitive=PlaylistModel.COL_SENSITIVE, |
| 1097 |
weight=PlaylistModel.COL_WEIGHT, |
| 1098 |
) |
| 1099 |
else: |
| 1100 |
playlist_column.set_attributes( |
| 1101 |
playlist_column.cellrenderer, sensitive=PlaylistModel.COL_SENSITIVE |
| 1102 |
) |
| 1103 |
|
| 1104 |
self.append_column(playlist_column) |
| 1105 |
header = playlist_column.get_widget() |
| 1106 |
header.show() |
| 1107 |
header.get_ancestor(Gtk.Button).connect( |
| 1108 |
'button-press-event', self.on_header_button_press, playlist_column |
| 1109 |
) |
| 1110 |
|
| 1111 |
header.get_ancestor(Gtk.Button).connect( |
| 1112 |
'key-press-event', self.on_header_key_press_event, playlist_column |
| 1113 |
) |
| 1114 |
|
| 1115 |
def _compute_font(self): |
| 1116 |
font = settings.get_option('gui/playlist_font', None) |
| 1117 |
if font is not None: |
| 1118 |
font = Pango.FontDescription(font) |
| 1119 |
|
| 1120 |
default_font = Gtk.Widget.get_default_style().font_desc |
| 1121 |
if font is None: |
| 1122 |
font = default_font |
| 1123 |
|
| 1124 |
def_font_sz = default_font.get_size() |
| 1125 |
|
| 1126 |
# how much has the font deviated from normal? |
| 1127 |
ratio = font.get_size() / def_font_sz |
| 1128 |
|
| 1129 |
# small fonts can be problematic.. |
| 1130 |
# -> TODO: perhaps default widths could be specified |
| 1131 |
# in character widths instead? then we could |
| 1132 |
# calculate it instead of using arbitrary widths |
| 1133 |
if ratio < 1: |
| 1134 |
ratio = ratio * 1.25 |
| 1135 |
|
| 1136 |
return font, ratio |
| 1137 |
|
| 1138 |
def _setup_fixed_column(self, ratio): |
| 1139 |
sz = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)[1] |
| 1140 |
sz = max(int(sz * ratio), 1) |
| 1141 |
|
| 1142 |
cell = Gtk.CellRendererPixbuf() |
| 1143 |
cell.set_property('xalign', 0.0) |
| 1144 |
|
| 1145 |
col = Gtk.TreeViewColumn('') |
| 1146 |
col.pack_start(cell, False) |
| 1147 |
col.set_max_width(sz) |
| 1148 |
col.set_attributes(cell, pixbuf=PlaylistModel.COL_PIXBUF) |
| 1149 |
col.set_resizable(False) |
| 1150 |
col.set_reorderable(False) |
| 1151 |
col.set_clickable(False) |
| 1152 |
col.set_sizing(Gtk.TreeViewColumnSizing.FIXED) |
| 1153 |
self.append_column(col) |
| 1154 |
|
| 1155 |
def _on_resize_columns(self): |
| 1156 |
for col in self.cols: |
| 1157 |
col._setup_sizing() |
| 1158 |
pass |
| 1159 |
|
| 1160 |
def _refresh_columns(self): |
| 1161 |
selection = self.get_selection() |
| 1162 |
if not selection: # The widget has been destroyed |
| 1163 |
return |
| 1164 |
|
| 1165 |
with self.handler_block(self.columns_changed_id): |
| 1166 |
columns = self.get_columns() |
| 1167 |
for col in columns: |
| 1168 |
self.remove_column(col) |
| 1169 |
col.destroyed = True |
| 1170 |
|
| 1171 |
self._setup_columns() |
| 1172 |
|
| 1173 |
self.queue_draw() |
| 1174 |
|
| 1175 |
def _setup_models(self): |
| 1176 |
self.model = PlaylistModel(self.playlist, [], self.player, self) |
| 1177 |
self.__setup_model_hook = self.model.connect( |
| 1178 |
'data-loading', self._on_after_model_loading |
| 1179 |
) |
| 1180 |
|
| 1181 |
self.modelfilter = self.model.filter_new() |
| 1182 |
self.modelfilter.set_visible_func(self._modelfilter_visible_func) |
| 1183 |
self.set_model(self.modelfilter) |
| 1184 |
|
| 1185 |
def _on_after_model_loading(self, ar1, now_loading): |
| 1186 |
""" |
| 1187 |
This is necessary to ensure that row-insert is connected after the initial loading |
| 1188 |
due to threaded PlaylistModel::_load_data_thread and playlists greater than 500 tracks |
| 1189 |
""" |
| 1190 |
if not now_loading: |
| 1191 |
self.model.connect('row-inserted', self.on_row_inserted) |
| 1192 |
self.model.disconnect(self.__setup_model_hook) |
| 1193 |
|
| 1194 |
def _modelfilter_visible_func(self, model, iter, data): |
| 1195 |
if self._filter_matcher is not None: |
| 1196 |
track = model.get_value(iter, 0) |
| 1197 |
return self._filter_matcher.match(trax.SearchResultTrack(track)) |
| 1198 |
return True |
| 1199 |
|
| 1200 |
def on_header_button_press( |
| 1201 |
self, |
| 1202 |
widget: Gtk.Widget, |
| 1203 |
event: Gdk.EventButton, |
| 1204 |
header_column: playlist_columns.Column, |
| 1205 |
): |
| 1206 |
if event.triggers_context_menu(): |
| 1207 |
self.set_selected_header(header_column) |
| 1208 |
self.header_menu.popup_at_pointer(event) |
| 1209 |
return True |
| 1210 |
|
| 1211 |
def on_header_key_press_event( |
| 1212 |
self, |
| 1213 |
widget: Gtk.Widget, |
| 1214 |
event: Gdk.EventKey, |
| 1215 |
header_column: playlist_columns.Column, |
| 1216 |
): |
| 1217 |
if event.keyval == Gdk.KEY_Menu: |
| 1218 |
# Open context menu for selecting visible columns |
| 1219 |
self.set_selected_header(header_column) |
| 1220 |
self.header_menu.popup_at_widget(widget, event) |
| 1221 |
return True |
| 1222 |
|
| 1223 |
def get_header_context(self, dummy): |
| 1224 |
context = {} |
| 1225 |
context['trigger_column'] = self.selected_header |
| 1226 |
return context |
| 1227 |
|
| 1228 |
def set_selected_header(self, header: playlist_columns.Column) -> None: |
| 1229 |
self.selected_header = header |
| 1230 |
|
| 1231 |
def on_columns_changed(self, widget): |
| 1232 |
columns = [c.name for c in self.get_columns()[1:]] |
| 1233 |
if columns != settings.get_option('gui/columns', []): |
| 1234 |
settings.set_option('gui/columns', columns) |
| 1235 |
|
| 1236 |
def on_column_clicked(self, column): |
| 1237 |
if self.model.data_loading: |
| 1238 |
return |
| 1239 |
order = None |
| 1240 |
for col in self.get_columns()[1:]: |
| 1241 |
if col.name == column.name: |
| 1242 |
order = column.get_sort_order() |
| 1243 |
if order == Gtk.SortType.ASCENDING: |
| 1244 |
order = Gtk.SortType.DESCENDING |
| 1245 |
else: |
| 1246 |
order = Gtk.SortType.ASCENDING |
| 1247 |
col.set_sort_indicator(True) |
| 1248 |
col.set_sort_order(order) |
| 1249 |
|
| 1250 |
self._sort_columns.insert(0, column.name) |
| 1251 |
else: |
| 1252 |
col.set_sort_indicator(False) |
| 1253 |
col.set_sort_order(Gtk.SortType.DESCENDING) |
| 1254 |
reverse = order == Gtk.SortType.DESCENDING |
| 1255 |
|
| 1256 |
# Uniquify the list of sort columns |
| 1257 |
def unique_ordered(seq): |
| 1258 |
seen = set() |
| 1259 |
return [x for x in seq if x not in seen and not seen.add(x)] |
| 1260 |
|
| 1261 |
self._sort_columns = unique_ordered(self._sort_columns) |
| 1262 |
|
| 1263 |
# If you don't unselect before sorting, a large number of selected will |
| 1264 |
# kill performance |
| 1265 |
self.get_selection().unselect_all() |
| 1266 |
with self.handler_block(self._cursor_changed): |
| 1267 |
self.playlist.sort(self._sort_columns, reverse=reverse) |
| 1268 |
|
| 1269 |
def on_option_set(self, typ, obj, data): |
| 1270 |
if data == "gui/columns" or data == 'gui/playlist_font': |
| 1271 |
self._refresh_columns() |
| 1272 |
|
| 1273 |
def on_playback_start(self, type, player, track): |
| 1274 |
if ( |
| 1275 |
player.queue.current_playlist == self.playlist |
| 1276 |
and player.current == self.playlist.current |
| 1277 |
and settings.get_option('gui/ensure_visible', True) |
| 1278 |
): |
| 1279 |
self.scroll_to_current() |
| 1280 |
|
| 1281 |
def scroll_to_current(self): |
| 1282 |
position = self.playlist.current_position |
| 1283 |
if position >= 0: |
| 1284 |
model = self.get_model() |
| 1285 |
# If it's a filter, then the position isn't actually the path |
| 1286 |
if hasattr(model, 'convert_child_path_to_path'): |
| 1287 |
path = model.convert_child_path_to_path(Gtk.TreePath((position,))) |
| 1288 |
if path: |
| 1289 |
self.scroll_to_cell(path) |
| 1290 |
self.set_cursor(path) |
| 1291 |
|
| 1292 |
def on_cursor_changed(self, widget): |
| 1293 |
context = common.LazyDict(self) |
| 1294 |
context['selection-empty'] = ( |
| 1295 |
lambda name, parent: parent.get_selection_count() == 0 |
| 1296 |
) |
| 1297 |
context['selected-items'] = lambda name, parent: parent.get_selected_items() |
| 1298 |
context['selected-tracks'] = lambda name, parent: parent.get_selected_tracks() |
| 1299 |
context['selection-count'] = lambda name, parent: parent.get_selection_count() |
| 1300 |
event.log_event('playlist_cursor_changed', self, context) |
| 1301 |
|
| 1302 |
def on_row_activated(self, *args): |
| 1303 |
try: |
| 1304 |
position, track = self.get_selected_items()[0] |
| 1305 |
except IndexError: |
| 1306 |
return |
| 1307 |
|
| 1308 |
# Call with restart_if_playing flag set to True, so that |
| 1309 |
# currently-playing track will be restarted |
| 1310 |
self._play_track_at(position, track, True, True) |
| 1311 |
|
| 1312 |
def on_row_inserted(self, model, path, iter): |
| 1313 |
""" |
| 1314 |
When something is inserted into the playlist, focus on it. If |
| 1315 |
there are multiple things inserted, focus only on the first. |
| 1316 |
""" |
| 1317 |
if not self._insert_focusing: |
| 1318 |
self._insert_focusing = True |
| 1319 |
# HACK: GI: We get a segfault if we don't do this, because the |
| 1320 |
# GtkTreePath gets deleted before the idle function is run. |
| 1321 |
path = path.copy() |
| 1322 |
|
| 1323 |
def _set_cursor(): |
| 1324 |
self.set_cursor(path) |
| 1325 |
self._insert_focusing = False |
| 1326 |
|
| 1327 |
GLib.idle_add(_set_cursor) |
| 1328 |
|
| 1329 |
def do_button_press_event(self, e): |
| 1330 |
""" |
| 1331 |
Adds some custom selection work to |
| 1332 |
1) unselect all rows if clicking an empty area, |
| 1333 |
2) updating the selection upon right click and |
| 1334 |
3) popping up the context menu upon right click |
| 1335 |
|
| 1336 |
Also sets the internal state for button pressed |
| 1337 |
|
| 1338 |
Taken from the following sources: |
| 1339 |
|
| 1340 |
* thunar_details_view_button_press_event() of thunar-details-view.c |
| 1341 |
* MultiDragTreeView.__button_press/__button.release of quodlibet/qltk/views.py |
| 1342 |
""" |
| 1343 |
|
| 1344 |
# need this to workaround bug in GTK+ on OSX when dragging/dropping |
| 1345 |
# -> https://bugzilla.gnome.org/show_bug.cgi?id=722815 |
| 1346 |
if self._hack_is_osx: |
| 1347 |
self._hack_osx_control_mask = ( |
| 1348 |
True if e.state & Gdk.ModifierType.CONTROL_MASK else False |
| 1349 |
) |
| 1350 |
|
| 1351 |
selection = self.get_selection() |
| 1352 |
pathtuple = self.get_path_at_pos(int(e.x), int(e.y)) |
| 1353 |
# We only need the tree path if present |
| 1354 |
if pathtuple: |
| 1355 |
path = pathtuple[0] |
| 1356 |
col = pathtuple[1] |
| 1357 |
else: |
| 1358 |
path = None |
| 1359 |
|
| 1360 |
# We unselect all selected items if the user clicks on an empty |
| 1361 |
# area of the treeview and no modifier key is active |
| 1362 |
if not e.state & Gtk.accelerator_get_default_mod_mask() and not path: |
| 1363 |
selection.unselect_all() |
| 1364 |
|
| 1365 |
if path and e.type == Gdk.EventType.BUTTON_PRESS: |
| 1366 |
# Prevent unselection of all except the clicked item on left |
| 1367 |
# clicks, required to preserve the selection for DnD |
| 1368 |
if ( |
| 1369 |
e.button == Gdk.BUTTON_PRIMARY |
| 1370 |
and not e.state & Gtk.accelerator_get_default_mod_mask() |
| 1371 |
and selection.path_is_selected(path) |
| 1372 |
): |
| 1373 |
if selection.count_selected_rows() > 1: |
| 1374 |
selection.set_select_function(lambda *args: False, None) |
| 1375 |
self.pending_event = (path, col) |
| 1376 |
elif hasattr(col, 'could_edit') and col.could_edit(self, path, e): |
| 1377 |
# TODO: should cache this? |
| 1378 |
tm = self.get_settings().props.gtk_double_click_time |
| 1379 |
if self.pending_edit_id: |
| 1380 |
GLib.source_remove(self.pending_edit_id) |
| 1381 |
self.pending_edit_data = (path, col) |
| 1382 |
self.pending_edit_ok = False |
| 1383 |
self.pending_edit_id = GLib.timeout_add( |
| 1384 |
tm, self._editing_double_click_ok |
| 1385 |
) |
| 1386 |
|
| 1387 |
if e.triggers_context_menu(): |
| 1388 |
# Select the path on which the user clicked if not selected yet |
| 1389 |
if not selection.path_is_selected(path): |
| 1390 |
# We don't unselect all other items if Control is active |
| 1391 |
if not e.state & Gdk.ModifierType.CONTROL_MASK: |
| 1392 |
selection.unselect_all() |
| 1393 |
|
| 1394 |
selection.select_path(path) |
| 1395 |
|
| 1396 |
self.menu.popup(None, None, None, None, e.button, e.time) |
| 1397 |
|
| 1398 |
return True |
| 1399 |
|
| 1400 |
elif e.type == Gdk.EventType.DOUBLE_BUTTON_PRESS: |
| 1401 |
self._cancel_editing() |
| 1402 |
|
| 1403 |
return Gtk.TreeView.do_button_press_event(self, e) |
| 1404 |
|
| 1405 |
def do_button_release_event(self, e): |
| 1406 |
""" |
| 1407 |
Unsets the internal state for button press |
| 1408 |
""" |
| 1409 |
self._hack_osx_control_mask = False |
| 1410 |
|
| 1411 |
# Restore regular selection behavior in any case |
| 1412 |
self.get_selection().set_select_function(lambda *args: True, None) |
| 1413 |
|
| 1414 |
if self.pending_event: |
| 1415 |
path, col = self.pending_event |
| 1416 |
# perform the normal selection that would have happened |
| 1417 |
self.set_cursor(path, col, 0) |
| 1418 |
self.pending_event = None |
| 1419 |
|
| 1420 |
self._maybe_start_editing() |
| 1421 |
|
| 1422 |
return Gtk.TreeView.do_button_release_event(self, e) |
| 1423 |
|
| 1424 |
def _cancel_editing(self): |
| 1425 |
self.pending_edit_ok = False |
| 1426 |
self.pending_edit_data = None |
| 1427 |
if self.pending_edit_id: |
| 1428 |
GLib.source_remove(self.pending_edit_id) |
| 1429 |
self.pending_edit_id = None |
| 1430 |
|
| 1431 |
def _editing_double_click_ok(self): |
| 1432 |
self.pending_edit_id = None |
| 1433 |
self._maybe_start_editing() |
| 1434 |
return False |
| 1435 |
|
| 1436 |
def _maybe_start_editing(self): |
| 1437 |
# this has to be called twice for an edit to start |
| 1438 |
# -> either by the double click timeout, or button release |
| 1439 |
if self.pending_edit_ok: |
| 1440 |
path, col = self.pending_edit_data |
| 1441 |
col.start_editing(self, path) |
| 1442 |
self.pending_edit_ok = False |
| 1443 |
self.pending_edit_data = None |
| 1444 |
elif self.pending_edit_data: |
| 1445 |
self.pending_edit_ok = True |
| 1446 |
|
| 1447 |
def on_key_press_event(self, widget, event): |
| 1448 |
if event.keyval == Gdk.KEY_Menu: |
| 1449 |
self.menu.popup(None, None, None, None, 0, event.time) |
| 1450 |
return True |
| 1451 |
|
| 1452 |
elif event.keyval == Gdk.KEY_Delete: |
| 1453 |
indexes = [x[0] for x in self.get_selected_paths()] |
| 1454 |
with guiutil.without_model(self): |
| 1455 |
if indexes and indexes == list( |
| 1456 |
range(indexes[0], indexes[0] + len(indexes)) |
| 1457 |
): |
| 1458 |
del self.playlist[indexes[0] : indexes[0] + len(indexes)] |
| 1459 |
else: |
| 1460 |
for i in indexes[::-1]: |
| 1461 |
del self.playlist[i] |
| 1462 |
|
| 1463 |
# TODO: localization? |
| 1464 |
# -> Also, would be good to expose these shortcuts somehow to the user... |
| 1465 |
# it seems that Gtk.BindingSet is the way to do it, but there isn't a |
| 1466 |
# mechanism to enumerate it in python |
| 1467 |
elif event.keyval == Gdk.KEY_q: |
| 1468 |
if self.playlist is not self.player.queue: |
| 1469 |
self.player.queue.extend(self.get_selected_tracks()) |
| 1470 |
|
| 1471 |
elif event.keyval == Gdk.KEY_Up and event.state & Gdk.ModifierType.MOD1_MASK: |
| 1472 |
indexes = [x[0] for x in self.get_selected_paths()] |
| 1473 |
if len(indexes) == 1 and indexes[0] != 0: |
| 1474 |
idx = indexes[0] |
| 1475 |
track = self.playlist.pop(idx) |
| 1476 |
self.playlist[idx - 1 : idx - 1] = [track] |
| 1477 |
|
| 1478 |
elif event.keyval == Gdk.KEY_Down and event.state & Gdk.ModifierType.MOD1_MASK: |
| 1479 |
indexes = [x[0] for x in self.get_selected_paths()] |
| 1480 |
if len(indexes) == 1 and indexes[0] != len(self.playlist) - 1: |
| 1481 |
idx = indexes[0] |
| 1482 |
track = self.playlist.pop(idx) |
| 1483 |
self.playlist[idx + 1 : idx + 1] = [track] |
| 1484 |
|
| 1485 |
elif event.keyval == Gdk.KEY_F2: |
| 1486 |
path, column = self.get_cursor() |
| 1487 |
if path and isinstance(column, playlist_columns.EditableColumn): |
| 1488 |
column.start_editing(self, path) |
| 1489 |
|
| 1490 |
# Prevent space-key from triggering 'row-activated' signal, |
| 1491 |
# which restarts the currently-playing track. Instead, we call |
| 1492 |
# _play_track_at() here with restart_if_playing flag set to |
| 1493 |
# False, so that pause will be always toggled instead. |
| 1494 |
elif event.keyval == Gdk.KEY_space: |
| 1495 |
try: |
| 1496 |
position, track = self.get_selected_items()[0] |
| 1497 |
except IndexError: |
| 1498 |
return True # Prevent 'row-activated' |
| 1499 |
|
| 1500 |
self._play_track_at(position, track, True, False) |
| 1501 |
|
| 1502 |
return True # Prevent 'row-activated' |
| 1503 |
|
| 1504 |
# Columns with editable rows will take row-activated and start editing |
| 1505 |
# but we want to start playback, so simulate it instead |
| 1506 |
elif event.keyval == Gdk.KEY_Return: |
| 1507 |
self.on_row_activated() |
| 1508 |
return True # Prevent 'row-activated' |
| 1509 |
|
| 1510 |
### DND handlers ### |
| 1511 |
# Source |
| 1512 |
def on_drag_begin(self, widget, context): |
| 1513 |
""" |
| 1514 |
Activates the dragging state |
| 1515 |
""" |
| 1516 |
# TODO: set drag icon |
| 1517 |
self.dragging = True |
| 1518 |
self.pending_event = None |
| 1519 |
self._cancel_editing() |
| 1520 |
self.get_selection().set_select_function(lambda *args: True, None) |
| 1521 |
|
| 1522 |
def on_drag_data_get(self, widget, context, selection, info, etime): |
| 1523 |
""" |
| 1524 |
Stores indices and URIs of the selected items in the drag selection |
| 1525 |
""" |
| 1526 |
target_atom = selection.get_target() |
| 1527 |
target = target_atom.name() |
| 1528 |
if target == "exaile-index-list": |
| 1529 |
positions = self.get_selected_paths() |
| 1530 |
if positions: |
| 1531 |
s = ",".join(str(i[0]) for i in positions) |
| 1532 |
selection.set(target_atom, 8, s.encode('utf-8')) |
| 1533 |
elif target == "text/uri-list": |
| 1534 |
tracks = self.get_selected_tracks() |
| 1535 |
uris = trax.util.get_uris_from_tracks(tracks) |
| 1536 |
selection.set_uris(uris) |
| 1537 |
|
| 1538 |
def on_drag_data_delete(self, widget, context): |
| 1539 |
""" |
| 1540 |
Stops the default handler from running, all |
| 1541 |
processing occurs in the drag-data-received handler |
| 1542 |
""" |
| 1543 |
self.stop_emission_by_name('drag-data-delete') |
| 1544 |
|
| 1545 |
def on_drag_end(self, widget, context): |
| 1546 |
""" |
| 1547 |
Deactivates the dragging state |
| 1548 |
""" |
| 1549 |
self.dragging = False |
| 1550 |
|
| 1551 |
# Dest |
| 1552 |
def on_drag_drop(self, widget, context, x, y, etime): |
| 1553 |
""" |
| 1554 |
Always allows processing of drop operations |
| 1555 |
""" |
| 1556 |
return True |
| 1557 |
|
| 1558 |
def on_drag_data_received(self, widget, context, x, y, selection, info, etime): |
| 1559 |
""" |
| 1560 |
Builds a list of tracks either from internal indices or |
| 1561 |
external URIs and inserts or appends them to the playlist |
| 1562 |
""" |
| 1563 |
# Stop default handler from running |
| 1564 |
self.stop_emission_by_name('drag-data-received') |
| 1565 |
|
| 1566 |
# Makes `self.on_row_inserted` to ignore inserted rows |
| 1567 |
# see https://github.com/exaile/exaile/issues/487 |
| 1568 |
self._insert_focusing = True |
| 1569 |
|
| 1570 |
drop_info = self.get_dest_row_at_pos(x, y) |
| 1571 |
|
| 1572 |
if drop_info: |
| 1573 |
path, position = drop_info |
| 1574 |
model = self.get_model() |
| 1575 |
if isinstance(model, Gtk.TreeModelFilter): |
| 1576 |
path = model.convert_path_to_child_path(path) |
| 1577 |
|
| 1578 |
insert_position = path[0] |
| 1579 |
if position in ( |
| 1580 |
Gtk.TreeViewDropPosition.AFTER, |
| 1581 |
Gtk.TreeViewDropPosition.INTO_OR_AFTER, |
| 1582 |
): |
| 1583 |
insert_position += 1 |
| 1584 |
else: |
| 1585 |
insert_position = -1 |
| 1586 |
|
| 1587 |
# hack: see https://github.com/exaile/exaile/issues/479 |
| 1588 |
if self._hack_is_osx: |
| 1589 |
source_widget = Gtk.drag_get_source_widget(context) |
| 1590 |
if not (source_widget is None or source_widget is self) and hasattr( |
| 1591 |
source_widget, 'get_selected_tracks' |
| 1592 |
): |
| 1593 |
try: |
| 1594 |
tracks = source_widget.get_selected_tracks() |
| 1595 |
if insert_position >= 0: |
| 1596 |
self.playlist[insert_position:insert_position] = tracks |
| 1597 |
else: |
| 1598 |
self.playlist.extend(tracks) |
| 1599 |
insert_position = len(self.playlist) - len(tracks) |
| 1600 |
except Exception: |
| 1601 |
pass # Any exception on hack is ignored |
| 1602 |
else: |
| 1603 |
# Select inserted items |
| 1604 |
if tracks: |
| 1605 |
self.selection.unselect_all() |
| 1606 |
self.selection.select_range( |
| 1607 |
self.model.get_path( |
| 1608 |
self.model.iter_nth_child(None, insert_position) |
| 1609 |
), |
| 1610 |
self.model.get_path( |
| 1611 |
self.model.iter_nth_child( |
| 1612 |
None, insert_position + len(tracks) - 1 |
| 1613 |
) |
| 1614 |
), |
| 1615 |
) |
| 1616 |
|
| 1617 |
# Restore state to `self.on_row_inserted` do not ignore inserted rows |
| 1618 |
# see https://github.com/exaile/exaile/issues/487 |
| 1619 |
self._insert_focusing = False |
| 1620 |
return |
| 1621 |
|
| 1622 |
tracks = [] |
| 1623 |
playlist = [] |
| 1624 |
positions = [] |
| 1625 |
pos = 0 |
| 1626 |
source_playlist_view = None |
| 1627 |
|
| 1628 |
target = selection.get_target().name() |
| 1629 |
if target == "exaile-index-list": |
| 1630 |
selection_data = selection.get_data().decode('utf-8') |
| 1631 |
if selection_data == '': # Ignore drops from empty areas |
| 1632 |
# Restore state to `self.on_row_inserted` do not ignore inserted rows |
| 1633 |
# see https://github.com/exaile/exaile/issues/487 |
| 1634 |
self._insert_focusing = False |
| 1635 |
return |
| 1636 |
positions = [int(pos) for pos in selection_data.split(",")] |
| 1637 |
tracks = common.MetadataList() |
| 1638 |
source_playlist_view = Gtk.drag_get_source_widget(context) |
| 1639 |
playlist = self.playlist |
| 1640 |
|
| 1641 |
# Get the playlist of the |
| 1642 |
if source_playlist_view is not self: |
| 1643 |
playlist = source_playlist_view.playlist |
| 1644 |
|
| 1645 |
current_position_index = -1 |
| 1646 |
for i, pos in enumerate(positions): |
| 1647 |
if pos == playlist.current_position: |
| 1648 |
current_position_index = i |
| 1649 |
|
| 1650 |
tracks.append(playlist[pos]) |
| 1651 |
|
| 1652 |
# Insert at specific position if possible |
| 1653 |
if insert_position >= 0: |
| 1654 |
self.playlist[insert_position:insert_position] = tracks |
| 1655 |
|
| 1656 |
if source_playlist_view is self: |
| 1657 |
# Update position for tracks after the insert position |
| 1658 |
for i, position in enumerate(positions[:]): |
| 1659 |
if position >= insert_position: |
| 1660 |
position += len(tracks) |
| 1661 |
positions[i] = position |
| 1662 |
|
| 1663 |
# Update playlist current position |
| 1664 |
if current_position_index >= 0: |
| 1665 |
self.playlist.current_position = ( |
| 1666 |
insert_position + current_position_index |
| 1667 |
) |
| 1668 |
self.model.update_row_params(self.playlist.current_position) |
| 1669 |
else: |
| 1670 |
# Otherwise just append the tracks |
| 1671 |
self.playlist.extend(tracks) |
| 1672 |
insert_position = len(self.playlist) - len(tracks) |
| 1673 |
elif target == "text/uri-list": |
| 1674 |
uris = selection.get_uris() |
| 1675 |
tracks = [] |
| 1676 |
for uri in uris: |
| 1677 |
if is_valid_playlist(uri): |
| 1678 |
tracks.extend(import_playlist(uri)) |
| 1679 |
else: |
| 1680 |
tracks.extend(trax.get_tracks_from_uri(uri)) |
| 1681 |
sort_by, reverse = self.get_sort_by() |
| 1682 |
tracks = trax.sort_tracks( |
| 1683 |
sort_by, tracks, reverse=reverse, artist_compilations=True |
| 1684 |
) |
| 1685 |
if insert_position >= 0: |
| 1686 |
self.playlist[insert_position:insert_position] = tracks |
| 1687 |
else: |
| 1688 |
self.playlist.extend(tracks) |
| 1689 |
insert_position = len(self.playlist) - len(tracks) |
| 1690 |
|
| 1691 |
# Remove tracks from the source playlist if moved |
| 1692 |
if context.get_selected_action() == Gdk.DragAction.MOVE: |
| 1693 |
for i in positions[::-1]: |
| 1694 |
del playlist[i] |
| 1695 |
|
| 1696 |
delete = context.get_selected_action() == Gdk.DragAction.MOVE |
| 1697 |
context.finish(True, delete, etime) |
| 1698 |
|
| 1699 |
scroll_when_appending_tracks = settings.get_option( |
| 1700 |
'gui/scroll_when_appending_tracks', False |
| 1701 |
) |
| 1702 |
|
| 1703 |
if scroll_when_appending_tracks and tracks: |
| 1704 |
self.scroll_to_cell(self.playlist.index(tracks[-1])) |
| 1705 |
elif 0 < len(tracks) <= 500: |
| 1706 |
# Keep insert position and length of selection for restoring after updating the playlist view |
| 1707 |
if ( |
| 1708 |
0 < pos < insert_position |
| 1709 |
and source_playlist_view is self |
| 1710 |
and context.get_selected_action() == Gdk.DragAction.MOVE |
| 1711 |
): |
| 1712 |
insert_position -= len(tracks) |
| 1713 |
self._insert_row = insert_position |
| 1714 |
self._insert_count = len(tracks) |
| 1715 |
|
| 1716 |
# Restore state to `self.on_row_inserted` do not ignore inserted rows |
| 1717 |
# see https://github.com/exaile/exaile/issues/487 |
| 1718 |
self._insert_focusing = False |
| 1719 |
|
| 1720 |
def on_drag_motion(self, widget, context, x, y, etime): |
| 1721 |
""" |
| 1722 |
Makes sure tracks can only be inserted before or after tracks |
| 1723 |
and sets the drop action to move or copy depending on target |
| 1724 |
and user interaction (e.g. Ctrl key) |
| 1725 |
""" |
| 1726 |
drop_info = self.get_dest_row_at_pos(x, y) |
| 1727 |
|
| 1728 |
if not drop_info: |
| 1729 |
return False |
| 1730 |
|
| 1731 |
path, position = drop_info |
| 1732 |
|
| 1733 |
if position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE: |
| 1734 |
position = Gtk.TreeViewDropPosition.BEFORE |
| 1735 |
elif position == Gtk.TreeViewDropPosition.INTO_OR_AFTER: |
| 1736 |
position = Gtk.TreeViewDropPosition.AFTER |
| 1737 |
|
| 1738 |
self.set_drag_dest_row(path, position) |
| 1739 |
|
| 1740 |
action = Gdk.DragAction.MOVE |
| 1741 |
_, _, _, modifier = self.get_window().get_pointer() |
| 1742 |
target = self.drag_dest_find_target(context, None).name() |
| 1743 |
|
| 1744 |
if ( |
| 1745 |
target == 'text/uri-list' |
| 1746 |
or (self._hack_is_osx and self._hack_osx_control_mask) |
| 1747 |
or (not self._hack_is_osx and modifier & Gdk.ModifierType.CONTROL_MASK) |
| 1748 |
): |
| 1749 |
action = Gdk.DragAction.COPY |
| 1750 |
|
| 1751 |
if self.dragdrop_copyonly and Gtk.drag_get_source_widget(context) != self: |
| 1752 |
action = Gdk.DragAction.COPY |
| 1753 |
|
| 1754 |
Gdk.drag_status(context, action, etime) |
| 1755 |
|
| 1756 |
return True |
| 1757 |
|
| 1758 |
def on_size_allocate(self, plView, selection): |
| 1759 |
if self._insert_row > -1: |
| 1760 |
# correction of selected rows |
| 1761 |
self.select_rows( |
| 1762 |
self._insert_row, self._insert_row + self._insert_count - 1 |
| 1763 |
) |
| 1764 |
self._insert_row = -1 |
| 1765 |
self._insert_count = 0 |
| 1766 |
|
| 1767 |
def show_properties_dialog(self): |
| 1768 |
from xlgui import properties |
| 1769 |
|
| 1770 |
items = self.get_selected_items() |
| 1771 |
|
| 1772 |
# If only one track is selected, we expand `tracks` to include all |
| 1773 |
# tracks in the playlist... except for really large playlists, this |
| 1774 |
# essentially hangs. Instead, only show all tracks *if* the playlist |
| 1775 |
# size is less than 100. |
| 1776 |
# |
| 1777 |
# A better option would be to lazy load the files, but I'm too lazy |
| 1778 |
# to implement that now.. :) |
| 1779 |
|
| 1780 |
if len(items) == 1 and len(self.playlist) < 100: |
| 1781 |
tracks = self.playlist[:] |
| 1782 |
current_position = items[0][0] |
| 1783 |
else: |
| 1784 |
tracks = [i[1] for i in items] |
| 1785 |
current_position = 0 |
| 1786 |
|
| 1787 |
properties.TrackPropertiesDialog(self.get_toplevel(), tracks, current_position) |
| 1788 |
|
| 1789 |
def on_provider_removed(self, provider): |
| 1790 |
""" |
| 1791 |
Called when a column provider is removed |
| 1792 |
""" |
| 1793 |
columns = settings.get_option('gui/columns') |
| 1794 |
|
| 1795 |
if provider.name in columns: |
| 1796 |
columns.remove(provider.name) |
| 1797 |
settings.set_option('gui/columns', columns) |
| 1798 |
|
| 1799 |
def select_rows(self, start, stop): |
| 1800 |
self.selection.unselect_all() |
| 1801 |
if self.model.iter_nth_child(None, start) == None: |
| 1802 |
return |
| 1803 |
if self.model.iter_nth_child(None, stop) == None: |
| 1804 |
return |
| 1805 |
self.selection.select_range( |
| 1806 |
self.model.get_path(self.model.iter_nth_child(None, start)), |
| 1807 |
self.model.get_path(self.model.iter_nth_child(None, stop)), |
| 1808 |
) |
| 1809 |
|
| 1810 |
|
| 1811 |
class PlaylistModel(Gtk.ListStore): |
| 1812 |
""" |
| 1813 |
This ListStore contains all the information needed to render a playlist |
| 1814 |
via a PlaylistView. There are five columns: |
| 1815 |
|
| 1816 |
* xl.trax.Track |
| 1817 |
* dictionary (tag cache) |
| 1818 |
* Gdk.Pixbuf (indicates whether track is playing or not) |
| 1819 |
* boolean (indicates whether row is sensitive) |
| 1820 |
* Pango.Weight (indicates if row is the playing track or not) |
| 1821 |
|
| 1822 |
The cache keys correspond to the tags rendered by each column. When a |
| 1823 |
track changes, the row's corresponding cache is cleared and the row |
| 1824 |
change event is fired. |
| 1825 |
|
| 1826 |
The cache keys are populated by the playlist columns. This arrangement |
| 1827 |
ensures that we don't have to recreate the playlist model each time the |
| 1828 |
columns are changed. |
| 1829 |
""" |
| 1830 |
|
| 1831 |
__gsignals__ = { |
| 1832 |
# Called with true indicates starting operation, False ends op |
| 1833 |
'data-loading': (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_BOOLEAN,)) |
| 1834 |
} |
| 1835 |
|
| 1836 |
COL_TRACK = 0 |
| 1837 |
COL_CACHE = 1 |
| 1838 |
COL_PIXBUF = 2 |
| 1839 |
COL_SENSITIVE = 3 |
| 1840 |
COL_WEIGHT = 4 |
| 1841 |
|
| 1842 |
PARAM_COLS = (COL_PIXBUF, COL_SENSITIVE, COL_WEIGHT) |
| 1843 |
|
| 1844 |
def __init__(self, playlist, column_names, player, parent): |
| 1845 |
# columns: Track, Pixbuf, dict (cache) |
| 1846 |
Gtk.ListStore.__init__( |
| 1847 |
self, object, object, GdkPixbuf.Pixbuf, bool, Pango.Weight |
| 1848 |
) |
| 1849 |
self.playlist = playlist |
| 1850 |
self.player = player |
| 1851 |
|
| 1852 |
self._set_columns(column_names) |
| 1853 |
|
| 1854 |
self.data_loading = False |
| 1855 |
self.data_load_queue = [] |
| 1856 |
|
| 1857 |
self._redraw_timer = None |
| 1858 |
self._redraw_queue = [] |
| 1859 |
|
| 1860 |
event.add_ui_callback( |
| 1861 |
self.on_tracks_added, "playlist_tracks_added", playlist, destroy_with=parent |
| 1862 |
) |
| 1863 |
event.add_ui_callback( |
| 1864 |
self.on_tracks_removed, |
| 1865 |
"playlist_tracks_removed", |
| 1866 |
playlist, |
| 1867 |
destroy_with=parent, |
| 1868 |
) |
| 1869 |
event.add_ui_callback( |
| 1870 |
self.on_current_position_changed, |
| 1871 |
"playlist_current_position_changed", |
| 1872 |
playlist, |
| 1873 |
destroy_with=parent, |
| 1874 |
) |
| 1875 |
event.add_ui_callback( |
| 1876 |
self.on_spat_position_changed, |
| 1877 |
"playlist_spat_position_changed", |
| 1878 |
playlist, |
| 1879 |
destroy_with=parent, |
| 1880 |
) |
| 1881 |
event.add_ui_callback( |
| 1882 |
self.on_playback_state_change, |
| 1883 |
"playback_track_start", |
| 1884 |
self.player, |
| 1885 |
destroy_with=parent, |
| 1886 |
) |
| 1887 |
event.add_ui_callback( |
| 1888 |
self.on_playback_state_change, |
| 1889 |
"playback_track_end", |
| 1890 |
self.player, |
| 1891 |
destroy_with=parent, |
| 1892 |
) |
| 1893 |
event.add_ui_callback( |
| 1894 |
self.on_playback_state_change, |
| 1895 |
"playback_player_pause", |
| 1896 |
self.player, |
| 1897 |
destroy_with=parent, |
| 1898 |
) |
| 1899 |
event.add_ui_callback( |
| 1900 |
self.on_playback_state_change, |
| 1901 |
"playback_player_resume", |
| 1902 |
self.player, |
| 1903 |
destroy_with=parent, |
| 1904 |
) |
| 1905 |
event.add_ui_callback( |
| 1906 |
self.on_track_tags_changed, "track_tags_changed", destroy_with=parent |
| 1907 |
) |
| 1908 |
|
| 1909 |
event.add_ui_callback(self.on_option_set, "gui_option_set", destroy_with=parent) |
| 1910 |
|
| 1911 |
self._setup_icons() |
| 1912 |
self.on_tracks_added( |
| 1913 |
None, self.playlist, list(enumerate(self.playlist)) |
| 1914 |
) # populate the list |
| 1915 |
|
| 1916 |
def _set_columns(self, column_names): |
| 1917 |
self.column_names = set(column_names) |
| 1918 |
|
| 1919 |
def _setup_icons(self): |
| 1920 |
self.play_pixbuf = icons.ExtendedPixbuf( |
| 1921 |
icons.MANAGER.pixbuf_from_icon_name('media-playback-start') |
| 1922 |
) |
| 1923 |
self.pause_pixbuf = icons.ExtendedPixbuf( |
| 1924 |
icons.MANAGER.pixbuf_from_icon_name('media-playback-pause') |
| 1925 |
) |
| 1926 |
self.stop_pixbuf = icons.ExtendedPixbuf( |
| 1927 |
icons.MANAGER.pixbuf_from_icon_name('media-playback-stop') |
| 1928 |
) |
| 1929 |
stop_overlay_pixbuf = self.stop_pixbuf.scale_simple( |
| 1930 |
dest_width=self.stop_pixbuf.pixbuf.get_width() // 2, |
| 1931 |
dest_height=self.stop_pixbuf.pixbuf.get_height() // 2, |
| 1932 |
interp_type=GdkPixbuf.InterpType.BILINEAR, |
| 1933 |
) |
| 1934 |
stop_overlay_pixbuf = stop_overlay_pixbuf.move( |
| 1935 |
offset_x=stop_overlay_pixbuf.pixbuf.get_width(), |
| 1936 |
offset_y=stop_overlay_pixbuf.pixbuf.get_height(), |
| 1937 |
resize=True, |
| 1938 |
) |
| 1939 |
self.play_stop_pixbuf = self.play_pixbuf & stop_overlay_pixbuf |
| 1940 |
self.pause_stop_pixbuf = self.pause_pixbuf & stop_overlay_pixbuf |
| 1941 |
self.clear_pixbuf = self.play_pixbuf.copy() |
| 1942 |
self.clear_pixbuf.pixbuf.fill(0x00000000) |
| 1943 |
|
| 1944 |
font = settings.get_option('gui/playlist_font', None) |
| 1945 |
if font is not None: |
| 1946 |
# get default font |
| 1947 |
default = float(Gtk.Widget.get_default_style().font_desc.get_size()) |
| 1948 |
new_font = Pango.FontDescription.from_string(font).get_size() |
| 1949 |
|
| 1950 |
# scale pixbuf accordingly |
| 1951 |
t = GdkPixbuf.InterpType.BILINEAR |
| 1952 |
s = max(int(self.play_pixbuf.get_width() * (new_font / default)), 1) |
| 1953 |
|
| 1954 |
self.play_pixbuf = self.play_pixbuf.scale_simple(s, s, t) |
| 1955 |
self.pause_pixbuf = self.pause_pixbuf.scale_simple(s, s, t) |
| 1956 |
self.stop_pixbuf = self.stop_pixbuf.scale_simple(s, s, t) |
| 1957 |
self.play_stop_pixbuf = self.play_stop_pixbuf.scale_simple(s, s, t) |
| 1958 |
self.pause_stop_pixbuf = self.pause_stop_pixbuf.scale_simple(s, s, t) |
| 1959 |
self.clear_pixbuf = self.clear_pixbuf.scale_simple(s, s, t) |
| 1960 |
|
| 1961 |
def _refresh_icons(self): |
| 1962 |
self._setup_icons() |
| 1963 |
itr = self.get_iter_first() |
| 1964 |
position = 0 |
| 1965 |
while itr: |
| 1966 |
self.set(itr, self.PARAM_COLS, self._compute_row_params(position)) |
| 1967 |
itr = self.iter_next(itr) |
| 1968 |
position += 1 |
| 1969 |
|
| 1970 |
def on_option_set(self, typ, obj, data): |
| 1971 |
if data == "gui/playlist_font": |
| 1972 |
self._refresh_icons() |
| 1973 |
|
| 1974 |
def _compute_row_params(self, rowidx): |
| 1975 |
""" |
| 1976 |
:returns: pixbuf, sensitive, weight |
| 1977 |
""" |
| 1978 |
|
| 1979 |
pixbuf = self.clear_pixbuf.pixbuf |
| 1980 |
weight = Pango.Weight.NORMAL |
| 1981 |
sensitive = True |
| 1982 |
|
| 1983 |
playlist = self.playlist |
| 1984 |
|
| 1985 |
spatpos = playlist.spat_position |
| 1986 |
spat = spatpos == rowidx |
| 1987 |
|
| 1988 |
if spat: |
| 1989 |
pixbuf = self.stop_pixbuf.pixbuf |
| 1990 |
|
| 1991 |
if playlist is self.player.queue.current_playlist: |
| 1992 |
if ( |
| 1993 |
playlist.current_position == rowidx |
| 1994 |
and playlist[rowidx] == self.player.current |
| 1995 |
): |
| 1996 |
# this row is the current track, set a special icon |
| 1997 |
state = self.player.get_state() |
| 1998 |
|
| 1999 |
weight = Pango.Weight.HEAVY |
| 2000 |
|
| 2001 |
if state == 'playing': |
| 2002 |
if spat: |
| 2003 |
pixbuf = self.play_stop_pixbuf.pixbuf |
| 2004 |
else: |
| 2005 |
pixbuf = self.play_pixbuf.pixbuf |
| 2006 |
elif state == 'paused': |
| 2007 |
if spat: |
| 2008 |
pixbuf = self.pause_stop_pixbuf.pixbuf |
| 2009 |
else: |
| 2010 |
pixbuf = self.pause_pixbuf.pixbuf |
| 2011 |
|
| 2012 |
if spatpos == -1 or spatpos > rowidx: |
| 2013 |
sensitive = True |
| 2014 |
else: |
| 2015 |
sensitive = False |
| 2016 |
|
| 2017 |
return pixbuf, sensitive, weight |
| 2018 |
|
| 2019 |
def update_row_params(self, position): |
| 2020 |
itr = self.iter_nth_child(None, position) |
| 2021 |
if itr is not None: |
| 2022 |
self.set(itr, self.PARAM_COLS, self._compute_row_params(position)) |
| 2023 |
|
| 2024 |
### Event callbacks to keep the model in sync with the playlist ### |
| 2025 |
|
| 2026 |
def on_tracks_added(self, event_type, playlist, tracks): |
| 2027 |
self._load_data(tracks) |
| 2028 |
|
| 2029 |
def on_tracks_removed(self, event_type, playlist, tracks): |
| 2030 |
for position, track in reversed(tracks): |
| 2031 |
if position < 0: |
| 2032 |
continue |
| 2033 |
self.remove(self.iter_nth_child(None, position)) |
| 2034 |
|
| 2035 |
def on_current_position_changed(self, event_type, playlist, positions): |
| 2036 |
for position in positions: |
| 2037 |
if position < 0: |
| 2038 |
continue |
| 2039 |
self.update_row_params(position) |
| 2040 |
|
| 2041 |
def on_spat_position_changed(self, event_type, playlist, positions): |
| 2042 |
pos = min(positions) |
| 2043 |
|
| 2044 |
if pos < 0: |
| 2045 |
pos = 0 |
| 2046 |
itr = self.get_iter_first() |
| 2047 |
else: |
| 2048 |
itr = self.iter_nth_child(None, pos) |
| 2049 |
|
| 2050 |
while itr: |
| 2051 |
self.set(itr, self.PARAM_COLS, self._compute_row_params(pos)) |
| 2052 |
itr = self.iter_next(itr) |
| 2053 |
pos += 1 |
| 2054 |
|
| 2055 |
def on_playback_state_change(self, event_type, player_obj, track): |
| 2056 |
position = self.playlist.current_position |
| 2057 |
if position < 0 or position >= len(self): |
| 2058 |
return |
| 2059 |
self.update_row_params(position) |
| 2060 |
|
| 2061 |
def on_track_tags_changed(self, type, track, tags): |
| 2062 |
if ( |
| 2063 |
not track |
| 2064 |
or not settings.get_option('gui/sync_on_tag_change', True) |
| 2065 |
or not (tags & self.column_names) |
| 2066 |
): |
| 2067 |
return |
| 2068 |
|
| 2069 |
if self._redraw_timer: |
| 2070 |
GLib.source_remove(self._redraw_timer) |
| 2071 |
self._redraw_queue.append(track) |
| 2072 |
self._redraw_timer = GLib.timeout_add(100, self._on_track_tags_changed) |
| 2073 |
|
| 2074 |
def _on_track_tags_changed(self): |
| 2075 |
self._redraw_timer = None |
| 2076 |
redraw_queue = set(self._redraw_queue) |
| 2077 |
self._redraw_queue = [] |
| 2078 |
|
| 2079 |
COL_TRACK = self.COL_TRACK |
| 2080 |
COL_CACHE = self.COL_CACHE |
| 2081 |
|
| 2082 |
for row in self: |
| 2083 |
if row[COL_TRACK] in redraw_queue: |
| 2084 |
row[COL_CACHE].clear() |
| 2085 |
self.row_changed(row.path, row.iter) |
| 2086 |
|
| 2087 |
# |
| 2088 |
# Loading data into the playlist: |
| 2089 |
# |
| 2090 |
# - Profiler reveals that most of the playlist loading time is spent in two |
| 2091 |
# places |
| 2092 |
# - Formatting values |
| 2093 |
# - Converting them to GValue objects for insert into the treeview |
| 2094 |
# |
| 2095 |
# Now, the program is annoyingly blocked when this happens, so we need to |
| 2096 |
# process new tracks on a different thread, and show some kind of loading |
| 2097 |
# indicator instead. That's what these four functions help us do. |
| 2098 |
# |
| 2099 |
|
| 2100 |
def _load_data(self, tracks): |
| 2101 |
# Don't allow race condition between adds.. there's probably a race |
| 2102 |
# condition for removal |
| 2103 |
if self.data_loading: |
| 2104 |
self.data_load_queue.extend(tracks) |
| 2105 |
return |
| 2106 |
|
| 2107 |
self.data_loading = True |
| 2108 |
self.emit('data-loading', True) |
| 2109 |
|
| 2110 |
if len(tracks) > 500: |
| 2111 |
self._load_data_thread(tracks) |
| 2112 |
else: |
| 2113 |
render_data = self._load_data_fn(tracks) |
| 2114 |
self._load_data_done(render_data) |
| 2115 |
|
| 2116 |
@common.threaded |
| 2117 |
def _load_data_thread(self, tracks): |
| 2118 |
render_data = self._load_data_fn(tracks) |
| 2119 |
GLib.idle_add(self._load_data_done, render_data) |
| 2120 |
|
| 2121 |
def _load_data_fn(self, tracks): |
| 2122 |
indices = (0, 1, 2, 3, 4) |
| 2123 |
return [ |
| 2124 |
(position, indices, (track, {}) + self._compute_row_params(position)) |
| 2125 |
for position, track in tracks |
| 2126 |
] |
| 2127 |
|
| 2128 |
def _load_data_done(self, render_data): |
| 2129 |
for args in render_data: |
| 2130 |
self.insert_with_valuesv(*args) |
| 2131 |
|
| 2132 |
self.data_loading = False |
| 2133 |
self.emit('data-loading', False) |
| 2134 |
|
| 2135 |
if self.data_load_queue: |
| 2136 |
tracks = self.data_load_queue |
| 2137 |
self.data_load_queue = [] |
| 2138 |
|
| 2139 |
self._load_data(tracks) |