21 if (str == "MAGENTA"):
27 if (str == "BLACK_GREEN"):
29 if (str == "BLACK_CYAN"):
31 if (str == "BLACK_RED"):
34 def GetFileTy(dirname, fileName):
35 if (dirname == '/kroot/media_unmount'):
37 elif (os.path.isdir(dirname + fileName)):
40 periodNum = string.rfind(fileName, '.')
43 extension = fileName[periodNum:].lower()
44 if extension == '.sh': return 'script'
45 elif extension == '.mp3': return 'music'
46 elif extension == '.mov': return 'movie'
47 elif extension == '.iso': return 'movieiso'
48 elif extension == '.divx': return 'movie'
49 elif extension == '.mpg': return 'movie'
50 elif extension == '.mp4': return 'movie'
51 elif extension == '.vob': return 'movie'
52 elif extension == '.avi': return 'movie'
53 elif extension == '.nes': return 'nes'
54 elif extension == '.smc': return 'snes'
55 elif extension == '.wav': return 'music'
58 def UseFile(filePath, fileTy):
60 if fileTy == "script":
61 os.spawnl(os.P_WAIT, filePath, filePath)
62 elif fileTy == "music":
63 os.spawnl(os.P_NOWAIT, "/usr/bin/xmms", "/usr/bin/xmms", filePath)
64 elif fileTy == "movie":
65 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-v", "85");
66 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-w", "89");
67 os.spawnl(os.P_WAIT, "/usr/local/bin/mplayer", "/usr/local/bin/mplayer", filePath);
68 elif fileTy == "movieiso":
69 os.spawnl(os.P_WAIT, "/usr/local/bin/mplayer", "/usr/local/bin/mplayer", filePath);
71 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-v", "65");
72 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-w", "65");
74 os.spawnl(os.P_NOWAIT, ines_path, ines_path,\
75 "-ntsc", "-uperiod", "1", "-sync", "60", filePath) #"-nosound",
76 #start the program that converts joystick presses to keypresses
77 os.spawnl(os.P_WAIT, joy2keyy_path, joy2keyy_path, "iNES Unix/X 3.0")
78 elif fileTy == "snes":
79 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-v", "65");
80 os.spawnl(os.P_WAIT, "/usr/bin/aumix", "/usr/bin/aumix", "-w", "65");
81 os.spawnl(os.P_WAIT, "/usr/bin/snes9x", "/usr/bin/snes9x", \
83 "-joydev1", "/dev/input/js0",\
84 "-joymap1", "1", "0", "3", "2", "10", "11", "5", "4",\
85 "-joydev2", "/dev/input/js1",\
86 "-joymap2", "1", "0", "3", "2", "10", "11", "5", "4",\
87 filePath); #'"' +filePath + '"')
88 #"-joymap1", "1", "2", "0", "3", "10", "11", "5", "4",\
89 #"-joymap2", "1", "2", "0", "3", "10", "11", "5", "4",\
96 curses.nocbreak(); stdscr.keypad(0); curses.echo()
103 stdscr = curses.initscr()
109 curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_BLACK)
110 curses.init_pair(1,curses.COLOR_BLUE, curses.COLOR_BLACK)
111 curses.init_pair(2,curses.COLOR_GREEN, curses.COLOR_BLACK)
112 curses.init_pair(3,curses.COLOR_CYAN, curses.COLOR_BLACK)
113 curses.init_pair(4,curses.COLOR_RED, curses.COLOR_BLACK)
114 curses.init_pair(5,curses.COLOR_MAGENTA, curses.COLOR_BLACK)
115 curses.init_pair(6,curses.COLOR_YELLOW, curses.COLOR_BLACK)
116 curses.init_pair(7,curses.COLOR_WHITE, curses.COLOR_BLACK)
117 curses.init_pair(12,curses.COLOR_BLACK, curses.COLOR_GREEN)
118 curses.init_pair(13,curses.COLOR_BLACK, curses.COLOR_CYAN)
119 curses.init_pair(14,curses.COLOR_BLACK, curses.COLOR_RED)
133 global boostX, topFileNum
134 global numSongsOnScreen
141 #curses initialization
145 mplayer_path = "/usr/bin/mplayer"
146 ines_path = "/usr/bin/ines"
147 joy2keyy_path ="/home/tvman/bin/joy2keyy"
149 #variable initialization
151 boostX, topFileNum = (0,0)
152 maxY, maxX = stdscr.getmaxyx()
153 numSongsOnScreen = maxY - 2 - 2
159 # print numSongsOnScreen;
162 #pad = curses.newpad(100, 100)
164 #These loops fill the pad with letters; this is
165 #explained in the next section
166 # for y in range(0, 100):
167 # for x in range(0, 100):
168 # try: stdscr.addch(y,x, ord('a') + (x*x+y*y) % 26 )
169 # except curses.error: pass
171 # s = curses.newwin(5,10,2,1)
178 stdscr.addstr(0, 0, "*" * (maxX - 1))
179 stdscr.addstr(1, 0, " " * 32 + "Welcome to Korhal")
180 stdscr.addstr(2, 0, "*" * (maxX - 1))
181 stdscr.addstr(maxY - 1, 0, "*" * (maxX - 1))
182 for f in dircache.listdir(curdir)[topFileNum:]:
183 if (y + topFileNum == highNum):
184 stdscr.addstr(2+y+1, 1, f[:maxX-1], curses.A_STANDOUT)
186 fileTy = GetFileTy(curdir, f)
187 if (fileTy == "script"): color = "RED"
188 elif (fileTy == "mp3"): color = "GREEN"
189 elif (fileTy == "dir"): color = "BLUE"
190 elif (fileTy == "movie"): color = "YELLOW"
191 elif (fileTy == "movieiso"): color = "YELLOW"
192 elif (fileTy == "nes"): color = "MAGENTA"
193 elif (fileTy == "snes"): color = "MAGENTA"
194 else: color = "WHITE"
195 stdscr.addstr(2+y+1, 1, f[:maxX-1], \
196 curses.color_pair(MyColor(color)))
198 if (y == numSongsOnScreen):
206 highNum = highNum - i
209 if (highNum < topFileNum):
217 highNum = highNum + i
218 if highNum >= len(dircache.listdir(curdir)):
219 highNum = len(dircache.listdir(curdir)) - 1
220 if (highNum >= topFileNum + numSongsOnScreen):
221 topFileNum = highNum - (numSongsOnScreen - 1)
227 # global sleepingFile
230 # stdscr.addstr(int(maxY / 2), 1, "Now Playing \"" + s + "\"")
232 # if (sleepingFile == s):
233 # #if this is the player process we put to sleep earlier,
235 # os.spawnl(os.P_WAIT, '/usr/bin/kill', '/usr/bin/kill',
236 # '-s', 'SIGCONT', str(sleepingPid))
239 # #kill any lingering sleeping player that might exist
240 # if (sleepingPid != -1):
241 # os.spawnl(os.P_WAIT, '/usr/bin/kill', '/usr/bin/kill',
242 # '-s', 'SIGCONT', str(sleepingPid))
243 # os.spawnl(os.P_WAIT, '/usr/bin/kill', '/usr/bin/kill',
244 # '-s', 'SIGTERM', str(sleepingPid))
254 # os.execl(mpg123path, mpg123path, "-o", "esd", s)
255 # #stdscr = curses.initscr()
263 # (_,waitret) = os.waitpid(pid, os.WNOHANG)
266 # #if (os.WIFEXITED(waitret) or os.WIFSIGNALED(waitret)):
268 # #Mpg123 process has exited; break from this loop
269 # #and treat this keypress as if it had happened in the main
272 # if (c == ord('q')):
273 # os.spawnl(os.P_WAIT, '/usr/bin/kill', '/usr/bin/kill', str(pid))
278 # #stdscr.addstr(int(maxY / 2), 1, "/usr/bin/kill"+str(pid))
279 # #os.spawnl('/usr/bin/kill', '/usr/bin/kill', str(pid))
281 # elif (c == ord(' ')):
284 # os.spawnl(os.P_WAIT, '/usr/bin/kill', '/usr/bin/kill',
285 # '-s', 'SIGSTOP', str(sleepingPid))
288 #Displays a section of the pad in the middle of the screen
289 #pad.refresh( 0,0, 5,5, 20,75)
290 # dirl = dircache.listdir(curdir)
291 # stdscr.addstr(1, 1, curdir + dirl[2], curses.A_STANDOUT)
296 nextc = stdscr.getch()
297 #if nextc == ord('q'):
300 if nextc == curses.KEY_UP:
302 elif nextc == curses.KEY_DOWN:
304 elif nextc == curses.KEY_PPAGE:
305 MoveUp(numSongsOnScreen)
306 elif nextc == curses.KEY_NPAGE:
307 MoveDown(numSongsOnScreen)
308 elif nextc == ord(' '):
309 MoveDown(int(numSongsOnScreen / 2))
310 elif nextc == ord('a'):
311 fileName = dircache.listdir(curdir)[highNum]
312 path = curdir + fileName
313 UseFile(path, "music")
314 elif nextc == 10 or nextc == curses.KEY_RIGHT:
315 #Special case: if the current directory contains no items,
317 if (dircache.listdir(curdir) != []):
318 fileName = dircache.listdir(curdir)[highNum]
319 path = curdir + fileName
320 fileTy = GetFileTy(curdir, fileName)
321 if (fileTy == 'umount_dir'):
322 os.execl("umount", "umount", path)
323 os.execl("eject", "eject", path)
324 elif (fileTy == 'dir'):
329 UseFile(path, fileTy)
331 elif nextc == curses.KEY_LEFT:
332 highSlash = string.rfind(curdir[:-1], "/")
334 ncurdir = curdir[0:highSlash+1]
338 #Only really change the directory if we haven't
339 #stepped out of the kroot area
340 hasRoot = string.find(ncurdir, "/b/")
350 traceback.print_exc()