Kaydet (Commit) e77ec175 authored tarafından Barry Warsaw's avatar Barry Warsaw

Rewrite, simplification of command line option parsing. Many GUI

fixes.  Input sources are mutually exclusive.
üst 4a1cdd7f
...@@ -61,14 +61,14 @@ class MainWindow: ...@@ -61,14 +61,14 @@ class MainWindow:
# #
# where does input come from? # where does input come from?
frame = Frame(root, bd=1, relief=RAISED) frame = Frame(root, bd=1, relief=RAISED)
frame.grid(row=0, column=0) frame.grid(row=0, column=0, sticky='NSEW')
label = Label(frame, text='Input From:') label = Label(frame, text='Input From:')
label.grid(row=0, column=0, sticky=E) label.grid(row=0, column=0, sticky=E)
self.__micvar = IntVar() self.__inputvar = IntVar()
btn = Checkbutton(frame, btn = Radiobutton(frame,
text='Microphone', text='Microphone',
variable=self.__micvar, variable=self.__inputvar,
onvalue=MICROPHONE, value=MICROPHONE,
command=self.__pushtodev, command=self.__pushtodev,
underline=0) underline=0)
btn.grid(row=0, column=1, sticky=W) btn.grid(row=0, column=1, sticky=W)
...@@ -78,11 +78,10 @@ class MainWindow: ...@@ -78,11 +78,10 @@ class MainWindow:
btn.configure(state=DISABLED) btn.configure(state=DISABLED)
buttons.append(btn) buttons.append(btn)
## ##
self.__lineinvar = IntVar() btn = Radiobutton(frame,
btn = Checkbutton(frame,
text='Line In', text='Line In',
variable=self.__lineinvar, variable=self.__inputvar,
onvalue=LINE_IN, value=LINE_IN,
command=self.__pushtodev, command=self.__pushtodev,
underline=5) underline=5)
btn.grid(row=1, column=1, sticky=W) btn.grid(row=1, column=1, sticky=W)
...@@ -92,11 +91,10 @@ class MainWindow: ...@@ -92,11 +91,10 @@ class MainWindow:
btn.configure(state=DISABLED) btn.configure(state=DISABLED)
buttons.append(btn) buttons.append(btn)
## ##
self.__cdvar = IntVar() btn = Radiobutton(frame,
btn = Checkbutton(frame,
text='CD', text='CD',
variable=self.__cdvar, variable=self.__inputvar,
onvalue=CD, value=CD,
command=self.__pushtodev, command=self.__pushtodev,
underline=0) underline=0)
btn.grid(row=2, column=1, sticky=W) btn.grid(row=2, column=1, sticky=W)
...@@ -108,7 +106,7 @@ class MainWindow: ...@@ -108,7 +106,7 @@ class MainWindow:
# #
# where does output go to? # where does output go to?
frame = Frame(root, bd=1, relief=RAISED) frame = Frame(root, bd=1, relief=RAISED)
frame.grid(row=1, column=0) frame.grid(row=1, column=0, sticky='NSEW')
label = Label(frame, text='Output To:') label = Label(frame, text='Output To:')
label.grid(row=0, column=0, sticky=E) label.grid(row=0, column=0, sticky=E)
self.__spkvar = IntVar() self.__spkvar = IntVar()
...@@ -181,10 +179,8 @@ class MainWindow: ...@@ -181,10 +179,8 @@ class MainWindow:
except AttributeError: except AttributeError:
pass pass
else: else:
import struct
import fcntl import fcntl
import signal import signal
import FCNTL
import STROPTS import STROPTS
# set up the signal handler # set up the signal handler
signal.signal(signal.SIGPOLL, self.__update) signal.signal(signal.SIGPOLL, self.__update)
...@@ -207,21 +203,19 @@ class MainWindow: ...@@ -207,21 +203,19 @@ class MainWindow:
# underlying module does not support the SIGPOLL notification # underlying module does not support the SIGPOLL notification
# interface. # interface.
info = self.__devctl.getinfo() info = self.__devctl.getinfo()
# input
self.__inputvar.set(info.i_port)
# output
self.__spkvar.set(info.o_port & SPEAKER) self.__spkvar.set(info.o_port & SPEAKER)
self.__headvar.set(info.o_port & HEADPHONE) self.__headvar.set(info.o_port & HEADPHONE)
self.__linevar.set(info.o_port & LINE_OUT) self.__linevar.set(info.o_port & LINE_OUT)
self.__micvar.set(info.i_port & MICROPHONE)
self.__lineinvar.set(info.i_port & LINE_IN)
self.__cdvar.set(info.i_port & CD)
def __pushtodev(self, event=None): def __pushtodev(self, event=None):
info = self.__devctl.getinfo() info = self.__devctl.getinfo()
info.o_port = self.__spkvar.get() + \ info.o_port = self.__spkvar.get() + \
self.__headvar.get() + \ self.__headvar.get() + \
self.__linevar.get() self.__linevar.get()
info.i_port = self.__micvar.get() + \ info.i_port = self.__inputvar.get()
self.__lineinvar.get() + \
self.__cdvar.get()
self.__devctl.setinfo(info) self.__devctl.setinfo(info)
def __getset(self, var, onvalue): def __getset(self, var, onvalue):
...@@ -232,15 +226,13 @@ class MainWindow: ...@@ -232,15 +226,13 @@ class MainWindow:
self.__pushtodev() self.__pushtodev()
def __mic(self, event=None): def __mic(self, event=None):
self.__getset(self.__micvar, MICROPHONE) self.__getset(self.__inputvar, MICROPHONE)
def __linein(self, event=None): def __linein(self, event=None):
self.__getset(self.__lineinvar, LINE_IN) self.__getset(self.__inputvar, LINE_IN)
def __cd(self, event=None): def __cd(self, event=None):
print 'pre:', self.__cdvar.get() self.__getset(self.__inputvar, CD)
self.__getset(self.__cdvar, CD)
print 'post:', self.__cdvar.get()
def __speaker(self, event=None): def __speaker(self, event=None):
self.__getset(self.__spkvar, SPEAKER) self.__getset(self.__spkvar, SPEAKER)
...@@ -286,113 +278,47 @@ def main(): ...@@ -286,113 +278,47 @@ def main():
('--speaker', '-s', 1, SPEAKER), ('--speaker', '-s', 1, SPEAKER),
('--lineout', '-o', 1, LINE_OUT), ('--lineout', '-o', 1, LINE_OUT),
) )
values = []
info = device.getinfo() info = device.getinfo()
# first get the existing values # first get the existing values
for long, short, io, mask in options:
if io == 0:
flags = info.i_port
else:
flags = info.o_port
values.append(flags & mask)
sval = None
hval = None
lval = None
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg in ('-h', '--help'): if arg in ('-h', '--help'):
usage(code=0) usage(code=0)
# SPEAKER # does not return
elif arg in ('-s', '--speaker'): for long, short, io, mask in options:
sval = -1 if arg in (long, short):
elif arg[:3] == '-s=': # toggle the option
try: if io == 0:
sval = int(arg[3:]) info.i_port = info.i_port ^ mask
except ValueError: else:
pass info.o_port = info.o_port ^ mask
if sval <> 0 and sval <> 1: break
usage('Invalid option: ' + arg) val = None
elif arg[:10] == '--speaker=':
try:
sval = int(arg[10:])
except ValueError:
pass
if sval <> 0 and sval <> 1:
usage('Invalid option: ' + arg)
# HEADPHONES
elif arg in ('-p', '--headphones'):
hval = -1
elif arg[:3] == '-p=':
try:
hval = int(arg[3:])
except ValueError:
pass
if hval <> 0 and hval <> 1:
usage('Invalid option: ' + arg)
elif arg[:13] == '--headphones=':
try:
hval = int(arg[130:])
except ValueError:
pass
if hval <> 0 and hval <> 1:
usage('Invalid option: ' + arg)
# LINEOUT
elif arg in ('-l', '--lineout'):
lval = -1
elif arg[:3] == '-l=':
try:
lval = int(arg[3:])
except ValueError:
pass
if lval <> 0 and lval <> 1:
usage('Invalid option: ' + arg)
elif arg[:10] == '--lineout=':
try: try:
lval = int(arg[10:]) if arg[:len(long)+1] == long+'=':
val = int(arg[len(long)+1:])
elif arg[:len(short)+1] == short+'=':
val = int(arg[len(short)+1:])
except ValueError: except ValueError:
pass usage(msg='Invalid option: ' + arg)
if lval <> 0 and lval <> 1: # does not return
usage('Invalid option: ' + arg) if val == 0:
else: if io == 0:
usage('Invalid option: ' + arg) info.i_port = info.i_port & ~mask
# now set the values
try:
devctl = sunaudiodev.open('control')
info = devctl.getinfo()
if sval is not None:
if sval == -1:
if info.o_port & SPEAKER:
sval = 0
else: else:
sval = SPEAKER info.o_port = info.o_port & ~mask
else: break
sval = sval * SPEAKER elif val == 1:
else: if io == 0:
sval = info.o_port & SPEAKER info.i_port = info.i_port | mask
if hval is not None:
if hval == -1:
if info.o_port & HEADPHONE:
hval = 0
else: else:
hval = HEADPHONE info.o_port = info.o_port | mask
else: break
hval = hval * HEADPHONE # else keep trying next option
else: else:
hval = info.o_port & HEADPHONE usage(msg='Invalid option: ' + arg)
if lval is not None: # now set the values
if lval == -1: device.setinfo(info)
if info.o_port & LINE_OUT: device.close()
lval = 0
else:
lval = LINE_OUT
else:
lval = lval * LINE_OUT
else:
lval = info.o_port & LINE_OUT
info.o_port = sval + hval + lval
devctl.setinfo(info)
finally:
devctl.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment