diff --git a/mopidy_touchscreen/.idea/workspace.xml b/mopidy_touchscreen/.idea/workspace.xml index 522f7b4..6f06ef1 100644 --- a/mopidy_touchscreen/.idea/workspace.xml +++ b/mopidy_touchscreen/.idea/workspace.xml @@ -26,8 +26,8 @@ - - + + @@ -36,11 +36,9 @@ - - - - - + + + @@ -48,18 +46,18 @@ - - + + - + - - + + @@ -67,14 +65,12 @@ - + - - - - - + + + @@ -82,11 +78,9 @@ - - - - - + + + @@ -106,10 +100,11 @@ @@ -146,6 +141,7 @@ + @@ -166,7 +162,6 @@ - @@ -337,7 +332,7 @@ - + @@ -351,11 +346,11 @@ - + - + @@ -380,16 +375,6 @@ - - - - - - - - - - @@ -409,9 +394,7 @@ - - - + @@ -419,9 +402,7 @@ - - - + @@ -451,9 +432,7 @@ - - - + @@ -461,9 +440,7 @@ - - - + @@ -485,9 +462,7 @@ - - - + @@ -495,9 +470,7 @@ - - - + @@ -527,9 +500,7 @@ - - - + @@ -537,9 +508,7 @@ - - - + @@ -562,9 +531,7 @@ - - - + @@ -572,9 +539,7 @@ - - - + @@ -604,9 +569,7 @@ - - - + @@ -614,9 +577,7 @@ - - - + @@ -646,9 +607,7 @@ - - - + @@ -671,9 +630,7 @@ - - - + @@ -696,9 +653,7 @@ - - - + @@ -753,58 +708,59 @@ + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + + - + diff --git a/mopidy_touchscreen/dynamic_background.py b/mopidy_touchscreen/dynamic_background.py index eac73da..c17daf2 100644 --- a/mopidy_touchscreen/dynamic_background.py +++ b/mopidy_touchscreen/dynamic_background.py @@ -2,24 +2,26 @@ import random class DynamicBackground(): - def __init__(self): - self.current=[0,0,0] - self.target=[0,0,0] - for x in range(0, 3): - self.target[x]=random.randint(0,255) + def __init__(self): + self.current=[0,0,0] + for x in range(0, 3): + self.current[x]=random.randint(0,255) + self.target=[0,0,0] + for x in range(0, 3): + self.target[x]=random.randint(0,255) - def drawBackground(self,surface): - same = True - for x in range(0, 3): - if self.current[x]> self.target[x]: - self.current[x]=self.current[x]-1 - elif self.current[x] self.target[x]: + self.current[x]=self.current[x]-1 + elif self.current[x] pos2[0]: + if size is not None: + BaseItem.__init__(self, pos, size) + else: + BaseItem.__init__(self, pos, self.box.get_rect().size) + if size is not None: + if self.pos[0] + self.box.get_rect().width > pos[0] + size[0]: self.fit_horizontal = False - self.text = self.text + " " + self.text += " " self.original_text = self.text self.step = 0 else: self.fit_horizontal = True - if self.pos[1] + self.box.get_rect().height > pos2[1]: + if self.pos[1] + self.box.get_rect().height > pos[1] + size[1]: self.fit_vertical = False else: self.fit_vertical = True else: - BaseItem.__init__(self,pos,(pos[0]+self.box.get_rect().width,pos[1]+self.box.get_rect().height)) + BaseItem.__init__(self, pos, (pos[0] + self.box.get_rect().width, pos[1] + self.box.get_rect().height)) self.fit_horizontal = True self.fit_vertical = True @@ -108,7 +98,7 @@ class TextItem(BaseItem): new_text = new_text + self.text[:1] self.text = new_text else: - self.step = self.step + 1 + self.step += 1 elif self.step > 5: self.step = 0 new_text = self.text[1:] @@ -117,24 +107,24 @@ class TextItem(BaseItem): else: self.step += 1 - def render(self,surface): + def render(self, surface): if self.fit_horizontal: self.box else: self.box = self.font.render(self.text, True, self.color) - surface.blit(self.box,self.pos,area=self.rect) + surface.blit(self.box, self.pos, area=self.rect) def set_text(self, text, same_size): if same_size: - TextItem.__init__(self, self.font, text, self.pos, None, self.color, self.text_size) + TextItem.__init__(self, self.font, text, self.pos, None) else: - TextItem.__init__(self, self.font, text, self.pos, self.pos2, self.color, self.text_size) + TextItem.__init__(self, self.font, text, self.pos, self.size) class TouchObject(BaseItem): - def __init__(self,pos,pos2): - BaseItem.__init__(self,pos,pos2) + def __init__(self, pos, size): + BaseItem.__init__(self, pos, size) self.active = False def is_pos_inside(self, pos): @@ -146,45 +136,35 @@ class TouchObject(BaseItem): class TouchAndTextItem(TouchObject, TextItem): - def __init__(self, font, text, pos, pos2, color,text_size): - TextItem.__init__(self, font, text, pos, pos2, color,text_size) - TouchObject.__init__(self, pos, self.pos2) + def __init__(self, font, text, pos, size): + TextItem.__init__(self, font, text, pos, size) + TouchObject.__init__(self, pos, self.size) def update(self): TextItem.update(self) - def set_active(self, active): - self.active = active - if active: - color = (0,150,255) - else: - color = (255,255,255) - TextItem.__init__(self.font,self.text,self.pos,self.pos2,color,self.text_size) +class Progressbar(TouchObject): -class Progressbar(TouchObject, TextItem): - - def __init__(self,font,text, pos, pos2, max,size, value_text): - BaseItem.__init__(self, pos, pos2) - logger.error(pos2) + def __init__(self, font, text, pos,size, max_value, value_text): + BaseItem.__init__(self, pos, size) self.value = 0 - self.max = max - self.back_color = (0,0,0,128) - self.main_color = (0,150,255) + self.max = max_value + self.back_color = (0, 0, 0, 128) + self.main_color = (0, 150, 255) self.surface = pygame.Surface(self.size, pygame.SRCALPHA) self.surface.fill(self.back_color) self.value_text = value_text if value_text: - self.text = TextItem(font,str(self.max),pos,None,(255,255,255),size) - self.text.set_text(str(self.value),True) + self.text = TextItem(font, str(self.max), pos, None, (255, 255, 255), size) + self.text.set_text(str(self.value), True) else: - self.text = TextItem(font,text,pos,None,(255,255,255),size) - self.text.pos = (self.pos[0] + self.size[0] / 2 - self.text.size[0] /2,self.text.pos[1]) + 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]) def update(self): pass - def render(self, surface): surface.blit(self.surface, self.pos) self.text.render(surface) @@ -196,7 +176,7 @@ class Progressbar(TouchObject, TextItem): self.set_text(str(self.value)) self.surface.fill(self.back_color) pos_pixel = value * self.size[0] / self.max - rect = pygame.Rect(0,0,pos_pixel,self.size[1]) + rect = pygame.Rect(0,0, pos_pixel, self.size[1]) self.surface.fill(self.main_color, rect) def get_pos_value(self, pos): @@ -204,26 +184,26 @@ class Progressbar(TouchObject, TextItem): return x * self.max / self.size[0] def set_text(self, text): - self.text.set_text(text , True) + self.text.set_text(text, True) class ScrollBar(TouchObject): - def __init__(self, pos, size, max, items_on_screen): - BaseItem.__init__(self, pos, (pos[0]+size[0],pos[1]+size[1])) + def __init__(self, pos, size, max_value, items_on_screen): + BaseItem.__init__(self, pos, (pos[0]+size[0], pos[1]+size[1])) self.pos = pos self.size = size - self.max = max + self.max = max_value self.items_on_screen = items_on_screen self.current_item = 0 self.back_bar = pygame.Surface(self.size) - self.back_bar.fill((255,255,255)) + self.back_bar.fill((255, 255, 255)) self.bar_pos = 0 if self.max < 1: - self.barsize = self.size[1] + self.bar_size = self.size[1] else: - self.barsize = math.ceil(float(self.items_on_screen)/float(self.max) * float(self.size[1])) - self.bar = pygame.Surface((self.size[0],self.barsize)) + 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, 0)) def render(self, surface): @@ -233,7 +213,7 @@ class ScrollBar(TouchObject): def touch(self, pos): if pos[1] < self.pos[1]+self.bar_pos: return -1 - elif pos[1] > self.pos[1] + self.bar_pos + self.barsize: + elif pos[1] > self.pos[1] + self.bar_pos + self.bar_size: return 1 else: return 0 diff --git a/mopidy_touchscreen/touch_screen.py b/mopidy_touchscreen/touch_screen.py index a4c08f8..ccaee0e 100644 --- a/mopidy_touchscreen/touch_screen.py +++ b/mopidy_touchscreen/touch_screen.py @@ -68,4 +68,7 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener): self.screen_manager.playback_state_changed(old_state, new_state) def tracklist_changed(self): - self.screen_manager.tracklist_changed() + try: + self.screen_manager.tracklist_changed() + except: + traceback.print_exc()