I wrote a Python MP3 player for Linux using PyGame, with a curses GUI and a mouse-only interface.
It's purely for personal use.
It hasn't been polished yet, but for now I'd like to know what I've done inefficiently so I can fill in some ignorance-holes. I know a few things could be handled more directly.
import curses
import pygame
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
player = pygame.mixer.music
song = "testshort.mp3"
player.load(song)
player.play()
screen = curses.initscr()
curses.noecho()
curses.mousemask(curses.ALL_MOUSE_EVENTS)
screen.keypad(1)
curses.curs_set(0)
screen.resize(6, 30)
screen.border(0)
screen.addstr(4, 19, "*"*5+"-"*5)
player.set_volume(0.5)
screen.addstr(4, 2, "|")
paused = 0
curses.halfdelay(1)
while True:
busycheck = player.get_busy()
if busycheck == 0:
screen.addstr(4, 2, ">")
char = screen.getch()
if char == curses.KEY_MOUSE:
cords = list(curses.getmouse())
mouse_x = cords[1]
mouse_y = cords[2]
vol_on = mouse_x - 18
vol_off = 10 - vol_on
screen.border(0)
if mouse_y == 4:
if 29 > mouse_x > 18:
vol_bar = screen.addstr(4, 19, "*"*vol_on+"-"*vol_off)
volchange = (mouse_x-19)/9.0
player.set_volume(volchange)
elif mouse_x == 2:
if paused == 0:
if busycheck == 1:
screen.addstr(4, 2, ">")
player.pause()
paused = 1
else:
player.play()
paused = 0
screen.addstr(4, 2, "|")
else:
player.unpause()
screen.addstr(4, 2, "|")
paused = 0