def BrowserInit(self): self.browser = Scroller(self.group, Browser(self.level), self.image, 30, BLACK, 36, 15, 400, 300) self.browser.level = self.browser.browser.level self.browser.rect = (300, 350) if self.isSelected: self.SetSelected()
def OpenPlaylist(self, level): """Open playlist with self.playlistID""" self.playlistID = playlistID = Database.CreatePlaylist() logger.info("Created new playlist ID = %i" % playlistID) #self.playlistID = playlistID = 26 #self.playlistID = playlistID = 444 #self.playlistID = playlistID = 1170 #if self.level == 'path': level = 'fs_playlist' self.browser = Scroller(self.group, Browser(level, self.playlistID), self.image, 30, BLACK, 28, 20, 500, 200) if self.isSelected: self.SetSelected() self.browser.level = self.browser.browser.level self.browser.rect = (500, 0) self.t_pl = TextSprite(self.group, "Playlist..........", 32, 520, 30, RED) self.title = self.t_pl.UpdateText("Playlist #%i" % self.playlistID) self.browser.Refresh() #self.render() logger.info("Playlist #%i opened!" % self.playlistID)
def __init__(self, panel, dmx): self.panel = panel self.dmx = dmx self.pan = Scroller(PAN_MIN, PAN_MAX) self.tilt = Scroller(TILT_MIN, TILT_MAX) self.color_index = 0 self.gobo_index = 0 self.brightness = Scroller(0, 255, 255 / 3.0) self.brightness_direction = 1 self.is_auto = False
def OpenPlaylist(self, level): """Open playlist with self.playlistID""" self.playlistID = playlistID = Database.CreatePlaylist() logger.info("Created new playlist ID = %i" % playlistID) #self.playlistID = playlistID = 26 #self.playlistID = playlistID = 444 #self.playlistID = playlistID = 1170 #if self.level == 'path': level = 'fs_playlist' self.browser = Scroller(self.group, Browser(level, self.playlistID), self.image, 30, BLACK, 28, 20, 500,200) if self.isSelected: self.SetSelected() self.browser.level = self.browser.browser.level self.browser.rect = (500,0) self.t_pl = TextSprite(self.group, "Playlist..........", 32, 520, 30, RED) self.title = self.t_pl.UpdateText("Playlist #%i" % self.playlistID) self.browser.Refresh() #self.render() logger.info("Playlist #%i opened!" % self.playlistID)
def BrowserInit(self): self.browser = Scroller(self.group, Browser(self.level), self.image, 30, BLACK, 36, 15, 400,300) self.browser.level = self.browser.browser.level self.browser.rect = (300,350) if self.isSelected: self.SetSelected()
class MusicBrowser(pygame.sprite.Sprite): """ The music browser sprite """ def __init__(self, group, type): pygame.sprite.Sprite.__init__(self, group) self.group = group self.infotext = [] self.isSelected = False self.speed = 0 self.keystart = 0 self.image = pygame.Surface((300,300)) self.image = self.image.convert() #self.image.fill((0,100,100)) self.rect = (0,250) self.mustRender = True if type == 'path': self.level = 'path' elif type == '': self.level = 'labels' elif type == 'labels': self.level = 'labels' else: self.level = 'labels' self.type = type self.BrowserInit() #self.InfopanelInit() self.la = Text("", 28, 570, 50, ORANGE) self.ar = Text("", 28, 570, 50, ORANGE) self.al = Text("", 28, 570, 50, ORANGE) #self.tr = Text("", 28, 570, 50, ORANGE) self.action = {} # arrow down self.action[274] = self.goDown # arrow up self.action[273] = self.goUp # arrow left self.action[275] = self.BrowseForward # arrow left self.action[276] = self.BrowseBack # a self.action[118] = self.AddToRemoveFromPlaylist #-------------------------------------------------------------------- def BrowserInit(self): self.browser = Scroller(self.group, Browser(self.level), self.image, 30, BLACK, 36, 15, 400,300) self.browser.level = self.browser.browser.level self.browser.rect = (300,350) if self.isSelected: self.SetSelected() #self.browser.Refresh() #-------------------------------------------------------------------- #def InfopanelInit(self): # self.infopanel = Textbox(self.group, self.infotext, self.image, 10, 30, WHITE, 36, 15, 400,300, False) # self.infopanel.rect = (700,350) #self.browser.Refresh() #-------------------------------------------------------------------- def SetType(self, type): if self.type == 'labels': self.type = 'path' elif self.type == 'path': self.type = 'labels' #logger.debug5( self.type ) #logger.debug5( self.browser.level ) #logger.debug5( self.browser.browser.level ) self.level = self.type self.browser.BrowserInit(self.level) #self.infopanel.BrowserInit([]) self.browser.level = self.type self.browser.browser.level = self.type self.SetLabel("") self.SetArtist("") self.SetAlbum("") self.Refresh() #-------------------------------------------------------------------- def Refresh(self): self.list = self.browser.list self.browser.Refresh() #self.infopanel.BrowserInit([{'name':'otro'}]) #self.infopanel.Refresh() self.mustRender = True #-------------------------------------------------------------------- def goUp(self): self.browser.goUp() self.mustRender = True #-------------------------------------------------------------------- def goDown(self): self.browser.goDown() self.mustRender = True #-------------------------------------------------------------------- def stopMoving(self): self.browser.stopMoving() #-------------------------------------------------------------------- def BrowseForward(self): name = self.browser.list[self.browser.selected]['name'] if self.browser.browser.level == 'artists': self.SetLabel(name) elif self.browser.browser.level == 'albums': self.SetArtist(name) elif self.browser.browser.level == 'tracks': self.SetAlbum(name) self.mustRender = True self.browser.BrowseForward() #-------------------------------------------------------------------- def BrowseBack(self): self.browser.BrowseBack() if self.browser.browser.level == 'artists': self.SetLabel("") elif self.browser.browser.level == 'albums': self.SetArtist("") elif self.browser.browser.level == 'tracks': self.SetAlbum("") self.mustRender = True #-------------------------------------------------------------------- def AddToRemoveFromPlaylist(self, playlistID): self.browser.AddToRemoveFromPlaylist(playlistID) #-------------------------------------------------------------------- def Next(self): print self.list[self.selected+1]['location'] #-------------------------------------------------------------------- def update(self): if self.mustRender: #self.infopanel.SetText(self.browser.list[self.browser.selected]['info']) #self.infopanel.mustRender = True #self.infopanel.Refresh() self.render() self.mustRender = False #-------------------------------------------------------------------- def render(self): self.image.fill(BLACK) self.selected = self.browser.selected # render the browser sprite #self.browser.mustRender = True self.navigation() self.browser.update() #self.infopanel.update() self.showRelatedImage((60,100), self.image) #logger.debug5( "self.level: " + self.level) #-------------------------------------------------------------------- def showRelatedImage(self, pos, image): # show related image itemImg = '' if type(self.selected) is int: try: itemImg = self.browser.list[self.selected]['img'] except Exception, e: logger.error("MusicBrowser EXCEPTION: %s" % str(e) ) if itemImg != '': imgsrc = ValidateImage(itemImg, self.browser.level) if imgsrc: #logger.debug( "loading image: " + imgsrc ) self.showImage(imgsrc, pos, self.image) else: return True else: return False #-------------------------------------------------------------------- def showImage(self, imgfile, pos, image): #self.image, self.rect = load_image(imgfile, -1) #self.image.blit(self.image, pos) img = pygame.image.load(imgfile) #frame = pygame.image.load('data/frame.png').convert_alpha() #img.blit(frame, (-22, -12)) self.image.blit(img, pos) #-------------------------------------------------------------------- def navigation(self): """Display navigation position""" self.image.blit(self.la.Show(), (0, 0)) self.image.blit(self.ar.Show(), (10, 30)) self.image.blit(self.al.Show(), (20, 60)) #self.image.blit(self.tr.Show(), (400, 85)) #-------------------------------------------------------------------- def SetLabel(self, s): if s == "": tag = "" else: tag = "Label : " self.la.UpdateText(tag + s) #-------------------------------------------------------------------- def SetArtist(self, s): if s == "": tag = "" else: tag = "Artist : " self.ar.UpdateText(tag + s) #-------------------------------------------------------------------- def SetAlbum(self, s): if s == "": tag = "" else: tag = "Album : " self.al.UpdateText(tag + s) #-------------------------------------------------------------------- def SetFocus(self, state): if state: self.SetSelected() else: self.SetUnSelected() #-------------------------------------------------------------------- def SetSelected(self): self.browser.SetSelected() self.isSelected = True #-------------------------------------------------------------------- def SetUnSelected(self): self.browser.SetUnSelected() self.isSelected = False self.render() #-------------------------------------------------------------------- def SetVisible(self): self.browser.rect = (400,350) #self.browser.mustRender() #-------------------------------------------------------------------- def SetUnVisible(self): self.browser.rect = (400,900) #-------------------------------------------------------------------- def loop(self): self.browser.loop()
def __init__(self, atlas): super(IsoMap, self).__init__() self.batch = c.batch.BatchNode() self.cells = [] self.start_cell = None self.current_cell = None self.highlight = Highlight() self.object_layer = ObjectLayer() self.scroller = Scroller() self.rhombuses = ( Rhombus((-MAP_WIDTH//4, MAP_HEIGHT//4-15), (0, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT//4-15), (0, -15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((-MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT-15), (MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT//2-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((-MAP_WIDTH//2, MAP_HEIGHT//2-15), (-MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT//2-15), (-MAP_WIDTH//4, MAP_HEIGHT//4-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((0, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (MAP_WIDTH//2, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT//4-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2) ) for rhombus in self.rhombuses: rhombus.subdivide() for row in range(MAP_SIZE): self.cells.append([]) for col in range(MAP_SIZE): cell = Cell(atlas, -row*30 + col*30, row*15 + col*15, row, col) self.cells[row].append(cell) self.batch.add(cell) # if random.randint(1, 100) > 95: # self.object_layer.batch.add(c.sprite.Sprite("tree1.png", position=cell.position, anchor=(29, 15))) # cell.passable = False size = MAP_SIZE rhombuses = self.rhombuses rhombus = None while size > RHOMBUS_SIZE: offset_i = 0 if not rhombus else rhombus.cells[0].i offset_j = 0 if not rhombus else rhombus.cells[0].j limit_row = row - offset_i limit_col = col - offset_j if limit_row < size // 2 and limit_col < size // 2: rhombus = rhombuses[0] elif limit_row >= size // 2 and limit_col >= size // 2: rhombus = rhombuses[1] elif limit_row >= size // 2 and limit_col < size // 2: rhombus = rhombuses[2] else: rhombus = rhombuses[3] rhombus.cells.append(cell) size //= 2 rhombuses = rhombus.subrhombuses # highlights.add(c.text.Label( # "{};{}".format((center_x-29) - row*29 + col*29, row*15 + col*15), # "{};{}".format(cell.i, cell.j), # font_size=8, # position=((center_x-29) - row*29 + col*29, row*15 + col*15), # anchor_x="center", # )) rows = len(self.cells) cols = len(self.cells[0]) for row in self.cells: for cell in row: for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)): cell_i = cell.i+i cell_j = cell.j+j if cell_i < 0 or cell_j < 0 or cell_i >= cols or cell_j >= rows: continue cell.neighbours.append(self.cells[cell_i][cell_j]) self.marked_cells = [] self.pillar_cell = None self.population = 0 self.add(self.batch) self.add(self.object_layer) self.add(self.highlight) self.buildings_queue = set() self.schedule_interval(self.process_buildings_queue, 1)
class IsoMap(c.layer.ScrollableLayer): is_event_handler = True def __init__(self, atlas): super(IsoMap, self).__init__() self.batch = c.batch.BatchNode() self.cells = [] self.start_cell = None self.current_cell = None self.highlight = Highlight() self.object_layer = ObjectLayer() self.scroller = Scroller() self.rhombuses = ( Rhombus((-MAP_WIDTH//4, MAP_HEIGHT//4-15), (0, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT//4-15), (0, -15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((-MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT-15), (MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT//2-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((-MAP_WIDTH//2, MAP_HEIGHT//2-15), (-MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (0, MAP_HEIGHT//2-15), (-MAP_WIDTH//4, MAP_HEIGHT//4-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2), Rhombus((0, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT*3//4-15), (MAP_WIDTH//2, MAP_HEIGHT//2-15), (MAP_WIDTH//4, MAP_HEIGHT//4-15), MAP_WIDTH // 2, MAP_HEIGHT // 2, MAP_SIZE // 2) ) for rhombus in self.rhombuses: rhombus.subdivide() for row in range(MAP_SIZE): self.cells.append([]) for col in range(MAP_SIZE): cell = Cell(atlas, -row*30 + col*30, row*15 + col*15, row, col) self.cells[row].append(cell) self.batch.add(cell) # if random.randint(1, 100) > 95: # self.object_layer.batch.add(c.sprite.Sprite("tree1.png", position=cell.position, anchor=(29, 15))) # cell.passable = False size = MAP_SIZE rhombuses = self.rhombuses rhombus = None while size > RHOMBUS_SIZE: offset_i = 0 if not rhombus else rhombus.cells[0].i offset_j = 0 if not rhombus else rhombus.cells[0].j limit_row = row - offset_i limit_col = col - offset_j if limit_row < size // 2 and limit_col < size // 2: rhombus = rhombuses[0] elif limit_row >= size // 2 and limit_col >= size // 2: rhombus = rhombuses[1] elif limit_row >= size // 2 and limit_col < size // 2: rhombus = rhombuses[2] else: rhombus = rhombuses[3] rhombus.cells.append(cell) size //= 2 rhombuses = rhombus.subrhombuses # highlights.add(c.text.Label( # "{};{}".format((center_x-29) - row*29 + col*29, row*15 + col*15), # "{};{}".format(cell.i, cell.j), # font_size=8, # position=((center_x-29) - row*29 + col*29, row*15 + col*15), # anchor_x="center", # )) rows = len(self.cells) cols = len(self.cells[0]) for row in self.cells: for cell in row: for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)): cell_i = cell.i+i cell_j = cell.j+j if cell_i < 0 or cell_j < 0 or cell_i >= cols or cell_j >= rows: continue cell.neighbours.append(self.cells[cell_i][cell_j]) self.marked_cells = [] self.pillar_cell = None self.population = 0 self.add(self.batch) self.add(self.object_layer) self.add(self.highlight) self.buildings_queue = set() self.schedule_interval(self.process_buildings_queue, 1) def on_mouse_motion(self, x, y, dx, dy): if y < 150 or interface.modal_window: return x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y)) cell = self.find_cell(x, y) if not cell: return self.highlight.tile_highlight.position = cell.position def on_mouse_press(self, x, y, button, modifiers): if y < 150 or interface.modal_window: return x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y)) if shared_data.mode == Modes.NORMAL: buildings = [(building.z, building) for building in self.object_layer.buildings if building.contains(x, y)] obj = min(buildings)[1] interface.show_infocard(obj) else: cell = self.find_cell(x, y) if cell: self.start_cell = cell if shared_data.mode == Modes.DELETE: self.mark_cells(cell) elif shared_data.mode == Modes.TREE: self.object_layer.add_object(cell, Tree) elif shared_data.mode == Modes.ROAD: if cell.passable: cell.add_road() elif shared_data.mode == Modes.HOUSING: self.object_layer.add_object(cell, House, building=True) elif shared_data.mode == Modes.PILLAR: if not self.pillar_cell: if self.object_layer.add_object(cell, Pillar): self.pillar_cell = cell cell.type = Cell.ROAD elif shared_data.mode in Modes.WALL: self.object_layer.add_wall(cell, int(shared_data.mode[-1])) elif shared_data.mode == Modes.STAIRS: self.object_layer.add_object(cell, Stairs) # Place road at bottom of the stairs, so stairs will have correct road continuation. top_cell = self.cells[cell.i+1][cell.j+1] top_cell.add_road() cell.add_road() # Set cells at bottom and at top of the stairs to neighbours of each other, # so they will be connected when finding path. right_cell = self.cells[cell.i-1][cell.j] left_cell = self.cells[cell.i+2][cell.j+1] right_cell.neighbours.append(left_cell) left_cell.neighbours.append(right_cell) right_cell.level = -1 elif shared_data.mode in Modes.LEVEL: if shared_data.mode == Modes.LEVEL[0]: cell.level += 1 if shared_data.mode == Modes.LEVEL[1]: cell.level -= 1 self.object_layer.add(c.text.Label(str(cell.level), position=cell.position)) def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if y < 150 or interface.modal_window: return x, y = director.get_virtual_coordinates(*self.scroller.pixel_from_screen(x, y)) cell = self.find_cell(x, y) if not cell: return self.highlight.tile_highlight.position = cell.position if shared_data.mode == Modes.ROAD: if self.start_cell and self.start_cell.passable and cell.passable: if cell != self.current_cell: self.current_cell = cell self.draw_road_path(cell) elif shared_data.mode == Modes.TREE: self.object_layer.add_object(cell, Tree) elif shared_data.mode == Modes.HOUSING: self.object_layer.add_object(cell, House, building=True) elif shared_data.mode == Modes.DELETE: if self.start_cell: self.mark_cells(cell) def on_mouse_release(self, x, y, button, modifiers): if interface.modal_window: return self.start_cell = None self.highlight.roads.clear() if shared_data.mode == Modes.DELETE: self.clear_cells() if y > 150: self.calculate_buildings_availability() elif shared_data.mode == Modes.ROAD: if y > 150: self.populate_buildings_queue() elif shared_data.mode == Modes.HOUSING: self.populate_buildings_queue() elif shared_data.mode == Modes.PILLAR: if y > 150: self.populate_buildings_queue() def populate_buildings_queue(self): self.calculate_buildings_availability() for building in self.object_layer.buildings: if isinstance(building, House) and building.connected and not building.is_full(): self.buildings_queue.add(building) def process_buildings_queue(self, dt): if self.buildings_queue: building = self.buildings_queue.pop() building.population += 1 self.population += 1 interface.update_population(self.population) path = self.calculate_path(building.cell, self.pillar_cell, only_roads=True) self.object_layer.summon_creature(path) if not building.is_full(): self.buildings_queue.add(building) def mark_cells(self, cell): self.unmark_cells() if self.start_cell.i < cell.i: range_i = (self.start_cell.i, cell.i+1) else: range_i = (cell.i, self.start_cell.i+1) if self.start_cell.j < cell.j: range_j = (self.start_cell.j, cell.j+1) else: range_j = (cell.j, self.start_cell.j+1) for i in range(*range_i): for j in range(*range_j): cell_to_mark = self.cells[i][j] cell_to_mark.color = (255, 0, 0) if cell_to_mark.child: cell_to_mark.child.color = (255, 0, 0) self.marked_cells.append(cell_to_mark) def unmark_cells(self): for marked_cell in self.marked_cells: marked_cell.color = (255, 255, 255) if marked_cell.child: marked_cell.child.color = (255, 255, 255) self.marked_cells.clear() def find_cell(self, x, y): rhombuses = self.rhombuses while rhombuses: for rhombus in rhombuses: if rhombus.contains(x, y): rhombuses = rhombus.subrhombuses break else: break for cell in rhombus.cells: if cell.contains(x, y): return cell return None def clear_cells(self): for cell in self.marked_cells: if cell == self.pillar_cell: self.pillar_cell = None if cell.child: if isinstance(cell.child, Building): self.object_layer.buildings.remove(cell.child) cell.child.kill() cell.child = None cell.passable = True if cell.type == Cell.ROAD: cell.remove_road() self.unmark_cells() def draw_road_path(self, cell): path = self.calculate_path(cell) for cell in self.highlight.roads[:]: self.highlight.roads.remove(cell) cell.remove_road() # пропускаем стартовую клетку, так как дорога туда уже добавилась при нажатии кнопки for cell in path[1:]: if cell.type != Cell.ROAD: self.highlight.roads.append(cell) cell.add_road() def calculate_path(self, finish_cell, start_cell=None, only_roads=False): """ Finding path from start cell to finish cell. """ # TODO: add "level" property to cells # this must be a virtual level of cell above the ground. # When finding path, enter to the another level is available only through the stairs. # So, level of current cell is compares with level of neighbour cell, and if their levels are different # the path here is blocked. And the stairs must have two levels at the same time. if not start_cell: start_cell = self.start_cell closed_list = set() opened_list = set() heap = [] opened_list.add(start_cell) heap.append((0, 0, start_cell)) cells_counter = 1 while opened_list: current_cell = heapq.heappop(heap)[2] if current_cell == finish_cell: break opened_list.remove(current_cell) closed_list.add(current_cell) for cell in current_cell.neighbours: if cell == finish_cell or (cell not in closed_list and cell.passable): if cell.level != -1 and current_cell.level != -1: if cell.level != current_cell.level: continue if only_roads and cell.type != Cell.ROAD and cell != finish_cell: closed_list.add(cell) continue if cell not in opened_list: cell.G = current_cell.G + 1 cell.H = abs(finish_cell.i - cell.i) + abs(finish_cell.j - cell.j) cell.F = cell.G + cell.H cell.parent_cell = current_cell opened_list.add(cell) heapq.heappush(heap, (cell.F, cells_counter, cell)) cells_counter += 1 else: if cell.G > current_cell.G + 1: cell.G = current_cell.G + 1 cell.F = cell.G + cell.H cell.parent_cell = current_cell else: return [] path = [] current_cell = finish_cell path.append(finish_cell) while current_cell != start_cell: next_cell = current_cell.parent_cell path.append(next_cell) current_cell = next_cell path.reverse() return path def calculate_buildings_availability(self): """ Checks which Houses connected with road to Pillar. """ for building in self.object_layer.buildings: building.connected = False start_cell = self.pillar_cell if not start_cell: return closed_list = set() opened_list = set() opened_list.add(start_cell) while opened_list: current_cell = opened_list.pop() closed_list.add(current_cell) for cell in current_cell.neighbours: if cell not in closed_list: if cell.type == Cell.ROAD: opened_list.add(cell) elif isinstance(cell.child, Building): cell.child.connected = True closed_list.add(cell) # for building in self.object_layer.buildings: # if building.connected: # building.color = (0, 255, 0) # else: # building.color = (255, 0, 0) # def change_cell_level(self, start_cell, level): # closed_list = set() # opened_list = set() # opened_list.add(start_cell) # while opened_list: # current_cell = opened_list.pop() # closed_list.add(current_cell) # # if current_cell.wall == "thick": # continue # elif current_cell.wall == "thin": # current_cell.level += level # continue # current_cell.level += level # for cell in current_cell.neighbours: # if cell not in closed_list: # # if cell.wall: # # if cell.wall == "thin": # # cell.level += 1 # # closed_list.add(cell) # # continue # if cell not in opened_list: # opened_list.add(cell) # # # for row in self.cells: # for cell in row: # if cell.level == 1: # cell.color = (0, 255, 0)
def output_handler(): scroller = Scroller() last_mouse_movement = datetime.datetime(1970, 1, 1) last_show_menu = False while True: try: global mouse_movement, launch_playlist, hotkey_map, menu_showing, last_menu_showing, playlists, playlists_index, syncing # ----------------------------------------- mpd_lock.acquire() playlist_entries = len(mpd.playlist()) current_song = copy.copy(mpd.currentsong()) status = mpd.status() mpd_lock.release() # ----------------------------------------- artist = '' album = '' pos = '' title = '' name = '' tfile = '' if 'artist' in current_song: artist = current_song['artist'] if 'album' in current_song: album = current_song['album'] if 'pos' in current_song: pos = current_song['pos'] if 'title' in current_song: title = current_song['title'] if 'name' in current_song: name = current_song['name'] if 'file' in current_song: tfile = current_song['file'] if len(current_song) > 0: if album == '' and artist == '': scroller.set_line(0, name, tfile) else: if artist != '': if album != '': scroller.set_line(0, artist + ': ' + album, tfile) else: scroller.set_line(0, artist, tfile) line2 = title if playlist_entries > 1 and pos != '': line2 = str(int(pos) + 1) + '. ' + line2 scroller.set_line(1, line2, tfile) else: scroller.clear() if 'state' in status: scroller.set_paused(status['state'] == 'pause') scroller.set_busy(syncing) elapsed = '' if 'elapsed' in status: elapsed = float(status['elapsed']) minutes = int(elapsed // 60) seconds = int(elapsed - minutes * 60) elapsed = "%d:%02d" % (minutes, seconds) scroller.set_elapsed(elapsed) #scroller.set_line(0, 'ABCD (E) FGHIJKLMNOPQRSTUVWXYZ') #scroller.set_line(1, '-> Eule findet den Beat') mouse_movement_lock.acquire() current_movement = copy.copy(mouse_movement) mouse_movement = [0, 0] mouse_movement_lock.release() menu_showing_lock.acquire() if current_movement[1] != 0: last_mouse_movement = datetime.datetime.now() else: if (menu_showing != None) and (menu_showing != last_menu_showing): last_mouse_movement = datetime.datetime.now() last_menu_showing = menu_showing menu_showing_lock.release() this_show_menu = ((datetime.datetime.now() - last_mouse_movement).seconds < 5) if last_show_menu == True and this_show_menu == False: menu_showing_lock.acquire() menu_showing = None menu_showing_lock.release() if last_show_menu == False and this_show_menu == True: mpd_lock.acquire() cycle_menu_showing() mpd_lock.release() current_movement = [0, 0] last_show_menu = this_show_menu launch_playlist_lock.acquire() this_launch_playlist = launch_playlist launch_playlist = False launch_playlist_lock.release() if this_show_menu: if current_movement[1] != 0: if current_movement[0] == 1: playlists_index = (playlists_index + len(playlists) + current_movement[1]) % len(playlists) elif current_movement[0] == 0: first_letter = playlists[playlists_index][0].lower() this_first_letter = first_letter # skip to another letter while first_letter == this_first_letter: playlists_index = (playlists_index + len(playlists) + current_movement[1]) % len(playlists) first_letter = playlists[playlists_index][0].lower() # skip to first entry with this letter while True: temp_playlists_index = (playlists_index + len(playlists) - 1) % len(playlists) test_letter = playlists[temp_playlists_index][0].lower() if test_letter != first_letter: break else: playlists_index = temp_playlists_index letters = ''.join([chr(x + 65) for x in range(26)]) + '?' letter_index = ord(playlists[playlists_index][0].lower()) - ord('a') if letter_index not in range(26): letter_index = 26 letters = letters[:letter_index] + ' [' + letters[letter_index] + '] ' + letters[(letter_index + 1):] letters = ' ~=] ' + letters + ' [=~' scroller.set_line(0, letters) line2 = playlists[playlists_index] menu_showing_lock.acquire() if menu_showing == 'artist': line2 = '[Artist] ' + line2 elif menu_showing == 'album': line2 = '[Album] ' + line2 elif menu_showing[0:13] == 'artist-album-': line2 = '[Album] ' + line2 menu_showing_lock.release() scroller.set_line(1, line2, line2) if this_launch_playlist: menu_showing_lock.acquire() previous_menu_showing = menu_showing menu_showing = None menu_showing_lock.release() mpd_lock.acquire() if previous_menu_showing == 'playlist': mpd.clear() mpd.load(playlists[playlists_index]) mpd.play() elif previous_menu_showing == 'artist': cycle_menu_showing('artist-album-' + playlists[playlists_index]) menu_showing_lock.acquire() last_menu_showing = None menu_showing_lock.release() elif previous_menu_showing == 'album': album = playlists[playlists_index] mpd.clear() mpd.findadd('album', album) mpd.play() elif previous_menu_showing[0:13] == 'artist-album-': artist = previous_menu_showing[13:] album = playlists[playlists_index] mpd.clear() if album == '(all titles)': mpd.findadd('artist', artist) else: mpd.findadd('artist', artist, 'album', album) mpd.play() mpd_lock.release() last_mouse_movement = datetime.datetime(1970, 1, 1) scroller.render() scroller.animate() #print(current_song) except: raise pass time.sleep(0.05)
def test_load_correct_type_of_pieces(self): image = TestScroller.MockImage(30) l = Scroller.load_pieces(image, 90) self.assertEqual(l[0][0], image)
class SystemState(object): def __init__(self, panel, dmx): self.panel = panel self.dmx = dmx self.pan = Scroller(PAN_MIN, PAN_MAX) self.tilt = Scroller(TILT_MIN, TILT_MAX) self.color_index = 0 self.gobo_index = 0 self.brightness = Scroller(0, 255, 255 / 3.0) self.brightness_direction = 1 self.is_auto = False def switch_changed(self, switch, value): if switch == JOY_UP: self.set_auto_mode(False) self.tilt.scroll_down(value) elif switch == JOY_DOWN: self.set_auto_mode(False) self.tilt.scroll_up(value) elif switch == JOY_RIGHT: self.set_auto_mode(False) self.pan.scroll_up(value) elif switch == JOY_LEFT: self.set_auto_mode(False) self.pan.scroll_down(value) elif switch in PAN_SPEED_SWITCHES and value: self.set_auto_mode(False) for sw, speed in zip(PAN_SPEED_SWITCHES, PAN_SPEEDS): self.panel.set_indicator(sw, sw == switch) if sw == switch: self.pan.speed = speed elif switch in TILT_SPEED_SWITCHES and value: self.set_auto_mode(False) for sw, speed in zip(TILT_SPEED_SWITCHES, TILT_SPEEDS): self.panel.set_indicator(sw, sw == switch) if sw == switch: self.tilt.speed = speed elif switch == COLOR_SWITCH: self.set_auto_mode(False) self.panel.set_indicator(switch, value) if value: self.color_index += 1 if self.color_index >= len(COLORS): self.color_index = 0 self.dmx[COLOR_CHANNEL] = COLORS[self.color_index] elif switch == GOBO_SWITCH: self.set_auto_mode(False) self.panel.set_indicator(switch, value) if value: self.gobo_index += 1 if self.gobo_index >= len(GOBOS): self.gobo_index = 0 self.dmx[GOBO_CHANNEL] = GOBOS[self.gobo_index] elif switch == BRIGHTNESS_SWITCH: self.set_auto_mode(False) self.panel.set_indicator(switch, value) self.brightness.scroll(self.brightness_direction, value) if value: self.brightness_direction = -self.brightness_direction elif switch == RESET_SWITCH: self.panel.set_indicator(switch, value) if value: self.set_auto_mode(False) self.brightness.value = 0 self.brightness_direction = 1 self.color_index = 0 self.dmx[COLOR_CHANNEL] = COLORS[0] self.gobo_index = 0 self.dmx[GOBO_CHANNEL] = GOBOS[0] elif switch in AUTO_SWITCHES and value: self.set_auto_mode(True) for sw, mode in zip(AUTO_SWITCHES, AUTO_MODES): self.panel.set_indicator(sw, sw == switch) if sw == switch: self.dmx[AUTO_CHANNEL] = mode def set_auto_mode(self, is_auto): if self.is_auto and not is_auto: self.dmx[AUTO_CHANNEL] = AUTO_DISABLE for switch in AUTO_SWITCHES: self.panel.set_indicator(switch, False) elif not self.is_auto and is_auto: pass self.is_auto = is_auto def update(self): if not self.is_auto: self.dmx.set16(PAN_CHANNEL, self.pan.value / PAN_FULL_SPAN) self.dmx.set16(TILT_CHANNEL, self.tilt.value / TILT_FULL_SPAN) self.dmx[BRIGHTNESS_CHANNEL] = self.brightness.value
print( f"[main][{row}][{widget}] placement: x: {vars()[widget].icon_x} y: {vars()[widget].icon_y}" ) vars()[widget].ci_icon.position = ( vars()[widget].icon_x, vars()[widget].icon_y) vars()[widget].ci_text.position = ( vars()[widget].text_x, vars()[widget].text_y) image_composition.refresh() if vars()[row][0]['scroll']: widget_scroller = widget + "_scroller" scrollers.append(widget_scroller) vars()[widget_scroller] = Scroller( image_composition, vars()[widget].ci_text, 100, synchronizer) # Draw the ImageComposition to the device, adding dividers between rows. with canvas(device, background=image_composition()) as draw: image_composition.refresh() for row in oled_config['arrangement'][0]: row_y = vars()[row][0]['y'] - 2 if row_y > 0: draw.line(((0, row_y), (device.width, row_y)), fill="white", width=1) # trigger an update to the clock widget if necessary. localTime = datetime.now().astimezone(tz.tzlocal()) clockTime = localTime.strftime(
class Playlist(pygame.sprite.Sprite): """ The playlist sprite """ def __init__(self, group, type): pygame.sprite.Sprite.__init__(self, group) self.group = group self.isSelected = False self.speed = 0 self.keystart = 0 self.image = pygame.Surface((600, 50)) self.image = self.image.convert() #self.image.fill((0,0,0)) self.mustRender = True if type == 'path': self.type = 'fs_playlist' else: self.type = 'playlist' self.OpenPlaylist(self.type) self.action = {} # arrow down self.action[274] = self.goDown # arrow up self.action[273] = self.goUp # arrow left self.action[275] = self.BrowseForward # arrow left self.action[276] = self.BrowseBack # a self.action[97] = self.AddToRemoveFromPlaylist #-------------------------------------------------------------------- def SetType(self, type): if self.type == 'playlist': self.type = 'fs_playlist' elif self.type == 'fs_playlist': self.type = 'playlist' #logger.debug5( self.type ) #logger.debug5( self.browser.level ) #logger.debug5( self.browser.browser.level ) self.level = self.type self.browser.BrowserInit(self.level) self.browser.level = self.type self.browser.browser.level = self.type #-------------------------------------------------------------------- def OpenPlaylist(self, level): """Open playlist with self.playlistID""" self.playlistID = playlistID = Database.CreatePlaylist() logger.info("Created new playlist ID = %i" % playlistID) #self.playlistID = playlistID = 26 #self.playlistID = playlistID = 444 #self.playlistID = playlistID = 1170 #if self.level == 'path': level = 'fs_playlist' self.browser = Scroller(self.group, Browser(level, self.playlistID), self.image, 30, BLACK, 28, 20, 500, 200) if self.isSelected: self.SetSelected() self.browser.level = self.browser.browser.level self.browser.rect = (500, 0) self.t_pl = TextSprite(self.group, "Playlist..........", 32, 520, 30, RED) self.title = self.t_pl.UpdateText("Playlist #%i" % self.playlistID) self.browser.Refresh() #self.render() logger.info("Playlist #%i opened!" % self.playlistID) #-------------------------------------------------------------------- def Publish(self, user, label): Database.PublishPlaylist(self.playlistID, user, label) #-------------------------------------------------------------------- def ChangePlaylist(self, color): self.title = self.t_pl.SetColor(color) #-------------------------------------------------------------------- def Refresh(self): self.list = self.browser.list self.browser.Refresh() self.render() #-------------------------------------------------------------------- def goUp(self): self.browser.goUp() self.mustRender = True #-------------------------------------------------------------------- def goDown(self): self.browser.goDown() self.mustRender = True #-------------------------------------------------------------------- def stopMoving(self): self.browser.stopMoving() self.speed = 0.0 self.playlistID = int(round(self.playlistID)) self.render() #-------------------------------------------------------------------- def previous(self): """Move to previous playlist by ID""" self.keystart = time.time() self.playlistID -= 1 self.speed = -1.0 self.OpenPlaylist() self.render() #-------------------------------------------------------------------- def next(self): """Move to next playlist by ID""" self.keystart = time.time() self.playlistID += 1 self.speed = 1.0 self.OpenPlaylist() self.render() #-------------------------------------------------------------------- def BrowseForward(self): self.browser.BrowseForward() #-------------------------------------------------------------------- def BrowseBack(self): self.browser.BrowseBack() #-------------------------------------------------------------------- def AddToRemoveFromPlaylist(self, playlistID): self.browser.AddToRemoveFromPlaylist(self.playlistID) self.browser.Refresh() self.render() #-------------------------------------------------------------------- def Next(self): print self.list[self.selected + 1]['location'] #-------------------------------------------------------------------- def update(self): if self.mustRender: self.render() self.mustRender = False #-------------------------------------------------------------------- def render(self): #self.image.fill(WHITE) self.selected = self.browser.selected # render the playlist browser sprite self.browser.render() # Set playlist title including playlist ID self.image.blit(self.title, (20, 0)) #-------------------------------------------------------------------- def SetFocus(self, state): if state: self.SetSelected() else: self.SetUnSelected() #-------------------------------------------------------------------- def SetSelected(self): self.browser.SetSelected() self.isSelected = True #-------------------------------------------------------------------- def SetUnSelected(self): self.browser.SetUnSelected() self.isSelected = False self.render() #-------------------------------------------------------------------- def loop(self): self.browser.loop() if self.speed and time.time() > self.keystart + DELAY: self.playlistID = self.playlistID + self.speed if (math.fabs(self.speed) < MAXSPEED): self.speed *= ACCELERATION self.OpenPlaylist() self.render()
class MusicBrowser(pygame.sprite.Sprite): """ The music browser sprite """ def __init__(self, group, type): pygame.sprite.Sprite.__init__(self, group) self.group = group self.infotext = [] self.isSelected = False self.speed = 0 self.keystart = 0 self.image = pygame.Surface((300, 300)) self.image = self.image.convert() #self.image.fill((0,100,100)) self.rect = (0, 250) self.mustRender = True if type == 'path': self.level = 'path' elif type == '': self.level = 'labels' elif type == 'labels': self.level = 'labels' else: self.level = 'labels' self.type = type self.BrowserInit() #self.InfopanelInit() self.la = Text("", 28, 570, 50, ORANGE) self.ar = Text("", 28, 570, 50, ORANGE) self.al = Text("", 28, 570, 50, ORANGE) #self.tr = Text("", 28, 570, 50, ORANGE) self.action = {} # arrow down self.action[274] = self.goDown # arrow up self.action[273] = self.goUp # arrow left self.action[275] = self.BrowseForward # arrow left self.action[276] = self.BrowseBack # a self.action[118] = self.AddToRemoveFromPlaylist #-------------------------------------------------------------------- def BrowserInit(self): self.browser = Scroller(self.group, Browser(self.level), self.image, 30, BLACK, 36, 15, 400, 300) self.browser.level = self.browser.browser.level self.browser.rect = (300, 350) if self.isSelected: self.SetSelected() #self.browser.Refresh() #-------------------------------------------------------------------- #def InfopanelInit(self): # self.infopanel = Textbox(self.group, self.infotext, self.image, 10, 30, WHITE, 36, 15, 400,300, False) # self.infopanel.rect = (700,350) #self.browser.Refresh() #-------------------------------------------------------------------- def SetType(self, type): if self.type == 'labels': self.type = 'path' elif self.type == 'path': self.type = 'labels' #logger.debug5( self.type ) #logger.debug5( self.browser.level ) #logger.debug5( self.browser.browser.level ) self.level = self.type self.browser.BrowserInit(self.level) #self.infopanel.BrowserInit([]) self.browser.level = self.type self.browser.browser.level = self.type self.SetLabel("") self.SetArtist("") self.SetAlbum("") self.Refresh() #-------------------------------------------------------------------- def Refresh(self): self.list = self.browser.list self.browser.Refresh() #self.infopanel.BrowserInit([{'name':'otro'}]) #self.infopanel.Refresh() self.mustRender = True #-------------------------------------------------------------------- def goUp(self): self.browser.goUp() self.mustRender = True #-------------------------------------------------------------------- def goDown(self): self.browser.goDown() self.mustRender = True #-------------------------------------------------------------------- def stopMoving(self): self.browser.stopMoving() #-------------------------------------------------------------------- def BrowseForward(self): name = self.browser.list[self.browser.selected]['name'] if self.browser.browser.level == 'artists': self.SetLabel(name) elif self.browser.browser.level == 'albums': self.SetArtist(name) elif self.browser.browser.level == 'tracks': self.SetAlbum(name) self.mustRender = True self.browser.BrowseForward() #-------------------------------------------------------------------- def BrowseBack(self): self.browser.BrowseBack() if self.browser.browser.level == 'artists': self.SetLabel("") elif self.browser.browser.level == 'albums': self.SetArtist("") elif self.browser.browser.level == 'tracks': self.SetAlbum("") self.mustRender = True #-------------------------------------------------------------------- def AddToRemoveFromPlaylist(self, playlistID): self.browser.AddToRemoveFromPlaylist(playlistID) #-------------------------------------------------------------------- def Next(self): print self.list[self.selected + 1]['location'] #-------------------------------------------------------------------- def update(self): if self.mustRender: #self.infopanel.SetText(self.browser.list[self.browser.selected]['info']) #self.infopanel.mustRender = True #self.infopanel.Refresh() self.render() self.mustRender = False #-------------------------------------------------------------------- def render(self): self.image.fill(BLACK) self.selected = self.browser.selected # render the browser sprite #self.browser.mustRender = True self.navigation() self.browser.update() #self.infopanel.update() self.showRelatedImage((60, 100), self.image) #logger.debug5( "self.level: " + self.level) #-------------------------------------------------------------------- def showRelatedImage(self, pos, image): # show related image itemImg = '' if type(self.selected) is int: try: itemImg = self.browser.list[self.selected]['img'] except Exception, e: logger.error("MusicBrowser EXCEPTION: %s" % str(e)) if itemImg != '': imgsrc = ValidateImage(itemImg, self.browser.level) if imgsrc: #logger.debug( "loading image: " + imgsrc ) self.showImage(imgsrc, pos, self.image) else: return True else:
screen_width = 700 screen_height = 500 screen = pygame.display.set_mode([screen_width, screen_height]) # part 2.4: Create a sprite group to hold all the sprites our game is going to have in a variable called all_sprites_list. all_sprites_list = pygame.sprite.Group() # part 2.3: To create a player, create a variable that is set to an instance of the RunnerSprite class. player = Block("Melissa.png") # part 2.5: Add your player to the all_sprites_list. def make_blocks(): all_sprites_list.add(player) # part 1.6a: Using the Scroller class that you imported, make three scrolling backgrounds. any_scroller = Scroller(screen_width, 300, screen_height, (255, 100, 100), 2) # part 1.5a-5b: Write a basic game loop. Make sure to include a way to exit out of the loop while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True # optional: elif event.type == pygame.KEYDOWN: if event.key == pygame.K_r and can_restart: score = 0 lives = 5 level = 1 make_sprites(level) can_restart = False elif event.key == pygame.K_n and next_level:
def test_load_correct_number_of_pieces(self): image = TestScroller.MockImage(30) l = Scroller.load_pieces(image, 90) self.assertEqual(len(l), 3)
if abs(mcp_values[7] - exp1_value) > 15: ldr_value = mcp_values[7] effects.lightsensor(ldr_value) for i in range(len(PUSH_BUTTON_PINS)): push[i] = push_buttons.get_button(i) comm_changes, comm_msg = communication.get() if comm_changes: print "TODO: Do something with %r" % comm_msg # Switch hi-res-mode if push[0] and not pushed_in[0]: hi_res_mode = not hi_res_mode scroller = Scroller('hi' if hi_res_mode else 'lo') scroller.reset() grid.bytes_array(scroller.up()) disp_timer_expiration = now + datetime.timedelta(seconds=2) scroller_timer_expiration = now + datetime.timedelta(seconds=2) disp_needs_updating = True pushed_in[0] = True # Switch 'setting switcher' and 'setting b' if push[1] and not pushed_in[1]: setting_switcher = not setting_switcher scroller = Scroller('set' if setting_switcher else 'b') scroller.reset() grid.bytes_array(scroller.up()) disp_timer_expiration = now + datetime.timedelta(seconds=2) scroller_timer_expiration = now + datetime.timedelta(seconds=SCROLLER_PRE_DELAY)
#!/usr/bin/python import time import datetime from rpstomp import EightByEightPlus from scroller import Scroller pos = 0 grid = EightByEightPlus(address=0x70, brightness=0) scroller = Scroller() while(True): pos += 1 grid.bytes_array(scroller.up()) time.sleep(0.1)
class Playlist(pygame.sprite.Sprite): """ The playlist sprite """ def __init__(self, group, type): pygame.sprite.Sprite.__init__(self, group) self.group = group self.isSelected = False self.speed = 0 self.keystart = 0 self.image = pygame.Surface((600,50)) self.image = self.image.convert() #self.image.fill((0,0,0)) self.mustRender = True if type == 'path': self.type = 'fs_playlist' else: self.type = 'playlist' self.OpenPlaylist(self.type) self.action = {} # arrow down self.action[274] = self.goDown # arrow up self.action[273] = self.goUp # arrow left self.action[275] = self.BrowseForward # arrow left self.action[276] = self.BrowseBack # a self.action[97] = self.AddToRemoveFromPlaylist #-------------------------------------------------------------------- def SetType(self, type): if self.type == 'playlist': self.type = 'fs_playlist' elif self.type == 'fs_playlist': self.type = 'playlist' #logger.debug5( self.type ) #logger.debug5( self.browser.level ) #logger.debug5( self.browser.browser.level ) self.level = self.type self.browser.BrowserInit(self.level) self.browser.level = self.type self.browser.browser.level = self.type #-------------------------------------------------------------------- def OpenPlaylist(self, level): """Open playlist with self.playlistID""" self.playlistID = playlistID = Database.CreatePlaylist() logger.info("Created new playlist ID = %i" % playlistID) #self.playlistID = playlistID = 26 #self.playlistID = playlistID = 444 #self.playlistID = playlistID = 1170 #if self.level == 'path': level = 'fs_playlist' self.browser = Scroller(self.group, Browser(level, self.playlistID), self.image, 30, BLACK, 28, 20, 500,200) if self.isSelected: self.SetSelected() self.browser.level = self.browser.browser.level self.browser.rect = (500,0) self.t_pl = TextSprite(self.group, "Playlist..........", 32, 520, 30, RED) self.title = self.t_pl.UpdateText("Playlist #%i" % self.playlistID) self.browser.Refresh() #self.render() logger.info("Playlist #%i opened!" % self.playlistID) #-------------------------------------------------------------------- def Publish(self, user, label): Database.PublishPlaylist(self.playlistID, user, label) #-------------------------------------------------------------------- def ChangePlaylist(self, color): self.title = self.t_pl.SetColor(color) #-------------------------------------------------------------------- def Refresh(self): self.list = self.browser.list self.browser.Refresh() self.render() #-------------------------------------------------------------------- def goUp(self): self.browser.goUp() self.mustRender = True #-------------------------------------------------------------------- def goDown(self): self.browser.goDown() self.mustRender = True #-------------------------------------------------------------------- def stopMoving(self): self.browser.stopMoving() self.speed = 0.0 self.playlistID = int(round(self.playlistID)) self.render() #-------------------------------------------------------------------- def previous(self): """Move to previous playlist by ID""" self.keystart = time.time() self.playlistID -= 1 self.speed = -1.0 self.OpenPlaylist() self.render() #-------------------------------------------------------------------- def next(self): """Move to next playlist by ID""" self.keystart = time.time() self.playlistID += 1 self.speed = 1.0 self.OpenPlaylist() self.render() #-------------------------------------------------------------------- def BrowseForward(self): self.browser.BrowseForward() #-------------------------------------------------------------------- def BrowseBack(self): self.browser.BrowseBack() #-------------------------------------------------------------------- def AddToRemoveFromPlaylist(self, playlistID): self.browser.AddToRemoveFromPlaylist(self.playlistID) self.browser.Refresh() self.render() #-------------------------------------------------------------------- def Next(self): print self.list[self.selected+1]['location'] #-------------------------------------------------------------------- def update(self): if self.mustRender: self.render() self.mustRender = False #-------------------------------------------------------------------- def render(self): #self.image.fill(WHITE) self.selected = self.browser.selected # render the playlist browser sprite self.browser.render() # Set playlist title including playlist ID self.image.blit(self.title, (20, 0)) #-------------------------------------------------------------------- def SetFocus(self, state): if state: self.SetSelected() else: self.SetUnSelected() #-------------------------------------------------------------------- def SetSelected(self): self.browser.SetSelected() self.isSelected = True #-------------------------------------------------------------------- def SetUnSelected(self): self.browser.SetUnSelected() self.isSelected = False self.render() #-------------------------------------------------------------------- def loop(self): self.browser.loop() if self.speed and time.time() > self.keystart + DELAY: self.playlistID = self.playlistID + self.speed if( math.fabs(self.speed) < MAXSPEED) : self.speed *= ACCELERATION self.OpenPlaylist() self.render()