diff --git a/docs/conf.py b/docs/conf.py index e3fcb6c..0aa3075 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,18 +12,18 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys -import os +# import sys +# import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -57,13 +57,13 @@ release = '0.2.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -71,27 +71,27 @@ exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- @@ -103,26 +103,26 @@ html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -132,48 +132,48 @@ html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'Mopidy-Touchscreendoc' @@ -181,16 +181,16 @@ htmlhelp_basename = 'Mopidy-Touchscreendoc' # -- Options for LaTeX output --------------------------------------------- -latex_elements = { +latex_elements = {} # The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', +# 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', +# 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. -#'preamble': '', -} +# 'preamble': '', +# } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, @@ -202,23 +202,23 @@ latex_documents = [ # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -231,7 +231,7 @@ man_pages = [ ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -240,19 +240,19 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'Mopidy-Touchscreen', u'Mopidy-Touchscreen Documentation', - u'9and3r', 'Mopidy-Touchscreen', 'One line description of project.', - 'Miscellaneous'), + ('index', 'Mopidy-Touchscreen', u'Mopidy-Touchscreen Documentation', + u'9and3r', 'Mopidy-Touchscreen', 'One line description of project.', + 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/mopidy_touchscreen/dynamic_background.py b/mopidy_touchscreen/dynamic_background.py index 9b9b15d..fc43290 100644 --- a/mopidy_touchscreen/dynamic_background.py +++ b/mopidy_touchscreen/dynamic_background.py @@ -1,5 +1,5 @@ -import random import logging +import random logger = logging.getLogger(__name__) @@ -24,7 +24,8 @@ class DynamicBackground(): # 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 +# 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/library_screen.py b/mopidy_touchscreen/library_screen.py index 34e7ccc..feee3db 100644 --- a/mopidy_touchscreen/library_screen.py +++ b/mopidy_touchscreen/library_screen.py @@ -15,8 +15,8 @@ class LibraryScreen(): 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['base']) + 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 @@ -63,7 +63,7 @@ class LibraryScreen(): self.go_up_directory() else: if self.library[ - clicked - 1].type == mopidy.models.Ref.TRACK: + clicked - 1].type == mopidy.models.Ref.TRACK: self.play_uri(self.library[clicked - 1].uri, True) else: self.go_inside_directory( diff --git a/mopidy_touchscreen/list_view.py b/mopidy_touchscreen/list_view.py index ca88ed6..770d907 100644 --- a/mopidy_touchscreen/list_view.py +++ b/mopidy_touchscreen/list_view.py @@ -1,5 +1,6 @@ +import logging +from .screen_objects import ScrollBar, ScreenObjectsManager, TouchAndTextItem from .touch_manager import TouchManager -from .screen_objects import * logger = logging.getLogger(__name__) @@ -58,7 +59,8 @@ class ListView(): self.screen_objects.render(surface) def touch_event(self, touch_event): - if touch_event.type == TouchManager.click or touch_event.type == TouchManager.long_click: + if touch_event.type == TouchManager.click \ + or touch_event.type == TouchManager.long_click: objects = self.screen_objects.get_touch_objects_in_pos( touch_event.current_pos) if objects is not None: @@ -76,9 +78,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 + # Scroll to direction + # direction == 1 will scroll down + # direction == -1 will scroll up def move_to(self, direction): if self.scrollbar: if direction == 1: @@ -97,7 +99,7 @@ class ListView(): self.current_item) self.set_selected(self.selected) - #Set selected items + # Set selected items def set_selected(self, selected): for number in self.selected: try: @@ -111,4 +113,4 @@ class ListView(): True) except KeyError: pass - self.selected = selected \ No newline at end of file + self.selected = selected diff --git a/mopidy_touchscreen/main_screen.py b/mopidy_touchscreen/main_screen.py index 16c6149..e62fe4a 100644 --- a/mopidy_touchscreen/main_screen.py +++ b/mopidy_touchscreen/main_screen.py @@ -5,9 +5,10 @@ from threading import Thread import urllib import urllib2 import json - +import pygame +import logging from .touch_manager import TouchManager -from .screen_objects import * +from .screen_objects import ScreenObjectsManager, Progressbar, TouchAndTextItem, TextItem logger = logging.getLogger(__name__) @@ -35,14 +36,14 @@ 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.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.core.playback.time_position.get() / 1000)) + "/" + + time.strftime('%M:%S', time.gmtime( + self.track.length / 1000))) self.touch_text_manager.render(screen) return screen @@ -136,12 +137,15 @@ class MainScreen(): safe_album = urllib.quote_plus( MainScreen.get_track_album_name(self.track)) url = "http://ws.audioscrobbler.com/2.0/?" - params = "method=album.getinfo&api_key=59a04c6a73fb99d6e8996e01db306829&artist=" + safe_artist + "&album=" + safe_album + "&format=json" + params = "method=album.getinfo&" + \ + "api_key=59a04c6a73fb99d6e8996e01db306829&artist=" \ + + safe_artist + "&album=" + safe_album + "&format=json" response = urllib2.urlopen(url + params) data = json.load(response) image = data['album']['image'][-1]['#text'] urllib.urlretrieve(image, - self.get_cover_folder() + self.get_image_file_name()) + self.get_cover_folder() + + self.get_image_file_name()) self.load_image() except: self.download_image(artist_index + 1) @@ -244,4 +248,3 @@ class MainScreen(): return track.album.name else: return "Unknow Album" - diff --git a/mopidy_touchscreen/menu_screen.py b/mopidy_touchscreen/menu_screen.py index d9a9477..0b75fd0 100644 --- a/mopidy_touchscreen/menu_screen.py +++ b/mopidy_touchscreen/menu_screen.py @@ -3,7 +3,7 @@ import socket import mopidy -from .screen_objects import * +from .screen_objects import ScreenObjectsManager, TouchAndTextItem class MenuScreen(): @@ -46,16 +46,10 @@ class MenuScreen(): (0, self.base_size * 4), None) self.screen_objects.set_touch_object("ip", button) - #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.set_list(["Exit mopidy", "Shutdown", "Restart"]) - - def update(self, screen): self.screen_objects.render(screen) - # self.list_view.render(screen) def touch_event(self, 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: diff --git a/mopidy_touchscreen/playlist_screen.py b/mopidy_touchscreen/playlist_screen.py index 0facce0..572c169 100644 --- a/mopidy_touchscreen/playlist_screen.py +++ b/mopidy_touchscreen/playlist_screen.py @@ -7,8 +7,8 @@ class PlaylistScreen(): 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['base']) + 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 3bd816b..1bb92fe 100644 --- a/mopidy_touchscreen/screen_manager.py +++ b/mopidy_touchscreen/screen_manager.py @@ -1,11 +1,12 @@ import traceback - +import logging import mopidy from pkg_resources import Requirement, resource_filename - +import pygame +import mopidy.core from .main_screen import MainScreen from .touch_manager import TouchManager -from .screen_objects import * +from .screen_objects import ScreenObjectsManager, TouchAndTextItem, Progressbar from .tracklist import Tracklist from .playlist_screen import PlaylistScreen from .dynamic_background import DynamicBackground @@ -109,13 +110,12 @@ class ScreenManager(): self.screen_objects_manager.set_touch_object("menu_3", button) x = button.get_right_pos() - #Menu button + # Menu button button = TouchAndTextItem(self.fonts['icon'], u" \ue60a", (x, self.base_size * 7), None) self.screen_objects_manager.set_touch_object("menu_4", button) - x = button.get_right_pos() - #Down bar + # Down bar self.down_bar = pygame.Surface( (self.size[0], self.size[1] - self.base_size * 7), pygame.SRCALPHA) self.down_bar.fill((0, 0, 0, 128)) @@ -153,19 +153,19 @@ class ScreenManager(): if objects is not None: for key in objects: if key == "volume": - value = self.screen_objects_manager.get_touch_object( - key).get_pos_value( - touch_event.current_pos) + manager = self.screen_objects_manager + volume = manager.get_touch_object(key) + pos = touch_event.current_pos + value = volume.get_pos_value(pos) self.backend.tell( {'action': 'volume', 'value': value}) self.volume_changed(value) elif key == "pause_play": - if self.core.playback.state.get() == mopidy.core.PlaybackState.PLAYING: + if self.core.playback.state.get() == \ + mopidy.core.PlaybackState.PLAYING: self.core.playback.pause() - logger.error("pausatzen") else: self.core.playback.play() - logger.error("erreproduzitzen") elif key == "mute": mute = not self.core.playback.mute.get() self.core.playback.set_mute(mute) @@ -198,7 +198,6 @@ class ScreenManager(): self.screen_objects_manager.get_touch_object("mute").set_text( u"\ue621", False) else: - logger.error("sartu naiz") self.screen_objects_manager.get_touch_object("mute").set_text( u"\ue622", False) self.screen_objects_manager.get_touch_object("volume").set_value(volume) diff --git a/mopidy_touchscreen/screen_objects.py b/mopidy_touchscreen/screen_objects.py index 71b65dc..46da2f7 100644 --- a/mopidy_touchscreen/screen_objects.py +++ b/mopidy_touchscreen/screen_objects.py @@ -1,6 +1,6 @@ -import pygame import logging import math +import pygame logger = logging.getLogger(__name__) @@ -70,7 +70,8 @@ class TextItem(BaseItem): self.box = self.font.render(text, True, self.color) if size is not None: if size[1] == -1: - BaseItem.__init__(self, pos, (size[0], self.font.size(text)[1])) + height = self.font.size(text)[1] + BaseItem.__init__(self, pos, (size[0], height)) else: BaseItem.__init__(self, pos, size) else: @@ -180,8 +181,8 @@ class Progressbar(TouchObject): self.text.set_text(str(self.value), True) else: self.text = TextItem(font, text, pos, None) - self.text.pos = (self.pos[0] + self.size[0] / 2 - self.text.size[0] / 2, - self.text.pos[1]) + self.text.pos = (self.pos[0] + self.size[0] / 2 - self.text.size[0] / + 2, self.text.pos[1]) def update(self): pass @@ -243,4 +244,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.size[1]) diff --git a/setup.py b/setup.py index 1477351..745acf5 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,8 @@ setup( license='Apache License, Version 2.0', author='9and3r', author_email='9and3r@gmail.com', - description='Mopidy extension to show info on a display and control from it', + description='Mopidy extension to show info ' + 'on a display and control from it', long_description=open('README.rst').read(), packages=find_packages(exclude=['tests', 'tests.*']), zip_safe=False,