class GUI(Tk): def __init__(self): Tk.__init__(self) self.title("App") self.geometry("600x500") self.main_menu = Main_menu(self) self.main_menu.pack(fill=BOTH, expand=1)
'right': pygame.K_RIGHT, 'up': pygame.K_UP, 'down': pygame.K_DOWN, 'fire': pygame.K_SPACE, 'left2': pygame.K_a, 'right2': pygame.K_d, 'up2': pygame.K_w, 'down2': pygame.K_s, 'acidspit': pygame.K_RETURN } # Font setup debug_font = pygame.font.SysFont("Courier", 12) # Sprite setup main_menu = Main_menu(WIDTH, HEIGHT) # Game initialisation ends # Event timers # Generate time-based events def generate_time_based_events(): ms_elapsed = pygame.time.get_ticks() # Check whether we should trigger any of the events for event_type, event_props in events.items(): if ms_elapsed / event_props["interval"] > event_props["count"]: new_event = pygame.event.Event(pygame.USEREVENT, {"subtype": event_type}) pygame.event.post(new_event)
def setUp(self): self.main_menu = Main_menu()
def open_main_menu(self): self.close=self.close_main_menu self.frame=Main_menu(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open()
def open_gaming(self): self.close=self.close_gaming self.frame=GFrame(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open()
def open_game_setup(self): self.close=self.close_game_setup self.frame=Game_setup(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open()
class Screen(DirectObject): ''' the screen manipulates Frames (subclasses of) that present stuff to the user. ''' sgn_intro_done='screen.intro_done' sgn_main_menu_join='screen.sgn_main_menu_join' sgn_main_menu_create='screen.sgn_main_menu_create' def __init__(self): DirectObject.__init__(self) self.close=lambda:None #create main window base=ShowBase() __builtin__.base=base props = WindowProperties() #props.setTitle(ConfigVariableString('win-title').getValue()) props.setFullscreen(ConfigVariableBool('fullscreen').getValue()) props.setSize(ConfigVariableInt('win-width').getValue(),ConfigVariableInt('win-height').getValue()) base.win.requestProperties(props) self.width=base.win.getXSize() self.height=base.win.getYSize() print 'size=',self.width,'x',self.height self.accept('window-event',self.on_resize) base.disableMouse() #set fps limit globalClock=ClockObject.getGlobalClock() globalClock.setMode(ClockObject.MLimited) globalClock.setFrameRate(ConfigVariableDouble('clock-frame-rate').getValue()) __builtin__.screen=self __builtin__.gui=pixel2d.attachNewNode('Screen.gui') #gui is the node for 2d rendering, scaled to the screen resolution, #with origin at bottom-left, and max at top-right gui.setZ(gui,-self.height) __builtin__.console=Console(print_messenger_events=False) __builtin__.out=console.out console.request('Open') __builtin__.mouse=base.pointerWatcherNodes[0] #is used as a stack. stores frames showed to the user (top at the front of the screen) self.frames=[] def on_resize(self,graphicswindow): self.width,self.height=graphicswindow.getXSize(),graphicswindow.getYSize() gui.setZ(-self.height) if len(self.frames): self.frame.size=self.width,self.height def open_game_setup(self): self.close=self.close_game_setup self.frame=Game_setup(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open() def close_game_setup(self): self.frame.close() self.frame=None self.frames.pop(-1) def open_gaming(self): self.close=self.close_gaming self.frame=GFrame(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open() def close_gaming(self): pass def open_intro(self): self.close=self.close_intro self.intro_message=OnscreenText(text='intro',style=1,fg=(1,1,1,1),pos=(.87,-.95),scale=.07) taskMgr.doMethodLater(ConfigVariableDouble('intro-delay').getValue(),messenger.send,Screen.sgn_intro_done, extraArgs = [Screen.sgn_intro_done]) def close_intro(self): self.intro_message.destroy() del self.intro_message def open_main_menu(self): self.close=self.close_main_menu self.frame=Main_menu(w=self.width,h=self.height) self.frames.append(self.frame) self.frame.open() def close_main_menu(self): self.frame.close() self.frame=None self.frames.pop(-1)
def start_app(): print("Please enter name of user:"******"> ") player = SongPlayer(player_name) menu = Main_menu() print("At any time, if you want to exit this program,") print("simply enter 'x' when prompted.") print("Is there a method that you would like to be able") print("to use to search your songs other than by song?") print("I.e. artist, genre, album, etc.") print("Please enter the method or enter 'no'") method_type = input("> ") player.end_program(method_type) if method_type != "no": player.create_playlist(method_type) # Making it so it will work regardless of songs in song_files, but then can't make classes for each song # containing various attributes like artist and genre based only on the mp3 files' names. # I would need more data than just the files, especially since these files will most likely be # downloaded from youtube. The data in files obtained legit contain that data. user_input = menu.menu(method_type) player.end_program(user_input) while user_input != 'x' or user_input != "X": if user_input == "1": player.play_playlist("all_songs") user_input = menu.menu(method_type) player.end_program(user_input) elif user_input == "2": print("What would you like to name your new playlist?") new_playlist = input("> ") player.end_program(new_playlist) player.create_playlist(new_playlist) user_input = menu.menu(method_type) player.end_program(user_input) # must input name of playlist w/o .txt elif user_input == "3": print("Please enter name of desired playlist:") playlist_name = input("> ") player.end_program(playlist_name) player.play_playlist(playlist_name) elif user_input == "4": print("To what playlist do you want to add a song?") playlist_add_to = input("> ") player.end_program(playlist_add_to) print("What song would you like to add to", playlist_add_to + "?") song_name = input("> ") player.end_program(song_name) player.add_to_playlist(playlist_add_to, song_name) elif user_input == "5": print("What song would you like to search for?") song_name = input("> ") player.end_program(song_name) song_search_file = open("playlists/all_songs.txt", "r") for line in song_search_file: if song_name in line: player.play_song(line) print("Enter 1 to pause, 2 to stop, 3 to skip, 4 to like") user_input = input("> ") player.end_program(user_input) if user_input == 1: mixer.music.pause() elif user_input == 2: mixer.music.stop() break elif user_input == 3: mixer.music.stop() elif user_input == 4: player.like_song(line) break elif user_input == "6": print("All inputted songs matching", method_type, "are listed below.") method_playlist_file = open("playlist/" + method_type + ".txt", "r") for line in method_playlist_file: print(line) print( "Please enter name of song you would like to listen to, or enter 'play all'" ) song_name = input("> ") player.end_program(song_name) if song_name == "play all": player.play_playlist(method_type) else: player.play_song(song_name)
from main_menu import Main_menu app = Main_menu()