def __init__(self, panel, position, size, dir): self.panel = panel self.__notify = "Wähle ein Spiel." self.surface = pygame.Surface(size) self.position = position self.dir = '%s/%s' % (os.getcwd(),dir) #List self.list = ScrollList(self.surface, pygame.Rect(LISTPOS)) self.dirList = DirList(dir) self.list.set(self.dirList) #Logo self.logo = pygame.image.load(LOGO) self.logo_position = ((size[0]/2) - (self.logo.get_width()/2), 0) self.__mpdClient = None #key actions self.actions = { "start_game" : self.__startGame }
class PyEmu(): def __init__(self, panel, position, size, dir): self.panel = panel self.__notify = "Wähle ein Spiel." self.surface = pygame.Surface(size) self.position = position self.dir = '%s/%s' % (os.getcwd(),dir) #List self.list = ScrollList(self.surface, pygame.Rect(LISTPOS)) self.dirList = DirList(dir) self.list.set(self.dirList) #Logo self.logo = pygame.image.load(LOGO) self.logo_position = ((size[0]/2) - (self.logo.get_width()/2), 0) self.__mpdClient = None #key actions self.actions = { "start_game" : self.__startGame } def set_mpd_commander(self, commander): self.__mpd_commander = commander def handle_events(self, event): if not keyActions(event, JOYSTICK_ACTIONS, KEYBOARD_ACTIONS, self.actions): #let the list handle the event self.list.handle_event(event) def __startGame(self): game = self.dirList.getList()[self.dirList.selected] print 'Starting Game: ', self.dir+game if self.__mpd_commander: self.__mpd_commander.mute() pygame.quit() os.execlp(EMULATOR,EMULATOR_ARGS, self.dir+game) sys.exit(0) def draw(self, surface): self.panel.notify(self.__notify) self.surface.fill(Color("black")) self.list.draw() self.surface.blit(self.logo, self.logo_position) surface.blit(self.surface, self.position)
def __init__(self, panel, position, size): self.logger = logging.getLogger('controlpanel.pympd') self.panel = panel self.surface = pygame.Surface(size) self.position = position #Set timer for playlist refresh. pygame.time.set_timer(USEREVENT+1, 5000) # Init Buttons self.buttons = {} for button in BUTTONS: self.buttons[button["name"]] = Button(button["inactive"], button["active"] , button["position"]) # Init the playlist view. self.list = ScrollList(self.surface, pygame.Rect(LISTPOS)) self.list.set(Playlist([])) self.commander = Commander() self.__data = Data() self.__commanderThread = CommanderThread(self.commander, self.__data, HOST, PORT) self.__commanderThread.start() # Retrieve current status. self.__updateData() self.__updateButtons() self.commander.unmute() self.__notify = "" #key actions self.actions = { "play" : self.commander.play, "stop" : self.commander.stop, "prev" : self.commander.previous, "next" : self.commander.next, "delete": self.commander.delete, "volume_up" : self.commander.volume_up, "volume_down" : self.commander.volume_down }
class PyMpd(): def __init__(self, panel, position, size): self.logger = logging.getLogger('controlpanel.pympd') self.panel = panel self.surface = pygame.Surface(size) self.position = position #Set timer for playlist refresh. pygame.time.set_timer(USEREVENT+1, 5000) # Init Buttons self.buttons = {} for button in BUTTONS: self.buttons[button["name"]] = Button(button["inactive"], button["active"] , button["position"]) # Init the playlist view. self.list = ScrollList(self.surface, pygame.Rect(LISTPOS)) self.list.set(Playlist([])) self.commander = Commander() self.__data = Data() self.__commanderThread = CommanderThread(self.commander, self.__data, HOST, PORT) self.__commanderThread.start() # Retrieve current status. self.__updateData() self.__updateButtons() self.commander.unmute() self.__notify = "" #key actions self.actions = { "play" : self.commander.play, "stop" : self.commander.stop, "prev" : self.commander.previous, "next" : self.commander.next, "delete": self.commander.delete, "volume_up" : self.commander.volume_up, "volume_down" : self.commander.volume_down } def exit(self): self.logger.debug('send exit command to MPD-client thread.') self.commander.exit() self.logger.debug('waiting for MPD-client thread.') while self.__commanderThread.is_alive(): pass self.logger.debug('MPD-client thread terminated.') del self.__commanderThread del self.commander del self.__data def handle_events(self, event): #Joypad Button down if event.type == USEREVENT+1: pass elif not keyActions(event, JOYSTICK_ACTIONS, KEYBOARD_ACTIONS, self.actions): #let the list handle the event self.list.handle_event(event) return self.__updateData() self.__updateButtons() def __updateData(self): """ Updates the status and the playlist of the MPD server. """ self.commander.update_status() self.commander.update_playlist() self.__updatePlaylist() #Update notification area try: if self.__data.status.state in ("play", "pause"): self.__notify = u"Lautstärke: %s %%" % self.__mpdClient.status.volume else: self.__notify = "" except AttributeError: self.__notify = "" def __updatePlaylist(self): """ Set local playlist to server playlist. """ if self.__data.playlist: self.list.set(self.__data.playlist) def __updateButtons(self): """ Updates all buttons according to their state in the MPD daemon. """ for button in self.buttons.values(): button.active = False try: state = self.__data.status.state if state == 'play': self.buttons['play'].active = True if state == 'stop': self.buttons['stop'].active = True if state == 'pause': self.buttons['pause'].active = True except AttributeError: pass def draw(self, surface): self.panel.notify(self.__notify) #self.surface.fill(Color("black")) for button in self.buttons.values(): button.draw(self.surface) self.list.draw() surface.blit(self.surface, self.position)