diff options
| author | Skip Montanaro <[email protected]> | 2021-02-16 20:14:16 -0600 |
|---|---|---|
| committer | Skip Montanaro <[email protected]> | 2021-02-16 20:14:16 -0600 |
| commit | c2587c76f1b416cdbecb979e54941933246bf856 (patch) | |
| tree | bb61ee9128075ce22af4eafa232f13c2e5a07896 | |
| parent | d90761a005b24018ae237bf551515772a1de656f (diff) | |
| download | python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.tar.xz python-0.9.1-patched-QoL-c2587c76f1b416cdbecb979e54941933246bf856.zip | |
starting over
239 files changed, 27034 insertions, 27056 deletions
@@ -5,43 +5,43 @@ This is version 0.9 (the first beta release), patchlevel 1. Python can be used instead of shell, Awk or Perl scripts, to write prototypes of real applications, or as an extension language of large -systems, you name it. There are built-in modules that interface to +systems, you name it. There are built-in modules that interface to the operating system and to various window systems: X11, the Mac window system (you need STDWIN for these two), and Silicon Graphics' -GL library. It runs on most modern versions of UNIX, on the Mac, and -I wouldn't be surprised if it ran on MS-DOS unchanged. I developed it +GL library. It runs on most modern versions of UNIX, on the Mac, and +I wouldn't be surprised if it ran on MS-DOS unchanged. I developed it mostly on an SGI IRIS workstation (using IRIX 3.1 and 3.2) and on the Mac, but have tested it also on SunOS (4.1) and BSD 4.3 (tahoe). Building and installing Python is easy (but do read the Makefile). A UNIX style manual page and extensive documentation (in LaTeX format) -are provided. (In the beta release, the documentation is still under +are provided. (In the beta release, the documentation is still under development.) Please try it out and send me your comments (on anything -- the language design, implementation, portability, installation, documentation) and the modules you wrote for it, to make the first -real release better. If you needed to hack the source to get it to +real release better. If you needed to hack the source to get it to compile and run on a particular machine, send me the fixes -- I'll try -to incorporate them into the next patch. If you can't get it to work +to incorporate them into the next patch. If you can't get it to work at all, send me a *detailed* description of the problem and I may look into it. If you want to profit of the X11 or Mac window interface, you'll need -STDWIN. This is a portable window system interface by the same -author. The versions of STDWIN floating around on some archives are -not sufficiently up-to-date for use with Python. I will distribute +STDWIN. This is a portable window system interface by the same +author. The versions of STDWIN floating around on some archives are +not sufficiently up-to-date for use with Python. I will distribute the latest and greatest STDWIN version at about the same time as Python. I am the author of Python: - Guido van Rossum - CWI, dept. CST - Kruislaan 413 - 1098 SJ Amsterdam - The Netherlands + Guido van Rossum + CWI, dept. CST + Kruislaan 413 + 1098 SJ Amsterdam + The Netherlands - E-mail: [email protected] + E-mail: [email protected] The Python source is copyrighted, but you can freely use and copy it as long as you don't change or remove the copyright: @@ -50,7 +50,7 @@ as long as you don't change or remove the copyright: Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The Netherlands. - All Rights Reserved + All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, diff --git a/demo/README b/demo/README index a9ff224..eb17d48 100644 --- a/demo/README +++ b/demo/README @@ -1,22 +1,22 @@ This directory contains various demonstrations of what you can do with -Python. The demos are grouped sub(sub*)directories according to +Python. The demos are grouped sub(sub*)directories according to required optional built-in modules. -scripts Some useful Python scripts that I put in my bin - directory. No optional built-in modules meeded. +scripts Some useful Python scripts that I put in my bin + directory. No optional built-in modules meeded. -sgi Demos that only run on Silicon Graphics machines. - Require the built-in modules 'audio' and/or 'gl'. +sgi Demos that only run on Silicon Graphics machines. + Require the built-in modules 'audio' and/or 'gl'. -stdwin Demos that use the STDWIN library. Require the 'stdwin' - built-in module. +stdwin Demos that use the STDWIN library. Require the 'stdwin' + built-in module. WARNING: some scripts are executable and have a first line saying - #! /ufs/guido/bin/sgi/python + #! /ufs/guido/bin/sgi/python This is unlikely to give good results anywhere else except in my -office. Edit the first line before installing such scripts; to try -them out, you can just say "python file.py". (The .py suffix is not +office. Edit the first line before installing such scripts; to try +them out, you can just say "python file.py". (The .py suffix is not necessary in this case, but makes it possible to debug the modules interactively by importing them.) diff --git a/demo/scripts/findlinksto.py b/demo/scripts/findlinksto.py index 210441e..35f5eea 100755 --- a/demo/scripts/findlinksto.py +++ b/demo/scripts/findlinksto.py @@ -7,23 +7,23 @@ import posix, path, sys def visit(pattern, dirname, names): - if path.islink(dirname): - names[:] = [] - return - if path.ismount(dirname): - print 'descend into', dirname - n = len(pattern) - for name in names: - name = path.cat(dirname, name) - try: - linkto = posix.readlink(name) - if linkto[:n] = pattern: - print name, '->', linkto - except posix.error: - pass + if path.islink(dirname): + names[:] = [] + return + if path.ismount(dirname): + print 'descend into', dirname + n = len(pattern) + for name in names: + name = path.cat(dirname, name) + try: + linkto = posix.readlink(name) + if linkto[:n] = pattern: + print name, '->', linkto + except posix.error: + pass def main(pattern, args): - for dirname in args: - path.walk(dirname, visit, pattern) + for dirname in args: + path.walk(dirname, visit, pattern) main(sys.argv[1], sys.argv[2:]) diff --git a/demo/scripts/mkreal.py b/demo/scripts/mkreal.py index 19fef28..1d62ba0 100755 --- a/demo/scripts/mkreal.py +++ b/demo/scripts/mkreal.py @@ -16,50 +16,50 @@ error = 'mkreal error' BUFSIZE = 32*1024 def mkrealfile(name): - st = posix.stat(name) # Get the mode - mode = S_IMODE(st[ST_MODE]) - linkto = posix.readlink(name) # Make sure again it's a symlink - f_in = open(name, 'r') # This ensures it's a file - posix.unlink(name) - f_out = open(name, 'w') - while 1: - buf = f_in.read(BUFSIZE) - if not buf: break - f_out.write(buf) - del f_out # Flush data to disk before changing mode - posix.chmod(name, mode) + st = posix.stat(name) # Get the mode + mode = S_IMODE(st[ST_MODE]) + linkto = posix.readlink(name) # Make sure again it's a symlink + f_in = open(name, 'r') # This ensures it's a file + posix.unlink(name) + f_out = open(name, 'w') + while 1: + buf = f_in.read(BUFSIZE) + if not buf: break + f_out.write(buf) + del f_out # Flush data to disk before changing mode + posix.chmod(name, mode) def mkrealdir(name): - st = posix.stat(name) # Get the mode - mode = S_IMODE(st[ST_MODE]) - linkto = posix.readlink(name) - files = posix.listdir(name) - posix.unlink(name) - posix.mkdir(name, mode) - posix.chmod(name, mode) - linkto = cat('..', linkto) - # - for file in files: - if file not in ('.', '..'): - posix.symlink(cat(linkto, file), cat(name, file)) + st = posix.stat(name) # Get the mode + mode = S_IMODE(st[ST_MODE]) + linkto = posix.readlink(name) + files = posix.listdir(name) + posix.unlink(name) + posix.mkdir(name, mode) + posix.chmod(name, mode) + linkto = cat('..', linkto) + # + for file in files: + if file not in ('.', '..'): + posix.symlink(cat(linkto, file), cat(name, file)) def main(): - sys.stdout = sys.stderr - progname = path.basename(sys.argv[0]) - args = sys.argv[1:] - if not args: - print 'usage:', progname, 'path ...' - sys.exit(2) - status = 0 - for name in args: - if not path.islink(name): - print progname+':', name+':', 'not a symlink' - status = 1 - else: - if path.isdir(name): - mkrealdir(name) - else: - mkrealfile(name) - sys.exit(status) + sys.stdout = sys.stderr + progname = path.basename(sys.argv[0]) + args = sys.argv[1:] + if not args: + print 'usage:', progname, 'path ...' + sys.exit(2) + status = 0 + for name in args: + if not path.islink(name): + print progname+':', name+':', 'not a symlink' + status = 1 + else: + if path.isdir(name): + mkrealdir(name) + else: + mkrealfile(name) + sys.exit(status) main() diff --git a/demo/scripts/ptags.py b/demo/scripts/ptags.py index 0f99650..8886a71 100755 --- a/demo/scripts/ptags.py +++ b/demo/scripts/ptags.py @@ -15,52 +15,52 @@ import posix import path import string -keywords = ['def', 'class'] # If you add keywords, update starts!!! -starts = 'dc' # Starting characters of keywords +keywords = ['def', 'class'] # If you add keywords, update starts!!! +starts = 'dc' # Starting characters of keywords whitespace = string.whitespace identchars = string.letters + string.digits + '_' -tags = [] # Modified! +tags = [] # Modified! def main(): - args = sys.argv[1:] - for file in args: treat_file(file) - if tags: - fp = open('tags', 'w') - tags.sort() - for s in tags: fp.write(s) + args = sys.argv[1:] + for file in args: treat_file(file) + if tags: + fp = open('tags', 'w') + tags.sort() + for s in tags: fp.write(s) def treat_file(file): - try: - fp = open(file, 'r') - except: - print 'Cannot open', file - return - base = path.basename(file) - if base[-3:] = '.py': base = base[:-3] - s = base + '\t' + file + '\t' + '1\n' - tags.append(s) - while 1: - line = fp.readline() - if not line: break - maketag(line, file) + try: + fp = open(file, 'r') + except: + print 'Cannot open', file + return + base = path.basename(file) + if base[-3:] = '.py': base = base[:-3] + s = base + '\t' + file + '\t' + '1\n' + tags.append(s) + while 1: + line = fp.readline() + if not line: break + maketag(line, file) def maketag(line, file): - i = 0 - while line[i:i+1] in whitespace: i = i+1 - if line[i:i+1] not in starts: return - n = len(line) - j = i - while i < n and line[i] not in whitespace: i = i+1 - if line[j:i] not in keywords: return - while i < n and line[i] in whitespace: i = i+1 - j = i - while i < n and line[i] in identchars: i = i+1 - name = line[j:i] - while i < n and line[i] in whitespace: i = i+1 - if i < n and line[i] = '(': i = i+1 - s = name + '\t' + file + '\t' + '/^' + line[:i] + '/\n' - tags.append(s) + i = 0 + while line[i:i+1] in whitespace: i = i+1 + if line[i:i+1] not in starts: return + n = len(line) + j = i + while i < n and line[i] not in whitespace: i = i+1 + if line[j:i] not in keywords: return + while i < n and line[i] in whitespace: i = i+1 + j = i + while i < n and line[i] in identchars: i = i+1 + name = line[j:i] + while i < n and line[i] in whitespace: i = i+1 + if i < n and line[i] = '(': i = i+1 + s = name + '\t' + file + '\t' + '/^' + line[:i] + '/\n' + tags.append(s) main() diff --git a/demo/scripts/suff.py b/demo/scripts/suff.py index f6bd6bf..d6abecc 100755 --- a/demo/scripts/suff.py +++ b/demo/scripts/suff.py @@ -7,23 +7,23 @@ import sys def main(): - files = sys.argv[1:] - suffixes = {} - for file in files: - suff = getsuffix(file) - if not suffixes.has_key(suff): - suffixes[suff] = [] - suffixes[suff].append(file) - keys = suffixes.keys() - keys.sort() - for suff in keys: - print `suff`, len(suffixes[suff]) + files = sys.argv[1:] + suffixes = {} + for file in files: + suff = getsuffix(file) + if not suffixes.has_key(suff): + suffixes[suff] = [] + suffixes[suff].append(file) + keys = suffixes.keys() + keys.sort() + for suff in keys: + print `suff`, len(suffixes[suff]) def getsuffix(file): - suff = '' - for i in range(len(file)): - if file[i] = '.': - suff = file[i:] - return suff + suff = '' + for i in range(len(file)): + if file[i] = '.': + suff = file[i:] + return suff main() diff --git a/demo/scripts/xxci.py b/demo/scripts/xxci.py index 43ea316..7f6a402 100755 --- a/demo/scripts/xxci.py +++ b/demo/scripts/xxci.py @@ -13,65 +13,65 @@ import commands MAXSIZE = 200*1024 # Files this big must be binaries and are skipped. def getargs(): - args = sys.argv[1:] - if args: - return args - print 'No arguments, checking almost *' - for file in posix.listdir('.'): - if not skipfile(file): - args.append(file) - if not args: - print 'Nothing to do -- exit 1' - sys.exit(1) - args.sort() - return args + args = sys.argv[1:] + if args: + return args + print 'No arguments, checking almost *' + for file in posix.listdir('.'): + if not skipfile(file): + args.append(file) + if not args: + print 'Nothing to do -- exit 1' + sys.exit(1) + args.sort() + return args badnames = ['tags', 'xyzzy'] badprefixes = ['.', ',', '@', '#', 'o.'] badsuffixes = \ - ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not'] + ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not'] # XXX Should generalize even more to use fnmatch! def skipfile(file): - if file in badnames or \ - badprefix(file) or badsuffix(file) or \ - path.islink(file) or path.isdir(file): - return 1 - # Skip huge files -- probably binaries. - try: - st = posix.stat(file) - except posix.error: - return 1 # Doesn't exist -- skip it - return st[stat.ST_SIZE] >= MAXSIZE + if file in badnames or \ + badprefix(file) or badsuffix(file) or \ + path.islink(file) or path.isdir(file): + return 1 + # Skip huge files -- probably binaries. + try: + st = posix.stat(file) + except posix.error: + return 1 # Doesn't exist -- skip it + return st[stat.ST_SIZE] >= MAXSIZE def badprefix(file): - for bad in badprefixes: - if file[:len(bad)] = bad: return 1 - return 0 + for bad in badprefixes: + if file[:len(bad)] = bad: return 1 + return 0 def badsuffix(file): - for bad in badsuffixes: - if file[-len(bad):] = bad: return 1 - return 0 + for bad in badsuffixes: + if file[-len(bad):] = bad: return 1 + return 0 def go(args): - for file in args: - print file + ':' - if run('rcsdiff -c', file): - if askyesno('Check in ' + file + ' ? '): - sts = run('rcs -l', file) # ignored - # can't use run() here because it's interactive - sts = posix.system('ci -l ' + file) + for file in args: + print file + ':' + if run('rcsdiff -c', file): + if askyesno('Check in ' + file + ' ? '): + sts = run('rcs -l', file) # ignored + # can't use run() here because it's interactive + sts = posix.system('ci -l ' + file) def run(cmd, file): - sts, output = commands.getstatusoutput(cmd + commands.mkarg(file)) - if sts: - print output - print 'Exit status', sts - return sts + sts, output = commands.getstatusoutput(cmd + commands.mkarg(file)) + if sts: + print output + print 'Exit status', sts + return sts def askyesno(prompt): - s = raw_input(prompt) - return s in ['y', 'yes'] + s = raw_input(prompt) + return s in ['y', 'yes'] go(getargs()) diff --git a/demo/sgi/README b/demo/sgi/README index 5740c22..ecf1e82 100644 --- a/demo/sgi/README +++ b/demo/sgi/README @@ -1,15 +1,15 @@ Demonstrations of Python that use various features of the Silicon Graphics IRIS machines. -audio Demonstrations of the audio capabilities of the 4D/25. - Require the built-in module 'audio'. +audio Demonstrations of the audio capabilities of the 4D/25. + Require the built-in module 'audio'. -audio_stdwin Window-based demonstrations the audio capabilities of - the 4D/25. Require the built-in modules 'stdwin' and - 'audio'. +audio_stdwin Window-based demonstrations the audio capabilities of + the 4D/25. Require the built-in modules 'stdwin' and + 'audio'. -gl Demonstrations of the Graphics Library (GL). - Require the built-in module 'gl'. +gl Demonstrations of the Graphics Library (GL). + Require the built-in module 'gl'. -gl_panel Demonstrations of the Panel Library by NASA Ames. - Require the built-in modules 'gl' and 'pnl'. +gl_panel Demonstrations of the Panel Library by NASA Ames. + Require the built-in modules 'gl' and 'pnl'. diff --git a/demo/sgi/audio/README b/demo/sgi/audio/README index 17dc9b2..5bf6120 100644 --- a/demo/sgi/audio/README +++ b/demo/sgi/audio/README @@ -1,5 +1,5 @@ Programs that demonstrate the use of the audio device on the SGI 4D/25. These require the built-in module 'audio'. -play Read a sound sample from a file and play it through the - speaker. Options to set volume, sampling rate etc. +play Read a sound sample from a file and play it through the + speaker. Options to set volume, sampling rate etc. diff --git a/demo/sgi/audio/play.py b/demo/sgi/audio/play.py index 8f6a802..1d214cf 100755 --- a/demo/sgi/audio/play.py +++ b/demo/sgi/audio/play.py @@ -12,64 +12,64 @@ debug = [] DEF_RATE = 3 def main(): - # - gain = 100 - rate = 0 - starter = audio.write - stopper = 0 - # - optlist, args = getopt.getopt(sys.argv[1:], 'adg:r:') - # - for optname, optarg in optlist: - if 0: - pass - elif optname = '-d': - debug.append(1) - elif optname = '-g': - gain = string.atoi(optarg) - if not (0 < gain < 256): - raise optarg.error, '-g gain out of range' - elif optname = '-r': - rate = string.atoi(optarg) - if not (1 <= rate <= 3): - raise optarg.error, '-r rate out of range' - elif optname = '-a': - starter = audio.start_playing - stopper = audio.wait_playing - # - audio.setoutgain(gain) - audio.setrate(rate) - # - if not args: - play(starter, rate, auds.loadfp(sys.stdin)) - else: - real_stopper = 0 - for file in args: - if real_stopper: - real_stopper() - play(starter, rate, auds.load(file)) - real_stopper = stopper + # + gain = 100 + rate = 0 + starter = audio.write + stopper = 0 + # + optlist, args = getopt.getopt(sys.argv[1:], 'adg:r:') + # + for optname, optarg in optlist: + if 0: + pass + elif optname = '-d': + debug.append(1) + elif optname = '-g': + gain = string.atoi(optarg) + if not (0 < gain < 256): + raise optarg.error, '-g gain out of range' + elif optname = '-r': + rate = string.atoi(optarg) + if not (1 <= rate <= 3): + raise optarg.error, '-r rate out of range' + elif optname = '-a': + starter = audio.start_playing + stopper = audio.wait_playing + # + audio.setoutgain(gain) + audio.setrate(rate) + # + if not args: + play(starter, rate, auds.loadfp(sys.stdin)) + else: + real_stopper = 0 + for file in args: + if real_stopper: + real_stopper() + play(starter, rate, auds.load(file)) + real_stopper = stopper def play(starter, rate, data): - magic = data[:4] - if magic = '0008': - mrate = 3 - elif magic = '0016': - mrate = 2 - elif magic = '0032': - mrate = 1 - else: - mrate = 0 - if mrate: - data = data[4:] - else: - mrate = DEF_RATE - if not rate: rate = mrate - audio.setrate(rate) - starter(data) + magic = data[:4] + if magic = '0008': + mrate = 3 + elif magic = '0016': + mrate = 2 + elif magic = '0032': + mrate = 1 + else: + mrate = 0 + if mrate: + data = data[4:] + else: + mrate = DEF_RATE + if not rate: rate = mrate + audio.setrate(rate) + starter(data) try: - main() + main() finally: - audio.setoutgain(0) - audio.done() + audio.setoutgain(0) + audio.done() diff --git a/demo/sgi/audio_stdwin/README b/demo/sgi/audio_stdwin/README index 3074715..24a710a 100644 --- a/demo/sgi/audio_stdwin/README +++ b/demo/sgi/audio_stdwin/README @@ -1,16 +1,16 @@ Three programs that provide a user interface based upon STDWIN to the -audio device of the SGI 4D/25. These scripts also demonstrate the power +audio device of the SGI 4D/25. These scripts also demonstrate the power of a set of window interface classes implemented in Python that simplify the construction of all sorts of buttons, etc. -jukebox Browses a directory full of sound samples and lets you - play selected ones. (Probably not fully functional, it - requires a conversion program.) +jukebox Browses a directory full of sound samples and lets you + play selected ones. (Probably not fully functional, it + requires a conversion program.) -rec A tape recorder that lets you record a sound sample, - play it back, and save it to a file. Various options to - set sampling rate, volume etc. When idle it doubles - as a VU meter. +rec A tape recorder that lets you record a sound sample, + play it back, and save it to a file. Various options to + set sampling rate, volume etc. When idle it doubles + as a VU meter. -vumeter A VU meter that displays a history of the volume of - sound recently sampled from the microphone. +vumeter A VU meter that displays a history of the volume of + sound recently sampled from the microphone. diff --git a/demo/sgi/audio_stdwin/jukebox.py b/demo/sgi/audio_stdwin/jukebox.py index 5267d73..855ed43 100755 --- a/demo/sgi/audio_stdwin/jukebox.py +++ b/demo/sgi/audio_stdwin/jukebox.py @@ -3,8 +3,8 @@ # JUKEBOX: browse directories full of sampled sound files. # # One or more "list windows" display the files and subdirectories of -# the arguments. Double-clicking on a subdirectory opens a new window -# displaying its contents (and so on recursively). Double clicking +# the arguments. Double-clicking on a subdirectory opens a new window +# displaying its contents (and so on recursively). Double clicking # on a file plays it as a sound file (assuming it is one). # # Playing is asynchronous: the application keeps listening to events @@ -16,7 +16,7 @@ # # Sound files must currently be in Dik Winter's compressed Mac format. # Since decompression is costly, decompressed samples are saved in -# /usr/tmp/@j* until the application is left. The files are read +# /usr/tmp/@j* until the application is left. The files are read # afresh each time, though. import audio @@ -38,205 +38,205 @@ from Sliders import ComplexSlider # Pathnames -HOME_BIN_SGI = '/ufs/guido/bin/sgi/' # Directory where macsound2sgi lives -DEF_DB = '/ufs/dik/sounds/Mac/HCOM' # Default directory of sounds +HOME_BIN_SGI = '/ufs/guido/bin/sgi/' # Directory where macsound2sgi lives +DEF_DB = '/ufs/dik/sounds/Mac/HCOM' # Default directory of sounds # Global variables -class struct(): pass # Class to define featureless structures +class struct(): pass # Class to define featureless structures -G = struct() # Holds writable global variables +G = struct() # Holds writable global variables # Main program def main(): - G.synchronous = 0 # If set, use synchronous audio.write() - G.debug = 0 # If set, print debug messages - G.gain = 75 # Output gain - G.rate = 3 # Sampling rate - G.busy = 0 # Set while asynchronous playing is active - G.windows = [] # List of open windows (except control) - G.mode = 'mac' # Macintosh mode - G.tempprefix = '/usr/tmp/@j' + `rand.rand()` + '-' - # - optlist, args = getopt.getopt(sys.argv[1:], 'dg:r:sSa') - for optname, optarg in optlist: - if optname = '-d': - G.debug = 1 - elif optname = '-g': - G.gain = string.atoi(optarg) - if not (0 < G.gain < 256): - raise optarg.error, '-g gain out of range' - elif optname = '-r': - G.rate = string.atoi(optarg) - if not (1 <= G.rate <= 3): - raise optarg.error, '-r rate out of range' - elif optname = '-s': - G.synchronous = 1 - elif optname = '-S': - G.mode = 'sgi' - elif optname = '-a': - G.mode = 'sun' - # - if not args: - args = [DEF_DB] - # - G.cw = opencontrolwindow() - for dirname in args: - G.windows.append(openlistwindow(dirname)) - # - # - savegain = audio.getoutgain() - try: - # Initialize stdaudio - audio.setoutgain(0) - audio.start_playing('') - dummy = audio.wait_playing() - audio.setoutgain(0) - maineventloop() - finally: - audio.setoutgain(savegain) - audio.done() - clearcache() + G.synchronous = 0 # If set, use synchronous audio.write() + G.debug = 0 # If set, print debug messages + G.gain = 75 # Output gain + G.rate = 3 # Sampling rate + G.busy = 0 # Set while asynchronous playing is active + G.windows = [] # List of open windows (except control) + G.mode = 'mac' # Macintosh mode + G.tempprefix = '/usr/tmp/@j' + `rand.rand()` + '-' + # + optlist, args = getopt.getopt(sys.argv[1:], 'dg:r:sSa') + for optname, optarg in optlist: + if optname = '-d': + G.debug = 1 + elif optname = '-g': + G.gain = string.atoi(optarg) + if not (0 < G.gain < 256): + raise optarg.error, '-g gain out of range' + elif optname = '-r': + G.rate = string.atoi(optarg) + if not (1 <= G.rate <= 3): + raise optarg.error, '-r rate out of range' + elif optname = '-s': + G.synchronous = 1 + elif optname = '-S': + G.mode = 'sgi' + elif optname = '-a': + G.mode = 'sun' + # + if not args: + args = [DEF_DB] + # + G.cw = opencontrolwindow() + for dirname in args: + G.windows.append(openlistwindow(dirname)) + # + # + savegain = audio.getoutgain() + try: + # Initialize stdaudio + audio.setoutgain(0) + audio.start_playing('') + dummy = audio.wait_playing() + audio.setoutgain(0) + maineventloop() + finally: + audio.setoutgain(savegain) + audio.done() + clearcache() def maineventloop(): - mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP - while G.windows: - type, w, detail = event = stdwin.getevent() - if w = G.cw.win: - if type = WE_CLOSE: - return - G.cw.dispatch(event) - else: - if type = WE_DRAW: - w.drawproc(w, detail) - elif type in mouse_events: - w.mouse(w, type, detail) - elif type = WE_CLOSE: - w.close(w) - del w, event - else: - if G.debug: print type, w, detail + mouse_events = WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP + while G.windows: + type, w, detail = event = stdwin.getevent() + if w = G.cw.win: + if type = WE_CLOSE: + return + G.cw.dispatch(event) + else: + if type = WE_DRAW: + w.drawproc(w, detail) + elif type in mouse_events: + w.mouse(w, type, detail) + elif type = WE_CLOSE: + w.close(w) + del w, event + else: + if G.debug: print type, w, detail # Control window -- to set gain and cancel play operations in progress def opencontrolwindow(): - cw = WindowParent().create('Jukebox', (0, 0)) - v = VSplit().create(cw) - # - gain = ComplexSlider().define(v) - gain.setminvalmax(0, G.gain, 255) - gain.settexts(' ', ' ') - gain.sethook(gain_setval_hook) - # - stop = PushButton().definetext(v, 'Stop') - stop.hook = stop_hook - # - cw.realize() - return cw + cw = WindowParent().create('Jukebox', (0, 0)) + v = VSplit().create(cw) + # + gain = ComplexSlider().define(v) + gain.setminvalmax(0, G.gain, 255) + gain.settexts(' ', ' ') + gain.sethook(gain_setval_hook) + # + stop = PushButton().definetext(v, 'Stop') + stop.hook = stop_hook + # + cw.realize() + return cw def gain_setval_hook(self): - G.gain = self.val - if G.busy: audio.setoutgain(G.gain) + G.gain = self.val + if G.busy: audio.setoutgain(G.gain) def stop_hook(self): - if G.busy: - audio.setoutgain(0) - dummy = audio.stop_playing() - G.busy = 0 + if G.busy: + audio.setoutgain(0) + dummy = audio.stop_playing() + G.busy = 0 # List windows -- to display list of files and subdirectories def openlistwindow(dirname): - list = posix.listdir(dirname) - list.sort() - i = 0 - while i < len(list): - if list[i] = '.' or list[i] = '..': - del list[i] - else: - i = i+1 - for i in range(len(list)): - name = list[i] - if path.isdir(path.cat(dirname, name)): - list[i] = list[i] + '/' - width = maxwidth(list) - width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround - height = len(list) * stdwin.lineheight() - stdwin.setdefwinsize(width, min(height, 500)) - w = stdwin.open(dirname) - stdwin.setdefwinsize(0, 0) - w.setdocsize(width, height) - w.drawproc = drawlistwindow - w.mouse = mouselistwindow - w.close = closelistwindow - w.dirname = dirname - w.list = list - w.selected = -1 - return w + list = posix.listdir(dirname) + list.sort() + i = 0 + while i < len(list): + if list[i] = '.' or list[i] = '..': + del list[i] + else: + i = i+1 + for i in range(len(list)): + name = list[i] + if path.isdir(path.cat(dirname, name)): + list[i] = list[i] + '/' + width = maxwidth(list) + width = width + stdwin.textwidth(' ') # XXX X11 stdwin bug workaround + height = len(list) * stdwin.lineheight() + stdwin.setdefwinsize(width, min(height, 500)) + w = stdwin.open(dirname) + stdwin.setdefwinsize(0, 0) + w.setdocsize(width, height) + w.drawproc = drawlistwindow + w.mouse = mouselistwindow + w.close = closelistwindow + w.dirname = dirname + w.list = list + w.selected = -1 + return w def maxwidth(list): - width = 1 - for name in list: - w = stdwin.textwidth(name) - if w > width: width = w - return width + width = 1 + for name in list: + w = stdwin.textwidth(name) + if w > width: width = w + return width def drawlistwindow(w, area): - d = w.begindrawing() - d.erase((0, 0), (1000, 10000)) - lh = d.lineheight() - h, v = 0, 0 - for name in w.list: - d.text((h, v), name) - v = v + lh - showselection(w, d) + d = w.begindrawing() + d.erase((0, 0), (1000, 10000)) + lh = d.lineheight() + h, v = 0, 0 + for name in w.list: + d.text((h, v), name) + v = v + lh + showselection(w, d) def hideselection(w, d): - if w.selected >= 0: - invertselection(w, d) + if w.selected >= 0: + invertselection(w, d) def showselection(w, d): - if w.selected >= 0: - invertselection(w, d) + if w.selected >= 0: + invertselection(w, d) def invertselection(w, d): - lh = d.lineheight() - h1, v1 = p1 = 0, w.selected*lh - h2, v2 = p2 = 1000, v1 + lh - d.invert(p1, p2) + lh = d.lineheight() + h1, v1 = p1 = 0, w.selected*lh + h2, v2 = p2 = 1000, v1 + lh + d.invert(p1, p2) def mouselistwindow(w, type, detail): - (h, v), clicks, button = detail[:3] - d = w.begindrawing() - lh = d.lineheight() - if 0 <= v < lh*len(w.list): - i = v / lh - else: - i = -1 - if w.selected <> i: - hideselection(w, d) - w.selected = i - showselection(w, d) - if type = WE_MOUSE_DOWN and clicks >= 2 and i >= 0: - name = path.cat(w.dirname, w.list[i]) - if name[-1:] = '/': - if clicks = 2: - G.windows.append(openlistwindow(name[:-1])) - else: - playfile(name) + (h, v), clicks, button = detail[:3] + d = w.begindrawing() + lh = d.lineheight() + if 0 <= v < lh*len(w.list): + i = v / lh + else: + i = -1 + if w.selected <> i: + hideselection(w, d) + w.selected = i + showselection(w, d) + if type = WE_MOUSE_DOWN and clicks >= 2 and i >= 0: + name = path.cat(w.dirname, w.list[i]) + if name[-1:] = '/': + if clicks = 2: + G.windows.append(openlistwindow(name[:-1])) + else: + playfile(name) def closelistwindow(w): - remove(G.windows, w) + remove(G.windows, w) def remove(list, item): - for i in range(len(list)): - if list[i] = item: - del list[i] - break + for i in range(len(list)): + if list[i] = item: + del list[i] + break # Playing tools @@ -244,78 +244,78 @@ def remove(list, item): cache = {} def clearcache(): - for x in cache.keys(): - try: - sts = posix.system('rm -f ' + cache[x]) - if sts: - print cmd - print 'Exit status', sts - except: - print cmd - print 'Exception?!' - del cache[x] + for x in cache.keys(): + try: + sts = posix.system('rm -f ' + cache[x]) + if sts: + print cmd + print 'Exit status', sts + except: + print cmd + print 'Exception?!' + del cache[x] def playfile(name): - if G.mode <> 'mac': - tempname = name - elif cache.has_key(name): - tempname = cache[name] - else: - tempname = G.tempprefix + `rand.rand()` - cmd = HOME_BIN_SGI + 'macsound2sgi' - cmd = cmd + ' ' + commands.mkarg(name) - cmd = cmd + ' >' + tempname - if G.debug: print cmd - sts = posix.system(cmd) - if sts: - print cmd - print 'Exit status', sts - stdwin.fleep() - return - cache[name] = tempname - fp = open(tempname, 'r') - try: - hdr = sunaudio.gethdr(fp) - except sunaudio.error, msg: - hdr = () - if hdr: - data_size = hdr[0] - data = fp.read(data_size) - # XXX this doesn't work yet, need to convert from uLAW!!! - del fp - else: - del fp - data = readfile(tempname) - if G.debug: print len(data), 'bytes read from', tempname - if G.busy: - G.busy = 0 - dummy = audio.stop_playing() - # - # Completely reset the audio device - audio.setrate(G.rate) - audio.setduration(0) - audio.setoutgain(G.gain) - # - if G.synchronous: - audio.write(data) - audio.setoutgain(0) - else: - try: - audio.start_playing(data) - G.busy = 1 - except: - stdwin.fleep() - del data + if G.mode <> 'mac': + tempname = name + elif cache.has_key(name): + tempname = cache[name] + else: + tempname = G.tempprefix + `rand.rand()` + cmd = HOME_BIN_SGI + 'macsound2sgi' + cmd = cmd + ' ' + commands.mkarg(name) + cmd = cmd + ' >' + tempname + if G.debug: print cmd + sts = posix.system(cmd) + if sts: + print cmd + print 'Exit status', sts + stdwin.fleep() + return + cache[name] = tempname + fp = open(tempname, 'r') + try: + hdr = sunaudio.gethdr(fp) + except sunaudio.error, msg: + hdr = () + if hdr: + data_size = hdr[0] + data = fp.read(data_size) + # XXX this doesn't work yet, need to convert from uLAW!!! + del fp + else: + del fp + data = readfile(tempname) + if G.debug: print len(data), 'bytes read from', tempname + if G.busy: + G.busy = 0 + dummy = audio.stop_playing() + # + # Completely reset the audio device + audio.setrate(G.rate) + audio.setduration(0) + audio.setoutgain(G.gain) + # + if G.synchronous: + audio.write(data) + audio.setoutgain(0) + else: + try: + audio.start_playing(data) + G.busy = 1 + except: + stdwin.fleep() + del data def readfile(filename): - return readfp(open(filename, 'r')) + return readfp(open(filename, 'r')) def readfp(fp): - data = '' - while 1: - buf = fp.read(102400) # Reads most samples in one fell swoop - if not buf: - return data - data = data + buf + data = '' + while 1: + buf = fp.read(102400) # Reads most samples in one fell swoop + if not buf: + return data + data = data + buf main() diff --git a/demo/sgi/audio_stdwin/rec.py b/demo/sgi/audio_stdwin/rec.py index 3ab3aea..a48716a 100755 --- a/demo/sgi/audio_stdwin/rec.py +++ b/demo/sgi/audio_stdwin/rec.py @@ -16,14 +16,14 @@ from WindowParent import WindowParent from HVSplit import HSplit, VSplit class TimeOutToggleButton() = ToggleButton(): - def define(self, parent): - self = ToggleButton.define(self, parent) - self.parent.need_timer(self) - self.timer_hook = 0 - return self - def timer(self): - if self.timer_hook: - self.timer_hook(self) + def define(self, parent): + self = ToggleButton.define(self, parent) + self.parent.need_timer(self) + self.timer_hook = 0 + return self + def timer(self): + if self.timer_hook: + self.timer_hook(self) K = 1024 BUFSIZE = 30*8*K @@ -34,238 +34,238 @@ class Struct(): pass G = Struct() def main(): - # - # Set default state - # - G.gain = 60 - G.rate = 3 - G.nomuting = 0 - G.savefile = '@rec' - # - # Set default values - # - G.data = '' - G.playing = 0 - G.recording = 0 - G.sogram = 0 - # - # Parse options - # - optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:') - # - for optname, optarg in optlist: - if 0: # (So all cases start with elif) - pass - elif optname = '-d': - G.debug = 1 - elif optname = '-g': - G.gain = string.atoi(optarg) - if not (0 < G.gain < 256): - raise optarg.error, '-g gain out of range' - elif optname = '-m': - G.nomuting = (not G.nomuting) - elif optname = '-r': - G.rate = string.atoi(optarg) - if not (1 <= G.rate <= 3): - raise optarg.error, '-r rate out of range' - # - if args: - G.savefile = args[0] - # - # Initialize the sound package - # - audio.setoutgain(G.nomuting * G.gain) # Silence the speaker - audio.setrate(G.rate) - # - # Create the WindowParent and VSplit - # - G.window = WindowParent().create('Recorder', (0, 0)) - w = G.vsplit = VSplit().create(G.window) - # - # VU-meter - # - G.vubtn = VUMeter().define(w) - # - # Radiobuttons for rates - # - r1btn = RadioButton().definetext(w, '32 K/sec') - r1btn.on_hook = rate_hook - r1btn.rate = 1 - # - r2btn = RadioButton().definetext(w, '16 K/sec') - r2btn.on_hook = rate_hook - r2btn.rate = 2 - # - r3btn = RadioButton().definetext(w, '8 K/sec') - r3btn.on_hook = rate_hook - r3btn.rate = 3 - # - radios = [r1btn, r2btn, r3btn] - r1btn.group = r2btn.group = r3btn.group = radios - for r in radios: - if r.rate = G.rate: r.select(1) - # - # Other controls - # - G.recbtn = TimeOutToggleButton().definetext(w, 'Record') - G.recbtn.on_hook = record_on_hook - G.recbtn.timer_hook = record_timer_hook - G.recbtn.off_hook = record_off_hook - # - G.mutebtn = CheckButton().definetext(w, 'Mute') - G.mutebtn.select(not G.nomuting) - G.mutebtn.hook = mute_hook - # - G.playbtn = TimeOutToggleButton().definetext(w, 'Playback') - G.playbtn.on_hook = play_on_hook - G.playbtn.timer_hook = play_timer_hook - G.playbtn.off_hook = play_off_hook - # - G.gainbtn = ComplexSlider().define(w) - G.gainbtn.settexts(' Volume: ', ' ') - G.gainbtn.setminvalmax(0, G.gain, 255) - G.gainbtn.sethook(gain_hook) - # - G.sizebtn = Label().definetext(w, `len(G.data)` + ' bytes') - # - #G.showbtn = PushButton().definetext(w, 'Sound-o-gram...') - #G.showbtn.hook = show_hook - # - G.savebtn = PushButton().definetext(w, 'Save...') - G.savebtn.hook = save_hook - # - G.quitbtn = PushButton().definetext(w, 'Quit') - G.quitbtn.hook = quit_hook - G.playbtn.enable(0) - G.savebtn.enable(0) - #G.showbtn.enable(0) - start_vu() - G.window.realize() - # - # Event loop - # - while 1: - e = stdwin.getevent() - G.window.dispatch(e) + # + # Set default state + # + G.gain = 60 + G.rate = 3 + G.nomuting = 0 + G.savefile = '@rec' + # + # Set default values + # + G.data = '' + G.playing = 0 + G.recording = 0 + G.sogram = 0 + # + # Parse options + # + optlist, args = getopt.getopt(sys.argv[1:], 'mdg:r:') + # + for optname, optarg in optlist: + if 0: # (So all cases start with elif) + pass + elif optname = '-d': + G.debug = 1 + elif optname = '-g': + G.gain = string.atoi(optarg) + if not (0 < G.gain < 256): + raise optarg.error, '-g gain out of range' + elif optname = '-m': + G.nomuting = (not G.nomuting) + elif optname = '-r': + G.rate = string.atoi(optarg) + if not (1 <= G.rate <= 3): + raise optarg.error, '-r rate out of range' + # + if args: + G.savefile = args[0] + # + # Initialize the sound package + # + audio.setoutgain(G.nomuting * G.gain) # Silence the speaker + audio.setrate(G.rate) + # + # Create the WindowParent and VSplit + # + G.window = WindowParent().create('Recorder', (0, 0)) + w = G.vsplit = VSplit().create(G.window) + # + # VU-meter + # + G.vubtn = VUMeter().define(w) + # + # Radiobuttons for rates + # + r1btn = RadioButton().definetext(w, '32 K/sec') + r1btn.on_hook = rate_hook + r1btn.rate = 1 + # + r2btn = RadioButton().definetext(w, '16 K/sec') + r2btn.on_hook = rate_hook + r2btn.rate = 2 + # + r3btn = RadioButton().definetext(w, '8 K/sec') + r3btn.on_hook = rate_hook + r3btn.rate = 3 + # + radios = [r1btn, r2btn, r3btn] + r1btn.group = r2btn.group = r3btn.group = radios + for r in radios: + if r.rate = G.rate: r.select(1) + # + # Other controls + # + G.recbtn = TimeOutToggleButton().definetext(w, 'Record') + G.recbtn.on_hook = record_on_hook + G.recbtn.timer_hook = record_timer_hook + G.recbtn.off_hook = record_off_hook + # + G.mutebtn = CheckButton().definetext(w, 'Mute') + G.mutebtn.select(not G.nomuting) + G.mutebtn.hook = mute_hook + # + G.playbtn = TimeOutToggleButton().definetext(w, 'Playback') + G.playbtn.on_hook = play_on_hook + G.playbtn.timer_hook = play_timer_hook + G.playbtn.off_hook = play_off_hook + # + G.gainbtn = ComplexSlider().define(w) + G.gainbtn.settexts(' Volume: ', ' ') + G.gainbtn.setminvalmax(0, G.gain, 255) + G.gainbtn.sethook(gain_hook) + # + G.sizebtn = Label().definetext(w, `len(G.data)` + ' bytes') + # + #G.showbtn = PushButton().definetext(w, 'Sound-o-gram...') + #G.showbtn.hook = show_hook + # + G.savebtn = PushButton().definetext(w, 'Save...') + G.savebtn.hook = save_hook + # + G.quitbtn = PushButton().definetext(w, 'Quit') + G.quitbtn.hook = quit_hook + G.playbtn.enable(0) + G.savebtn.enable(0) + #G.showbtn.enable(0) + start_vu() + G.window.realize() + # + # Event loop + # + while 1: + e = stdwin.getevent() + G.window.dispatch(e) # XXX Disabled... def show_hook(self): - savetext = self.text - self.settext('Be patient...') - close_sogram() - stdwin.setdefwinsize(400, 300) - win = stdwin.open('Sound-o-gram') - G.sogram = Soundogram().define(win, G.data) - win.buttons = [G.sogram] - self.settext(savetext) + savetext = self.text + self.settext('Be patient...') + close_sogram() + stdwin.setdefwinsize(400, 300) + win = stdwin.open('Sound-o-gram') + G.sogram = Soundogram().define(win, G.data) + win.buttons = [G.sogram] + self.settext(savetext) def close_sogram(): - if G.sogram: - # Break circular references - G.sogram.win.buttons[:] = [] - del G.sogram.win - G.sogram = 0 + if G.sogram: + # Break circular references + G.sogram.win.buttons[:] = [] + del G.sogram.win + G.sogram = 0 def mute_hook(self): - G.nomuting = (not self.selected) - audio.setoutgain(G.nomuting * G.gain) + G.nomuting = (not self.selected) + audio.setoutgain(G.nomuting * G.gain) def rate_hook(self): - G.rate = self.rate - audio.setrate(G.rate) + G.rate = self.rate + audio.setrate(G.rate) def record_on_hook(self): - stop_vu() - close_sogram() - audio.setrate(G.rate) - audio.setoutgain(G.nomuting * G.gain) - audio.start_recording(BUFSIZE) - G.recording = 1 - G.playbtn.enable(0) - G.window.settimer(10 * BUFSIZE / Rates[G.rate]) + stop_vu() + close_sogram() + audio.setrate(G.rate) + audio.setoutgain(G.nomuting * G.gain) + audio.start_recording(BUFSIZE) + G.recording = 1 + G.playbtn.enable(0) + G.window.settimer(10 * BUFSIZE / Rates[G.rate]) def record_timer_hook(self): - if G.recording: - if audio.poll_recording(): - self.hilite(0) - record_off_hook(self) - else: - self.parent.settimer(5) + if G.recording: + if audio.poll_recording(): + self.hilite(0) + record_off_hook(self) + else: + self.parent.settimer(5) def record_off_hook(self): - if not G.recording: - return - G.data = audio.stop_recording() - G.recording = 0 - G.sizebtn.settext(`len(G.data)` + ' bytes') - audio.setoutgain(G.nomuting * G.gain) - G.playbtn.enable((len(G.data) > 0)) - G.savebtn.enable((len(G.data) > 0)) - #G.showbtn.enable((len(G.data) > 0)) - G.window.settimer(0) - start_vu() + if not G.recording: + return + G.data = audio.stop_recording() + G.recording = 0 + G.sizebtn.settext(`len(G.data)` + ' bytes') + audio.setoutgain(G.nomuting * G.gain) + G.playbtn.enable((len(G.data) > 0)) + G.savebtn.enable((len(G.data) > 0)) + #G.showbtn.enable((len(G.data) > 0)) + G.window.settimer(0) + start_vu() def play_on_hook(self): - stop_vu() - audio.setrate(G.rate) - audio.setoutgain(G.gain) - audio.start_playing(G.data) - G.playing = 1 - G.recbtn.enable(0) - G.window.settimer(max(10 * len(G.data) / Rates[G.rate], 1)) + stop_vu() + audio.setrate(G.rate) + audio.setoutgain(G.gain) + audio.start_playing(G.data) + G.playing = 1 + G.recbtn.enable(0) + G.window.settimer(max(10 * len(G.data) / Rates[G.rate], 1)) def play_timer_hook(self): - if G.playing: - if audio.poll_playing(): - self.hilite(0) - play_off_hook(self) - else: - self.parent.settimer(5) + if G.playing: + if audio.poll_playing(): + self.hilite(0) + play_off_hook(self) + else: + self.parent.settimer(5) def play_off_hook(self): - if not G.playing: - return - x = audio.stop_playing() - G.playing = 0 - audio.setoutgain(G.nomuting * G.gain) - G.recbtn.enable(1) - G.window.settimer(0) - start_vu() + if not G.playing: + return + x = audio.stop_playing() + G.playing = 0 + audio.setoutgain(G.nomuting * G.gain) + G.recbtn.enable(1) + G.window.settimer(0) + start_vu() def gain_hook(self): - G.gain = self.val - if G.playing or G.nomuting: audio.setoutgain(G.gain) + G.gain = self.val + if G.playing or G.nomuting: audio.setoutgain(G.gain) def save_hook(self): - if not G.data: - stdwin.fleep() - else: - prompt = 'Store sampled data on file: ' - try: - G.savefile = stdwin.askfile(prompt, G.savefile, 1) - except KeyboardInterrupt: - return - try: - fp = open(G.savefile, 'w') - fp.write(Magics[G.rate] + G.data) - except: - stdwin.message('Cannot create ' + file) + if not G.data: + stdwin.fleep() + else: + prompt = 'Store sampled data on file: ' + try: + G.savefile = stdwin.askfile(prompt, G.savefile, 1) + except KeyboardInterrupt: + return + try: + fp = open(G.savefile, 'w') + fp.write(Magics[G.rate] + G.data) + except: + stdwin.message('Cannot create ' + file) def stop_vu(): - G.vubtn.stop() + G.vubtn.stop() def start_vu(): - G.vubtn.start() + G.vubtn.start() Exit = 'exit' # exception def quit_hook(self): - raise Exit, 0 + raise Exit, 0 try: - try: - main() - finally: - audio.setoutgain(0) + try: + main() + finally: + audio.setoutgain(0) except Exit, sts: - sys.exit(sts) + sys.exit(sts) diff --git a/demo/sgi/audio_stdwin/vumeter.py b/demo/sgi/audio_stdwin/vumeter.py index 1685ba2..86b9484 100755 --- a/demo/sgi/audio_stdwin/vumeter.py +++ b/demo/sgi/audio_stdwin/vumeter.py @@ -12,24 +12,24 @@ BUFSIZE = NBUFS*48 SCALE=128 class MyVUMeter() = VUMeter(): - def init_reactivity(self): - self.parent.need_mouse(self) - def mouse_down(self, detail): - if self.enabled: - self.stop() - else: - self.start() - def mouse_move(self, detail): pass - def mouse_up(self, detail): pass + def init_reactivity(self): + self.parent.need_mouse(self) + def mouse_down(self, detail): + if self.enabled: + self.stop() + else: + self.start() + def mouse_move(self, detail): pass + def mouse_up(self, detail): pass def main(): - audio.setrate(3) - audio.setoutgain(0) - w = WindowParent().create('VU Meter', (200, 100)) - v = MyVUMeter().define(w) - v.start() - w.realize() - while 1: - w.dispatch(stdwin.getevent()) + audio.setrate(3) + audio.setoutgain(0) + w = WindowParent().create('VU Meter', (200, 100)) + v = MyVUMeter().define(w) + v.start() + w.realize() + while 1: + w.dispatch(stdwin.getevent()) main() diff --git a/demo/sgi/gl/README b/demo/sgi/gl/README index f191cf5..a2cd17a 100644 --- a/demo/sgi/gl/README +++ b/demo/sgi/gl/README @@ -1,22 +1,22 @@ These demos run only on SGI machines and require the 'gl' built-in module. The demonstrate the abilities of SGI's GL library as well as the ease of -GL programming in Python. Most demos require the Z-buffer (aka +GL programming in Python. Most demos require the Z-buffer (aka 24-bitplane) option. -backface Demonstrates the 'backface' GL function. +backface Demonstrates the 'backface' GL function. -kites Show 3 flying kites. Demonstrates the rendering speed - obtainable by Python programs. +kites Show 3 flying kites. Demonstrates the rendering speed + obtainable by Python programs. -mclock A colorful clock with more options than you can - remember. Works on 8-bit machines (but allows more - colors on 24-bit machines). +mclock A colorful clock with more options than you can + remember. Works on 8-bit machines (but allows more + colors on 24-bit machines). -mixing Demonstrates the effect of color mixing: through - frequent color switching it gives the effect of white - light. +mixing Demonstrates the effect of color mixing: through + frequent color switching it gives the effect of white + light. -nurbs A simple demonstration of the 'nurbs' GL functions. +nurbs A simple demonstration of the 'nurbs' GL functions. -zrgb Displays a 3-D Gouraud-shaded figure which can be moved - around with the mouse. +zrgb Displays a 3-D Gouraud-shaded figure which can be moved + around with the mouse. diff --git a/demo/sgi/gl/backface.py b/demo/sgi/gl/backface.py index 5936f75..8192589 100755 --- a/demo/sgi/gl/backface.py +++ b/demo/sgi/gl/backface.py @@ -1,9 +1,9 @@ #! /ufs/guido/bin/sgi/python -# backface +# backface # -# draw a cube that can run with backface() turned on or off. -# cube is moved when LEFTMOUSE is pressed and mouse itself is moved. +# draw a cube that can run with backface() turned on or off. +# cube is moved when LEFTMOUSE is pressed and mouse itself is moved. from gl import * from DEVICE import * @@ -13,128 +13,128 @@ CUBE_SIZE = 200.0 CUBE_OBJ = 1 def main () : - # - x = 0 - y = 0 - moveit = 0 - # - initialize() - # - while (1) : - # - while (qtest()) : - dev, val = qread() - # - if dev = ESCKEY : - backface(0) - return - # - elif dev = REDRAW : - reshapeviewport() - drawcube(x,y) - # - elif dev = LEFTMOUSE : - # - # LEFTMOUSE down - moveit = val - # - elif dev = BKEY : - backface(1) - drawcube(x,y) - # - elif dev = FKEY : - backface(0) - drawcube(x,y) - # - if moveit : - x = getvaluator(MOUSEX) - y = getvaluator(MOUSEY) - drawcube(x,y) + # + x = 0 + y = 0 + moveit = 0 + # + initialize() + # + while (1) : + # + while (qtest()) : + dev, val = qread() + # + if dev = ESCKEY : + backface(0) + return + # + elif dev = REDRAW : + reshapeviewport() + drawcube(x,y) + # + elif dev = LEFTMOUSE : + # + # LEFTMOUSE down + moveit = val + # + elif dev = BKEY : + backface(1) + drawcube(x,y) + # + elif dev = FKEY : + backface(0) + drawcube(x,y) + # + if moveit : + x = getvaluator(MOUSEX) + y = getvaluator(MOUSEY) + drawcube(x,y) def initialize () : - foreground () - keepaspect (1, 1) - gid = winopen('backface') - winset(gid) - winconstraints() - # - doublebuffer() - gconfig() - shademodel(FLAT) - # - ortho(-1024.0, 1024.0, -1024.0, 1024.0, -1024.0, 1024.0) - # - qdevice(ESCKEY) - qdevice(REDRAW) - qdevice(LEFTMOUSE) - qdevice(BKEY) - qdevice(FKEY) - qenter(REDRAW,gid) - # - backface(1) + foreground () + keepaspect (1, 1) + gid = winopen('backface') + winset(gid) + winconstraints() + # + doublebuffer() + gconfig() + shademodel(FLAT) + # + ortho(-1024.0, 1024.0, -1024.0, 1024.0, -1024.0, 1024.0) + # + qdevice(ESCKEY) + qdevice(REDRAW) + qdevice(LEFTMOUSE) + qdevice(BKEY) + qdevice(FKEY) + qenter(REDRAW,gid) + # + backface(1) # # define a cube def cube () : - # - # front face - pushmatrix() - translate(0.0,0.0,CUBE_SIZE) - color(RED) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() - # - # right face - pushmatrix() - translate(CUBE_SIZE, 0.0, 0.0) - rotate(900, 'y') - color(GREEN) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() - # - # back face - pushmatrix() - translate(0.0, 0.0, -CUBE_SIZE) - rotate(1800, 'y') - color(BLUE) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() - # - # left face - pushmatrix() - translate(-CUBE_SIZE, 0.0, 0.0) - rotate(-900, 'y') - color(CYAN) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() - # - # top face - pushmatrix() - translate(0.0, CUBE_SIZE, 0.0) - rotate(-900, 'x') - color(MAGENTA) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() - # - # bottom face - pushmatrix() - translate(0.0, -CUBE_SIZE, 0.0) - rotate(900, 'x') - color(YELLOW) - rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) - popmatrix() + # + # front face + pushmatrix() + translate(0.0,0.0,CUBE_SIZE) + color(RED) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() + # + # right face + pushmatrix() + translate(CUBE_SIZE, 0.0, 0.0) + rotate(900, 'y') + color(GREEN) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() + # + # back face + pushmatrix() + translate(0.0, 0.0, -CUBE_SIZE) + rotate(1800, 'y') + color(BLUE) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() + # + # left face + pushmatrix() + translate(-CUBE_SIZE, 0.0, 0.0) + rotate(-900, 'y') + color(CYAN) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() + # + # top face + pushmatrix() + translate(0.0, CUBE_SIZE, 0.0) + rotate(-900, 'x') + color(MAGENTA) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() + # + # bottom face + pushmatrix() + translate(0.0, -CUBE_SIZE, 0.0) + rotate(900, 'x') + color(YELLOW) + rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE) + popmatrix() def drawcube(x,y) : - # - pushmatrix() - rotate(2*x, 'x') - rotate(2*y, 'y') - color(BLACK) - clear() - cube() - popmatrix() - swapbuffers() + # + pushmatrix() + rotate(2*x, 'x') + rotate(2*y, 'y') + color(BLACK) + clear() + cube() + popmatrix() + swapbuffers() main () diff --git a/demo/sgi/gl/kites.py b/demo/sgi/gl/kites.py index 764ad2c..36dc5d7 100755 --- a/demo/sgi/gl/kites.py +++ b/demo/sgi/gl/kites.py @@ -12,15 +12,15 @@ # # This program show 3 kites flying around the screen. It uses # -# * bgnpolygon, endpolygon -# * v3, n3 -# * lmdef, lmbind +# * bgnpolygon, endpolygon +# * v3, n3 +# * lmdef, lmbind # # Usage : -# -# ESC -> exit program -# MOUSE3 -> freeze toggle -# MOUSE2 -> one step (use this in freeze state) +# +# ESC -> exit program +# MOUSE3 -> freeze toggle +# MOUSE2 -> one step (use this in freeze state) from GL import * from gl import * @@ -32,28 +32,28 @@ from math import * # set appropiate material, call drawobject() # def viewobj (r, s, t, mat) : - pushmatrix() - rot (r * 10.0, 'X') - rot (r * 10.0, 'Y') - rot (r * 10.0, 'Z') - scale (s[0], s[1], s[2]) - translate (t[0], t[1], t[2]) - lmbind(MATERIAL, mat) - drawobject() - popmatrix() + pushmatrix() + rot (r * 10.0, 'X') + rot (r * 10.0, 'Y') + rot (r * 10.0, 'Z') + scale (s[0], s[1], s[2]) + translate (t[0], t[1], t[2]) + lmbind(MATERIAL, mat) + drawobject() + popmatrix() # # makeobj : the contructor of the object # def mkobj () : - v0 = (-5.0 ,0.0, 0.0) - v1 = (0.0 ,5.0, 0.0) - v2 = (5.0 ,0.0, 0.0) - v3 = (0.0 ,2.0, 0.0) - n0 = (sqrt(2.0)/2.0, sqrt(2.0)/2.0, 0.0) - vn = ((v0, n0), (v1, n0), (v2, n0), (v3, n0)) - # - return vn + v0 = (-5.0 ,0.0, 0.0) + v1 = (0.0 ,5.0, 0.0) + v2 = (5.0 ,0.0, 0.0) + v3 = (0.0 ,2.0, 0.0) + n0 = (sqrt(2.0)/2.0, sqrt(2.0)/2.0, 0.0) + vn = ((v0, n0), (v1, n0), (v2, n0), (v3, n0)) + # + return vn # # the object itself as an array of vertices and normals @@ -64,10 +64,10 @@ kite = mkobj () # drawobject : draw a triangle. with bgnpolygon # def drawobject () : - # - bgnpolygon() - vnarray (kite) - endpolygon() + # + bgnpolygon() + vnarray (kite) + endpolygon() # # identity matrix @@ -75,7 +75,7 @@ def drawobject () : idmat=[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0] # -# the rgb-value of light-blue +# the rgb-value of light-blue # LightBlue = (43,169,255) @@ -102,93 +102,93 @@ model = [AMBIENT,0.2,0.2,0.2,LMNULL] # sets the viewing, defines and binds the materials # def initgl () : - # - # open window - # - foreground () - keepaspect (1, 1) - prefposition (100, 500, 100, 500) - w = winopen ('PYTHON lights') - keepaspect (1, 1) - winconstraints() - # - # configure pipeline (zbuf, 2buf, GOURAUD and RGBmode) - # - zbuffer (1) - doublebuffer () - shademodel (GOURAUD) - RGBmode () - gconfig () - # - # define and bind materials (set perspective BEFORE loadmat !) - # - mmode(MVIEWING) - perspective (900, 1.0, 1.0, 20.0) - loadmatrix(idmat) - lmdef(DEFMATERIAL, 1, m1) - lmdef(DEFMATERIAL, 2, m2) - lmdef(DEFMATERIAL, 3, m3) - lmdef(DEFLIGHT, 1, light1) - lmdef(DEFLIGHT, 2, light2) - lmdef(DEFLMODEL, 1, model) - lmbind(LIGHT0,1) - lmbind(LIGHT1,2) - lmbind(LMODEL,1) - # - # set viewing - # - lookat (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0) - # - # ask for the REDRAW and ESCKEY events - # - qdevice(DEVICE.MOUSE3) - qdevice(DEVICE.MOUSE2) - qdevice(DEVICE.REDRAW) - qdevice(DEVICE.ESCKEY) - -# -# GoForIT : use 2buf to redraw the object 2n times. index i is used as + # + # open window + # + foreground () + keepaspect (1, 1) + prefposition (100, 500, 100, 500) + w = winopen ('PYTHON lights') + keepaspect (1, 1) + winconstraints() + # + # configure pipeline (zbuf, 2buf, GOURAUD and RGBmode) + # + zbuffer (1) + doublebuffer () + shademodel (GOURAUD) + RGBmode () + gconfig () + # + # define and bind materials (set perspective BEFORE loadmat !) + # + mmode(MVIEWING) + perspective (900, 1.0, 1.0, 20.0) + loadmatrix(idmat) + lmdef(DEFMATERIAL, 1, m1) + lmdef(DEFMATERIAL, 2, m2) + lmdef(DEFMATERIAL, 3, m3) + lmdef(DEFLIGHT, 1, light1) + lmdef(DEFLIGHT, 2, light2) + lmdef(DEFLMODEL, 1, model) + lmbind(LIGHT0,1) + lmbind(LIGHT1,2) + lmbind(LMODEL,1) + # + # set viewing + # + lookat (0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0) + # + # ask for the REDRAW and ESCKEY events + # + qdevice(DEVICE.MOUSE3) + qdevice(DEVICE.MOUSE2) + qdevice(DEVICE.REDRAW) + qdevice(DEVICE.ESCKEY) + +# +# GoForIT : use 2buf to redraw the object 2n times. index i is used as # the (smoothly changing) rotation angle # def GoForIt(i) : - freeze = 1 - while 1 : - if freeze <> 0 : - i = i + 1 - # - # clear z-buffer and clear background to light-blue - # - zclear() - c3i (LightBlue) - clear() - # - # draw the 3 traiangles scaled above each other. - # - viewobj(float(i),[1.0,1.0,1.0],[1.0,1.0,1.0],1) - viewobj(float(i),[0.75,0.75,0.75],[0.0,2.0,2.0],2) - viewobj(float(i),[0.5,0.5,0.5],[0.0,4.0,4.0],3) - # - swapbuffers() - # - if qtest() <> 0 : - dev, val = qread() - if dev = DEVICE.ESCKEY : - break - elif dev = DEVICE.REDRAW : - reshapeviewport () - elif dev = DEVICE.MOUSE3 and val <> 0 : - freeze = 1 - freeze - elif dev = DEVICE.MOUSE2 and val <> 0 : - i = i + 1 + freeze = 1 + while 1 : + if freeze <> 0 : + i = i + 1 + # + # clear z-buffer and clear background to light-blue + # + zclear() + c3i (LightBlue) + clear() + # + # draw the 3 traiangles scaled above each other. + # + viewobj(float(i),[1.0,1.0,1.0],[1.0,1.0,1.0],1) + viewobj(float(i),[0.75,0.75,0.75],[0.0,2.0,2.0],2) + viewobj(float(i),[0.5,0.5,0.5],[0.0,4.0,4.0],3) + # + swapbuffers() + # + if qtest() <> 0 : + dev, val = qread() + if dev = DEVICE.ESCKEY : + break + elif dev = DEVICE.REDRAW : + reshapeviewport () + elif dev = DEVICE.MOUSE3 and val <> 0 : + freeze = 1 - freeze + elif dev = DEVICE.MOUSE2 and val <> 0 : + i = i + 1 # the main program # def main () : - initgl () - GoForIt (0) + initgl () + GoForIt (0) # # exec main # -main () +main () diff --git a/demo/sgi/gl/mclock.doc b/demo/sgi/gl/mclock.doc index 610e9ab..256e062 100644 --- a/demo/sgi/gl/mclock.doc +++ b/demo/sgi/gl/mclock.doc @@ -8,7 +8,7 @@ Last week I wrote: >For your enjoyment I have implemented a colorful clock. The clock has now been extended with some new facilities: a menu, an -alarm and a gong. These may require some explanation beyond what's in +alarm and a gong. These may require some explanation beyond what's in the usage message. Menu @@ -19,37 +19,37 @@ seconds hand on or off and to switch the alarm off. Alarm ----- -The left and middle buttons set the alarm. When it is on, the alarm +The left and middle buttons set the alarm. When it is on, the alarm time is displayed as a time on a 24 hour clock in the bottom left -corner. It is also indicated by two red triangles, corresponding to the -little (hours) and big (minutes) hand. These hands can be moved around: +corner. It is also indicated by two red triangles, corresponding to the +little (hours) and big (minutes) hand. These hands can be moved around: the left mouse button moves the minutes hand, the middle button moves -the hourds hand. Watch out for differences of twelve hours (always +the hourds hand. Watch out for differences of twelve hours (always check the digital display); these can be corrected by dragging the hours hand once around the dial. When the alarm goes off, two things happen: a shell command specified on the command line with the -a option is executed (in the background), and -the clock's colors change every two seconds, for five minutes. You can +the clock's colors change every two seconds, for five minutes. You can also turn the alarm off by using the menu accessible through the right mouse button. There is no default command for the -a option; if it is not specified, -only the changing of the colors happens. If you have an 8 ohm speaker +only the changing of the colors happens. If you have an 8 ohm speaker connected to the audio output of your Personal Iris, a suitable command would be: - mclock -a '/ufs/guido/bin/sgi/play /ufs/guido/lib/sounds/alarm' + mclock -a '/ufs/guido/bin/sgi/play /ufs/guido/lib/sounds/alarm' Gong ---- Some people like a clock that makes noises every hour, or even more -often. This is supported by the -g and -G options. With -g you specify +often. This is supported by the -g and -G options. With -g you specify a shell command to be executed to sound the gong; with -G you can specify the interval between gong calls, in seconds (default is one hour). -The shell command is executed in the background. It is given two -arguments: the hours (on a 24 hour clock!) and the minutes. The +The shell command is executed in the background. It is given two +arguments: the hours (on a 24 hour clock!) and the minutes. The executable Python script /ufs/guido/bin/sgi/chime is a suitable example. Again, this only works if you have installed a speaker (I bet 8 ohm speakers are going to be in demand!) diff --git a/demo/sgi/gl/mclock.py b/demo/sgi/gl/mclock.py index 806511c..43b219c 100755 --- a/demo/sgi/gl/mclock.py +++ b/demo/sgi/gl/mclock.py @@ -29,701 +29,701 @@ from math import pi import math import posix -FULLC = 3600 # Full circle in 1/10-ths of a degree -MIDN = 900 # Angle of the 12 o'clock position -R, G, B = 0, 1, 2 # Indices of colors in RGB list +FULLC = 3600 # Full circle in 1/10-ths of a degree +MIDN = 900 # Angle of the 12 o'clock position +R, G, B = 0, 1, 2 # Indices of colors in RGB list -HOUR = 3600 # Number of seconds per hour -MINUTE = 60 # Number of seconds per minute +HOUR = 3600 # Number of seconds per hour +MINUTE = 60 # Number of seconds per minute -class struct(): pass # Class to define featureless structures -Gl = struct() # Object to hold writable global variables +class struct(): pass # Class to define featureless structures +Gl = struct() # Object to hold writable global variables # Default constants (used in multiple places) SCREENBG = 127, 156, 191 NPARTS = 9 TITLE = 'M Clock' -TZDIFF = -1*HOUR # <--- change this to reflect your local time zone +TZDIFF = -1*HOUR # <--- change this to reflect your local time zone # Default parameters -Gl.foreground = 0 # If set, run in the foreground -Gl.fullscreen = 0 # If set, run on full screen -Gl.tzdiff = TZDIFF # Seconds west of Greenwich (winter time) -Gl.nparts = NPARTS # Number of parts each circle is divided in (>= 2) -Gl.debug = 0 # If set, print debug output -Gl.doublebuffer = 1 # If set, use double buffering -Gl.update = 0 # Update interval; seconds hand is suppressed if > 1 -Gl.colorsubset = 0 # If set, display only a subset of the colors -Gl.cyan = 0 # If set, display cyan overlay (big hand) -Gl.magenta = 0 # If set, display magenta overlay (little hand) -Gl.yellow = 0 # If set, display yellow overlay (fixed background) -Gl.black = 0 # If set, display black overlay (hands) -Gl.colormap = 0 # If set, use colormap mode instead of RGB mode -Gl.warnings = 0 # If set, print warnings -Gl.title = '- - ' # Window title (default set later) -Gl.border = 1 # If set, use a window border (and title) -Gl.bg = 0, 0, 0 # Background color R, G, B value -Gl.iconic = 0 # Set in iconic state -Gl.fg = 255, 0, 0 # Alarm background RGB (either normal or alarm) -Gl.ox,Gl.oy = 0,0 # Window origin -Gl.cx,Gl.cy = 0,0 # Window size -Gl.alarm_set = 0 # Alarm on or off -Gl.alarm_on = 0 # Alarm is ringing -Gl.alarm_time = 0 # Alarm time in seconds after midnight -Gl.alarm_hours = 0 # Alarm hour setting, 24 hour clock -Gl.alarm_minutes = 0 # Alarm minutes setting -Gl.alarm_rgb = 0,0,0 # Alarm display RGB colors -Gl.alarm_cmd = '' # Command to execute when alarm goes off -Gl.mouse2down = 0 # Mouse button state -Gl.mouse3down = 0 # Mouse button state -Gl.gong_cmd = '' # Command to execute when chimes go off -Gl.gong_int = 3600 # Gong interval -Gl.indices = R, G, B # Colors (permuted when alarm is on) +Gl.foreground = 0 # If set, run in the foreground +Gl.fullscreen = 0 # If set, run on full screen +Gl.tzdiff = TZDIFF # Seconds west of Greenwich (winter time) +Gl.nparts = NPARTS # Number of parts each circle is divided in (>= 2) +Gl.debug = 0 # If set, print debug output +Gl.doublebuffer = 1 # If set, use double buffering +Gl.update = 0 # Update interval; seconds hand is suppressed if > 1 +Gl.colorsubset = 0 # If set, display only a subset of the colors +Gl.cyan = 0 # If set, display cyan overlay (big hand) +Gl.magenta = 0 # If set, display magenta overlay (little hand) +Gl.yellow = 0 # If set, display yellow overlay (fixed background) +Gl.black = 0 # If set, display black overlay (hands) +Gl.colormap = 0 # If set, use colormap mode instead of RGB mode +Gl.warnings = 0 # If set, print warnings +Gl.title = '- - ' # Window title (default set later) +Gl.border = 1 # If set, use a window border (and title) +Gl.bg = 0, 0, 0 # Background color R, G, B value +Gl.iconic = 0 # Set in iconic state +Gl.fg = 255, 0, 0 # Alarm background RGB (either normal or alarm) +Gl.ox,Gl.oy = 0,0 # Window origin +Gl.cx,Gl.cy = 0,0 # Window size +Gl.alarm_set = 0 # Alarm on or off +Gl.alarm_on = 0 # Alarm is ringing +Gl.alarm_time = 0 # Alarm time in seconds after midnight +Gl.alarm_hours = 0 # Alarm hour setting, 24 hour clock +Gl.alarm_minutes = 0 # Alarm minutes setting +Gl.alarm_rgb = 0,0,0 # Alarm display RGB colors +Gl.alarm_cmd = '' # Command to execute when alarm goes off +Gl.mouse2down = 0 # Mouse button state +Gl.mouse3down = 0 # Mouse button state +Gl.gong_cmd = '' # Command to execute when chimes go off +Gl.gong_int = 3600 # Gong interval +Gl.indices = R, G, B # Colors (permuted when alarm is on) def main(): - # - sys.stdout = sys.stderr # All output is errors/warnings etc. - # - try: - args = getoptions() - except string.atoi_error, value: - usage(string.atoi_error, value) - except getopt.error, msg: - usage(getopt.error, msg) - # - if args: - realtime = 0 - hours = string.atoi(args[0]) - minutes = seconds = 0 - if args[1:]: minutes = string.atoi(args[1]) - if args[2:]: seconds = string.atoi(args[2]) - localtime = ((hours*60)+minutes)*60+seconds - else: - realtime = 1 - # - if Gl.title = '- - ': - if realtime: - Gl.title = TITLE - else: - title = '' - for arg in args: title = title + ' ' + arg - Gl.title = title[1:] - del title - # - wid = makewindow() - Gl.ox,Gl.oy = getorigin() - Gl.cx,Gl.cy = getsize() - initmenu() - clearall() - # - if not Gl.update: - Gl.update = 60 - # - if Gl.update <= 1: - Gl.timernoise = 6 - else: - Gl.timernoise = 60 - noise(TIMER0, Gl.timernoise) - # - qdevice(WINSHUT) - qdevice(WINQUIT) - qdevice(ESCKEY) - if realtime: - qdevice(TIMER0) - qdevice(REDRAW) - qdevice(WINFREEZE) - qdevice(WINTHAW) - qdevice(MENUBUTTON) # MOUSE1 - qdevice(MOUSE3) # Left button - qdevice(MOUSE2) # Middle button - unqdevice(INPUTCHANGE) - # - lasttime = 0 - Gl.change = 1 - while 1: - if realtime: - localtime = time.time() - Gl.tzdiff - if Gl.alarm_set: - if localtime%(24*HOUR) = Gl.alarm_time: - # Ring the alarm! - if Gl.debug: - print 'Rrrringg!' - Gl.alarm_on = 1 - if Gl.alarm_cmd <> '': - d = posix.system(Gl.alarm_cmd+' '+`Gl.alarm_time/3600`+' '+`(Gl.alarm_time/60)%60` + ' &') - Gl.change = 1 - clearall() - if Gl.alarm_on: - if (localtime - Gl.alarm_time) % (24*HOUR) > 300: - # More than 5 minutes away from alarm - Gl.alarm_on = 0 - if Gl.debug: - print 'Alarm turned off' - Gl.change = 1 - clearall() - Gl.indices = R, G, B - else: - if localtime % 2 = 0: - # Permute color indices - Gl.indices = Gl.indices[2:] + Gl.indices[:2] - Gl.change = 1 - if Gl.gong_cmd <> '' and localtime%Gl.gong_int = 0: - d = posix.system(Gl.gong_cmd+' '+`(localtime/3600)%24`+' '+`(localtime/60)%60` + ' &') - if localtime/Gl.update <> lasttime/Gl.update: - if Gl.debug: print 'new time' - Gl.change = 1 - if Gl.change: - if Gl.debug: print 'drawing' - doit(localtime) - lasttime = localtime - Gl.change = 0 - dev, data = qread() - if Gl.debug and dev <> TIMER0: - print dev, data - if dev = TIMER0: - if Gl.debug > 1: - print dev, data - elif dev = MOUSE3: - mousex = getvaluator(MOUSEX) - mousey = getvaluator(MOUSEY) - if mouseclick(3, data, mousex, mousey): - Gl.change = 1 - elif dev = MOUSE2: - mousex = getvaluator(MOUSEX) - mousey = getvaluator(MOUSEY) - if mouseclick(2, data, mousex, mousey): - Gl.change = 1 - elif dev = MOUSEX: - mousex = data - if Gl.mouse2down: - mouse2track(mousex, mousey) - if Gl.mouse3down: - mouse3track(mousex, mousey) - elif dev = MOUSEY: - mousey = data - if Gl.mouse2down: - mouse2track(mousex, mousey) - if Gl.mouse3down: - mouse3track(mousex, mousey) - elif dev = REDRAW or dev = REDRAWICONIC: - if Gl.debug: - if dev = REDRAW: print 'REDRAW' - else: print 'REDRAWICONIC' - reshapeviewport() - Gl.ox,Gl.oy = getorigin() - Gl.cx,Gl.cy = getsize() - Gl.change = 1 - clearall() - elif dev = MENUBUTTON: - if Gl.debug: print 'MENUBUTTON' - handlemenu() - elif dev = WINFREEZE: - if Gl.debug: print 'WINFREEZE' - Gl.iconic = 1 - noise(TIMER0, 60*60) # Redraw every 60 seconds only - elif dev = WINTHAW: - if Gl.debug: print 'WINTHAW' - Gl.iconic = 0 - noise(TIMER0, Gl.timernoise) - Gl.change = 1 - elif dev = ESCKEY or dev = WINSHUT or dev = WINQUIT: - if Gl.debug: print 'Exit' - sys.exit(0) + # + sys.stdout = sys.stderr # All output is errors/warnings etc. + # + try: + args = getoptions() + except string.atoi_error, value: + usage(string.atoi_error, value) + except getopt.error, msg: + usage(getopt.error, msg) + # + if args: + realtime = 0 + hours = string.atoi(args[0]) + minutes = seconds = 0 + if args[1:]: minutes = string.atoi(args[1]) + if args[2:]: seconds = string.atoi(args[2]) + localtime = ((hours*60)+minutes)*60+seconds + else: + realtime = 1 + # + if Gl.title = '- - ': + if realtime: + Gl.title = TITLE + else: + title = '' + for arg in args: title = title + ' ' + arg + Gl.title = title[1:] + del title + # + wid = makewindow() + Gl.ox,Gl.oy = getorigin() + Gl.cx,Gl.cy = getsize() + initmenu() + clearall() + # + if not Gl.update: + Gl.update = 60 + # + if Gl.update <= 1: + Gl.timernoise = 6 + else: + Gl.timernoise = 60 + noise(TIMER0, Gl.timernoise) + # + qdevice(WINSHUT) + qdevice(WINQUIT) + qdevice(ESCKEY) + if realtime: + qdevice(TIMER0) + qdevice(REDRAW) + qdevice(WINFREEZE) + qdevice(WINTHAW) + qdevice(MENUBUTTON) # MOUSE1 + qdevice(MOUSE3) # Left button + qdevice(MOUSE2) # Middle button + unqdevice(INPUTCHANGE) + # + lasttime = 0 + Gl.change = 1 + while 1: + if realtime: + localtime = time.time() - Gl.tzdiff + if Gl.alarm_set: + if localtime%(24*HOUR) = Gl.alarm_time: + # Ring the alarm! + if Gl.debug: + print 'Rrrringg!' + Gl.alarm_on = 1 + if Gl.alarm_cmd <> '': + d = posix.system(Gl.alarm_cmd+' '+`Gl.alarm_time/3600`+' '+`(Gl.alarm_time/60)%60` + ' &') + Gl.change = 1 + clearall() + if Gl.alarm_on: + if (localtime - Gl.alarm_time) % (24*HOUR) > 300: + # More than 5 minutes away from alarm + Gl.alarm_on = 0 + if Gl.debug: + print 'Alarm turned off' + Gl.change = 1 + clearall() + Gl.indices = R, G, B + else: + if localtime % 2 = 0: + # Permute color indices + Gl.indices = Gl.indices[2:] + Gl.indices[:2] + Gl.change = 1 + if Gl.gong_cmd <> '' and localtime%Gl.gong_int = 0: + d = posix.system(Gl.gong_cmd+' '+`(localtime/3600)%24`+' '+`(localtime/60)%60` + ' &') + if localtime/Gl.update <> lasttime/Gl.update: + if Gl.debug: print 'new time' + Gl.change = 1 + if Gl.change: + if Gl.debug: print 'drawing' + doit(localtime) + lasttime = localtime + Gl.change = 0 + dev, data = qread() + if Gl.debug and dev <> TIMER0: + print dev, data + if dev = TIMER0: + if Gl.debug > 1: + print dev, data + elif dev = MOUSE3: + mousex = getvaluator(MOUSEX) + mousey = getvaluator(MOUSEY) + if mouseclick(3, data, mousex, mousey): + Gl.change = 1 + elif dev = MOUSE2: + mousex = getvaluator(MOUSEX) + mousey = getvaluator(MOUSEY) + if mouseclick(2, data, mousex, mousey): + Gl.change = 1 + elif dev = MOUSEX: + mousex = data + if Gl.mouse2down: + mouse2track(mousex, mousey) + if Gl.mouse3down: + mouse3track(mousex, mousey) + elif dev = MOUSEY: + mousey = data + if Gl.mouse2down: + mouse2track(mousex, mousey) + if Gl.mouse3down: + mouse3track(mousex, mousey) + elif dev = REDRAW or dev = REDRAWICONIC: + if Gl.debug: + if dev = REDRAW: print 'REDRAW' + else: print 'REDRAWICONIC' + reshapeviewport() + Gl.ox,Gl.oy = getorigin() + Gl.cx,Gl.cy = getsize() + Gl.change = 1 + clearall() + elif dev = MENUBUTTON: + if Gl.debug: print 'MENUBUTTON' + handlemenu() + elif dev = WINFREEZE: + if Gl.debug: print 'WINFREEZE' + Gl.iconic = 1 + noise(TIMER0, 60*60) # Redraw every 60 seconds only + elif dev = WINTHAW: + if Gl.debug: print 'WINTHAW' + Gl.iconic = 0 + noise(TIMER0, Gl.timernoise) + Gl.change = 1 + elif dev = ESCKEY or dev = WINSHUT or dev = WINQUIT: + if Gl.debug: print 'Exit' + sys.exit(0) def getoptions(): - optlist, args = getopt.getopt(sys.argv[1:], 'A:a:B:bc:dFfG:g:n:sT:t:u:wCMYK') - for optname, optarg in optlist: - if optname = '-A': - Gl.fg = eval(optarg) # Should be (r,g,b) - elif optname = '-a': - Gl.alarm_cmd = optarg - elif optname = '-B': - Gl.bg = eval(optarg) # Should be (r,g,b) - elif optname = '-b': - Gl.border = 0 - elif optname = '-c': - Gl.colormap = string.atoi(optarg) - elif optname = '-d': - Gl.debug = Gl.debug + 1 - Gl.warnings = 1 - elif optname = '-F': - Gl.foreground = 1 - elif optname = '-f': - Gl.fullscreen = 1 - elif optname = '-G': - Gl.gong_int = 60*string.atoi(optarg) - elif optname = '-g': - Gl.gong_cmd = optarg - elif optname = '-n': - Gl.nparts = string.atoi(optarg) - elif optname = '-s': - Gl.doublebuffer = 0 - elif optname = '-T': - Gl.title = optarg - elif optname = '-t': - Gl.tzdiff = string.atoi(optarg) - elif optname = '-u': - Gl.update = string.atoi(optarg) - elif optname = '-w': - Gl.warnings = 1 - elif optname = '-C': - Gl.cyan = Gl.colorsubset = 1 - elif optname = '-M': - Gl.magenta = Gl.colorsubset = 1 - elif optname = '-Y': - Gl.yellow = Gl.colorsubset = 1 - elif optname = '-K': - Gl.black = Gl.colorsubset = 1 - else: - print 'Unsupported option', optname - return args + optlist, args = getopt.getopt(sys.argv[1:], 'A:a:B:bc:dFfG:g:n:sT:t:u:wCMYK') + for optname, optarg in optlist: + if optname = '-A': + Gl.fg = eval(optarg) # Should be (r,g,b) + elif optname = '-a': + Gl.alarm_cmd = optarg + elif optname = '-B': + Gl.bg = eval(optarg) # Should be (r,g,b) + elif optname = '-b': + Gl.border = 0 + elif optname = '-c': + Gl.colormap = string.atoi(optarg) + elif optname = '-d': + Gl.debug = Gl.debug + 1 + Gl.warnings = 1 + elif optname = '-F': + Gl.foreground = 1 + elif optname = '-f': + Gl.fullscreen = 1 + elif optname = '-G': + Gl.gong_int = 60*string.atoi(optarg) + elif optname = '-g': + Gl.gong_cmd = optarg + elif optname = '-n': + Gl.nparts = string.atoi(optarg) + elif optname = '-s': + Gl.doublebuffer = 0 + elif optname = '-T': + Gl.title = optarg + elif optname = '-t': + Gl.tzdiff = string.atoi(optarg) + elif optname = '-u': + Gl.update = string.atoi(optarg) + elif optname = '-w': + Gl.warnings = 1 + elif optname = '-C': + Gl.cyan = Gl.colorsubset = 1 + elif optname = '-M': + Gl.magenta = Gl.colorsubset = 1 + elif optname = '-Y': + Gl.yellow = Gl.colorsubset = 1 + elif optname = '-K': + Gl.black = Gl.colorsubset = 1 + else: + print 'Unsupported option', optname + return args def usage(exc, msg): - if sys.argv: - progname = path.basename(sys.argv[0]) - else: - progname = 'mclock' - # - print progname + ':', - if exc = string.atoi_error: - print 'non-numeric argument:', - print msg - # - print 'usage:', progname, '[options] [hh [mm [ss]]]' - # - print '-A r,g,b : alarm background red,green,blue [255,0,0]' - print '-a cmd : shell command executed when alarm goes off' - print '-B r,g,b : background red,green,blue [0,0,0]' - print ' (-B SCREENBG uses the default screen background)' - print '-b : suppress window border and title' - print '-c cmapid : select explicit colormap' - print '-d : more debug output (implies -F, -w)' - print '-F : run in foreground' - print '-f : use full screen' - print '-G intrvl : interval between chimes in minutes [60]' - print '-g cmd : shell command executed when chimes go off' - print '-s : single buffer mode' - print '-w : print various warnings' - print '-n nparts : number of parts [' + `NPARTS` + ']' - print '-T title : alternate window title [\'' + TITLE + '\']' - print '-t tzdiff : time zone difference [' + `TZDIFF` + ']' - print '-u update : update interval [60]' - print '-CMYK : Cyan, Magenta, Yellow or blacK overlay only' - print 'if hh [mm [ss]] is specified, display that time statically' - print 'on machines with < 12 bitplanes, -c and -s are forced on' - # - sys.exit(2) + if sys.argv: + progname = path.basename(sys.argv[0]) + else: + progname = 'mclock' + # + print progname + ':', + if exc = string.atoi_error: + print 'non-numeric argument:', + print msg + # + print 'usage:', progname, '[options] [hh [mm [ss]]]' + # + print '-A r,g,b : alarm background red,green,blue [255,0,0]' + print '-a cmd : shell command executed when alarm goes off' + print '-B r,g,b : background red,green,blue [0,0,0]' + print ' (-B SCREENBG uses the default screen background)' + print '-b : suppress window border and title' + print '-c cmapid : select explicit colormap' + print '-d : more debug output (implies -F, -w)' + print '-F : run in foreground' + print '-f : use full screen' + print '-G intrvl : interval between chimes in minutes [60]' + print '-g cmd : shell command executed when chimes go off' + print '-s : single buffer mode' + print '-w : print various warnings' + print '-n nparts : number of parts [' + `NPARTS` + ']' + print '-T title : alternate window title [\'' + TITLE + '\']' + print '-t tzdiff : time zone difference [' + `TZDIFF` + ']' + print '-u update : update interval [60]' + print '-CMYK : Cyan, Magenta, Yellow or blacK overlay only' + print 'if hh [mm [ss]] is specified, display that time statically' + print 'on machines with < 12 bitplanes, -c and -s are forced on' + # + sys.exit(2) def doit(localtime): - hands = makehands(localtime) - list = makelist(hands) - render(list, hands) + hands = makehands(localtime) + list = makelist(hands) + render(list, hands) def makehands(localtime): - localtime = localtime % (12*HOUR) - seconds_hand = MIDN + FULLC - (localtime*60) % FULLC - big_hand = (MIDN + FULLC - (localtime%HOUR)) % FULLC - little_hand = (MIDN + FULLC - ((localtime/12) % HOUR)) % FULLC - return little_hand, big_hand, seconds_hand + localtime = localtime % (12*HOUR) + seconds_hand = MIDN + FULLC - (localtime*60) % FULLC + big_hand = (MIDN + FULLC - (localtime%HOUR)) % FULLC + little_hand = (MIDN + FULLC - ((localtime/12) % HOUR)) % FULLC + return little_hand, big_hand, seconds_hand def makelist(little_hand, big_hand, seconds_hand): - total = [] - if Gl.cyan or not Gl.colorsubset: - total = total + makesublist(big_hand, Gl.indices[0]) - if Gl.magenta or not Gl.colorsubset: - total = total + makesublist(little_hand, Gl.indices[1]) - if Gl.yellow or not Gl.colorsubset: - total = total + makesublist(MIDN, Gl.indices[2]) - total.sort() - return total + total = [] + if Gl.cyan or not Gl.colorsubset: + total = total + makesublist(big_hand, Gl.indices[0]) + if Gl.magenta or not Gl.colorsubset: + total = total + makesublist(little_hand, Gl.indices[1]) + if Gl.yellow or not Gl.colorsubset: + total = total + makesublist(MIDN, Gl.indices[2]) + total.sort() + return total def makesublist(first, icolor): - list = [] - alpha = FULLC/Gl.nparts - a = first - alpha/2 - for i in range(Gl.nparts): - angle = (a + i*alpha + FULLC) % FULLC - value = 255*(Gl.nparts-1-i)/(Gl.nparts-1) - list.append(angle, icolor, value) - list.sort() - a, icolor, value = list[0] - if a <> 0: - a, icolor, value = list[len(list)-1] - t = 0, icolor, value - list.insert(0, t) - return list + list = [] + alpha = FULLC/Gl.nparts + a = first - alpha/2 + for i in range(Gl.nparts): + angle = (a + i*alpha + FULLC) % FULLC + value = 255*(Gl.nparts-1-i)/(Gl.nparts-1) + list.append(angle, icolor, value) + list.sort() + a, icolor, value = list[0] + if a <> 0: + a, icolor, value = list[len(list)-1] + t = 0, icolor, value + list.insert(0, t) + return list def rgb_fg(): - return Gl.fg - # Obsolete code: - if Gl.alarm_on: - return Gl.bg - else: - return Gl.fg + return Gl.fg + # Obsolete code: + if Gl.alarm_on: + return Gl.bg + else: + return Gl.fg def rgb_bg(): - return Gl.bg - # Obsolete code: - if Gl.alarm_on: - return Gl.fg - else: - return Gl.bg + return Gl.bg + # Obsolete code: + if Gl.alarm_on: + return Gl.fg + else: + return Gl.bg def clearall(): - Gl.c3i(rgb_bg()) - clear() - if Gl.doublebuffer: - swapbuffers() - clear() + Gl.c3i(rgb_bg()) + clear() + if Gl.doublebuffer: + swapbuffers() + clear() def draw_alarm(color): - frontbuffer(TRUE) - Gl.c3i(color) - pushmatrix() - rotate(-((Gl.alarm_time/12)%3600), 'z') - bgnpolygon() - v2f( 0.00,1.00) - v2f( 0.04,1.05) - v2f(-0.04,1.05) - endpolygon() - popmatrix() - # - pushmatrix() - rotate(-((Gl.alarm_time)%3600), 'z') - bgnpolygon() - v2f( 0.00,1.05) - v2f( 0.07,1.10) - v2f(-0.07,1.10) - endpolygon() - popmatrix() - # - cmov2(-1.06, -1.06) - charstr(string.rjust(`Gl.alarm_time/3600`,2)) - charstr(':') - charstr(string.zfill((Gl.alarm_time/60)%60,2)) - frontbuffer(FALSE) + frontbuffer(TRUE) + Gl.c3i(color) + pushmatrix() + rotate(-((Gl.alarm_time/12)%3600), 'z') + bgnpolygon() + v2f( 0.00,1.00) + v2f( 0.04,1.05) + v2f(-0.04,1.05) + endpolygon() + popmatrix() + # + pushmatrix() + rotate(-((Gl.alarm_time)%3600), 'z') + bgnpolygon() + v2f( 0.00,1.05) + v2f( 0.07,1.10) + v2f(-0.07,1.10) + endpolygon() + popmatrix() + # + cmov2(-1.06, -1.06) + charstr(string.rjust(`Gl.alarm_time/3600`,2)) + charstr(':') + charstr(string.zfill((Gl.alarm_time/60)%60,2)) + frontbuffer(FALSE) def render(list, (little_hand, big_hand, seconds_hand)): - # - if Gl.colormap: - resetindex() - # - if not list: - Gl.c3i(255, 255, 255) # White - circf(0.0, 0.0, 1.0) - else: - list.append(3600, 0, 255) # Sentinel - # - rgb = [255, 255, 255] - a_prev = 0 - for a, icolor, value in list: - if a <> a_prev: - [r, g, b] = rgb - if Gl.debug > 1: - print rgb, a_prev, a - Gl.c3i(r, g, b) - arcf(0.0, 0.0, 1.0, a_prev, a) - rgb[icolor] = value - a_prev = a - # - if Gl.black or not Gl.colorsubset: - # - # Draw the hands -- in black - # - Gl.c3i(0, 0, 0) - # - if Gl.update = 1 and not Gl.iconic: - # Seconds hand is only drawn if we update every second - pushmatrix() - rotate(seconds_hand, 'z') - bgnline() - v2f(0.0, 0.0) - v2f(1.0, 0.0) - endline() - popmatrix() - # - pushmatrix() - rotate(big_hand, 'z') - rectf(0.0, -0.01, 0.97, 0.01) - circf(0.0, 0.0, 0.01) - circf(0.97, 0.0, 0.01) - popmatrix() - # - pushmatrix() - rotate(little_hand, 'z') - rectf(0.04, -0.02, 0.63, 0.02) - circf(0.04, 0.0, 0.02) - circf(0.63, 0.0, 0.02) - popmatrix() - # - # Draw the alarm time, if set or being set - # - if Gl.alarm_set: - draw_alarm(rgb_fg()) - # - if Gl.doublebuffer: swapbuffers() + # + if Gl.colormap: + resetindex() + # + if not list: + Gl.c3i(255, 255, 255) # White + circf(0.0, 0.0, 1.0) + else: + list.append(3600, 0, 255) # Sentinel + # + rgb = [255, 255, 255] + a_prev = 0 + for a, icolor, value in list: + if a <> a_prev: + [r, g, b] = rgb + if Gl.debug > 1: + print rgb, a_prev, a + Gl.c3i(r, g, b) + arcf(0.0, 0.0, 1.0, a_prev, a) + rgb[icolor] = value + a_prev = a + # + if Gl.black or not Gl.colorsubset: + # + # Draw the hands -- in |
