def __init__(screen): # define function for printing text in a specific place with a specific width and height with a specific colour and border def make_button(text, xpo, ypo, height, width, colour): font=pygame.font.Font(None,28) label=font.render(str(text), 1, (colour)) screen.blit(label,(xpo,ypo)) pygame.draw.rect(screen, blue, (xpo-10,ypo-10,width,height),2) # define function for printing text in a specific place with a specific colour def make_label(text, xpo, ypo, fontsize, colour): font=pygame.font.Font(None,fontsize) label=font.render(str(text), 1, (colour)) screen.blit(label,(xpo,ypo)) # define function that checks for touch location def on_touch(): effect = pygame.mixer.Sound('beep2.ogg') effect.play() # get the position that was touched touch_pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1]) # x_min x_max y_min y_max # button 1 event if 30 <= touch_pos[0] <= 240 and 30 <= touch_pos[1] <=70: button(1) # button 2 event if 260 <= touch_pos[0] <= 470 and 30 <= touch_pos[1] <=70: button(2) # button 3 event if 30 <= touch_pos[0] <= 240 and 71 <= touch_pos[1] <=120: button(3) # button 4 event if 260 <= touch_pos[0] <= 470 and 71 <= touch_pos[1] <=120: button(4) # button 5 event if 30 <= touch_pos[0] <= 240 and 121 <= touch_pos[1] <=170: button(5) # button 6 event if 260 <= touch_pos[0] <= 470 and 121 <= touch_pos[1] <=170: button(6) # button 7 event if 30 <= touch_pos[0] <= 240 and 171 <= touch_pos[1] <=220: button(7) # button 8 event if 260 <= touch_pos[0] <= 470 and 171 <= touch_pos[1] <=220: button(8) # button 9 event if 30 <= touch_pos[0] <= 240 and 221 <= touch_pos[1] <=270: button(9) # button 10 event if 260 <= touch_pos[0] <= 470 and 221 <= touch_pos[1] <=270: button(10) # button 11 event if 30 <= touch_pos[0] <= 240 and 271 <= touch_pos[1] <=320: button(11) # button 12 event if 260 <= touch_pos[0] <= 470 and 271 <= touch_pos[1] <=320: button (12) # PianoBar Next Station def next_station(): command = "echo n >> ~/.config/pianobar/ctl" process = Popen(command.split(), stdout=PIPE) output = process.communicate()[0] return output # Wraper for shell comands def run_cmd(cmd): process = Popen(cmd.split(), stdout=PIPE) output = process.communicate()[0] return output # Define button selection def button(number): cwd = os.getcwd() if number == 1: # Music Data Screen music_data() if number == 2: # Music Data Screen music_data() if number == 3: # Pause Pianobar hotkey = cwd + "/hotkey.sh p" run_cmd(hotkey) if number == 4: # Next Track Pianobar hotkey = cwd + "/hotkey.sh n" run_cmd(hotkey) if number == 5: # Dislike Song hotkey = cwd + "/volumeDown.sh" run_cmd(hotkey) if number == 6: # Like Song hotkey = cwd + "/volumeUp.sh" run_cmd(hotkey) if number == 7: StationSelect = cwd + "/stationSelect.sh 10" run_cmd(StationSelect) if number == 8: StationSelect = cwd + "/stationSelect.sh 11" run_cmd(StationSelect) if number == 9: # Like Song hotkey = cwd + "/hotkey.sh -" run_cmd(hotkey) if number == 10: # Like Song hotkey = cwd + "/hotkey.sh +" run_cmd(hotkey) if number == 11: stations() if number == 12: music_data() # Set up the base menu you can customize your menu with the colors above #set size of the screen size = width, height = 480, 320 #screen = pygame.display.set_mode(size) screen = pygame.display.set_mode((size), pygame.FULLSCREEN ) # First Row #make_button(song(), 30, 30, 40, 215, black) #make_button(artist(), 260, 30, 40, 215, black) # Second Row make_button(" Pause ", 30, 80, 40, 215, menu_color) make_button(" Next ", 260, 80, 40, 215, menu_color) # Third Row make_button(" Volume Down", 30, 130, 40, 215, menu_color) make_button(" Volume Up", 260, 130, 40, 215, menu_color) # Fourth Row make_button(stationlist(10), 30, 180,40, 215, menu_color) make_button(stationlist(11), 260, 180, 40, 215, menu_color) # Fith Row make_button(" DisLike ", 30, 230,40, 215, menu_color) make_button(" Like! ", 260, 230, 40, 215, menu_color) # Sixth Row make_button(" Stations ", 30, 280,40, 215, menu_color) make_button(" Music Data ", 260, 280, 40, 215, menu_color) pygame.display.update() def menu_lable(): lable = song() + ' ... By ... ' + artist() pygame.draw.rect(screen, black, [ 30, 30, 469, 30]) make_button(lable , 30, 30, 40, 445, menu_color) pygame.display.update() clock = pygame.time.Clock() menu_lable() menu_var1 = song() menu_var2 = song() #While loop to manage touch screen inputs while 1: clock.tick(10) if menu_var1 != menu_var2: menu_lable() menu_var1 = menu_var2 else: menu_var2 = song() for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() on_touch() #ensure there is always a safe way to end the program if the touch screen fails if event.type == KEYDOWN: if event.key == K_ESCAPE: sys.exit()
def __init__(screen): # define function for printing text in a specific place with a specific width and height with a specific colour and border def make_button(text, xpo, ypo, height, width, colour): font=pygame.font.Font(None,28) label=font.render(str(text), 1, (colour)) screen.blit(label,(xpo,ypo)) pygame.draw.rect(screen, blue, (xpo-10,ypo-10,width,height),2) # define function for printing text in a specific place with a specific colour def make_label(text, xpo, ypo, fontsize, colour): font=pygame.font.Font(None,fontsize) label=font.render(str(text), 1, (colour)) screen.blit(label,(xpo,ypo)) # Wraper for shell comands def run_cmd(cmd): process = Popen(cmd.split(), stdout=PIPE) output = process.communicate()[0] return output def button(number): # print "You pressed button ",number cwd = os.getcwd() effect = pygame.mixer.Sound('beep2.ogg') effect.play() if number == 1: StationSelect = cwd + "/stationSelect.sh 0" effect.play() run_cmd(StationSelect) if number == 2: StationSelect = cwd + "/stationSelect.sh 1" effect.play() run_cmd(StationSelect) if number == 3: StationSelect = cwd + "/stationSelect.sh 2" effect.play() run_cmd(StationSelect) if number == 4: StationSelect = cwd + "/stationSelect.sh 3" effect.play() run_cmd(StationSelect) if number == 5: StationSelect = cwd + "/stationSelect.sh 4" effect.play() run_cmd(StationSelect) if number == 6: StationSelect = cwd + "/stationSelect.sh 5" effect.play() run_cmd(StationSelect) if number == 7: StationSelect = cwd + "/stationSelect.sh 6" effect.play() run_cmd(StationSelect) if number == 8: StationSelect = cwd + "/stationSelect.sh 7" run_cmd(StationSelect) if number == 9: StationSelect = cwd + "/stationSelect.sh 8" run_cmd(StationSelect) if number == 10: StationSelect = cwd + "/stationSelect.sh 9" run_cmd(StationSelect) if number == 11: main() if number == 12: music_data() # define function that checks for touch location def on_touch(): effect = pygame.mixer.Sound('beep2.ogg') effect.play() # get the position that was touched touch_pos = (pygame.mouse.get_pos() [0], pygame.mouse.get_pos() [1]) # x_min x_max y_min y_max # button 1 event if 30 <= touch_pos[0] <= 240 and 30 <= touch_pos[1] <=70: button(1) # button 2 event if 260 <= touch_pos[0] <= 470 and 30 <= touch_pos[1] <=70: button(2) # button 3 event if 30 <= touch_pos[0] <= 240 and 71 <= touch_pos[1] <=120: button(3) # button 4 event if 260 <= touch_pos[0] <= 470 and 71 <= touch_pos[1] <=120: button(4) # button 5 event if 30 <= touch_pos[0] <= 240 and 121 <= touch_pos[1] <=170: button(5) # button 6 event if 260 <= touch_pos[0] <= 470 and 121 <= touch_pos[1] <=170: button(6) # button 7 event if 30 <= touch_pos[0] <= 240 and 171 <= touch_pos[1] <=220: button(7) # button 8 event if 260 <= touch_pos[0] <= 470 and 171 <= touch_pos[1] <=220: button(8) # button 9 event if 30 <= touch_pos[0] <= 240 and 221 <= touch_pos[1] <=270: button(9) # button 10 event if 260 <= touch_pos[0] <= 470 and 221 <= touch_pos[1] <=270: button(10) # button 11 event if 30 <= touch_pos[0] <= 240 and 271 <= touch_pos[1] <=320: button(11) # button 12 event if 260 <= touch_pos[0] <= 470 and 271 <= touch_pos[1] <=320: button (12) # Set up the base menu you can customize your menu with the colors above #set size of the screen size = width, height = 480, 320 screen = pygame.display.set_mode((size), pygame.FULLSCREEN ) # Set Screen Setting for PC Window #screen = pygame.display.set_mode((size)) # Background Color screen.fill(black) # Buttons and labels # First Row make_button(stationlist(0), 30, 30, 40, 215, blue) make_button(stationlist(1), 260, 30, 40, 215, blue) # Second Row make_button(stationlist(2), 30, 80, 40, 215, blue) make_button(stationlist(3), 260, 80, 40, 215, blue) # Third Row make_button(stationlist(4), 30, 130, 40, 215, blue) make_button(stationlist(5), 260, 130, 40, 215, blue) # Fourth Row make_button(stationlist(6), 30, 180,40, 215, blue) make_button(stationlist(7), 260, 180, 40, 215, blue) # Fith Row make_button(stationlist(8), 30, 230,40, 215, blue) make_button(stationlist(9), 260, 230, 40, 215, blue) # Sixth Row make_button(" Main Menu ", 30, 280,40, 215, blue) make_button("Music Data ", 260, 280, 40, 215, blue) #update screen pygame.display.update() # always use a Clock to keep your framerate constant clock = pygame.time.Clock() # While loop to manage touch screen inputs while 1: clock.tick(10) for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: pos = pygame.mouse.get_pos() on_touch() #ensure there is always a safe way to end the program if the touch screen fails if event.type == KEYDOWN: if event.key == K_ESCAPE: sys.exit()