From 28169f1dc737e5e22c1cbc6ed3e15b61a4b69db0 Mon Sep 17 00:00:00 2001 From: Ander <9and3r@gmail.com> Date: Sat, 10 Jan 2015 00:37:45 +0100 Subject: [PATCH] Playing a song in from library will add all songs to tracklist and play the selected one --- mopidy_touchscreen/library_screen.py | 60 +++++++++++----------------- mopidy_touchscreen/touch_screen.py | 2 +- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/mopidy_touchscreen/library_screen.py b/mopidy_touchscreen/library_screen.py index ecde1ae..7652946 100644 --- a/mopidy_touchscreen/library_screen.py +++ b/mopidy_touchscreen/library_screen.py @@ -19,7 +19,7 @@ class LibraryScreen(BaseScreen): self.current_directory = None self.library = None self.library_strings = None - self.lookup_uri(None) + self.browse_uri(None) def get_dirty_area(self): return self.list_view.get_dirty_area() @@ -27,12 +27,12 @@ class LibraryScreen(BaseScreen): def go_inside_directory(self, uri): self.directory_list.append(self.current_directory) self.current_directory = uri - self.lookup_uri(uri) + self.browse_uri(uri) - def lookup_uri(self, uri): + def browse_uri(self, uri): self.library_strings = [] if uri is not None: - self.library_strings.append("..") + self.library_strings.append("../") self.library = self.manager.core.library.browse(uri).get() for lib in self.library: self.library_strings.append(lib.name) @@ -42,7 +42,7 @@ class LibraryScreen(BaseScreen): if len(self.directory_list): directory = self.directory_list.pop() self.current_directory = directory - self.lookup_uri(directory) + self.browse_uri(directory) def update(self, screen, update_all): self.list_view.render(screen) @@ -50,40 +50,28 @@ class LibraryScreen(BaseScreen): def touch_event(self, touch_event): clicked = self.list_view.touch_event(touch_event) if clicked is not None: - if touch_event.type == InputManager.long_click: - if self.current_directory is not None: - if clicked == 0: - self.go_up_directory() - else: - self.play_uri(self.library[clicked - 1].uri, - False) - else: - self.play_uri(self.library[clicked].uri, False) - else: - if self.current_directory is not None: - if clicked == 0: - self.go_up_directory() - else: - if self.library[ - clicked - 1].type == mopidy.models.Ref.TRACK: - self.play_uri( - self.library[clicked - 1].uri, True) - else: - self.go_inside_directory( - self.library[clicked - 1].uri) + if self.current_directory is not None: + if clicked == 0: + self.go_up_directory() else: if self.library[ - clicked].type == mopidy.models.Track: - self.play_uri(self.library[clicked].uri, True) + clicked - 1].type == mopidy.models.Ref.TRACK: + self.play_uri(self.current_directory, clicked-1) else: self.go_inside_directory( - self.library[clicked].uri) + self.library[clicked - 1].uri) + else: + self.go_inside_directory( + self.library[clicked].uri) - def play_uri(self, uri, track): + def play_uri(self, uri, track_pos): self.manager.core.tracklist.clear() - if track: - self.manager.core.tracklist.add(uri=uri) - self.manager.core.playback.play() - else: - # TODO: add folder to tracks to play - pass + tracks = [] + for item in self.library: + if item.type == mopidy.models.Ref.TRACK: + tracks.append(self.manager.core.library.lookup(item.uri).get()[0]) + else: + track_pos = track_pos - 1 + self.manager.core.tracklist.add(tracks) + self.manager.core.playback.play(tl_track=self.manager.core.tracklist.tl_tracks.get()[track_pos]) + diff --git a/mopidy_touchscreen/touch_screen.py b/mopidy_touchscreen/touch_screen.py index 5b7a92b..27eda2f 100644 --- a/mopidy_touchscreen/touch_screen.py +++ b/mopidy_touchscreen/touch_screen.py @@ -62,7 +62,7 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): def start_thread(self): clock = pygame.time.Clock() while self.running: - clock.tick(15) + clock.tick(8) self.screen.blit(self.screen_manager.update(), (0, 0)) pygame.display.flip() for event in pygame.event.get():