Commit 14d98346 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Add a smart progressbar

parent bdc799b7
......@@ -57,6 +57,7 @@ app_PYTHON = \
pop_radio.py\
pop_search.py\
pop_tunein.py\
progressbar.py\
radios.py\
search_item.py\
search_network.py\
......
......@@ -57,11 +57,13 @@ class CollectionScanner(GObject.GObject, TagReader):
Update database
"""
if not self.is_locked():
Lp().window.progress.show()
paths = Lp().settings.get_music_paths()
if not paths:
return
Lp().window.progress.add(self)
Lp().window.progress.set_fraction(0.0, self)
if Lp().notify is not None:
Lp().notify.send(_("Your music is updating"))
self.__thread = Thread(target=self.__scan, args=(paths,))
......@@ -79,8 +81,6 @@ class CollectionScanner(GObject.GObject, TagReader):
Stop scan
"""
self.__thread = None
Lp().window.progress.hide()
Lp().window.progress.set_fraction(0.0)
#######################
# PRIVATE #
......@@ -120,12 +120,13 @@ class CollectionScanner(GObject.GObject, TagReader):
Update progress bar status
@param scanned items as int, total items as int
"""
Lp().window.progress.set_fraction(current/total)
Lp().window.progress.set_fraction(current / total, self)
def __finish(self):
"""
Notify from main thread when scan finished
"""
Lp().window.progress.set_fraction(1.0, self)
self.stop()
self.emit("scan-finished")
if Lp().settings.get_value('artist-artwork'):
......@@ -194,7 +195,8 @@ class CollectionScanner(GObject.GObject, TagReader):
for uri in orig_tracks:
i += 1
GLib.idle_add(self.__update_progress, i, count)
self.__del_from_db(uri)
if uri.startswith('file:'):
self.__del_from_db(uri)
sql.commit()
GLib.idle_add(self.__finish)
......
......@@ -21,6 +21,7 @@ from lollypop.view_container import ViewContainer
from lollypop.view_albums import AlbumsView
from lollypop.view_artist import ArtistView
from lollypop.view_radios import RadiosView
from lollypop.progressbar import ProgressBar
from lollypop.view_playlists import PlaylistsView
from lollypop.view_playlists import PlaylistsManageView, PlaylistEditView
from lollypop.view_device import DeviceView, DeviceLocked, DeviceMigration
......@@ -77,9 +78,7 @@ class Container:
Lp().scanner.stop()
GLib.timeout_add(250, self.update_db)
else:
# Something (device manager) is using progress bar
if not self.__progress.is_visible():
Lp().scanner.update()
Lp().scanner.update()
def get_genre_id(self):
"""
......@@ -264,7 +263,7 @@ class Container:
def progress(self):
"""
Progress bar
@return Gtk.ProgressBar
@return ProgressBar
"""
return self.__progress
......@@ -302,7 +301,7 @@ class Container:
self.__list_one.connect('populated', self.__on_list_populated)
self.__list_two.connect('item-selected', self.__on_list_two_selected)
self.__progress = Gtk.ProgressBar()
self.__progress = ProgressBar()
self.__progress.set_property('hexpand', True)
vgrid.add(self.__stack)
......
# Copyright (c) 2014-2016 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
class ProgressBar(Gtk.ProgressBar):
"""
A smart progress bar
"""
def __init__(self):
"""
Init progress bar
"""
Gtk.ProgressBar.__init__(self)
self.__callers = []
def add(self, caller):
"""
Add caller
@param caller as Instance
"""
if caller not in self.__callers:
self.__callers.insert(0, caller)
def set_fraction(self, fraction, caller):
"""
Set fraction if caller is on top.
"""
if not self.__callers:
return
self.show()
if caller == self.__callers[0]:
Gtk.ProgressBar.set_fraction(self, fraction)
if fraction == 1:
self.__callers.remove(caller)
self.hide()
Gtk.ProgressBar.set_fraction(self, 0.0)
......@@ -205,8 +205,6 @@ class DeviceView(View):
Restore widgets state
@param device widget as DeviceManager
"""
Lp().window.progress.hide()
Lp().window.progress.set_fraction(0)
self.__memory_combo.show()
self.__syncing_btn.set_label(_("Synchronize %s") %
self.__device.name)
......
......@@ -43,7 +43,6 @@ class DeviceManagerWidget(Gtk.Bin, MtpSync):
MtpSync.__init__(self)
self.__parent = parent
self.__stop = False
self._progress = Lp().window.progress
self._uri = None
builder = Gtk.Builder()
......@@ -141,8 +140,7 @@ class DeviceManagerWidget(Gtk.Bin, MtpSync):
Start synchronisation
"""
self._syncing = True
self._progress.show()
self._progress.set_fraction(0.0)
Lp().window.progress.add(self)
self.__menu.set_sensitive(False)
playlists = []
if not Lp().settings.get_value('sync-albums'):
......@@ -179,15 +177,13 @@ class DeviceManagerWidget(Gtk.Bin, MtpSync):
"""
Update progress bar smoothly
"""
if not self._progress.is_visible():
return
current = self._progress.get_fraction()
current = Lp().window.progress.get_fraction()
if self._syncing:
progress = (self._fraction-current)/10
else:
progress = 0.01
if current < self._fraction:
self._progress.set_fraction(current+progress)
Lp().window.progress.set_fraction(current+progress, self)
if current < 1.0:
if progress < 0.0002:
GLib.timeout_add(500, self._update_progress)
......@@ -215,6 +211,7 @@ class DeviceManagerWidget(Gtk.Bin, MtpSync):
Emit finished signal
"""
MtpSync._on_finished(self)
Lp().window.progress.set_fraction(1.0, self)
if not self.__switch_albums.get_state():
self.__view.set_sensitive(True)
self.__menu.set_sensitive(True)
......
......@@ -52,6 +52,7 @@ class Youtube(GObject.GObject):
@param item as SearchItem
@param persistent as DbPersistent
"""
Lp().window.progress.add(self)
t = Thread(target=self.__save_album_thread, args=(item, persistent))
t.daemon = True
t.start()
......@@ -65,13 +66,6 @@ class Youtube(GObject.GObject):
@param item as SearchItem
@param persistent as DbPersistent
"""
progress = Lp().window.progress
if progress.is_visible():
progress = None
else:
GLib.idle_add(progress.set_fraction, 0)
GLib.idle_add(progress.show)
nb_items = len(item.subitems)
start = 0
for track_item in item.subitems:
......@@ -84,11 +78,8 @@ class Youtube(GObject.GObject):
t.daemon = True
t.start()
start += 1
if progress is not None:
GLib.idle_add(progress.set_fraction, start / nb_items)
if progress is not None:
GLib.idle_add(progress.hide)
GLib.idle_add(progress.set_fraction, 0)
GLib.idle_add(Lp().window.progress.set_fraction,
start / nb_items, self)
# Play if needed
if persistent == DbPersistent.NONE:
Lp().player.clear_albums()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment