From 3a503ed48a7018a8f76a692ce5627ee84f326c80 Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 22 May 2015 00:47:46 -0400 Subject: [PATCH 1/2] Added groundwork for supporting a better resolution --- mopidy_touchscreen/__init__.py | 1 + mopidy_touchscreen/ext.conf | 1 + mopidy_touchscreen/screen_manager.py | 27 ++++++++++++++------------- mopidy_touchscreen/touch_screen.py | 5 +++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/mopidy_touchscreen/__init__.py b/mopidy_touchscreen/__init__.py index 4fa7bde..3e49203 100644 --- a/mopidy_touchscreen/__init__.py +++ b/mopidy_touchscreen/__init__.py @@ -24,6 +24,7 @@ class Extension(ext.Extension): schema = super(Extension, self).get_config_schema() schema['screen_width'] = config.Integer(minimum=1) schema['screen_height'] = config.Integer(minimum=1) + schema['resolution_factor'] = config.Integer(minimum=0) schema['cursor'] = config.Boolean() schema['fullscreen'] = config.Boolean() schema['cache_dir'] = config.Path() diff --git a/mopidy_touchscreen/ext.conf b/mopidy_touchscreen/ext.conf index f02c0f1..1de4914 100644 --- a/mopidy_touchscreen/ext.conf +++ b/mopidy_touchscreen/ext.conf @@ -2,6 +2,7 @@ enabled = true screen_width = 320 screen_height = 240 +resolution_factor = 0 cursor = True fullscreen = False cache_dir = $XDG_CACHE_DIR/mopidy/touchscreen diff --git a/mopidy_touchscreen/screen_manager.py b/mopidy_touchscreen/screen_manager.py index 24f51e0..20a260d 100644 --- a/mopidy_touchscreen/screen_manager.py +++ b/mopidy_touchscreen/screen_manager.py @@ -25,7 +25,7 @@ menu_index = 5 class ScreenManager(): - def __init__(self, size, core, cache): + def __init__(self, size, core, cache, resolution_factor): self.core = core self.cache = cache self.fonts = {} @@ -43,12 +43,13 @@ class ScreenManager(): self.keyboard = None self.update_type = BaseScreen.update_all - self.init_manager(size) + self.init_manager(size, resolution_factor) - def init_manager(self, size): + def init_manager(self, size, resolution_factor): self.size = size + self.resolution_factor = resolution_factor self.background = DynamicBackground(self.size) - self.base_size = self.size[1] / 8 + self.base_size = self.size[1] / (8+self.resolution_factor) #change this for more screen space font = resource_filename( Requirement.parse("mopidy-touchscreen"), "mopidy_touchscreen/icomoon.ttf") @@ -75,35 +76,35 @@ class ScreenManager(): # Search button button = TouchAndTextItem(self.fonts['icon'], u" \ue986", - (0, self.base_size * 7), + (0, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_0", button) x = button.get_right_pos() # Main button button = TouchAndTextItem(self.fonts['icon'], u" \ue600", - (x, self.base_size * 7), + (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_1", button) x = button.get_right_pos() # Tracklist button button = TouchAndTextItem(self.fonts['icon'], u" \ue60d", - (x, self.base_size * 7), + (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_2", button) x = button.get_right_pos() # Library button button = TouchAndTextItem(self.fonts['icon'], u" \ue604", - (x, self.base_size * 7), + (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_3", button) x = button.get_right_pos() # Playlist button button = TouchAndTextItem(self.fonts['icon'], u" \ue605", - (x, self.base_size * 7), + (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_4", button) @@ -111,18 +112,18 @@ class ScreenManager(): # Menu button button = TouchAndTextItem(self.fonts['icon'], u" \ue60a", - (x, self.base_size * 7), + (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_5", button) # Down bar Solid self.down_bar_solid = pygame.Surface( - (self.size[0], self.size[1] - self.base_size * 7)) + (self.size[0], self.size[1] - self.base_size * (7+self.resolution_factor))) #change the 7 to move the bar # Down bar self.down_bar = pygame.Surface( - (self.size[0], self.size[1] - self.base_size * 7), + (self.size[0], self.size[1] - self.base_size * (7+self.resolution_factor)), #change the 7 to move the bar pygame.SRCALPHA) self.down_bar.fill((0, 0, 0, 200)) @@ -161,7 +162,7 @@ class ScreenManager(): else: self.screens[self.current_screen].\ update(surface, update_type, rects) - surface.blit(self.down_bar, (0, self.base_size * 7)) + surface.blit(self.down_bar, (0, self.base_size * (7+self.resolution_factor))) self.down_bar_objects.render(surface) if update_type == BaseScreen.update_all or len(rects) < 1: diff --git a/mopidy_touchscreen/touch_screen.py b/mopidy_touchscreen/touch_screen.py index cdfedbf..da3735d 100644 --- a/mopidy_touchscreen/touch_screen.py +++ b/mopidy_touchscreen/touch_screen.py @@ -25,7 +25,7 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): self.fullscreen = config['touchscreen']['fullscreen'] self.screen_size = (config['touchscreen']['screen_width'], config['touchscreen']['screen_height']) - + self.resolution_factor = (config['touchscreen']['resolution_factor']) if config['touchscreen']['sdl_fbdev'].lower() != "none": os.environ["SDL_FBDEV"] = config['touchscreen']['sdl_fbdev'] if config['touchscreen']['sdl_mousdrv'].lower() != "none": @@ -46,7 +46,8 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): pygame.mouse.set_visible(self.cursor) self.screen_manager = ScreenManager(self.screen_size, self.core, - self.cache_dir) + self.cache_dir, + self.resolution_factor) # Raspberry pi GPIO self.gpio = config['touchscreen']['gpio'] From 9a7c5afa4f77da42b03c7d9a3bc014243ae36974 Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 22 May 2015 22:37:41 -0400 Subject: [PATCH 2/2] Removed magic numbers and replaced them with just resolution_factor. Set resolution_factor to 8 in ext.conf --- mopidy_touchscreen/ext.conf | 2 +- mopidy_touchscreen/screen_manager.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mopidy_touchscreen/ext.conf b/mopidy_touchscreen/ext.conf index 1de4914..9cf9669 100644 --- a/mopidy_touchscreen/ext.conf +++ b/mopidy_touchscreen/ext.conf @@ -2,7 +2,7 @@ enabled = true screen_width = 320 screen_height = 240 -resolution_factor = 0 +resolution_factor = 8 cursor = True fullscreen = False cache_dir = $XDG_CACHE_DIR/mopidy/touchscreen diff --git a/mopidy_touchscreen/screen_manager.py b/mopidy_touchscreen/screen_manager.py index 20a260d..7db89ff 100644 --- a/mopidy_touchscreen/screen_manager.py +++ b/mopidy_touchscreen/screen_manager.py @@ -49,7 +49,7 @@ class ScreenManager(): self.size = size self.resolution_factor = resolution_factor self.background = DynamicBackground(self.size) - self.base_size = self.size[1] / (8+self.resolution_factor) #change this for more screen space + self.base_size = self.size[1] / self.resolution_factor font = resource_filename( Requirement.parse("mopidy-touchscreen"), "mopidy_touchscreen/icomoon.ttf") @@ -76,35 +76,35 @@ class ScreenManager(): # Search button button = TouchAndTextItem(self.fonts['icon'], u" \ue986", - (0, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (0, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_0", button) x = button.get_right_pos() # Main button button = TouchAndTextItem(self.fonts['icon'], u" \ue600", - (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (x, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_1", button) x = button.get_right_pos() # Tracklist button button = TouchAndTextItem(self.fonts['icon'], u" \ue60d", - (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (x, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_2", button) x = button.get_right_pos() # Library button button = TouchAndTextItem(self.fonts['icon'], u" \ue604", - (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (x, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_3", button) x = button.get_right_pos() # Playlist button button = TouchAndTextItem(self.fonts['icon'], u" \ue605", - (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (x, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_4", button) @@ -112,18 +112,18 @@ class ScreenManager(): # Menu button button = TouchAndTextItem(self.fonts['icon'], u" \ue60a", - (x, self.base_size * (7+self.resolution_factor)), #change these to move the location of the icons + (x, self.size[1] - self.base_size), #change these to move the location of the icons button_size, center=True) self.down_bar_objects.set_touch_object("menu_5", button) # Down bar Solid self.down_bar_solid = pygame.Surface( - (self.size[0], self.size[1] - self.base_size * (7+self.resolution_factor))) #change the 7 to move the bar + (self.size[0], self.size[1] - self.base_size )) #change the 7 to move the bar # Down bar self.down_bar = pygame.Surface( - (self.size[0], self.size[1] - self.base_size * (7+self.resolution_factor)), #change the 7 to move the bar + (self.size[0], self.size[1] - self.base_size ), #change the 7 to move the bar pygame.SRCALPHA) self.down_bar.fill((0, 0, 0, 200)) @@ -162,7 +162,7 @@ class ScreenManager(): else: self.screens[self.current_screen].\ update(surface, update_type, rects) - surface.blit(self.down_bar, (0, self.base_size * (7+self.resolution_factor))) + surface.blit(self.down_bar, (0, self.size[1] - self.base_size)) self.down_bar_objects.render(surface) if update_type == BaseScreen.update_all or len(rects) < 1: