fixed errors on fast profile switch

This commit is contained in:
Martin Wagner 2022-10-01 17:06:00 +02:00
parent 7d744f21dd
commit da87188a78

View File

@ -653,6 +653,7 @@ class Client(MPDClient):
self._last_status={} self._last_status={}
self._refresh_interval=self._settings.get_int("refresh-interval") self._refresh_interval=self._settings.get_int("refresh-interval")
self._main_timeout_id=None self._main_timeout_id=None
self._start_idle_id=None
self.lib_path=None self.lib_path=None
self.current_cover=None self.current_cover=None
@ -723,6 +724,7 @@ class Client(MPDClient):
self.password(profile.get_string("password")) self.password(profile.get_string("password"))
except: except:
self.emitter.emit("connection_error") self.emitter.emit("connection_error")
self._start_idle_id=None
return False return False
# connect successful # connect successful
if profile.get_boolean("socket-connection"): if profile.get_boolean("socket-connection"):
@ -738,13 +740,17 @@ class Client(MPDClient):
self.disconnect() self.disconnect()
self.emitter.emit("connection_error") self.emitter.emit("connection_error")
print("No read permission, check your mpd config.") print("No read permission, check your mpd config.")
self._start_idle_id=None
return False return False
GLib.idle_add(callback) self._start_idle_id=GLib.idle_add(callback)
def reconnect(self): def reconnect(self):
if self._main_timeout_id is not None: if self._main_timeout_id is not None:
GLib.source_remove(self._main_timeout_id) GLib.source_remove(self._main_timeout_id)
self._main_timeout_id=None self._main_timeout_id=None
if self._start_idle_id is not None:
GLib.source_remove(self._start_idle_id)
self._start_idle_id=None
self.disconnect() self.disconnect()
self.start() self.start()
@ -1823,6 +1829,7 @@ class SelectionList(TreeView):
self._selection.connect("changed", self._on_selection_changed) self._selection.connect("changed", self._on_selection_changed)
def clear(self): def clear(self):
self._selection.set_mode(Gtk.SelectionMode.NONE)
self._store.clear() self._store.clear()
self._store.append([self.select_all_string, "", Pango.Weight.NORMAL]) self._store.append([self.select_all_string, "", Pango.Weight.NORMAL])
self._selected_path=None self._selected_path=None
@ -1840,6 +1847,7 @@ class SelectionList(TreeView):
else: else:
self._store.insert_with_valuesv(-1, range(3), [item[0], char, Pango.Weight.BOLD]) self._store.insert_with_valuesv(-1, range(3), [item[0], char, Pango.Weight.BOLD])
char="" char=""
self._selection.set_mode(Gtk.SelectionMode.BROWSE)
def get_item_at_path(self, path): def get_item_at_path(self, path):
if path == Gtk.TreePath(0): if path == Gtk.TreePath(0):
@ -1996,9 +2004,17 @@ class AlbumLoadingThread(threading.Thread):
self._genre=genre self._genre=genre
def _get_albums(self): def _get_albums(self):
@main_thread_function
def client_list(*args):
if self._stop_flag:
raise ValueError("Stop requested")
else:
return self._client.list(*args)
for albumartist in self._artists: for albumartist in self._artists:
albums=main_thread_function(self._client.list)( try:
"albumsort", "albumartist", albumartist, *self._genre_filter, "group", "date", "group", "album") albums=client_list("albumsort", "albumartist", albumartist, *self._genre_filter, "group", "date", "group", "album")
except ValueError:
break
for _, album in itertools.groupby(albums, key=lambda x: (x["album"], x["date"])): for _, album in itertools.groupby(albums, key=lambda x: (x["album"], x["date"])):
tmp=next(album) tmp=next(album)
# ignore multiple albumsort values # ignore multiple albumsort values
@ -2053,6 +2069,9 @@ class AlbumLoadingThread(threading.Thread):
self._exit() self._exit()
return return
idle_add(self._progress_bar.pulse) idle_add(self._progress_bar.pulse)
if self._stop_flag:
self._exit()
return
# sort model # sort model
if main_thread_function(self._settings.get_boolean)("sort-albums-by-year"): if main_thread_function(self._settings.get_boolean)("sort-albums-by-year"):
main_thread_function(self._store.set_sort_column_id)(5, Gtk.SortType.ASCENDING) main_thread_function(self._store.set_sort_column_id)(5, Gtk.SortType.ASCENDING)
@ -2060,7 +2079,17 @@ class AlbumLoadingThread(threading.Thread):
main_thread_function(self._store.set_sort_column_id)(6, Gtk.SortType.ASCENDING) main_thread_function(self._store.set_sort_column_id)(6, Gtk.SortType.ASCENDING)
idle_add(self._iconview.set_model, self._store) idle_add(self._iconview.set_model, self._store)
# select album # select album
path=main_thread_function(self._iconview.get_current_album_path)() @main_thread_function
def get_current_album_path():
if self._stop_flag:
raise ValueError("Stop requested")
else:
return self._iconview.get_current_album_path()
try:
path=get_current_album_path()
except ValueError:
self._exit()
return
if path is None: if path is None:
path=Gtk.TreePath(0) path=Gtk.TreePath(0)
idle_add(self._iconview.set_cursor, path, None, False) idle_add(self._iconview.set_cursor, path, None, False)