diff --git a/mopidy_touchscreen/.idea/workspace.xml b/mopidy_touchscreen/.idea/workspace.xml index a48c587..57cbb9e 100644 --- a/mopidy_touchscreen/.idea/workspace.xml +++ b/mopidy_touchscreen/.idea/workspace.xml @@ -23,13 +23,13 @@ - - + + - - + + - + @@ -45,13 +45,14 @@ @@ -87,6 +88,7 @@ + @@ -107,7 +109,6 @@ - @@ -262,7 +263,6 @@ - @@ -272,10 +272,11 @@ + - + @@ -298,11 +299,20 @@ + + + + + + + + + + - @@ -310,7 +320,6 @@ - @@ -318,7 +327,6 @@ - @@ -326,9 +334,6 @@ - - - @@ -336,9 +341,6 @@ - - - @@ -346,7 +348,6 @@ - @@ -354,7 +355,6 @@ - @@ -362,7 +362,6 @@ - @@ -370,7 +369,6 @@ - @@ -378,7 +376,6 @@ - @@ -386,7 +383,6 @@ - @@ -394,9 +390,6 @@ - - - @@ -404,7 +397,6 @@ - @@ -412,7 +404,6 @@ - @@ -420,7 +411,6 @@ - @@ -438,18 +428,10 @@ - - - - - - - - @@ -460,19 +442,10 @@ - - - - - - - - - @@ -480,7 +453,6 @@ - @@ -488,18 +460,36 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/mopidy_touchscreen/library_screen.py b/mopidy_touchscreen/library_screen.py index 6df5c2c..ce68662 100644 --- a/mopidy_touchscreen/library_screen.py +++ b/mopidy_touchscreen/library_screen.py @@ -1,8 +1,10 @@ from .list_view import ListView import logging +import mopidy.models logger = logging.getLogger(__name__) + class LibraryScreen(): def __init__(self, size, base_size, manager): @@ -11,14 +13,19 @@ class LibraryScreen(): self.manager = manager self.list_view = ListView((0,self.base_size),(self.size[0],self.size[1]-2*self.base_size), self.base_size, manager.fonts) self.directory_list = [] + self.current_directory = None self.library = None self.library_strings = None self.lookup_uri(None) + def go_inside_directory(self, uri): + self.directory_list.append(self.current_directory) + self.current_directory = uri + self.lookup_uri(uri) + def lookup_uri(self, uri): self.library_strings = [] if uri is not None: - self.directory_list.append(uri) self.library_strings.append("..") self.library = self.manager.core.library.browse(uri).get() for lib in self.library: @@ -26,10 +33,10 @@ class LibraryScreen(): self.list_view.set_list(self.library_strings) def go_up_directory(self): - if len(self.directory_list) > 0: - self.lookup_uri(self.directory_list.pop()) - else: - self.lookup_uri(None) + if len(self.directory_list): + directory = self.directory_list.pop() + self.current_directory = directory + self.lookup_uri(directory) def update(self, screen): self.list_view.render(screen) @@ -37,10 +44,21 @@ class LibraryScreen(): def touch_event(self, touch_event): clicked = self.list_view.touch_event(touch_event) if clicked is not None: - if len(self.directory_list) > 0: + if self.current_directory is not None: if clicked == 0: self.go_up_directory() else: - self.lookup_uri(self.library[clicked-1].uri) + if self.library[clicked-1].type == mopidy.models.Ref.TRACK: + self.play_uri(self.library[clicked-1].uri) + else: + self.go_inside_directory(self.library[clicked-1].uri) else: - self.lookup_uri(self.library[clicked].uri) + if self.library[clicked].type == mopidy.models.Track: + self.play_uri(self.library[clicked].uri) + else: + self.go_inside_directory(self.library[clicked].uri) + + def play_uri(self, uri): + self.manager.core.tracklist.clear() + self.manager.core.tracklist.add(uri=uri) + self.manager.core.playback.play() diff --git a/mopidy_touchscreen/main_screen.py b/mopidy_touchscreen/main_screen.py index 8df8436..89d7594 100644 --- a/mopidy_touchscreen/main_screen.py +++ b/mopidy_touchscreen/main_screen.py @@ -89,7 +89,7 @@ class MainScreen(): def get_image_file_name(self): name = self.track.album.name + '-' + self.get_artist_string() - md5name = hashlib.md5(name).hexdigest() + md5name = hashlib.md5(name.encode('utf-8')).hexdigest() return md5name def get_cover_folder(self): diff --git a/mopidy_touchscreen/touch_manager.py b/mopidy_touchscreen/touch_manager.py index 1778e5b..1e780eb 100644 --- a/mopidy_touchscreen/touch_manager.py +++ b/mopidy_touchscreen/touch_manager.py @@ -1,5 +1,6 @@ import pygame -import logging +import logging +import time logger = logging.getLogger(__name__) @@ -8,6 +9,9 @@ class TouchManager(): click = 1 swipe = 2 + long_click = 3 + + long_click_min_time = 0.3 up = 0 down = 1 @@ -21,6 +25,7 @@ class TouchManager(): self.max_move_margin = self.screen_size[1] / 6 self.min_swipe_move = self.screen_size[1] / 3 self.down_button = -1 + self.down_time = -1 def event(self, event): if event.type == pygame.MOUSEBUTTONUP: @@ -33,7 +38,11 @@ class TouchManager(): touch_event.direction = TouchManager.down return touch_event elif event.button == 1 and self.down_button == 1: - return self.mouse_up(event) + touch_event = self.mouse_up(event) + return touch_event + elif event.button == 2 and self.down_button == 2: + touch_event = TouchEvent(TouchManager.long_click, self.down_pos, self.up_pos, None) + return TouchEvent else: return None elif event.type == pygame.MOUSEBUTTONDOWN: @@ -43,16 +52,22 @@ class TouchManager(): def mouse_down(self, event): self.down_pos = event.pos self.down_button = event.button + self.down_time = time.time() def mouse_up(self, event): self.up_pos = event.pos if abs(self.down_pos[0] - self.up_pos[0]) < self.max_move_margin: if abs(self.down_pos[1] - self.up_pos[1]) < self.max_move_margin: - return TouchEvent(TouchManager.click, self.down_pos, self.up_pos, None) + logger.error(time.time()) + logger.error(self.down_time) + if time.time() - TouchManager.long_click_min_time > self.down_time: + logger.error("longpress") + return TouchEvent(TouchManager.long_click, self.down_pos, self.up_pos, None) + else: + return TouchEvent(TouchManager.click, self.down_pos, self.up_pos, None) elif abs(self.down_pos[1] - self.up_pos[1]) > self.min_swipe_move: return TouchEvent(TouchManager.swipe, self.down_pos, self.up_pos, True) elif self.down_pos[1] - self.up_pos[1] < self.max_move_margin: - logger.error( abs(self.down_pos[1] - self.up_pos[1])) if abs(self.down_pos[0] - self.up_pos[0]) > self.min_swipe_move: return TouchEvent(TouchManager.swipe, self.down_pos, self.up_pos, False)