audiopy: slightly revamped UI... includes a menubar, no quit button,

and added a `Help' menu item that puts the README (or docstring if
that can't be found) in a scrolling text widget.

README: fixed a few nits
This commit is contained in:
Barry Warsaw 1998-12-03 19:32:38 +00:00
parent 7531d507c1
commit f622a33b29
2 changed files with 102 additions and 17 deletions

View File

@ -1,5 +1,8 @@
audiopy - a program to control the Solaris audio device. audiopy - a program to control the Solaris audio device.
Author: Barry A. Warsaw <bwarsaw@python.org>
Author: Barry Warsaw
Email: bwarsaw@python.org
Version: 0.1
Introduction Introduction
@ -34,7 +37,8 @@ Running as a GUI
Note the underlined characters in the button labels. These Note the underlined characters in the button labels. These
indicate keyboard accelerators so that pressing Alt+character you indicate keyboard accelerators so that pressing Alt+character you
can select that device. For example, Alt-s toggles the Speaker can select that device. For example, Alt-s toggles the Speaker
device. device. The Alt accelerators are the same as those you'd use in
as the short-form command line switches (see below).
Alt-q is also an accelerator for selecting Quit from the File Alt-q is also an accelerator for selecting Quit from the File
menu. menu.

View File

@ -41,6 +41,8 @@ Other options are:
""" """
import sys import sys
import os
import string
import sunaudiodev import sunaudiodev
from SUNAUDIODEV import * from SUNAUDIODEV import *
@ -54,13 +56,34 @@ __version__ = '0.1'
class MainWindow: class MainWindow:
def __init__(self, device): def __init__(self, device):
from Tkinter import * from Tkinter import *
self.__helpwin = None
self.__devctl = device self.__devctl = device
info = device.getinfo() info = device.getinfo()
# #
self.__tkroot = tkroot = Tk(className='Audiopy') self.__tkroot = tkroot = Tk(className='Audiopy')
tkroot.withdraw() tkroot.withdraw()
# create the menubar
menubar = Menu(tkroot)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label='Quit',
command=self.__quit,
accelerator='Alt-Q',
underline=0)
helpmenu = Menu(menubar, name='help', tearoff=0)
helpmenu.add_command(label='About Audiopy...',
command=self.__popup_about,
underline=0)
helpmenu.add_command(label='Help...',
command=self.__popup_using,
underline=0)
menubar.add_cascade(label='File',
menu=filemenu,
underline=0)
menubar.add_cascade(label='Help',
menu=helpmenu,
underline=0)
# now create the top level window # now create the top level window
root = self.__root = Toplevel(tkroot, class_='Audiopy') root = self.__root = Toplevel(tkroot, class_='Audiopy', menu=menubar)
root.protocol('WM_DELETE_WINDOW', self.__quit) root.protocol('WM_DELETE_WINDOW', self.__quit)
root.title('audiopy ' + __version__) root.title('audiopy ' + __version__)
root.iconname('audiopy ' + __version__) root.iconname('audiopy ' + __version__)
@ -70,7 +93,7 @@ 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, sticky='NSEW') frame.grid(row=1, 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.__inputvar = IntVar() self.__inputvar = IntVar()
@ -133,7 +156,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, sticky='NSEW') frame.grid(row=2, 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()
@ -156,10 +179,10 @@ class MainWindow:
variable=self.__headvar, variable=self.__headvar,
onvalue=HEADPHONE, onvalue=HEADPHONE,
command=self.__pushtodev, command=self.__pushtodev,
underline=0) underline=4)
btn.grid(row=1, column=1, sticky=W) btn.grid(row=1, column=1, sticky=W)
root.bind('<Alt-h>', self.__headphones) root.bind('<Alt-p>', self.__headphones)
root.bind('<Alt-H>', self.__headphones) root.bind('<Alt-P>', self.__headphones)
if not info.o_avail_ports & HEADPHONE: if not info.o_avail_ports & HEADPHONE:
btn.configure(state=DISABLED) btn.configure(state=DISABLED)
buttons.append(btn) buttons.append(btn)
@ -186,15 +209,7 @@ class MainWindow:
widest = width widest = width
for b in buttons: for b in buttons:
b.configure(width=widest) b.configure(width=widest)
# # root bindings
# Add quit button
frame = Frame(root)
frame.grid(row=2, column=0, sticky='EW', ipady=5)
btn = Button(frame,
text='Quit',
command=self.__quit,
underline=0)
btn.pack(expand=YES)
root.bind('<Alt-q>', self.__quit) root.bind('<Alt-q>', self.__quit)
root.bind('<Alt-Q>', self.__quit) root.bind('<Alt-Q>', self.__quit)
# #
@ -218,6 +233,23 @@ class MainWindow:
self.__devctl.close() self.__devctl.close()
self.__root.quit() self.__root.quit()
def __popup_about(self, event=None):
import tkMessageBox
tkMessageBox.showinfo('About Audiopy ' + __version__,
'''\
Audiopy %s
Control the Solaris audio device
For information contact
author: Barry A. Warsaw
email : bwarsaw@python.org''' % __version__)
def __popup_using(self, event=None):
if not self.__helpwin:
self.__helpwin = Helpwin(self.__tkroot, self.__quit)
self.__helpwin.deiconify()
def __keepalive(self): def __keepalive(self):
# Exercise the Python interpreter regularly so keyboard interrupts get # Exercise the Python interpreter regularly so keyboard interrupts get
# through. # through.
@ -279,6 +311,55 @@ class MainWindow:
self.__tkroot.mainloop() self.__tkroot.mainloop()
class Helpwin:
def __init__(self, master, quitfunc):
from Tkinter import *
self.__root = root = Toplevel(master, class_='Audiopy')
root.protocol('WM_DELETE_WINDOW', self.__withdraw)
root.title('Audiopy Help Window')
root.iconname('Audiopy Help Window')
root.bind('<Alt-q>', quitfunc)
root.bind('<Alt-Q>', quitfunc)
root.bind('<Alt-w>', self.__withdraw)
root.bind('<Alt-W>', self.__withdraw)
# more elaborate help is available in the README file
readmefile = os.path.join(sys.path[0], 'README')
try:
fp = None
try:
fp = open(readmefile)
contents = fp.read()
# wax the last page, it contains Emacs cruft
i = string.rfind(contents, '\f')
if i > 0:
contents = string.rstrip(contents[:i])
finally:
if fp:
fp.close()
except IOError:
sys.stderr.write("Couldn't open audiopy's README, "
'using docstring instead.\n')
contents = __doc__ % globals()
self.__text = text = Text(root, relief=SUNKEN,
width=80, height=24)
text.insert(0.0, contents)
scrollbar = Scrollbar(root)
scrollbar.pack(fill=Y, side=RIGHT)
text.pack(fill=BOTH, expand=YES)
text.configure(yscrollcommand=(scrollbar, 'set'))
scrollbar.configure(command=(text, 'yview'))
def __withdraw(self, event=None):
self.__root.withdraw()
def deiconify(self):
self.__root.deiconify()
def usage(msg='', code=1): def usage(msg='', code=1):
print __doc__ % globals() print __doc__ % globals()