mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Small improvements everywhere; added info field to the display.
This commit is contained in:
parent
157e3f8a11
commit
ef96359379
1 changed files with 40 additions and 25 deletions
|
|
@ -19,17 +19,19 @@
|
||||||
#
|
#
|
||||||
# Most sound file formats recognized by SOX or SFPLAY are recognized.
|
# Most sound file formats recognized by SOX or SFPLAY are recognized.
|
||||||
# Since conversion is costly, converted files are cached in
|
# Since conversion is costly, converted files are cached in
|
||||||
# /usr/tmp/@j* until the user quits.
|
# /usr/tmp/@j* until the user quits or changes the sampling rate via
|
||||||
|
# the Rate menu.
|
||||||
|
|
||||||
import commands
|
import commands
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
|
from stat import *
|
||||||
import rand
|
import rand
|
||||||
import stdwin
|
import stdwin
|
||||||
from stdwinevents import *
|
from stdwinevents import *
|
||||||
import string
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import sndhdr
|
||||||
|
|
||||||
from WindowParent import WindowParent
|
from WindowParent import WindowParent
|
||||||
from Buttons import PushButton
|
from Buttons import PushButton
|
||||||
|
|
@ -96,13 +98,17 @@ def main():
|
||||||
killchild()
|
killchild()
|
||||||
|
|
||||||
# Entries in Rate menu:
|
# Entries in Rate menu:
|
||||||
rates = ['default', \
|
rates = ['default', '7350', \
|
||||||
'8000', '11025', '16000', '22050', '32000', '41000', '48000']
|
'8000', '11025', '16000', '22050', '32000', '41000', '48000']
|
||||||
|
|
||||||
def maineventloop():
|
def maineventloop():
|
||||||
mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
|
mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP
|
||||||
while G.windows:
|
while G.windows:
|
||||||
|
try:
|
||||||
type, w, detail = event = stdwin.getevent()
|
type, w, detail = event = stdwin.getevent()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
killchild()
|
||||||
|
continue
|
||||||
if w == G.cw.win:
|
if w == G.cw.win:
|
||||||
if type == WE_CLOSE:
|
if type == WE_CLOSE:
|
||||||
return
|
return
|
||||||
|
|
@ -185,14 +191,22 @@ def openlistwindow(dirname):
|
||||||
list.sort()
|
list.sort()
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(list):
|
while i < len(list):
|
||||||
if list[i] == '.' or list[i] == '..':
|
if list[i][0] == '.':
|
||||||
del list[i]
|
del list[i]
|
||||||
else:
|
else:
|
||||||
i = i+1
|
i = i+1
|
||||||
for i in range(len(list)):
|
for i in range(len(list)):
|
||||||
name = list[i]
|
fullname = os.path.join(dirname, list[i])
|
||||||
if os.path.isdir(os.path.join(dirname, name)):
|
if os.path.isdir(fullname):
|
||||||
list[i] = list[i] + '/'
|
info = '/'
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
size = os.stat(fullname)[ST_SIZE]
|
||||||
|
info = `(size + 1023)/1024` + 'k'
|
||||||
|
except IOError:
|
||||||
|
info = '???'
|
||||||
|
info = '(' + info + ')'
|
||||||
|
list[i] = list[i], info
|
||||||
width = maxwidth(list)
|
width = maxwidth(list)
|
||||||
# width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround
|
# width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround
|
||||||
height = len(list) * stdwin.lineheight()
|
height = len(list) * stdwin.lineheight()
|
||||||
|
|
@ -211,8 +225,8 @@ def openlistwindow(dirname):
|
||||||
|
|
||||||
def maxwidth(list):
|
def maxwidth(list):
|
||||||
width = 1
|
width = 1
|
||||||
for name in list:
|
for name, info in list:
|
||||||
w = stdwin.textwidth(name)
|
w = stdwin.textwidth(name + ' ' + info)
|
||||||
if w > width: width = w
|
if w > width: width = w
|
||||||
return width
|
return width
|
||||||
|
|
||||||
|
|
@ -222,8 +236,12 @@ def drawlistwindow(w, area):
|
||||||
d.erase((0, 0), (1000, 10000))
|
d.erase((0, 0), (1000, 10000))
|
||||||
lh = d.lineheight()
|
lh = d.lineheight()
|
||||||
h, v = 0, 0
|
h, v = 0, 0
|
||||||
for name in w.list:
|
for name, info in w.list:
|
||||||
d.text((h, v), name)
|
if info == '/':
|
||||||
|
text = name + '/'
|
||||||
|
else:
|
||||||
|
text = name + ' ' + info
|
||||||
|
d.text((h, v), text)
|
||||||
v = v + lh
|
v = v + lh
|
||||||
showselection(w, d)
|
showselection(w, d)
|
||||||
d.close()
|
d.close()
|
||||||
|
|
@ -257,22 +275,17 @@ def mouselistwindow(w, type, detail):
|
||||||
d.close()
|
d.close()
|
||||||
if type == WE_MOUSE_DOWN and clicks >= 2 and i >= 0:
|
if type == WE_MOUSE_DOWN and clicks >= 2 and i >= 0:
|
||||||
setcursors('watch')
|
setcursors('watch')
|
||||||
name = os.path.join(w.dirname, w.list[i])
|
name, info = w.list[i]
|
||||||
if name[-1:] == '/':
|
fullname = os.path.join(w.dirname, name)
|
||||||
|
if info == '/':
|
||||||
if clicks == 2:
|
if clicks == 2:
|
||||||
G.windows.append(openlistwindow(name[:-1]))
|
G.windows.append(openlistwindow(fullname))
|
||||||
else:
|
else:
|
||||||
playfile(name)
|
playfile(fullname)
|
||||||
setcursors('cross')
|
setcursors('cross')
|
||||||
|
|
||||||
def closelistwindow(w):
|
def closelistwindow(w):
|
||||||
remove(G.windows, w)
|
G.windows.remove(w)
|
||||||
|
|
||||||
def remove(list, item):
|
|
||||||
for i in range(len(list)):
|
|
||||||
if list[i] == item:
|
|
||||||
del list[i]
|
|
||||||
break
|
|
||||||
|
|
||||||
def setcursors(cursor):
|
def setcursors(cursor):
|
||||||
for w in G.windows:
|
for w in G.windows:
|
||||||
|
|
@ -298,7 +311,6 @@ validrates = (8000, 11025, 16000, 22050, 32000, 44100, 48000)
|
||||||
|
|
||||||
def playfile(filename):
|
def playfile(filename):
|
||||||
killchild()
|
killchild()
|
||||||
import sndhdr
|
|
||||||
tuple = sndhdr.what(filename)
|
tuple = sndhdr.what(filename)
|
||||||
raw = 0
|
raw = 0
|
||||||
if tuple:
|
if tuple:
|
||||||
|
|
@ -338,6 +350,10 @@ def playfile(filename):
|
||||||
print cmd
|
print cmd
|
||||||
print 'Exit status', sts
|
print 'Exit status', sts
|
||||||
stdwin.fleep()
|
stdwin.fleep()
|
||||||
|
try:
|
||||||
|
os.unlink(tempname)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
cache[filename] = tempname
|
cache[filename] = tempname
|
||||||
if raw:
|
if raw:
|
||||||
|
|
@ -352,7 +368,6 @@ def playfile(filename):
|
||||||
G.cw.win.settimer(1)
|
G.cw.win.settimer(1)
|
||||||
|
|
||||||
def sfplayraw(filename, tuple):
|
def sfplayraw(filename, tuple):
|
||||||
import sndhdr
|
|
||||||
args = ['-i']
|
args = ['-i']
|
||||||
type, rate, channels, frames, bits = tuple
|
type, rate, channels, frames, bits = tuple
|
||||||
if type == 'ul':
|
if type == 'ul':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue