From 433ac14704da4dba5d422aa41b91bc1311602481 Mon Sep 17 00:00:00 2001 From: 9and3r <9and3r@gmail.com> Date: Sat, 2 Aug 2014 12:53:50 +0200 Subject: [PATCH] Code cleanup --- mopidy_touchscreen/__init__.py | 6 +- mopidy_touchscreen/dynamic_background.py | 4 +- mopidy_touchscreen/fonts/icomoon/demo.html | 1158 ++++++++++---------- mopidy_touchscreen/library_screen.py | 26 +- mopidy_touchscreen/list_view.py | 21 +- mopidy_touchscreen/main_screen.py | 30 +- mopidy_touchscreen/menu_screen.py | 31 +- mopidy_touchscreen/playlist_screen.py | 4 +- mopidy_touchscreen/screen_manager.py | 27 +- mopidy_touchscreen/screen_objects.py | 19 +- mopidy_touchscreen/touch_manager.py | 3 - mopidy_touchscreen/touch_screen.py | 13 +- mopidy_touchscreen/touch_screen_backend.py | 7 +- mopidy_touchscreen/tracklist.py | 5 +- 14 files changed, 688 insertions(+), 666 deletions(-) diff --git a/mopidy_touchscreen/__init__.py b/mopidy_touchscreen/__init__.py index 02ae29d..8a3a245 100644 --- a/mopidy_touchscreen/__init__.py +++ b/mopidy_touchscreen/__init__.py @@ -3,11 +3,12 @@ from __future__ import unicode_literals import logging import os - from mopidy import config, ext + from .touch_screen import TouchScreen from .touch_screen_backend import TouchScreenBackend + __version__ = '0.1.0' # TODO: If you need to log, use loggers named after the current Python module @@ -15,7 +16,6 @@ logger = logging.getLogger(__name__) class Extension(ext.Extension): - dist_name = 'Mopidy-Touchscreen' ext_name = 'touchscreen' version = __version__ @@ -35,4 +35,6 @@ class Extension(ext.Extension): def setup(self, registry): registry.add('frontend', TouchScreen) + + #Backend used for controling volume registry.add('backend', TouchScreenBackend) \ No newline at end of file diff --git a/mopidy_touchscreen/dynamic_background.py b/mopidy_touchscreen/dynamic_background.py index 1417564..e4590ff 100644 --- a/mopidy_touchscreen/dynamic_background.py +++ b/mopidy_touchscreen/dynamic_background.py @@ -5,7 +5,6 @@ logger = logging.getLogger(__name__) class DynamicBackground(): - def __init__(self): self.current = get_valid_color() self.target = get_valid_color() @@ -23,7 +22,8 @@ class DynamicBackground(): self.target = get_valid_color() surface.fill(self.current) -#Returns an array with 3 integers in range of 0-255 + +# Returns an array with 3 integers in range of 0-255 #The sum of the three integers will be lower than 255*2 (510) to avoid very bright colors #White text should be seen ok with this background color diff --git a/mopidy_touchscreen/fonts/icomoon/demo.html b/mopidy_touchscreen/fonts/icomoon/demo.html index 255435b..1e63de2 100644 --- a/mopidy_touchscreen/fonts/icomoon/demo.html +++ b/mopidy_touchscreen/fonts/icomoon/demo.html @@ -1,585 +1,589 @@ - - IcoMoon Demo - - - - + + IcoMoon Demo + + + + + -
-

Font Name: icomoon (Glyphs: 42)

-
-
-

Grid Size: 16

-
-
- icon-music -
-
- - -
-
- liga: - -
-
-
-
- icon-headphones -
-
- - -
-
- liga: - -
-
-
-
- icon-connection -
-
- - -
-
- liga: - -
-
-
-
- icon-book -
-
- - -
-
- liga: - -
-
-
-
- icon-books -
-
- - -
-
- liga: - -
-
-
-
- icon-file -
-
- - -
-
- liga: - -
-
-
-
- icon-folder -
-
- - -
-
- liga: - -
-
-
-
- icon-folder-open -
-
- - -
-
- liga: - -
-
-
-
- icon-cabinet -
-
- - -
-
- liga: - -
-
-
-
- icon-spinner -
-
- - -
-
- liga: - -
-
-
-
- icon-cog -
-
- - -
-
- liga: - -
-
-
-
- icon-switch -
-
- - -
-
- liga: - -
-
-
-
- icon-list -
-
- - -
-
- liga: - -
-
-
-
- icon-list2 -
-
- - -
-
- liga: - -
-
-
-
- icon-numbered-list -
-
- - -
-
- liga: - -
-
-
-
- icon-menu -
-
- - -
-
- liga: - -
-
-
-
- icon-spam -
-
- - -
-
- liga: - -
-
-
-
- icon-close -
-
- - -
-
- liga: - -
-
-
-
- icon-checkmark -
-
- - -
-
- liga: - -
-
-
-
- icon-minus -
-
- - -
-
- liga: - -
-
-
-
- icon-plus -
-
- - -
-
- liga: - -
-
-
-
- icon-play -
-
- - -
-
- liga: - -
-
-
-
- icon-pause -
-
- - -
-
- liga: - -
-
-
-
- icon-stop -
-
- - -
-
- liga: - -
-
-
-
- icon-backward -
-
- - -
-
- liga: - -
-
-
-
- icon-forward -
-
- - -
-
- liga: - -
-
-
-
- icon-first -
-
- - -
-
- liga: - -
-
-
-
- icon-last -
-
- - -
-
- liga: - -
-
-
-
- icon-previous -
-
- - -
-
- liga: - -
-
-
-
- icon-next -
-
- - -
-
- liga: - -
-
-
-
- icon-eject -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-high -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-medium -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-low -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-mute -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-mute2 -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-increase -
-
- - -
-
- liga: - -
-
-
-
- icon-volume-decrease -
-
- - -
-
- liga: - -
-
-
-
- icon-loop -
-
- - -
-
- liga: - -
-
-
-
- icon-loop2 -
-
- - -
-
- liga: - -
-
-
-
- icon-loop3 -
-
- - -
-
- liga: - -
-
-
-
- icon-shuffle -
-
- - -
-
- liga: - -
-
-
+
+

Font Name: icomoon + (Glyphs: 42) +

+
+
+

Grid Size: 16

- -
-

Font Test Drive

- - - -
  -
-
- -
-

Generated by IcoMoon

-
+
+
+ icon-music +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-headphones +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-connection +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-book +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-books +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-file +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-folder +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-folder-open +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-cabinet +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-spinner +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-cog +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-switch +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-list +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-list2 +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-numbered-list +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-menu +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-spam +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-close +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-checkmark +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-minus +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-plus +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-play +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-pause +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-stop +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-backward +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-forward +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-first +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-last +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-previous +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-next +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-eject +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-high +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-medium +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-low +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-mute +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-mute2 +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-increase +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-volume-decrease +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-loop +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-loop2 +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-loop3 +
+
+ + +
+
+ liga: + +
+
+
+
+ icon-shuffle +
+
+ + +
+
+ liga: + +
+
+
- + +
+

Font Test Drive

+ + + +
  +
+
+ +
+

Generated by IcoMoon

+
+ + \ No newline at end of file diff --git a/mopidy_touchscreen/library_screen.py b/mopidy_touchscreen/library_screen.py index c37d55d..f4d19d7 100644 --- a/mopidy_touchscreen/library_screen.py +++ b/mopidy_touchscreen/library_screen.py @@ -1,18 +1,21 @@ +import logging + +import mopidy.models + from .list_view import ListView from .touch_manager import TouchManager -import logging -import mopidy.models + logger = logging.getLogger(__name__) class LibraryScreen(): - def __init__(self, size, base_size, manager): self.size = size self.base_size = base_size 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.list_view = ListView((0, self.base_size), (self.size[0], self.size[1] - 2 * self.base_size), + self.base_size, manager.fonts['base']) self.directory_list = [] self.current_directory = None self.library = None @@ -50,7 +53,7 @@ class LibraryScreen(): if clicked == 0: self.go_up_directory() else: - self.play_uri(self.library[clicked-1].uri, False) + self.play_uri(self.library[clicked - 1].uri, False) else: self.play_uri(self.library[clicked].uri, False) else: @@ -58,10 +61,10 @@ class LibraryScreen(): 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) + 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) + self.go_inside_directory(self.library[clicked - 1].uri) else: if self.library[clicked].type == mopidy.models.Track: self.play_uri(self.library[clicked].uri, True) @@ -72,7 +75,8 @@ class LibraryScreen(): self.manager.core.tracklist.clear() if track: self.manager.core.tracklist.add(uri=uri) + self.manager.core.playback.play() else: - logger.error(uri) - self.manager.core.tracklist.add(tracks=self.manager.core.library.search(query={'any':'*'}, uris=[uri]).get()[0].tracks) - self.manager.core.playback.play() + #TODO: add folder to tracks to play + pass + diff --git a/mopidy_touchscreen/list_view.py b/mopidy_touchscreen/list_view.py index 1d76297..8dce9e8 100644 --- a/mopidy_touchscreen/list_view.py +++ b/mopidy_touchscreen/list_view.py @@ -1,40 +1,38 @@ -from .screen_objects import ScreenObjectsManager -import logging -import pygame from .touch_manager import TouchManager -from .touch_manager import TouchEvent from .screen_objects import * logger = logging.getLogger(__name__) class ListView(): - - def __init__(self, pos, size, base_size, fonts): + def __init__(self, pos, size, base_size, font): self.size = size self.pos = pos self.base_size = base_size self.screen_objects = ScreenObjectsManager() self.max_rows = self.size[1] / self.base_size self.current_item = 0 - self.fonts = fonts + self.font = font self.list_size = 0 self.list = [] self.scrollbar = False self.set_list([]) self.selected = [] + #Sets the list for the lisview. It should be an iterable of strings def set_list(self, item_list): self.list = item_list self.list_size = len(item_list) if self.max_rows < self.list_size: self.scrollbar = True - scroll_bar = ScrollBar((self.pos[0]+self.size[0]-self.base_size,self.pos[1]), (self.base_size, self.size[1]),self.list_size,self.max_rows) + scroll_bar = ScrollBar((self.pos[0] + self.size[0] - self.base_size, self.pos[1]), + (self.base_size, self.size[1]), self.list_size, self.max_rows) self.screen_objects.set_touch_object("scrollbar", scroll_bar) else: self.scrollbar = False self.load_new_item_position(0) + #Will load items currently displaying in item_pos def load_new_item_position(self, item_pos): self.current_item = item_pos if self.scrollbar: @@ -48,7 +46,8 @@ class ListView(): else: width = self.size[0] while i < self.list_size and z < self.max_rows: - item = TouchAndTextItem(self.fonts['base'], self.list[i], (self.pos[0], self.pos[1]+self.base_size*z), (width, -1)) + item = TouchAndTextItem(self.font, self.list[i], (self.pos[0], self.pos[1] + self.base_size * z), + (width, -1)) self.screen_objects.set_touch_object(str(i), item) i += 1 z += 1 @@ -73,6 +72,9 @@ class ListView(): elif touch_event.direction == TouchManager.down: self.move_to(1) + #Scroll to direction + #direction == 1 will scroll down + #direction == -1 will scroll up def move_to(self, direction): if self.scrollbar: if direction == 1: @@ -89,6 +91,7 @@ class ListView(): self.screen_objects.get_touch_object("scrollbar").set_item(self.current_item) self.set_selected(self.selected) + #Set selected items def set_selected(self, selected): for number in self.selected: try: diff --git a/mopidy_touchscreen/main_screen.py b/mopidy_touchscreen/main_screen.py index a81719c..7975b52 100644 --- a/mopidy_touchscreen/main_screen.py +++ b/mopidy_touchscreen/main_screen.py @@ -5,6 +5,7 @@ from threading import Thread import urllib import urllib2 import json + from .touch_manager import TouchManager from .screen_objects import * @@ -34,8 +35,11 @@ class MainScreen(): if self.track is not None: if self.image is not None: screen.blit(self.image, (self.base_size / 2, self.base_size + self.base_size / 2)) - self.touch_text_manager.get_touch_object("time_progress").set_value(self.core.playback.time_position.get() / 1000) - self.touch_text_manager.get_touch_object("time_progress").set_text(time.strftime('%M:%S', time.gmtime(self.core.playback.time_position.get() / 1000)) + "/" + time.strftime('%M:%S', time.gmtime(self.track.length / 1000))) + self.touch_text_manager.get_touch_object("time_progress").set_value( + self.core.playback.time_position.get() / 1000) + self.touch_text_manager.get_touch_object("time_progress").set_text(time.strftime('%M:%S', time.gmtime( + self.core.playback.time_position.get() / 1000)) + "/" + time.strftime('%M:%S', time.gmtime( + self.track.length / 1000))) self.touch_text_manager.render(screen) return screen @@ -49,12 +53,14 @@ class MainScreen(): for artist in track.artists: self.artists.append(artist) - #Track name - label = TextItem(self.fonts['base'], MainScreen.get_track_name(track), (x, self.base_size * 2), (width, self.size[1])) + # Track name + label = TextItem(self.fonts['base'], MainScreen.get_track_name(track), (x, self.base_size * 2), + (width, self.size[1])) self.touch_text_manager.set_object("track_name", label) #Album name - label = TextItem(self.fonts['base'], MainScreen.get_track_album_name(track), (x, self.base_size * 3), (width, self.size[1])) + label = TextItem(self.fonts['base'], MainScreen.get_track_album_name(track), (x, self.base_size * 3), + (width, self.size[1])) self.touch_text_manager.set_object("album_name", label) #Artist @@ -129,11 +135,13 @@ class MainScreen(): # There is no cover so it will use all the screen size for the text width = self.size[0] - self.base_size - current = TextItem(self.fonts['base'], MainScreen.get_track_name(self.track), (self.base_size / 2, self.base_size * 2), + current = TextItem(self.fonts['base'], MainScreen.get_track_name(self.track), + (self.base_size / 2, self.base_size * 2), (width, -1)) self.touch_text_manager.set_object("track_name", current) - current = TextItem(self.fonts['base'], MainScreen.get_track_album_name(self.track), (self.base_size / 2, self.base_size * 3), + current = TextItem(self.fonts['base'], MainScreen.get_track_album_name(self.track), + (self.base_size / 2, self.base_size * 3), (width, -1)) self.touch_text_manager.set_object("album_name", current) @@ -149,15 +157,15 @@ class MainScreen(): width = self.size[0] - self.base_size current = TextItem(self.fonts['base'], "Stopped", (self.base_size / 2, self.base_size * 2), - (width, -1)) + (width, -1)) self.touch_text_manager.set_object("track_name", current) current = TextItem(self.fonts['base'], "", (self.base_size / 2, self.base_size * 3), - (width, -1)) + (width, -1)) self.touch_text_manager.set_object("album_name", current) current = TextItem(self.fonts['base'], "", (self.base_size / 2, self.base_size * 4), - (width, -1)) + (width, -1)) self.touch_text_manager.set_object("artist_name", current) def load_image(self): @@ -204,7 +212,7 @@ class MainScreen(): @staticmethod def get_track_album_name(track): - if track.album is not None and track.album.name is not None and len(track.album.name)>0: + if track.album is not None and track.album.name is not None and len(track.album.name) > 0: return track.album.name else: return "Unknow Album" diff --git a/mopidy_touchscreen/menu_screen.py b/mopidy_touchscreen/menu_screen.py index 4ffcdc4..94bcf23 100644 --- a/mopidy_touchscreen/menu_screen.py +++ b/mopidy_touchscreen/menu_screen.py @@ -1,12 +1,12 @@ -from .list_view import ListView -from .screen_objects import * -import mopidy import os import socket +import mopidy + +from .screen_objects import * + class MenuScreen(): - def __init__(self, size, base_size, manager): self.size = size self.base_size = base_size @@ -14,22 +14,25 @@ class MenuScreen(): self.ip = None self.screen_objects = ScreenObjectsManager() - #Exit mopidy button + # Exit mopidy button button = TouchAndTextItem(self.manager.fonts['icon'], u"\ue611", (0, self.base_size), None) self.screen_objects.set_touch_object("exit_icon", button) - button = TouchAndTextItem(self.manager.fonts['base'], "Exit Mopidy", (button.get_right_pos(), self.base_size), None) + button = TouchAndTextItem(self.manager.fonts['base'], "Exit Mopidy", (button.get_right_pos(), self.base_size), + None) self.screen_objects.set_touch_object("exit", button) #Shutdown button button = TouchAndTextItem(self.manager.fonts['icon'], u"\ue60b", (0, self.base_size * 2), None) self.screen_objects.set_touch_object("shutdown_icon", button) - button = TouchAndTextItem(self.manager.fonts['base'], "Shutdown", (button.get_right_pos(), self.base_size * 2), None) + button = TouchAndTextItem(self.manager.fonts['base'], "Shutdown", (button.get_right_pos(), self.base_size * 2), + None) self.screen_objects.set_touch_object("shutdown", button) #Restart button button = TouchAndTextItem(self.manager.fonts['icon'], u"\ue609", (0, self.base_size * 3), None) self.screen_objects.set_touch_object("restart_icon", button) - button = TouchAndTextItem(self.manager.fonts['base'], "Restart", (button.get_right_pos(), self.base_size * 3), None) + button = TouchAndTextItem(self.manager.fonts['base'], "Restart", (button.get_right_pos(), self.base_size * 3), + None) self.screen_objects.set_touch_object("restart", button) #IP addres @@ -40,22 +43,26 @@ class MenuScreen(): #self.list_view.set_list(["Exit mopidy", "Shutdown", "Restart"]) - def update(self, screen): self.screen_objects.render(screen) - #self.list_view.render(screen) + # self.list_view.render(screen) def touch_event(self, touch_event): - #clicked = self.list_view.touch_event(touch_event) + # clicked = self.list_view.touch_event(touch_event) clicked = self.screen_objects.get_touch_objects_in_pos(touch_event.current_pos) for key in clicked: if key == "exit_icon" or key == "exit": mopidy.utils.process.exit_process() elif key == "shutdown_icon" or key == "shutdown": - os.system("shutdown now -h") + if os.system("gksu -- shutdown now -h") != 0: + os.system("shutdown now -h") + elif key == "restart_icon" or key == "restart": + if os.system("gksu -- shutdown -r now") != 0: + os.system("shutdown -r now") elif key == "ip": self.check_connection() + #Will check internet connection def check_connection(self): try: self.manager.set_connection(False, True) diff --git a/mopidy_touchscreen/playlist_screen.py b/mopidy_touchscreen/playlist_screen.py index c7b52d5..a8dd297 100644 --- a/mopidy_touchscreen/playlist_screen.py +++ b/mopidy_touchscreen/playlist_screen.py @@ -2,12 +2,12 @@ from .list_view import ListView class PlaylistScreen(): - def __init__(self, size, base_size, manager): self.size = size self.base_size = base_size 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.list_view = ListView((0, self.base_size), (self.size[0], self.size[1] - 2 * self.base_size), + self.base_size, manager.fonts['base']) self.playlists_strings = [] self.playlists = [] self.playlists_loaded() diff --git a/mopidy_touchscreen/screen_manager.py b/mopidy_touchscreen/screen_manager.py index 7273c59..47e71d5 100644 --- a/mopidy_touchscreen/screen_manager.py +++ b/mopidy_touchscreen/screen_manager.py @@ -1,3 +1,10 @@ +import logging +import traceback +import os +import pygame + +import mopidy + from .main_screen import MainScreen from .touch_manager import TouchManager from .screen_objects import * @@ -5,12 +12,8 @@ from .tracklist import Tracklist from .playlist_screen import PlaylistScreen from .dynamic_background import DynamicBackground from .library_screen import LibraryScreen -import logging -import mopidy -import traceback -import os from .menu_screen import MenuScreen -import pygame + logger = logging.getLogger(__name__) @@ -24,7 +27,7 @@ class ScreenManager(): self.background = DynamicBackground() self.current_screen = 0 self.base_size = self.size[1] / 8 - font = os.path.join(os.path.dirname(os.path.realpath(__file__)),"fonts","icomoon","fonts", "icomoon.ttf") + font = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fonts", "icomoon", "fonts", "icomoon.ttf") self.fonts['base'] = pygame.font.SysFont("verdana", self.base_size) self.fonts['icon'] = pygame.font.Font(font, self.base_size) try: @@ -43,7 +46,7 @@ class ScreenManager(): self.top_bar = pygame.Surface((self.size[0], self.base_size), pygame.SRCALPHA) self.top_bar.fill((0, 0, 0, 128)) - #Play/pause + # Play/pause button = TouchAndTextItem(self.fonts['icon'], u"\ue615 ", (0, 0), None) self.screen_objects_manager.set_touch_object("pause_play", button) x = button.get_right_pos() @@ -80,7 +83,7 @@ class ScreenManager(): #Menu buttons - button_size = (self.size[0]/5, self.base_size) + button_size = (self.size[0] / 5, self.base_size) #Main button button = TouchAndTextItem(self.fonts['icon'], u" \ue600", (0, self.base_size * 7), button_size) @@ -206,9 +209,9 @@ class ScreenManager(): self.screen_objects_manager.get_touch_object("single").set_active(self.core.tracklist.single.get()) def change_screen(self, new_screen): - self.screen_objects_manager.get_touch_object("menu_"+str(self.current_screen)).set_active(False) + self.screen_objects_manager.get_touch_object("menu_" + str(self.current_screen)).set_active(False) self.current_screen = new_screen - self.screen_objects_manager.get_touch_object("menu_"+str(new_screen)).set_active(True) + self.screen_objects_manager.get_touch_object("menu_" + str(new_screen)).set_active(True) def playlists_loaded(self): self.screens[3].playlists_loaded() @@ -216,10 +219,10 @@ class ScreenManager(): def set_connection(self, connection, loading): internet = self.screen_objects_manager.get_touch_object("internet") if loading: - internet.set_text(u"\ue627",None) + internet.set_text(u"\ue627", None) internet.set_active(False) else: - internet.set_text(u"\ue602",None) + internet.set_text(u"\ue602", None) internet.set_active(connection) diff --git a/mopidy_touchscreen/screen_objects.py b/mopidy_touchscreen/screen_objects.py index bd81c88..c8430e7 100644 --- a/mopidy_touchscreen/screen_objects.py +++ b/mopidy_touchscreen/screen_objects.py @@ -6,7 +6,6 @@ logger = logging.getLogger(__name__) class ScreenObjectsManager(): - def __init__(self): self.touch_objects = {} self.text_objects = {} @@ -49,7 +48,6 @@ class ScreenObjectsManager(): class BaseItem(): - def __init__(self, pos, size): self.pos = pos self.size = size @@ -64,7 +62,6 @@ class BaseItem(): class TextItem(BaseItem): - def __init__(self, font, text, pos, size): self.font = font self.text = text @@ -126,7 +123,6 @@ class TextItem(BaseItem): class TouchObject(BaseItem): - def __init__(self, pos, size): BaseItem.__init__(self, pos, size) self.active = False @@ -139,7 +135,6 @@ class TouchObject(BaseItem): class TouchAndTextItem(TouchObject, TextItem): - def __init__(self, font, text, pos, size): TextItem.__init__(self, font, text, pos, size) TouchObject.__init__(self, pos, self.size) @@ -162,14 +157,13 @@ class TouchAndTextItem(TouchObject, TextItem): else: self.box = self.font.render(self.text, True, self.color) if self.active: - #Area h*2 to render letters like g, j, y... + # Area h*2 to render letters like g, j, y... surface.blit(self.active_box, self.pos, area=self.rect) else: surface.blit(self.box, self.pos, area=self.rect) class Progressbar(TouchObject): - def __init__(self, font, text, pos, size, max_value, value_text): BaseItem.__init__(self, pos, size) self.value = 0 @@ -212,9 +206,8 @@ class Progressbar(TouchObject): class ScrollBar(TouchObject): - def __init__(self, pos, size, max_value, items_on_screen): - BaseItem.__init__(self, pos, (pos[0]+size[0], pos[1]+size[1])) + BaseItem.__init__(self, pos, (pos[0] + size[0], pos[1] + size[1])) self.pos = pos self.size = size self.max = max_value @@ -226,16 +219,16 @@ class ScrollBar(TouchObject): if self.max < 1: self.bar_size = self.size[1] else: - self.bar_size = math.ceil(float(self.items_on_screen)/float(self.max) * float(self.size[1])) + self.bar_size = math.ceil(float(self.items_on_screen) / float(self.max) * float(self.size[1])) self.bar = pygame.Surface((self.size[0], self.bar_size)) self.bar.fill((255, 255, 255)) def render(self, surface): surface.blit(self.back_bar, self.pos) - surface.blit(self.bar, (self.pos[0], self.pos[1]+self.bar_pos)) + surface.blit(self.bar, (self.pos[0], self.pos[1] + self.bar_pos)) def touch(self, pos): - if pos[1] < self.pos[1]+self.bar_pos: + if pos[1] < self.pos[1] + self.bar_pos: return -1 elif pos[1] > self.pos[1] + self.bar_pos + self.bar_size: return 1 @@ -244,4 +237,4 @@ class ScrollBar(TouchObject): def set_item(self, current_item): self.current_item = current_item - self.bar_pos = float(self.current_item)/float(self.max) * float(self.size[1]) \ No newline at end of file + self.bar_pos = float(self.current_item) / float(self.max) * float(self.size[1]) \ No newline at end of file diff --git a/mopidy_touchscreen/touch_manager.py b/mopidy_touchscreen/touch_manager.py index b65b11c..7d8bb72 100644 --- a/mopidy_touchscreen/touch_manager.py +++ b/mopidy_touchscreen/touch_manager.py @@ -6,7 +6,6 @@ logger = logging.getLogger(__name__) class TouchManager(): - click = 1 swipe = 2 long_click = 3 @@ -56,7 +55,6 @@ class TouchManager(): self.down_time = time.time() def mouse_up(self, event): - logger.error(event.button) 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: @@ -72,7 +70,6 @@ class TouchManager(): class TouchEvent(): - def __init__(self, event_type, down_pos, current_pos, vertical): self.type = event_type self.down_pos = down_pos diff --git a/mopidy_touchscreen/touch_screen.py b/mopidy_touchscreen/touch_screen.py index b945266..ac9c6a7 100644 --- a/mopidy_touchscreen/touch_screen.py +++ b/mopidy_touchscreen/touch_screen.py @@ -3,20 +3,19 @@ import traceback import logging from threading import Thread import pygame -from .screen_manager import ScreenManager from mopidy import core +from .screen_manager import ScreenManager + logger = logging.getLogger(__name__) class TouchScreen(pykka.ThreadingActor, core.CoreListener): - def __init__(self, config, core): super(TouchScreen, self).__init__() self.backend = pykka.ActorRegistry.get_by_class_name("TouchScreenBackend")[0] - logger.error(self.backend) self.core = core self.running = False self.screen_size = (config['touchscreen']['screen_width'], config['touchscreen']['screen_height']) @@ -24,7 +23,7 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): self.fullscreen = config['touchscreen']['fullscreen'] pygame.init() pygame.mouse.set_visible(config['touchscreen']['cursor']) - self.screen_manager = ScreenManager(self.screen_size,self.core, self.backend, self.cache_dir) + self.screen_manager = ScreenManager(self.screen_size, self.core, self.backend, self.cache_dir) def start_thread(self): clock = pygame.time.Clock() @@ -65,7 +64,7 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): def volume_changed(self, volume): self.screen_manager.volume_changed(volume) - def playback_state_changed(self,old_state, new_state): + def playback_state_changed(self, old_state, new_state): self.screen_manager.playback_state_changed(old_state, new_state) def tracklist_changed(self): @@ -78,9 +77,9 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): self.screen_manager.track_playback_ended(tl_track, time_position) def options_changed(self): - try: + try: self.screen_manager.options_changed() - except: + except: traceback.print_exc() def playlists_loaded(self): diff --git a/mopidy_touchscreen/touch_screen_backend.py b/mopidy_touchscreen/touch_screen_backend.py index 67e61af..67f15bd 100644 --- a/mopidy_touchscreen/touch_screen_backend.py +++ b/mopidy_touchscreen/touch_screen_backend.py @@ -1,15 +1,16 @@ import pykka -from mopidy import backend import logging +from mopidy import backend + + logger = logging.getLogger(__name__) -class TouchScreenBackend(pykka.ThreadingActor, backend.Backend): +class TouchScreenBackend(pykka.ThreadingActor, backend.Backend): def __init__(self, config, audio): super(TouchScreenBackend, self).__init__() self.audio = audio - logger.error("backend funciona") def on_receive(self, message): action = message['action'] diff --git a/mopidy_touchscreen/tracklist.py b/mopidy_touchscreen/tracklist.py index 409ed1e..4eaa2ad 100644 --- a/mopidy_touchscreen/tracklist.py +++ b/mopidy_touchscreen/tracklist.py @@ -1,13 +1,14 @@ from .list_view import ListView from .main_screen import MainScreen -class Tracklist(): +class Tracklist(): def __init__(self, size, base_size, manager): self.size = size self.base_size = base_size 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.list_view = ListView((0, self.base_size), (self.size[0], self.size[1] - 2 * self.base_size), + self.base_size, manager.fonts['base']) self.tracks = [] self.tracks_strings = [] self.update_list()