Code cleanup

This commit is contained in:
9and3r
2014-08-04 11:33:40 +02:00
parent efd5201b65
commit cd8d9d1c17
10 changed files with 101 additions and 100 deletions

View File

@@ -12,18 +12,18 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
import sys # import sys
import os # import os
# If extensions (or modules to document with autodoc) are in another directory, # 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 # 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. # 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 ------------------------------------------------ # -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here. # 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 # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
#language = None # language = None
# There are two options for replacing |today|: either, you set today to some # There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used: # non-false value, then it is used:
#today = '' # today = ''
# Else, today_fmt is used as the format for a strftime call. # 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 # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # 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 # The reST default role (used for this markup: `text`) to use for all
# documents. # documents.
#default_role = None # default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text. # 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 # If true, the current module name will be prepended to all description
# unit titles (such as .. function::). # unit titles (such as .. function::).
#add_module_names = True # add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the # If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default. # output. They are ignored by default.
#show_authors = False # show_authors = False
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting. # 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. # If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False # keep_warnings = False
# -- Options for HTML output ---------------------------------------------- # -- 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 # 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 # further. For a list of options available for each theme, see the
# documentation. # documentation.
#html_theme_options = {} # html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory. # 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 # The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation". # "<project> v<release> documentation".
#html_title = None # html_title = None
# A shorter title for the navigation bar. Default is the same as html_title. # 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 # The name of an image file (relative to this directory) to place at the top
# of the sidebar. # 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 # 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 # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large. # pixels large.
#html_favicon = None # html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here, # 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, # 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 # Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied # .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation. # 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, # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format. # 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 # If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities. # typographically correct entities.
#html_use_smartypants = True # html_use_smartypants = True
# Custom sidebar templates, maps document names to template names. # 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 # Additional templates that should be rendered to pages, maps page names to
# template names. # template names.
#html_additional_pages = {} # html_additional_pages = {}
# If false, no module index is generated. # If false, no module index is generated.
#html_domain_indices = True # html_domain_indices = True
# If false, no index is generated. # 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. # 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. # 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. # 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. # 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 # If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the # contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served. # 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"). # 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. # Output file base name for HTML help builder.
htmlhelp_basename = 'Mopidy-Touchscreendoc' htmlhelp_basename = 'Mopidy-Touchscreendoc'
@@ -181,16 +181,16 @@ htmlhelp_basename = 'Mopidy-Touchscreendoc'
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
latex_elements = { latex_elements = {}
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt', # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
#'preamble': '', # 'preamble': '',
} # }
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, # (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 name of an image file (relative to this directory) to place at the top of
# the title page. # the title page.
#latex_logo = None # latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts, # For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters. # not chapters.
#latex_use_parts = False # latex_use_parts = False
# If true, show page references after internal links. # If true, show page references after internal links.
#latex_show_pagerefs = False # latex_show_pagerefs = False
# If true, show URL addresses after external links. # 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. # Documents to append as an appendix to all manuals.
#latex_appendices = [] # latex_appendices = []
# If false, no module index is generated. # If false, no module index is generated.
#latex_domain_indices = True # latex_domain_indices = True
# -- Options for manual page output --------------------------------------- # -- Options for manual page output ---------------------------------------
@@ -231,7 +231,7 @@ man_pages = [
] ]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
#man_show_urls = False # man_show_urls = False
# -- Options for Texinfo output ------------------------------------------- # -- Options for Texinfo output -------------------------------------------
@@ -246,13 +246,13 @@ texinfo_documents = [
] ]
# Documents to append as an appendix to all manuals. # Documents to append as an appendix to all manuals.
#texinfo_appendices = [] # texinfo_appendices = []
# If false, no module index is generated. # If false, no module index is generated.
#texinfo_domain_indices = True # texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'. # 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. # If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False # texinfo_no_detailmenu = False

View File

@@ -1,5 +1,5 @@
import random
import logging import logging
import random
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -24,7 +24,8 @@ class DynamicBackground():
# 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 # 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 # White text should be seen ok with this background color

View File

@@ -1,5 +1,6 @@
import logging
from .screen_objects import ScrollBar, ScreenObjectsManager, TouchAndTextItem
from .touch_manager import TouchManager from .touch_manager import TouchManager
from .screen_objects import *
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -58,7 +59,8 @@ class ListView():
self.screen_objects.render(surface) self.screen_objects.render(surface)
def touch_event(self, touch_event): 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( objects = self.screen_objects.get_touch_objects_in_pos(
touch_event.current_pos) touch_event.current_pos)
if objects is not None: if objects is not None:
@@ -76,9 +78,9 @@ class ListView():
elif touch_event.direction == TouchManager.down: elif touch_event.direction == TouchManager.down:
self.move_to(1) self.move_to(1)
#Scroll to direction # Scroll to direction
#direction == 1 will scroll down # direction == 1 will scroll down
#direction == -1 will scroll up # direction == -1 will scroll up
def move_to(self, direction): def move_to(self, direction):
if self.scrollbar: if self.scrollbar:
if direction == 1: if direction == 1:
@@ -97,7 +99,7 @@ class ListView():
self.current_item) self.current_item)
self.set_selected(self.selected) self.set_selected(self.selected)
#Set selected items # Set selected items
def set_selected(self, selected): def set_selected(self, selected):
for number in self.selected: for number in self.selected:
try: try:

View File

@@ -5,9 +5,10 @@ from threading import Thread
import urllib import urllib
import urllib2 import urllib2
import json import json
import pygame
import logging
from .touch_manager import TouchManager from .touch_manager import TouchManager
from .screen_objects import * from .screen_objects import ScreenObjectsManager, Progressbar, TouchAndTextItem, TextItem
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -40,8 +41,8 @@ class MainScreen():
self.core.playback.time_position.get() / 1000) self.core.playback.time_position.get() / 1000)
self.touch_text_manager.get_touch_object("time_progress").set_text( self.touch_text_manager.get_touch_object("time_progress").set_text(
time.strftime('%M:%S', time.gmtime( time.strftime('%M:%S', time.gmtime(
self.core.playback.time_position.get() / 1000)) + "/" + time.strftime( self.core.playback.time_position.get() / 1000)) + "/" +
'%M:%S', time.gmtime( time.strftime('%M:%S', time.gmtime(
self.track.length / 1000))) self.track.length / 1000)))
self.touch_text_manager.render(screen) self.touch_text_manager.render(screen)
return screen return screen
@@ -136,12 +137,15 @@ class MainScreen():
safe_album = urllib.quote_plus( safe_album = urllib.quote_plus(
MainScreen.get_track_album_name(self.track)) MainScreen.get_track_album_name(self.track))
url = "http://ws.audioscrobbler.com/2.0/?" 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) response = urllib2.urlopen(url + params)
data = json.load(response) data = json.load(response)
image = data['album']['image'][-1]['#text'] image = data['album']['image'][-1]['#text']
urllib.urlretrieve(image, urllib.urlretrieve(image,
self.get_cover_folder() + self.get_image_file_name()) self.get_cover_folder() +
self.get_image_file_name())
self.load_image() self.load_image()
except: except:
self.download_image(artist_index + 1) self.download_image(artist_index + 1)
@@ -244,4 +248,3 @@ class MainScreen():
return track.album.name return track.album.name
else: else:
return "Unknow Album" return "Unknow Album"

View File

@@ -3,7 +3,7 @@ import socket
import mopidy import mopidy
from .screen_objects import * from .screen_objects import ScreenObjectsManager, TouchAndTextItem
class MenuScreen(): class MenuScreen():
@@ -46,16 +46,10 @@ class MenuScreen():
(0, self.base_size * 4), None) (0, self.base_size * 4), None)
self.screen_objects.set_touch_object("ip", button) 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): def update(self, screen):
self.screen_objects.render(screen) self.screen_objects.render(screen)
# self.list_view.render(screen)
def touch_event(self, touch_event): def touch_event(self, touch_event):
# clicked = self.list_view.touch_event(touch_event)
clicked = self.screen_objects.get_touch_objects_in_pos( clicked = self.screen_objects.get_touch_objects_in_pos(
touch_event.current_pos) touch_event.current_pos)
for key in clicked: for key in clicked:

View File

@@ -1,11 +1,12 @@
import traceback import traceback
import logging
import mopidy import mopidy
from pkg_resources import Requirement, resource_filename from pkg_resources import Requirement, resource_filename
import pygame
import mopidy.core
from .main_screen import MainScreen from .main_screen import MainScreen
from .touch_manager import TouchManager from .touch_manager import TouchManager
from .screen_objects import * from .screen_objects import ScreenObjectsManager, TouchAndTextItem, Progressbar
from .tracklist import Tracklist from .tracklist import Tracklist
from .playlist_screen import PlaylistScreen from .playlist_screen import PlaylistScreen
from .dynamic_background import DynamicBackground from .dynamic_background import DynamicBackground
@@ -109,13 +110,12 @@ class ScreenManager():
self.screen_objects_manager.set_touch_object("menu_3", button) self.screen_objects_manager.set_touch_object("menu_3", button)
x = button.get_right_pos() x = button.get_right_pos()
#Menu button # Menu button
button = TouchAndTextItem(self.fonts['icon'], u" \ue60a", button = TouchAndTextItem(self.fonts['icon'], u" \ue60a",
(x, self.base_size * 7), None) (x, self.base_size * 7), None)
self.screen_objects_manager.set_touch_object("menu_4", button) 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.down_bar = pygame.Surface(
(self.size[0], self.size[1] - self.base_size * 7), pygame.SRCALPHA) (self.size[0], self.size[1] - self.base_size * 7), pygame.SRCALPHA)
self.down_bar.fill((0, 0, 0, 128)) self.down_bar.fill((0, 0, 0, 128))
@@ -153,19 +153,19 @@ class ScreenManager():
if objects is not None: if objects is not None:
for key in objects: for key in objects:
if key == "volume": if key == "volume":
value = self.screen_objects_manager.get_touch_object( manager = self.screen_objects_manager
key).get_pos_value( volume = manager.get_touch_object(key)
touch_event.current_pos) pos = touch_event.current_pos
value = volume.get_pos_value(pos)
self.backend.tell( self.backend.tell(
{'action': 'volume', 'value': value}) {'action': 'volume', 'value': value})
self.volume_changed(value) self.volume_changed(value)
elif key == "pause_play": 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() self.core.playback.pause()
logger.error("pausatzen")
else: else:
self.core.playback.play() self.core.playback.play()
logger.error("erreproduzitzen")
elif key == "mute": elif key == "mute":
mute = not self.core.playback.mute.get() mute = not self.core.playback.mute.get()
self.core.playback.set_mute(mute) self.core.playback.set_mute(mute)
@@ -198,7 +198,6 @@ class ScreenManager():
self.screen_objects_manager.get_touch_object("mute").set_text( self.screen_objects_manager.get_touch_object("mute").set_text(
u"\ue621", False) u"\ue621", False)
else: else:
logger.error("sartu naiz")
self.screen_objects_manager.get_touch_object("mute").set_text( self.screen_objects_manager.get_touch_object("mute").set_text(
u"\ue622", False) u"\ue622", False)
self.screen_objects_manager.get_touch_object("volume").set_value(volume) self.screen_objects_manager.get_touch_object("volume").set_value(volume)

View File

@@ -1,6 +1,6 @@
import pygame
import logging import logging
import math import math
import pygame
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -70,7 +70,8 @@ class TextItem(BaseItem):
self.box = self.font.render(text, True, self.color) self.box = self.font.render(text, True, self.color)
if size is not None: if size is not None:
if size[1] == -1: 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: else:
BaseItem.__init__(self, pos, size) BaseItem.__init__(self, pos, size)
else: else:
@@ -180,8 +181,8 @@ class Progressbar(TouchObject):
self.text.set_text(str(self.value), True) self.text.set_text(str(self.value), True)
else: else:
self.text = TextItem(font, text, pos, None) 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 = (self.pos[0] + self.size[0] / 2 - self.text.size[0] /
self.text.pos[1]) 2, self.text.pos[1])
def update(self): def update(self):
pass pass

View File

@@ -18,7 +18,8 @@ setup(
license='Apache License, Version 2.0', license='Apache License, Version 2.0',
author='9and3r', author='9and3r',
author_email='9and3r@gmail.com', 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(), long_description=open('README.rst').read(),
packages=find_packages(exclude=['tests', 'tests.*']), packages=find_packages(exclude=['tests', 'tests.*']),
zip_safe=False, zip_safe=False,