From c2587c76f1b416cdbecb979e54941933246bf856 Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Tue, 16 Feb 2021 20:14:16 -0600 Subject: starting over --- README | 32 +- demo/README | 20 +- demo/scripts/findlinksto.py | 32 +- demo/scripts/mkreal.py | 82 +- demo/scripts/ptags.py | 74 +- demo/scripts/suff.py | 32 +- demo/scripts/xxci.py | 86 +- demo/sgi/README | 18 +- demo/sgi/audio/README | 4 +- demo/sgi/audio/play.py | 112 +- demo/sgi/audio_stdwin/README | 20 +- demo/sgi/audio_stdwin/jukebox.py | 456 +++--- demo/sgi/audio_stdwin/rec.py | 414 ++--- demo/sgi/audio_stdwin/vumeter.py | 34 +- demo/sgi/gl/README | 26 +- demo/sgi/gl/backface.py | 232 +-- demo/sgi/gl/kites.py | 214 +-- demo/sgi/gl/mclock.doc | 22 +- demo/sgi/gl/mclock.py | 1268 +++++++-------- demo/sgi/gl/mixing.py | 148 +- demo/sgi/gl/nurbs.py | 252 +-- demo/sgi/gl/zrgb.py | 264 ++-- demo/sgi/gl_panel/README | 34 +- demo/sgi/gl_panel/apanel/apanel.py | 90 +- demo/sgi/gl_panel/flying/flying.py | 590 +++---- demo/sgi/gl_panel/flying/light.py | 42 +- demo/sgi/gl_panel/flying/material.py | 34 +- demo/sgi/gl_panel/flying/materials.s | 4 +- demo/sgi/gl_panel/flying/objdict.py | 6 +- demo/sgi/gl_panel/flying/objectdef.py | 234 +-- demo/sgi/gl_panel/nurbs/nurbs.py | 318 ++-- demo/sgi/gl_panel/nurbs/nurbsdata.py | 90 +- demo/sgi/gl_panel/twoview/block.py | 124 +- demo/sgi/gl_panel/twoview/twoview.py | 634 ++++---- demo/stdwin/wdiff.py | 670 ++++---- doc/Makefile | 46 +- doc/README | 10 +- doc/SetClass.py | 32 +- doc/fibo.py | 22 +- doc/mod.tex | 18 +- doc/mod1.tex | 38 +- doc/mod2.tex | 64 +- doc/mod3.tex | 10 +- doc/myformat.sty | 38 +- doc/pytry | 22 +- doc/tut.tex | 304 ++-- lib/Abstract.py | 76 +- lib/Buttons.py | 590 +++---- lib/CSplit.py | 124 +- lib/DEVICE.py | 794 +++++----- lib/GL.py | 176 +-- lib/HVSplit.py | 84 +- lib/Histogram.py | 54 +- lib/Sliders.py | 270 ++-- lib/Soundogram.py | 54 +- lib/Split.py | 212 +-- lib/StripChart.py | 118 +- lib/Tcl.py | 712 ++++----- lib/TclShell.py | 434 +++--- lib/TclUtil.py | 386 ++--- lib/TestCSplit.py | 32 +- lib/TransParent.py | 174 +-- lib/VUMeter.py | 76 +- lib/WindowParent.py | 180 +-- lib/adv.py | 426 ++--- lib/anywin.py | 12 +- lib/auds.py | 148 +- lib/calendar.py | 216 +-- lib/clock.py | 292 ++-- lib/cmp.py | 92 +- lib/cmpcache.py | 80 +- lib/commands.py | 64 +- lib/dircache.py | 40 +- lib/dircmp.py | 318 ++-- lib/dirwin.py | 32 +- lib/dis.py | 172 +- lib/dump.py | 60 +- lib/fact.py | 48 +- lib/filewin.py | 12 +- lib/fnmatch.py | 52 +- lib/getopt.py | 54 +- lib/glob.py | 66 +- lib/grep.py | 52 +- lib/gwin.py | 176 +-- lib/lambda.py | 88 +- lib/listwin.py | 64 +- lib/localtime.py | 70 +- lib/maccache.py | 52 +- lib/macglob.py | 64 +- lib/macpath.py | 110 +- lib/macshell.py | 594 +++---- lib/packmail.py | 62 +- lib/panel.py | 344 ++-- lib/panelparser.py | 122 +- lib/path.py | 114 +- lib/poly.py | 66 +- lib/rand.py | 6 +- lib/rect.py | 76 +- lib/selection.py | 78 +- lib/shutil.py | 78 +- lib/stat.py | 44 +- lib/statcache.py | 72 +- lib/stdwinevents.py | 62 +- lib/stdwinsupport.py | 42 +- lib/string.py | 140 +- lib/sunaudio.py | 64 +- lib/tablewin.py | 382 ++--- lib/tb.py | 360 ++--- lib/testall.py | 106 +- lib/textwin.py | 196 +-- lib/util.py | 24 +- lib/whrandom.py | 82 +- lib/zmod.py | 92 +- python.man | 2 +- src/Grammar | 30 +- src/Makefile | 439 +++--- src/PROTO.h | 14 +- src/README | 2 +- src/To.do | 4 +- src/acceler.c | 170 +- src/allobjects.h | 9 +- src/amoebamodule.c | 1016 ++++++------ src/asa.c | 670 ++++---- src/asa.h | 8 +- src/assert.h | 8 +- src/audiomodule.c | 864 +++++----- src/bitset.c | 86 +- src/bitset.h | 22 +- src/bltinmodule.c | 780 ++++----- src/bltinmodule.h | 8 +- src/ceval.c | 2430 ++++++++++++++--------------- src/ceval.h | 8 +- src/cgen | 694 ++++----- src/cgensupport.c | 550 +++---- src/cgensupport.h | 8 +- src/classobject.c | 354 ++--- src/classobject.h | 10 +- src/compile.c | 2774 ++++++++++++++++----------------- src/compile.h | 24 +- src/config.c | 128 +- src/configmac.c | 52 +- src/cstubs | 1548 +++++++++--------- src/dictobject.c | 752 ++++----- src/dictobject.h | 12 +- src/errcode.h | 28 +- src/errors.c | 192 +-- src/errors.h | 16 +- src/fgetsintr.c | 82 +- src/fgetsintr.h | 8 +- src/fileobject.c | 384 ++--- src/fileobject.h | 8 +- src/firstsets.c | 186 +-- src/floatobject.c | 298 ++-- src/floatobject.h | 12 +- src/fmod.c | 40 +- src/frameobject.c | 186 +-- src/frameobject.h | 40 +- src/funcobject.c | 100 +- src/funcobject.h | 8 +- src/getcwd.c | 96 +- src/graminit.c | 1248 +++++++-------- src/graminit.h | 8 +- src/grammar.c | 314 ++-- src/grammar.h | 60 +- src/grammar1.c | 74 +- src/import.c | 308 ++-- src/import.h | 8 +- src/intobject.c | 354 ++--- src/intobject.h | 16 +- src/intrcheck.c | 94 +- src/listnode.c | 96 +- src/listobject.c | 731 +++++---- src/listobject.h | 18 +- src/macmodule.c | 292 ++-- src/malloc.h | 21 +- src/mathmodule.c | 170 +- src/metagrammar.c | 178 +-- src/metagrammar.h | 8 +- src/methodobject.c | 154 +- src/methodobject.h | 12 +- src/modsupport.c | 464 +++--- src/modsupport.h | 10 +- src/moduleobject.c | 166 +- src/moduleobject.h | 8 +- src/node.c | 98 +- src/node.h | 36 +- src/object.c | 344 ++-- src/object.h | 164 +- src/objimpl.h | 14 +- src/opcode.h | 152 +- src/panelmodule.c | 1514 +++++++++--------- src/parser.c | 496 +++--- src/parser.h | 26 +- src/parsetok.c | 206 +-- src/parsetok.h | 10 +- src/patchlevel.h | 2 +- src/pgen.c | 1062 ++++++------- src/pgen.h | 8 +- src/pgenheaders.h | 12 +- src/pgenmain.c | 164 +- src/posixmodule.c | 478 +++--- src/printgrammar.c | 178 +-- src/profmain.c | 138 +- src/pythonmain.c | 518 +++--- src/pythonrun.h | 8 +- src/regexp.c | 1948 +++++++++++------------ src/regexp.h | 26 +- src/regexpmodule.c | 212 +-- src/regmagic.h | 10 +- src/regsub.c | 124 +- src/rltokenizer.c | 8 +- src/sc_errors.c | 214 +-- src/sc_errors.h | 32 +- src/sc_global.h | 144 +- src/sc_interpr.c | 2122 ++++++++++++------------- src/scdbg.c | 222 +-- src/sigtype.h | 16 +- src/stdwinmodule.c | 2292 +++++++++++++-------------- src/stdwinobject.h | 8 +- src/strdup.c | 22 +- src/strerror.c | 22 +- src/stringobject.c | 476 +++--- src/stringobject.h | 20 +- src/strtol.c | 158 +- src/structmember.c | 246 +-- src/structmember.h | 50 +- src/stubcode.h | 14 +- src/sysmodule.c | 224 +-- src/sysmodule.h | 8 +- src/timemodule.c | 184 +-- src/token.h | 78 +- src/tokenizer.c | 788 +++++----- src/tokenizer.h | 42 +- src/traceback.c | 258 +-- src/traceback.h | 8 +- src/tupleobject.c | 388 ++--- src/tupleobject.h | 18 +- src/typeobject.c | 46 +- src/xxobject.c | 134 +- 239 files changed, 27034 insertions(+), 27056 deletions(-) diff --git a/README b/README index 5fe1ff7..d411c9e 100644 --- a/README +++ b/README @@ -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: gu...@cwi.nl + E-mail: gu...@cwi.nl 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 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() def makewindow(): - # - if Gl.debug or Gl.foreground: - foreground() - # - if Gl.fullscreen: - # XXX Should find out true screen size using getgdesc() - prefposition(0, 1279, 0, 1023) - else: - keepaspect(1, 1) - minsize(64, 64) - # - if not Gl.border: - noborder() - wid = winopen(Gl.title) - # - if not Gl.fullscreen: - keepaspect(1, 1) - minsize(10, 10) - maxsize(2000, 2000) - iconsize(66, 66) - winconstraints() - # - nplanes = getplanes() - nmaps = getgdesc(GD_NMMAPS) - if Gl.warnings: - print nplanes, 'color planes,', nmaps, 'color maps' - # - if nplanes < 12 or Gl.colormap: - if not Gl.colormap: - Gl.colormap = nmaps - 1 - if Gl.warnings: - print 'not enough color planes available', - print 'for RGB mode; forcing colormap mode' - print 'using color map number', Gl.colormap - if not Gl.colorsubset: - needed = 3 - else: - needed = Gl.cyan + Gl.magenta + Gl.yellow - needed = needed*Gl.nparts - if Gl.bg <> (0, 0, 0): - needed = needed+1 - if Gl.fg <> (0, 0, 0): - needed = needed+1 - if Gl.doublebuffer: - if needed > available(nplanes/2): - Gl.doublebuffer = 0 - if Gl.warnings: - print 'not enough colors available', - print 'for double buffer mode;', - print 'forcing single buffer mode' - else: - nplanes = nplanes/2 - if needed > available(nplanes): - # Do this warning always - print 'still not enough colors available;', - print 'parts will be left white' - print '(needed', needed, 'but have only', - print available(nplanes), 'colors available)' - # - if Gl.doublebuffer: - doublebuffer() - gconfig() - # - if Gl.colormap: - Gl.c3i = pseudo_c3i - fixcolormap() - else: - Gl.c3i = c3i - RGBmode() - gconfig() - # - if Gl.fullscreen: - # XXX Should find out true screen size using getgdesc() - ortho2(-1.1*1.280, 1.1*1.280, -1.1*1.024, 1.1*1.024) - else: - ortho2(-1.1, 1.1, -1.1, 1.1) - # - return wid + # + if Gl.debug or Gl.foreground: + foreground() + # + if Gl.fullscreen: + # XXX Should find out true screen size using getgdesc() + prefposition(0, 1279, 0, 1023) + else: + keepaspect(1, 1) + minsize(64, 64) + # + if not Gl.border: + noborder() + wid = winopen(Gl.title) + # + if not Gl.fullscreen: + keepaspect(1, 1) + minsize(10, 10) + maxsize(2000, 2000) + iconsize(66, 66) + winconstraints() + # + nplanes = getplanes() + nmaps = getgdesc(GD_NMMAPS) + if Gl.warnings: + print nplanes, 'color planes,', nmaps, 'color maps' + # + if nplanes < 12 or Gl.colormap: + if not Gl.colormap: + Gl.colormap = nmaps - 1 + if Gl.warnings: + print 'not enough color planes available', + print 'for RGB mode; forcing colormap mode' + print 'using color map number', Gl.colormap + if not Gl.colorsubset: + needed = 3 + else: + needed = Gl.cyan + Gl.magenta + Gl.yellow + needed = needed*Gl.nparts + if Gl.bg <> (0, 0, 0): + needed = needed+1 + if Gl.fg <> (0, 0, 0): + needed = needed+1 + if Gl.doublebuffer: + if needed > available(nplanes/2): + Gl.doublebuffer = 0 + if Gl.warnings: + print 'not enough colors available', + print 'for double buffer mode;', + print 'forcing single buffer mode' + else: + nplanes = nplanes/2 + if needed > available(nplanes): + # Do this warning always + print 'still not enough colors available;', + print 'parts will be left white' + print '(needed', needed, 'but have only', + print available(nplanes), 'colors available)' + # + if Gl.doublebuffer: + doublebuffer() + gconfig() + # + if Gl.colormap: + Gl.c3i = pseudo_c3i + fixcolormap() + else: + Gl.c3i = c3i + RGBmode() + gconfig() + # + if Gl.fullscreen: + # XXX Should find out true screen size using getgdesc() + ortho2(-1.1*1.280, 1.1*1.280, -1.1*1.024, 1.1*1.024) + else: + ortho2(-1.1, 1.1, -1.1, 1.1) + # + return wid def available(nplanes): - return pow(2, nplanes) - 1 # Reserve one pixel for black + return pow(2, nplanes) - 1 # Reserve one pixel for black def fixcolormap(): - multimap() - gconfig() - nplanes = getplanes() - if Gl.warnings: - print 'multimap mode has', nplanes, 'color planes' - imap = Gl.colormap - Gl.startindex = pow(2, nplanes) - 1 - Gl.stopindex = 1 - setmap(imap) - mapcolor(0, 0, 0, 0) # Fixed entry for black - if Gl.bg <> (0, 0, 0): - r, g, b = Gl.bg - mapcolor(1, r, g, b) # Fixed entry for Gl.bg - Gl.stopindex = 2 - if Gl.fg <> (0, 0, 0): - r, g, b = Gl.fg - mapcolor(2, r, g, b) # Fixed entry for Gl.fg - Gl.stopindex = 3 - Gl.overflow_seen = 0 - resetindex() + multimap() + gconfig() + nplanes = getplanes() + if Gl.warnings: + print 'multimap mode has', nplanes, 'color planes' + imap = Gl.colormap + Gl.startindex = pow(2, nplanes) - 1 + Gl.stopindex = 1 + setmap(imap) + mapcolor(0, 0, 0, 0) # Fixed entry for black + if Gl.bg <> (0, 0, 0): + r, g, b = Gl.bg + mapcolor(1, r, g, b) # Fixed entry for Gl.bg + Gl.stopindex = 2 + if Gl.fg <> (0, 0, 0): + r, g, b = Gl.fg + mapcolor(2, r, g, b) # Fixed entry for Gl.fg + Gl.stopindex = 3 + Gl.overflow_seen = 0 + resetindex() def resetindex(): - Gl.index = Gl.startindex + Gl.index = Gl.startindex r0g0b0 = (0, 0, 0) def pseudo_c3i(rgb): - if rgb = r0g0b0: - index = 0 - elif rgb = Gl.bg: - index = 1 - elif rgb = Gl.fg: - index = 2 - else: - index = definecolor(rgb) - color(index) + if rgb = r0g0b0: + index = 0 + elif rgb = Gl.bg: + index = 1 + elif rgb = Gl.fg: + index = 2 + else: + index = definecolor(rgb) + color(index) def definecolor(rgb): - index = Gl.index - if index < Gl.stopindex: - if Gl.debug: print 'definecolor hard case', rgb - # First see if we already have this one... - for index in range(Gl.stopindex, Gl.startindex+1): - if rgb = getmcolor(index): - if Gl.debug: print 'return', index - return index - # Don't clobber reserverd colormap entries - if not Gl.overflow_seen: - # Shouldn't happen any more, hence no Gl.warnings test - print 'mclock: out of colormap entries' - Gl.overflow_seen = 1 - return Gl.stopindex - r, g, b = rgb - if Gl.debug > 1: print 'mapcolor', (index, r, g, b) - mapcolor(index, r, g, b) - Gl.index = index - 1 - return index + index = Gl.index + if index < Gl.stopindex: + if Gl.debug: print 'definecolor hard case', rgb + # First see if we already have this one... + for index in range(Gl.stopindex, Gl.startindex+1): + if rgb = getmcolor(index): + if Gl.debug: print 'return', index + return index + # Don't clobber reserverd colormap entries + if not Gl.overflow_seen: + # Shouldn't happen any more, hence no Gl.warnings test + print 'mclock: out of colormap entries' + Gl.overflow_seen = 1 + return Gl.stopindex + r, g, b = rgb + if Gl.debug > 1: print 'mapcolor', (index, r, g, b) + mapcolor(index, r, g, b) + Gl.index = index - 1 + return index # Compute n**i def pow(n, i): - x = 1 - for j in range(i): x = x*n - return x + x = 1 + for j in range(i): x = x*n + return x def mouseclick(mouse, updown, x, y): - if updown = 1: - # mouse button came down, start tracking - if Gl.debug: - print 'mouse', mouse, 'down at', x, y - if mouse = 2: - Gl.mouse2down = 1 - mouse2track(x, y) - elif mouse = 3: - Gl.mouse3down = 1 - mouse3track(x, y) - else: - print 'fatal error' - qdevice(MOUSEX) - qdevice(MOUSEY) - return 0 - else: - # mouse button came up, stop tracking - if Gl.debug: - print 'mouse', mouse, 'up at', x, y - unqdevice(MOUSEX) - unqdevice(MOUSEY) - if mouse = 2: - mouse2track(x, y) - Gl.mouse2down = 0 - elif mouse = 3: - mouse3track(x, y) - Gl.mouse3down = 0 - else: - print 'fatal error' - Gl.alarm_set = 1 - return 1 + if updown = 1: + # mouse button came down, start tracking + if Gl.debug: + print 'mouse', mouse, 'down at', x, y + if mouse = 2: + Gl.mouse2down = 1 + mouse2track(x, y) + elif mouse = 3: + Gl.mouse3down = 1 + mouse3track(x, y) + else: + print 'fatal error' + qdevice(MOUSEX) + qdevice(MOUSEY) + return 0 + else: + # mouse button came up, stop tracking + if Gl.debug: + print 'mouse', mouse, 'up at', x, y + unqdevice(MOUSEX) + unqdevice(MOUSEY) + if mouse = 2: + mouse2track(x, y) + Gl.mouse2down = 0 + elif mouse = 3: + mouse3track(x, y) + Gl.mouse3down = 0 + else: + print 'fatal error' + Gl.alarm_set = 1 + return 1 def mouse3track(x, y): - # first compute polar coordinates from x and y - cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2 - x, y = x - cx, y - cy - if (x, y) = (0, 0): return # would cause an exception - minutes = int(30.5 + 30.0*math.atan2(float(-x), float(-y))/pi) - if minutes = 60: minutes = 0 - a,b = Gl.alarm_minutes/15, minutes/15 - if (a,b) = (0,3): - # Moved backward through 12 o'clock: - Gl.alarm_hours = Gl.alarm_hours - 1 - if Gl.alarm_hours < 0: Gl.alarm_hours = Gl.alarm_hours + 24 - if (a,b) = (3,0): - # Moved forward through 12 o'clock: - Gl.alarm_hours = Gl.alarm_hours + 1 - if Gl.alarm_hours >= 24: Gl.alarm_hours = Gl.alarm_hours - 24 - Gl.alarm_minutes = minutes - seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE - if seconds <> Gl.alarm_time: - draw_alarm(rgb_bg()) - Gl.alarm_time = seconds - draw_alarm(rgb_fg()) + # first compute polar coordinates from x and y + cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2 + x, y = x - cx, y - cy + if (x, y) = (0, 0): return # would cause an exception + minutes = int(30.5 + 30.0*math.atan2(float(-x), float(-y))/pi) + if minutes = 60: minutes = 0 + a,b = Gl.alarm_minutes/15, minutes/15 + if (a,b) = (0,3): + # Moved backward through 12 o'clock: + Gl.alarm_hours = Gl.alarm_hours - 1 + if Gl.alarm_hours < 0: Gl.alarm_hours = Gl.alarm_hours + 24 + if (a,b) = (3,0): + # Moved forward through 12 o'clock: + Gl.alarm_hours = Gl.alarm_hours + 1 + if Gl.alarm_hours >= 24: Gl.alarm_hours = Gl.alarm_hours - 24 + Gl.alarm_minutes = minutes + seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE + if seconds <> Gl.alarm_time: + draw_alarm(rgb_bg()) + Gl.alarm_time = seconds + draw_alarm(rgb_fg()) def mouse2track(x, y): - # first compute polar coordinates from x and y - cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2 - x, y = x - cx, y - cy - if (x, y) = (0, 0): return # would cause an exception - hours = int(6.5 - float(Gl.alarm_minutes)/60.0 + 6.0*math.atan2(float(-x), float(-y))/pi) - if hours = 12: hours = 0 - if (Gl.alarm_hours,hours) = (0,11): - # Moved backward through midnight: - Gl.alarm_hours = 23 - elif (Gl.alarm_hours,hours) = (12,11): - # Moved backward through noon: - Gl.alarm_hours = 11 - elif (Gl.alarm_hours,hours) = (11,0): - # Moved forward through noon: - Gl.alarm_hours = 12 - elif (Gl.alarm_hours,hours) = (23,0): - # Moved forward through midnight: - Gl.alarm_hours = 0 - elif Gl.alarm_hours < 12: - Gl.alarm_hours = hours - else: - Gl.alarm_hours = hours + 12 - seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE - if seconds <> Gl.alarm_time: - draw_alarm(rgb_bg()) - Gl.alarm_time = seconds - draw_alarm(rgb_fg()) + # first compute polar coordinates from x and y + cx, cy = Gl.ox + Gl.cx/2, Gl.oy + Gl.cy/2 + x, y = x - cx, y - cy + if (x, y) = (0, 0): return # would cause an exception + hours = int(6.5 - float(Gl.alarm_minutes)/60.0 + 6.0*math.atan2(float(-x), float(-y))/pi) + if hours = 12: hours = 0 + if (Gl.alarm_hours,hours) = (0,11): + # Moved backward through midnight: + Gl.alarm_hours = 23 + elif (Gl.alarm_hours,hours) = (12,11): + # Moved backward through noon: + Gl.alarm_hours = 11 + elif (Gl.alarm_hours,hours) = (11,0): + # Moved forward through noon: + Gl.alarm_hours = 12 + elif (Gl.alarm_hours,hours) = (23,0): + # Moved forward through midnight: + Gl.alarm_hours = 0 + elif Gl.alarm_hours < 12: + Gl.alarm_hours = hours + else: + Gl.alarm_hours = hours + 12 + seconds = Gl.alarm_hours * HOUR + Gl.alarm_minutes * MINUTE + if seconds <> Gl.alarm_time: + draw_alarm(rgb_bg()) + Gl.alarm_time = seconds + draw_alarm(rgb_fg()) def initmenu(): - Gl.pup = pup = newpup() - addtopup(pup, 'M Clock%t|Alarm On/Off|Seconds Hand On/Off|Quit', 0) + Gl.pup = pup = newpup() + addtopup(pup, 'M Clock%t|Alarm On/Off|Seconds Hand On/Off|Quit', 0) def handlemenu(): - item = dopup(Gl.pup) - if item = 1: - # Toggle alarm - if Gl.alarm_set: - Gl.alarm_set = 0 - Gl.alarm_on = 0 - else: - Gl.alarm_set = 1 - Gl.change = 1 - clearall() - elif item = 2: - # Toggle Seconds Hand - if Gl.update = 1: - Gl.update = 60 - Gl.timernoise = 60 - else: - Gl.update = 1 - Gl.timernoise = 6 - Gl.change = 1 - elif item = 3: - if Gl.debug: print 'Exit' - sys.exit(0) + item = dopup(Gl.pup) + if item = 1: + # Toggle alarm + if Gl.alarm_set: + Gl.alarm_set = 0 + Gl.alarm_on = 0 + else: + Gl.alarm_set = 1 + Gl.change = 1 + clearall() + elif item = 2: + # Toggle Seconds Hand + if Gl.update = 1: + Gl.update = 60 + Gl.timernoise = 60 + else: + Gl.update = 1 + Gl.timernoise = 6 + Gl.change = 1 + elif item = 3: + if Gl.debug: print 'Exit' + sys.exit(0) main() diff --git a/demo/sgi/gl/mixing.py b/demo/sgi/gl/mixing.py index 294e65f..85af96c 100755 --- a/demo/sgi/gl/mixing.py +++ b/demo/sgi/gl/mixing.py @@ -1,8 +1,8 @@ #! /ufs/guido/bin/sgi/python -# Use Gouraud shading to mix colors. Requires Z-buffer. +# Use Gouraud shading to mix colors. Requires Z-buffer. # It changes the color assignments so fast that you see white. -# Left button pauses, middle rotates the square. ESC to quit. +# Left button pauses, middle rotates the square. ESC to quit. # Experiment with a larger window (too slow) or smaller window (really white). from GL import * @@ -11,57 +11,57 @@ import DEVICE from math import * # -# tekenvlak : draw a square. with bgnpolygon +# tekenvlak : draw a square. with bgnpolygon # def tekenvlak (vc) : - bgnpolygon() - #vcarray (vc) - for i in vc : - c3f (i[1]) - v3f (i[0]) - endpolygon() + bgnpolygon() + #vcarray (vc) + for i in vc : + c3f (i[1]) + v3f (i[0]) + endpolygon() # # tekendoos : draw a box # def tekendoos (col) : - v = [(-5.0,0.0,0.0),(0.0,5.0,0.0),(5.0,0.0,0.0),(0.0,-5.0,0.0)] - vc = [(v[0],col[0]),(v[1],col[1]),(v[2],col[2]),(v[3],col[1])] - tekenvlak (vc) + v = [(-5.0,0.0,0.0),(0.0,5.0,0.0),(5.0,0.0,0.0),(0.0,-5.0,0.0)] + vc = [(v[0],col[0]),(v[1],col[1]),(v[2],col[2]),(v[3],col[1])] + tekenvlak (vc) # # initialize gl # def initgl () : - # - # open window - # - foreground () - keepaspect (1, 1) - prefposition (100, 500, 100, 500) - w = winopen ('PYTHON RGB') - keepaspect (1, 1) - winconstraints() - # - # configure pipeline (2buf, GOURAUD and RGBmode) - # - doublebuffer () - zbuffer (1) - shademodel (GOURAUD) - RGBmode () - gconfig () - # - # set viewing - # - perspective (900, 1, 1.0, 10.0) - polarview (10.0, 0, 0, 0) - # - # ask for the REDRAW and ESCKEY events - # - qdevice(DEVICE.MOUSE2) - qdevice(DEVICE.MOUSE3) - qdevice(DEVICE.REDRAW) - qdevice(DEVICE.ESCKEY) + # + # open window + # + foreground () + keepaspect (1, 1) + prefposition (100, 500, 100, 500) + w = winopen ('PYTHON RGB') + keepaspect (1, 1) + winconstraints() + # + # configure pipeline (2buf, GOURAUD and RGBmode) + # + doublebuffer () + zbuffer (1) + shademodel (GOURAUD) + RGBmode () + gconfig () + # + # set viewing + # + perspective (900, 1, 1.0, 10.0) + polarview (10.0, 0, 0, 0) + # + # ask for the REDRAW and ESCKEY events + # + qdevice(DEVICE.MOUSE2) + qdevice(DEVICE.MOUSE3) + qdevice(DEVICE.REDRAW) + qdevice(DEVICE.ESCKEY) # @@ -69,48 +69,48 @@ def initgl () : # black = 0 # -# GoForIT : use 2buf to redraw the object 2n times. index i is used as +# GoForIT : use 2buf to redraw the object 2n times. index i is used as # the (smoothly changing) rotation angle # def GoForIt(i) : - col = [(255.0,0.0,0.0), (0.0,255.0,0.0), (0.0,0.0,255.0)] - twist = 0 - freeze = 1 - while 1 : - if freeze <> 0 : - col[0],col[1],col[2] = col[1],col[2],col[0] - # - # clear z-buffer and clear background to light-blue - # - zclear() - cpack (black) - clear() - # - tekendoos (col) - # - swapbuffers() - # - if qtest() <> 0 : - dev, val = qread() - if dev = DEVICE.ESCKEY : - break - elif dev = DEVICE.REDRAW : - reshapeviewport () - elif dev = DEVICE.MOUSE2 and val <> 0 : - twist = twist + 30 - perspective (900, 1, 1.0, 10.0) - polarview (10.0, 0, 0, twist) - elif dev = DEVICE.MOUSE3 and val <> 0 : - freeze = 1 - freeze + col = [(255.0,0.0,0.0), (0.0,255.0,0.0), (0.0,0.0,255.0)] + twist = 0 + freeze = 1 + while 1 : + if freeze <> 0 : + col[0],col[1],col[2] = col[1],col[2],col[0] + # + # clear z-buffer and clear background to light-blue + # + zclear() + cpack (black) + clear() + # + tekendoos (col) + # + swapbuffers() + # + if qtest() <> 0 : + dev, val = qread() + if dev = DEVICE.ESCKEY : + break + elif dev = DEVICE.REDRAW : + reshapeviewport () + elif dev = DEVICE.MOUSE2 and val <> 0 : + twist = twist + 30 + perspective (900, 1, 1.0, 10.0) + polarview (10.0, 0, 0, twist) + elif dev = DEVICE.MOUSE3 and val <> 0 : + freeze = 1 - freeze # the main program # def main () : - initgl () - GoForIt (0) + initgl () + GoForIt (0) # # exec main # -main () +main () diff --git a/demo/sgi/gl/nurbs.py b/demo/sgi/gl/nurbs.py index ee48e23..dbcc18e 100755 --- a/demo/sgi/gl/nurbs.py +++ b/demo/sgi/gl/nurbs.py @@ -20,152 +20,152 @@ idmat = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1] surfknots = [-1, -1, -1, -1, 1, 1, 1, 1] def make_ctlpoints(): - c = [] - # - ci = [] - ci.append(-2.5, -3.7, 1.0) - ci.append(-1.5, -3.7, 3.0) - ci.append(1.5, -3.7, -2.5) - ci.append(2.5, -3.7, -0.75) - c.append(ci) - # - ci = [] - ci.append(-2.5, -2.0, 3.0) - ci.append(-1.5, -2.0, 4.0) - ci.append(1.5, -2.0, -3.0) - ci.append(2.5, -2.0, 0.0) - c.append(ci) - # - ci = [] - ci.append(-2.5, 2.0, 1.0) - ci.append(-1.5, 2.0, 0.0) - ci.append(1.5, 2.0, -1.0) - ci.append(2.5, 2.0, 2.0) - c.append(ci) - # - ci = [] - ci.append(-2.5, 2.7, 1.25) - ci.append(-1.5, 2.7, 0.1) - ci.append(1.5, 2.7, -0.6) - ci.append(2.5, 2.7, 0.2) - c.append(ci) - # - return c + c = [] + # + ci = [] + ci.append(-2.5, -3.7, 1.0) + ci.append(-1.5, -3.7, 3.0) + ci.append(1.5, -3.7, -2.5) + ci.append(2.5, -3.7, -0.75) + c.append(ci) + # + ci = [] + ci.append(-2.5, -2.0, 3.0) + ci.append(-1.5, -2.0, 4.0) + ci.append(1.5, -2.0, -3.0) + ci.append(2.5, -2.0, 0.0) + c.append(ci) + # + ci = [] + ci.append(-2.5, 2.0, 1.0) + ci.append(-1.5, 2.0, 0.0) + ci.append(1.5, 2.0, -1.0) + ci.append(2.5, 2.0, 2.0) + c.append(ci) + # + ci = [] + ci.append(-2.5, 2.7, 1.25) + ci.append(-1.5, 2.7, 0.1) + ci.append(1.5, 2.7, -0.6) + ci.append(2.5, 2.7, 0.2) + c.append(ci) + # + return c ctlpoints = make_ctlpoints() -trimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] +trimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] def make_trimpoints(): - c = [] - c.append(1.0, 0.0, 1.0) - c.append(1.0, 1.0, 1.0) - c.append(0.0, 2.0, 2.0) - c.append(-1.0, 1.0, 1.0) - c.append(-1.0, 0.0, 1.0) - c.append(-1.0, -1.0, 1.0) - c.append(0.0, -2.0, 2.0) - c.append(1.0, -1.0, 1.0) - c.append(1.0, 0.0, 1.0) - return c + c = [] + c.append(1.0, 0.0, 1.0) + c.append(1.0, 1.0, 1.0) + c.append(0.0, 2.0, 2.0) + c.append(-1.0, 1.0, 1.0) + c.append(-1.0, 0.0, 1.0) + c.append(-1.0, -1.0, 1.0) + c.append(0.0, -2.0, 2.0) + c.append(1.0, -1.0, 1.0) + c.append(1.0, 0.0, 1.0) + return c trimpoints = make_trimpoints() def main(): - init_windows() - setup_queue() - make_lights() - init_view() - # - set_scene() - setnurbsproperty( N_ERRORCHECKING, 1.0 ) - setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) - trim_flag = 0 - draw_trim_surface(trim_flag) - # - while 1: - while qtest(): - dev, val = qread() - if dev = ESCKEY: - return - elif dev = WINQUIT: - dglclose(-1) # this for DGL only - return - elif dev = REDRAW: - reshapeviewport() - set_scene() - draw_trim_surface(trim_flag) - elif dev = LEFTMOUSE: - if val: - trim_flag = (not trim_flag) - set_scene() - draw_trim_surface(trim_flag) + init_windows() + setup_queue() + make_lights() + init_view() + # + set_scene() + setnurbsproperty( N_ERRORCHECKING, 1.0 ) + setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) + trim_flag = 0 + draw_trim_surface(trim_flag) + # + while 1: + while qtest(): + dev, val = qread() + if dev = ESCKEY: + return + elif dev = WINQUIT: + dglclose(-1) # this for DGL only + return + elif dev = REDRAW: + reshapeviewport() + set_scene() + draw_trim_surface(trim_flag) + elif dev = LEFTMOUSE: + if val: + trim_flag = (not trim_flag) + set_scene() + draw_trim_surface(trim_flag) def init_windows(): - foreground() - #prefposition(0, 500, 0, 500) - wid = winopen('nurbs') - wintitle('NURBS Surface') - doublebuffer() - RGBmode() - gconfig() - lsetdepth(0x000, 0x7fffff) - zbuffer( TRUE ) + foreground() + #prefposition(0, 500, 0, 500) + wid = winopen('nurbs') + wintitle('NURBS Surface') + doublebuffer() + RGBmode() + gconfig() + lsetdepth(0x000, 0x7fffff) + zbuffer( TRUE ) def setup_queue(): - qdevice(ESCKEY) - qdevice(REDRAW) - qdevice(RIGHTMOUSE) - qdevice(WINQUIT) - qdevice(LEFTMOUSE) #trimming + qdevice(ESCKEY) + qdevice(REDRAW) + qdevice(RIGHTMOUSE) + qdevice(WINQUIT) + qdevice(LEFTMOUSE) #trimming def init_view(): - mmode(MPROJECTION) - ortho( -4., 4., -4., 4., -4., 4. ) - # - mmode(MVIEWING) - loadmatrix(idmat) - # - lmbind(MATERIAL, 1) + mmode(MPROJECTION) + ortho( -4., 4., -4., 4., -4., 4. ) + # + mmode(MVIEWING) + loadmatrix(idmat) + # + lmbind(MATERIAL, 1) def set_scene(): - lmbind(MATERIAL, 0) - RGBcolor(150,150,150) - lmbind(MATERIAL, 1) - clear() - zclear() - # - rotate( 100, 'y' ) - rotate( 100, 'z' ) + lmbind(MATERIAL, 0) + RGBcolor(150,150,150) + lmbind(MATERIAL, 1) + clear() + zclear() + # + rotate( 100, 'y' ) + rotate( 100, 'z' ) def draw_trim_surface(trim_flag): - bgnsurface() - nurbssurface(surfknots, surfknots, ctlpoints, ORDER, ORDER, N_XYZ) - if trim_flag: - bgntrim() - nurbscurve(trimknots, trimpoints, ORDER-1, N_STW) - endtrim() - endsurface() - swapbuffers() + bgnsurface() + nurbssurface(surfknots, surfknots, ctlpoints, ORDER, ORDER, N_XYZ) + if trim_flag: + bgntrim() + nurbscurve(trimknots, trimpoints, ORDER-1, N_STW) + endtrim() + endsurface() + swapbuffers() def make_lights(): - lmdef(DEFLMODEL,1,[]) - lmdef(DEFLIGHT,1,[]) - # - # define material #1 - # - a = [] - a = a + [EMISSION, 0.0, 0.0, 0.0] - a = a + [AMBIENT, 0.1, 0.1, 0.1] - a = a + [DIFFUSE, 0.6, 0.3, 0.3] - a = a + [SPECULAR, 0.0, 0.6, 0.0] - a = a + [SHININESS, 2.0] - a = a + [LMNULL] - lmdef(DEFMATERIAL, 1, a) - # - # turn on lighting - # - lmbind(LIGHT0, 1) - lmbind(LMODEL, 1) + lmdef(DEFLMODEL,1,[]) + lmdef(DEFLIGHT,1,[]) + # + # define material #1 + # + a = [] + a = a + [EMISSION, 0.0, 0.0, 0.0] + a = a + [AMBIENT, 0.1, 0.1, 0.1] + a = a + [DIFFUSE, 0.6, 0.3, 0.3] + a = a + [SPECULAR, 0.0, 0.6, 0.0] + a = a + [SHININESS, 2.0] + a = a + [LMNULL] + lmdef(DEFMATERIAL, 1, a) + # + # turn on lighting + # + lmbind(LIGHT0, 1) + lmbind(LMODEL, 1) main() diff --git a/demo/sgi/gl/zrgb.py b/demo/sgi/gl/zrgb.py index c3f934a..a49b86b 100755 --- a/demo/sgi/gl/zrgb.py +++ b/demo/sgi/gl/zrgb.py @@ -1,13 +1,13 @@ #! /ufs/guido/bin/sgi/python -# zrgb (Requires Z buffer.) +# zrgb (Requires Z buffer.) # # This program demostrates zbuffering 3 intersecting RGB polygons while -# in doublebuffer mode where, movement of the mouse with the LEFTMOUSE +# in doublebuffer mode where, movement of the mouse with the LEFTMOUSE # button depressed will, rotate the 3 polygons. This is done by compound -# rotations allowing continuous screen-oriented rotations. +# rotations allowing continuous screen-oriented rotations. # -# Press the "Esc" key to exit. +# Press the "Esc" key to exit. from gl import * from GL import * @@ -19,115 +19,115 @@ objmat=[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] 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] def main() : - # - # old and new mouse position - # - # - mode = 0 - omx = 0 - mx = 0 - omy = 0 - my = 0 - # - initialize () - # - draw_scene (objmat) - # - while (1) : - # - dev, val = qread() - # - if dev = ESCKEY : - if val : - break - # exit when key is going up, not down - # this avoids the scenario where a window - # underneath this program's window - # would otherwise "eat up" the up- - # event of the Esc key being released - return - # - elif dev = REDRAW : - reshapeviewport() - draw_scene(objmat) - # - elif dev = LEFTMOUSE: - omx = mx - omy = my - if val : - mode = 1 - else : - mode = 0 - elif dev = MOUSEX : - omx = mx - mx = val - #print omx, mx - objmat = update_scene(objmat,mx,my,omx,omy,mode) - # - elif dev = MOUSEY : - omy = my - my = val - #print omy, my - objmat = update_scene(objmat,mx,my,omx,omy,mode) - # + # + # old and new mouse position + # + # + mode = 0 + omx = 0 + mx = 0 + omy = 0 + my = 0 + # + initialize () + # + draw_scene (objmat) + # + while (1) : + # + dev, val = qread() + # + if dev = ESCKEY : + if val : + break + # exit when key is going up, not down + # this avoids the scenario where a window + # underneath this program's window + # would otherwise "eat up" the up- + # event of the Esc key being released + return + # + elif dev = REDRAW : + reshapeviewport() + draw_scene(objmat) + # + elif dev = LEFTMOUSE: + omx = mx + omy = my + if val : + mode = 1 + else : + mode = 0 + elif dev = MOUSEX : + omx = mx + mx = val + #print omx, mx + objmat = update_scene(objmat,mx,my,omx,omy,mode) + # + elif dev = MOUSEY : + omy = my + my = val + #print omy, my + objmat = update_scene(objmat,mx,my,omx,omy,mode) + # def initialize () : - # - foreground () - keepaspect(5, 4) - w = winopen('Zbuffered RGB') - # - doublebuffer() - RGBmode() - gconfig() - zbuffer(1) - lsetdepth(0x0, 0x7FFFFF) - # - qdevice(ESCKEY) - qdevice(LEFTMOUSE) - qdevice(MOUSEX) - qdevice(MOUSEY) + # + foreground () + keepaspect(5, 4) + w = winopen('Zbuffered RGB') + # + doublebuffer() + RGBmode() + gconfig() + zbuffer(1) + lsetdepth(0x0, 0x7FFFFF) + # + qdevice(ESCKEY) + qdevice(LEFTMOUSE) + qdevice(MOUSEX) + qdevice(MOUSEY) def update_scene (mat, mx, my, omx, omy, mode) : - # - if mode = 1 : - mat = orient(mat, mx, my, omx, omy) - draw_scene(mat) - return mat + # + if mode = 1 : + mat = orient(mat, mx, my, omx, omy) + draw_scene(mat) + return mat def orient (mat, mx, my, omx, omy) : - # - # - pushmatrix() - loadmatrix(idmat) - # - if mx - omx : rot (float (mx - omx), 'y') - if omy - my : rot (float (omy - my), 'x') - # - multmatrix(mat) - mat = getmatrix() - # - # - popmatrix() - # - return mat + # + # + pushmatrix() + loadmatrix(idmat) + # + if mx - omx : rot (float (mx - omx), 'y') + if omy - my : rot (float (omy - my), 'x') + # + multmatrix(mat) + mat = getmatrix() + # + # + popmatrix() + # + return mat def draw_scene (mat) : - RGBcolor(40, 100, 200) - clear() - zclear() - # - perspective(400, 1.25, 30.0, 60.0) - translate(0.0, 0.0, -40.0) - multmatrix(mat) - # - # skews original view to show all polygons - # - rotate(-580, 'y') - draw_polys() - # - swapbuffers() + RGBcolor(40, 100, 200) + clear() + zclear() + # + perspective(400, 1.25, 30.0, 60.0) + translate(0.0, 0.0, -40.0) + multmatrix(mat) + # + # skews original view to show all polygons + # + rotate(-580, 'y') + draw_polys() + # + swapbuffers() polygon1 = [(-10.0,-10.0,0.0),(10.0,-10.0,0.0),(-10.0,10.0,0.0)] @@ -136,34 +136,34 @@ polygon2 = [(0.0,-10.0,-10.0),(0.0,-10.0,10.0),(0.0,5.0,-10.0)] polygon3 = [(-10.0,6.0,4.0),(-10.0,3.0,4.0),(4.0,-9.0,-10.0),(4.0,-6.0,-10.0)] def draw_polys(): - bgnpolygon() - cpack(0x0) - v3f(polygon1[0]) - cpack(0x007F7F7F) - v3f(polygon1[1]) - cpack(0x00FFFFFF) - v3f(polygon1[2]) - endpolygon() - # - bgnpolygon() - cpack(0x0000FFFF) - v3f(polygon2[0]) - cpack(0x007FFF00) - v3f(polygon2[1]) - cpack(0x00FF0000) - v3f(polygon2[2]) - endpolygon() - # - bgnpolygon() - cpack(0x0000FFFF) - v3f(polygon3[0]) - cpack(0x00FF00FF) - v3f(polygon3[1]) - cpack(0x00FF0000) - v3f(polygon3[2]) - cpack(0x00FF00FF) - v3f(polygon3[3]) - endpolygon() + bgnpolygon() + cpack(0x0) + v3f(polygon1[0]) + cpack(0x007F7F7F) + v3f(polygon1[1]) + cpack(0x00FFFFFF) + v3f(polygon1[2]) + endpolygon() + # + bgnpolygon() + cpack(0x0000FFFF) + v3f(polygon2[0]) + cpack(0x007FFF00) + v3f(polygon2[1]) + cpack(0x00FF0000) + v3f(polygon2[2]) + endpolygon() + # + bgnpolygon() + cpack(0x0000FFFF) + v3f(polygon3[0]) + cpack(0x00FF00FF) + v3f(polygon3[1]) + cpack(0x00FF0000) + v3f(polygon3[2]) + cpack(0x00FF00FF) + v3f(polygon3[3]) + endpolygon() main () diff --git a/demo/sgi/gl_panel/README b/demo/sgi/gl_panel/README index 889a2cf..ccf255d 100644 --- a/demo/sgi/gl_panel/README +++ b/demo/sgi/gl_panel/README @@ -1,23 +1,23 @@ This directory contains demos that use the Panel Library by NASA Ames. They only run on SGI machines and require the 'pnl' and 'gl' built-in -modules. Each subdirectory contains one demo. +modules. Each subdirectory contains one demo. -apanel A trivial user interface to the audio capabilities of - the 4D/25 (Personal IRIS). Lets you record a sample and - play it back at different volumes. Requires the 'audio' - built-in module. +apanel A trivial user interface to the audio capabilities of + the 4D/25 (Personal IRIS). Lets you record a sample and + play it back at different volumes. Requires the 'audio' + built-in module. -flying A large demonstration that can display several - differently shaped objects through space. Control - panels let you manipulate light sources, material - properties and drawing modes. +flying A large demonstration that can display several + differently shaped objects through space. Control + panels let you manipulate light sources, material + properties and drawing modes. -nurbs A demo of the capabilities of the GL 'nurbs' functions - that can display the control points. (It was intended - to let you move these as well, but there was a problem - with the mapping of mouse movements in a 3-D world.) +nurbs A demo of the capabilities of the GL 'nurbs' functions + that can display the control points. (It was intended + to let you move these as well, but there was a problem + with the mapping of mouse movements in a 3-D world.) -twoview A demo of GL's transformation primitives. Two views on - a scene are given, and the position and orientation of a - viewer in one of the views can be changed through - various buttons and dials in a control panel. +twoview A demo of GL's transformation primitives. Two views on + a scene are given, and the position and orientation of a + viewer in one of the views can be changed through + various buttons and dials in a control panel. diff --git a/demo/sgi/gl_panel/apanel/apanel.py b/demo/sgi/gl_panel/apanel/apanel.py index de9a710..a5adfdb 100755 --- a/demo/sgi/gl_panel/apanel/apanel.py +++ b/demo/sgi/gl_panel/apanel/apanel.py @@ -14,50 +14,50 @@ panel.block(1) import audio def main(): - gl.foreground() - gl.noport() - #gl.prefposition(700, 850, 950, 970) - wid = gl.winopen('audio demo') - # - panels = panel.defpanellist('apanel.s') # XXX - p = panels[0] - p.playbackbutton.back = p - p.recordbutton.back = p - p.sample = '' - # - def quit(a): - sys.exit(0) - # - p.quitbutton.downfunc = quit - # - def playback(a): - p = a.back - gain = int(255.0*p.outputgain.val) - a.val = 1.0 - a.fixact() - panel.drawpanel() - audio.setoutgain(gain) - audio.write(p.sample) - audio.setoutgain(0) - a.val = 0.0 - a.fixact() - # - p.playbackbutton.downfunc = playback - # - def record(a): - p = a.back - size = int(10.0 * 8192.0 * p.recordsize.val) - a.val = 1.0 - a.fixact() - panel.drawpanel() - audio.setoutgain(0) - p.sample = audio.read(size) - a.val = 0.0 - a.fixact() - # - p.recordbutton.downfunc = record - # - while 1: - act = panel.dopanel() + gl.foreground() + gl.noport() + #gl.prefposition(700, 850, 950, 970) + wid = gl.winopen('audio demo') + # + panels = panel.defpanellist('apanel.s') # XXX + p = panels[0] + p.playbackbutton.back = p + p.recordbutton.back = p + p.sample = '' + # + def quit(a): + sys.exit(0) + # + p.quitbutton.downfunc = quit + # + def playback(a): + p = a.back + gain = int(255.0*p.outputgain.val) + a.val = 1.0 + a.fixact() + panel.drawpanel() + audio.setoutgain(gain) + audio.write(p.sample) + audio.setoutgain(0) + a.val = 0.0 + a.fixact() + # + p.playbackbutton.downfunc = playback + # + def record(a): + p = a.back + size = int(10.0 * 8192.0 * p.recordsize.val) + a.val = 1.0 + a.fixact() + panel.drawpanel() + audio.setoutgain(0) + p.sample = audio.read(size) + a.val = 0.0 + a.fixact() + # + p.recordbutton.downfunc = record + # + while 1: + act = panel.dopanel() main() diff --git a/demo/sgi/gl_panel/flying/flying.py b/demo/sgi/gl_panel/flying/flying.py index e6fd823..b51f466 100755 --- a/demo/sgi/gl_panel/flying/flying.py +++ b/demo/sgi/gl_panel/flying/flying.py @@ -7,369 +7,369 @@ import DEVICE, time import objectdef, light, panel, material def fixmatact (p) : - p.diffR.fixact () - p.diffG.fixact () - p.diffB.fixact () - p.specR.fixact () - p.specG.fixact () - p.specB.fixact () - p.shine.fixact () + p.diffR.fixact () + p.diffG.fixact () + p.diffB.fixact () + p.specR.fixact () + p.specG.fixact () + p.specB.fixact () + p.shine.fixact () def fixlichtact (p) : - p.R.fixact () - p.G.fixact () - p.B.fixact () - p.X.fixact () - p.Y.fixact () - p.Z.fixact () - p.local.fixact () + p.R.fixact () + p.G.fixact () + p.B.fixact () + p.X.fixact () + p.Y.fixact () + p.Z.fixact () + p.local.fixact () def cbsetlight (a) : - p = a.back - setlight (p, a.label) + p = a.back + setlight (p, a.label) def cbsetmaterial (a) : - p = a.back - setmaterial (p, a.label) + p = a.back + setmaterial (p, a.label) mater = [0] licht = [0] def setmaterial (p, mname) : - # - mater [0:1] = [material.materdict [mname]] - # - p.diffR.val = mater [0][1] - p.diffG.val = mater [0][2] - p.diffB.val = mater [0][3] - # - p.specR.val = mater [0][5] - p.specG.val = mater [0][6] - p.specB.val = mater [0][7] - # - p.shine.val = mater [0][9] / 128.0 - fixmatact (p) + # + mater [0:1] = [material.materdict [mname]] + # + p.diffR.val = mater [0][1] + p.diffG.val = mater [0][2] + p.diffB.val = mater [0][3] + # + p.specR.val = mater [0][5] + p.specG.val = mater [0][6] + p.specB.val = mater [0][7] + # + p.shine.val = mater [0][9] / 128.0 + fixmatact (p) def setlight (p, mname) : - # - licht [0:1] = [material.lichtdict [mname]] - # - p.R.val = licht [0][1] - p.G.val = licht [0][2] - p.B.val = licht [0][3] - # - p.X.val = (licht [0][5] + 10.0) / 20.0 - p.Y.val = (licht [0][6] + 10.0) / 20.0 - p.Z.val = (licht [0][7] + 10.0) / 20.0 - # - p.local.val = licht [0][8] - # - fixlichtact (p) + # + licht [0:1] = [material.lichtdict [mname]] + # + p.R.val = licht [0][1] + p.G.val = licht [0][2] + p.B.val = licht [0][3] + # + p.X.val = (licht [0][5] + 10.0) / 20.0 + p.Y.val = (licht [0][6] + 10.0) / 20.0 + p.Z.val = (licht [0][7] + 10.0) / 20.0 + # + p.local.val = licht [0][8] + # + fixlichtact (p) def cbmaterial (a) : - # - if mater[0] = 0 : return - # - p = a.back - mater [0][5:8] = [p.diffR.val, p.diffG.val, p.diffB.val] - mater [0][1:4] = [p.specR.val, p.specG.val, p.specB.val] - mater [0][9:10] = [128.0 * p.shine.val] - light.bindlight (0) + # + if mater[0] = 0 : return + # + p = a.back + mater [0][5:8] = [p.diffR.val, p.diffG.val, p.diffB.val] + mater [0][1:4] = [p.specR.val, p.specG.val, p.specB.val] + mater [0][9:10] = [128.0 * p.shine.val] + light.bindlight (0) def cblight (a) : - # - if licht[0] = 0 : return - # - p = a.back - licht [0][1:4] = [p.R.val, p.G.val, p.B.val] - licht [0][5:8] = [20.0 * p.X.val - 10.0, 20.0 * p.Y.val - 10.0, 20.0 * p.Z.val - 10.0] - if p.local.val = 0.0 : - licht [0][8:9] = [0.0] - else: - licht [0][8:9] = [1.0] - # - light.bindlight (0) + # + if licht[0] = 0 : return + # + p = a.back + licht [0][1:4] = [p.R.val, p.G.val, p.B.val] + licht [0][5:8] = [20.0 * p.X.val - 10.0, 20.0 * p.Y.val - 10.0, 20.0 * p.Z.val - 10.0] + if p.local.val = 0.0 : + licht [0][8:9] = [0.0] + else: + licht [0][8:9] = [1.0] + # + light.bindlight (0) # # initgl : initialize window, pipeline, light, viewing # def initgl () : - # - # init window - # - foreground () - keepaspect (1, 1) - prefposition (100, 500, 100, 500) - w = winopen ('flying objects') - keepaspect (1, 1) - winconstraints () - # - # configure pipline - # - doublebuffer () - shademodel (GOURAUD) - zbuffer (1) - RGBmode () - gconfig () - # - # init lighting - # - light.bindlight (1) - # - # set viewing - # - lookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0) - # + # + # init window + # + foreground () + keepaspect (1, 1) + prefposition (100, 500, 100, 500) + w = winopen ('flying objects') + keepaspect (1, 1) + winconstraints () + # + # configure pipline + # + doublebuffer () + shademodel (GOURAUD) + zbuffer (1) + RGBmode () + gconfig () + # + # init lighting + # + light.bindlight (1) + # + # set viewing + # + lookat (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0) + # # # drawit : draws the object with the given attributes. # # rfac : the rotation factor. -# mat : the material identification -# attr : a list of attributes : +# mat : the material identification +# attr : a list of attributes : # -# [[rotate vector ], [tranlate vector], [scale vector]] -# i.e : -# [[rX, rY, rZ], [tX, tY, tZ], [sX, sY, sZ]] +# [[rotate vector ], [tranlate vector], [scale vector]] +# i.e : +# [[rX, rY, rZ], [tX, tY, tZ], [sX, sY, sZ]] # def drawit(object, rfac, attr, mat) : - pushmatrix() - rot (attr[0][0] * float (rfac), 'X') - rot (attr[0][1] * float (rfac), 'Y') - rot (attr[0][2] * float (rfac), 'Z') - translate(attr[1][0], attr[1][1], attr[1][2]) - scale(attr[2][0], attr[2][1], attr[2][2]) - lmbind(MATERIAL, mat) - objectdef.drawobject(object) - popmatrix() + pushmatrix() + rot (attr[0][0] * float (rfac), 'X') + rot (attr[0][1] * float (rfac), 'Y') + rot (attr[0][2] * float (rfac), 'Z') + translate(attr[1][0], attr[1][1], attr[1][2]) + scale(attr[2][0], attr[2][1], attr[2][2]) + lmbind(MATERIAL, mat) + objectdef.drawobject(object) + popmatrix() def callbacksphere (a) : - putDict (objects, 'sphere', int (a.val)) + putDict (objects, 'sphere', int (a.val)) def callbackcylinder (a) : - putDict (objects, 'cylinder', int (a.val)) + putDict (objects, 'cylinder', int (a.val)) def callbackcube (a) : - putDict (objects, 'cube', int (a.val)) + putDict (objects, 'cube', int (a.val)) def callbackicecream (a) : - putDict (objects, 'icecream', int (a.val)) + putDict (objects, 'icecream', int (a.val)) def callbackdisk (a) : - putDict (objects, 'disk', int (a.val)) + putDict (objects, 'disk', int (a.val)) def callbackdiamond (a) : - putDict (objects, 'diamond', int (a.val)) + putDict (objects, 'diamond', int (a.val)) def callbackglass (a) : - putDict (objects, 'glass', int (a.val)) + putDict (objects, 'glass', int (a.val)) def callbackpyramid (a) : - putDict (objects, 'pyramid', int (a.val)) + putDict (objects, 'pyramid', int (a.val)) def callbacktable (a) : - putDict (objects, 'table', int (a.val)) + putDict (objects, 'table', int (a.val)) def callbackflat (a) : - shademodel(FLAT) + shademodel(FLAT) def callbackgouraud (a) : - shademodel(GOURAUD) + shademodel(GOURAUD) def callbackwire (a) : - objectdef.putFunc ([bgnclosedline, endclosedline]) + objectdef.putFunc ([bgnclosedline, endclosedline]) def callbackfilled (a) : - objectdef.putFunc ([bgnpolygon, endpolygon]) + objectdef.putFunc ([bgnpolygon, endpolygon]) def callbackquit (a) : - import sys - sys.exit (-1) + import sys + sys.exit (-1) def allObjects(p, val) : - p.sphere.val = val - p.sphere.fixact () - p.cube.val = val - p.cube.fixact () - p.cylinder.val = val - p.cylinder.fixact () - p.pyramid.val = val - p.pyramid.fixact () - p.disk.val = val - p.disk.fixact () - p.diamond.val = val - p.diamond.fixact () - p.icecream.val = val - p.icecream.fixact () - p.table.val = val - p.table.fixact () - p.fixpanel() - + p.sphere.val = val + p.sphere.fixact () + p.cube.val = val + p.cube.fixact () + p.cylinder.val = val + p.cylinder.fixact () + p.pyramid.val = val + p.pyramid.fixact () + p.disk.val = val + p.disk.fixact () + p.diamond.val = val + p.diamond.fixact () + p.icecream.val = val + p.icecream.fixact () + p.table.val = val + p.table.fixact () + p.fixpanel() + def callbackshowall (a) : - #print objects - for key in objects.keys () : - #print key - putDict (objects, key, 1) - allObjects (a.back, 1.0) + #print objects + for key in objects.keys () : + #print key + putDict (objects, key, 1) + allObjects (a.back, 1.0) def callbackshownone (a) : - for key in objects.keys () : - putDict (objects, key, 0) - allObjects (a.back, 0.0) + for key in objects.keys () : + putDict (objects, key, 0) + allObjects (a.back, 0.0) # # main : makeobjects, initialze graphics, and loop continuously. # def main () : - # - # iter keeps track of the iterations. It is used as the - # (x, y, z) rotation increments to which the objects rotate. - iter = 0 - # - # make the objects. the objects are put in the odict dictionary - # - od = objectdef.makeobjects () - # - # initialize gl - # - initgl () - # - # initialize time and iterations per second - # - time0 = time.time () # epoch-time of previous second - fps = 0 # frames per second - # - # initialize panels - # - panel.needredraw() - panels = panel.defpanellist('flying.s') #XXX - p = panels[0] - p.sphere.upfunc = callbacksphere - p.cylinder.upfunc = callbackcylinder - p.cube.upfunc = callbackcube - p.icecream.upfunc = callbackicecream - p.disk.upfunc = callbackdisk - p.diamond.upfunc = callbackdiamond - # NOT YET IMPLEMENTED p.glass.upfunc = callbackglass - p.pyramid.upfunc = callbackpyramid - p.table.upfunc = callbacktable - p.wire.upfunc = callbackwire - p.filled.upfunc = callbackfilled - p.flat.upfunc = callbackflat - p.gouraud.upfunc = callbackgouraud - p.quit.upfunc = callbackquit - p.showall.upfunc = callbackshowall - p.shownone.upfunc = callbackshownone - p.showall.back = p - p.shownone.back = p - # - qanels = panel.defpanellist('freeze.s') #XXX - q = qanels[0] - # - ranels = panel.defpanellist('materials.s') #XXX - r = ranels[0] - r.m9.upfunc = cbsetmaterial - r.m8.upfunc = cbsetmaterial - r.m7.upfunc = cbsetmaterial - r.m6.upfunc = cbsetmaterial - r.m5.upfunc = cbsetmaterial - r.m4.upfunc = cbsetmaterial - r.m3.upfunc = cbsetmaterial - r.m2.upfunc = cbsetmaterial - r.m1.upfunc = cbsetmaterial - r.specR.activefunc = cbmaterial - r.specG.activefunc = cbmaterial - r.specB.activefunc = cbmaterial - r.diffR.activefunc = cbmaterial - r.diffG.activefunc = cbmaterial - r.diffB.activefunc = cbmaterial - r.shine.activefunc = cbmaterial - r.m9.back = r - r.m8.back = r - r.m7.back = r - r.m6.back = r - r.m5.back = r - r.m4.back = r - r.m3.back = r - r.m2.back = r - r.m1.back = r - r.diffR.back = r - r.diffG.back = r - r.diffB.back = r - r.specR.back = r - r.specG.back = r - r.specB.back = r - r.shine.back = r - # - sanels = panel.defpanellist('light.s') #XXX - s = sanels[0] - s.X.back = s - s.Y.back = s - s.Z.back = s - s.R.back = s - s.G.back = s - s.B.back = s - s.light1.back = s - s.light2.back = s - s.local.back = s - s.light1.upfunc = cbsetlight - s.light2.upfunc = cbsetlight - s.R.activefunc = cblight - s.G.activefunc = cblight - s.B.activefunc = cblight - s.X.activefunc = cblight - s.Y.activefunc = cblight - s.Z.activefunc = cblight - # - while 1 : - # - act = panel.dopanel() - # - wid = panel.userredraw () - if wid : - winset (wid) - reshapeviewport() - # - # increment iter - # - if int (q.freeze.val) = 0 : - iter = iter + 1 - fps = fps + 1 - if time.time() - time0 >= 1 : - f = float(fps)/float(time.time()-time0) - q.mystrip.val = f - q.mystrip.fixact () - q.fixpanel() - time0 = time.time() - fps = 0 - # - # clear the zbuffer and make the background light blue - # - zclear() - c3i (LightBlue) - clear() - # - # for each object in the objects dictionary - # - for key in objects.keys() : - # - # if the object should be displayed - # - if getDict (objects, key, 0) = ONE : - loo = getDict (objects, key, 1) - for o in loo : - # - # get attributes and materail - # - attr = o [1] - mat = o [2] - # - # display the object - # - drawit(od[o[0]],iter,attr,mat) - # - swapbuffers() - # + # + # iter keeps track of the iterations. It is used as the + # (x, y, z) rotation increments to which the objects rotate. + iter = 0 + # + # make the objects. the objects are put in the odict dictionary + # + od = objectdef.makeobjects () + # + # initialize gl + # + initgl () + # + # initialize time and iterations per second + # + time0 = time.time () # epoch-time of previous second + fps = 0 # frames per second + # + # initialize panels + # + panel.needredraw() + panels = panel.defpanellist('flying.s') #XXX + p = panels[0] + p.sphere.upfunc = callbacksphere + p.cylinder.upfunc = callbackcylinder + p.cube.upfunc = callbackcube + p.icecream.upfunc = callbackicecream + p.disk.upfunc = callbackdisk + p.diamond.upfunc = callbackdiamond + # NOT YET IMPLEMENTED p.glass.upfunc = callbackglass + p.pyramid.upfunc = callbackpyramid + p.table.upfunc = callbacktable + p.wire.upfunc = callbackwire + p.filled.upfunc = callbackfilled + p.flat.upfunc = callbackflat + p.gouraud.upfunc = callbackgouraud + p.quit.upfunc = callbackquit + p.showall.upfunc = callbackshowall + p.shownone.upfunc = callbackshownone + p.showall.back = p + p.shownone.back = p + # + qanels = panel.defpanellist('freeze.s') #XXX + q = qanels[0] + # + ranels = panel.defpanellist('materials.s') #XXX + r = ranels[0] + r.m9.upfunc = cbsetmaterial + r.m8.upfunc = cbsetmaterial + r.m7.upfunc = cbsetmaterial + r.m6.upfunc = cbsetmaterial + r.m5.upfunc = cbsetmaterial + r.m4.upfunc = cbsetmaterial + r.m3.upfunc = cbsetmaterial + r.m2.upfunc = cbsetmaterial + r.m1.upfunc = cbsetmaterial + r.specR.activefunc = cbmaterial + r.specG.activefunc = cbmaterial + r.specB.activefunc = cbmaterial + r.diffR.activefunc = cbmaterial + r.diffG.activefunc = cbmaterial + r.diffB.activefunc = cbmaterial + r.shine.activefunc = cbmaterial + r.m9.back = r + r.m8.back = r + r.m7.back = r + r.m6.back = r + r.m5.back = r + r.m4.back = r + r.m3.back = r + r.m2.back = r + r.m1.back = r + r.diffR.back = r + r.diffG.back = r + r.diffB.back = r + r.specR.back = r + r.specG.back = r + r.specB.back = r + r.shine.back = r + # + sanels = panel.defpanellist('light.s') #XXX + s = sanels[0] + s.X.back = s + s.Y.back = s + s.Z.back = s + s.R.back = s + s.G.back = s + s.B.back = s + s.light1.back = s + s.light2.back = s + s.local.back = s + s.light1.upfunc = cbsetlight + s.light2.upfunc = cbsetlight + s.R.activefunc = cblight + s.G.activefunc = cblight + s.B.activefunc = cblight + s.X.activefunc = cblight + s.Y.activefunc = cblight + s.Z.activefunc = cblight + # + while 1 : + # + act = panel.dopanel() + # + wid = panel.userredraw () + if wid : + winset (wid) + reshapeviewport() + # + # increment iter + # + if int (q.freeze.val) = 0 : + iter = iter + 1 + fps = fps + 1 + if time.time() - time0 >= 1 : + f = float(fps)/float(time.time()-time0) + q.mystrip.val = f + q.mystrip.fixact () + q.fixpanel() + time0 = time.time() + fps = 0 + # + # clear the zbuffer and make the background light blue + # + zclear() + c3i (LightBlue) + clear() + # + # for each object in the objects dictionary + # + for key in objects.keys() : + # + # if the object should be displayed + # + if getDict (objects, key, 0) = ONE : + loo = getDict (objects, key, 1) + for o in loo : + # + # get attributes and materail + # + attr = o [1] + mat = o [2] + # + # display the object + # + drawit(od[o[0]],iter,attr,mat) + # + swapbuffers() + # main() diff --git a/demo/sgi/gl_panel/flying/light.py b/demo/sgi/gl_panel/flying/light.py index f6bf379..51803fc 100644 --- a/demo/sgi/gl_panel/flying/light.py +++ b/demo/sgi/gl_panel/flying/light.py @@ -23,24 +23,24 @@ light2 = [LCOLOR,1.0,1.0,1.0,POSITION,-10.0,10.0,5.0,0.0,LMNULL] model = [AMBIENT,0.4,0.4,0.4,LMNULL] def bindlight (bool) : - # Initializes all settings for a window. - if bool <> 0 : - mmode(MVIEWING) - perspective (900, 1.0, 1.0, 35.0) - loadmatrix(idmat) - # define materials and lights - lmdef(DEFMATERIAL, 1, m1) - lmdef(DEFMATERIAL, 2, m2) - lmdef(DEFMATERIAL, 3, m3) - lmdef(DEFMATERIAL, 4, m4) - lmdef(DEFMATERIAL, 5, m5) - lmdef(DEFMATERIAL, 6, m6) - lmdef(DEFMATERIAL, 7, m7) - lmdef(DEFMATERIAL, 8, m8) - lmdef(DEFMATERIAL, 9, m9) - lmdef(DEFLIGHT, 1, light1) - lmdef(DEFLIGHT, 2, light2) - lmdef(DEFLMODEL, 1, model) - lmbind(LIGHT0,1) - lmbind(LIGHT1,2) - lmbind(LMODEL,1) + # Initializes all settings for a window. + if bool <> 0 : + mmode(MVIEWING) + perspective (900, 1.0, 1.0, 35.0) + loadmatrix(idmat) + # define materials and lights + lmdef(DEFMATERIAL, 1, m1) + lmdef(DEFMATERIAL, 2, m2) + lmdef(DEFMATERIAL, 3, m3) + lmdef(DEFMATERIAL, 4, m4) + lmdef(DEFMATERIAL, 5, m5) + lmdef(DEFMATERIAL, 6, m6) + lmdef(DEFMATERIAL, 7, m7) + lmdef(DEFMATERIAL, 8, m8) + lmdef(DEFMATERIAL, 9, m9) + lmdef(DEFLIGHT, 1, light1) + lmdef(DEFLIGHT, 2, light2) + lmdef(DEFLMODEL, 1, model) + lmbind(LIGHT0,1) + lmbind(LIGHT1,2) + lmbind(LMODEL,1) diff --git a/demo/sgi/gl_panel/flying/material.py b/demo/sgi/gl_panel/flying/material.py index f9137ea..f091fbb 100644 --- a/demo/sgi/gl_panel/flying/material.py +++ b/demo/sgi/gl_panel/flying/material.py @@ -1,26 +1,26 @@ import light def mkmatdict () : - m = {} - m['material 1'] = light.m1 - m['material 2'] = light.m2 - m['material 3'] = light.m3 - m['material 4'] = light.m4 - m['material 5'] = light.m5 - m['material 6'] = light.m6 - m['material 7'] = light.m7 - m['material 8'] = light.m8 - m['material 9'] = light.m9 - # - return m + m = {} + m['material 1'] = light.m1 + m['material 2'] = light.m2 + m['material 3'] = light.m3 + m['material 4'] = light.m4 + m['material 5'] = light.m5 + m['material 6'] = light.m6 + m['material 7'] = light.m7 + m['material 8'] = light.m8 + m['material 9'] = light.m9 + # + return m materdict = mkmatdict () def mklichtdict () : - m = {} - m['light 1'] = light.light1 - m['light 2'] = light.light2 - # - return m + m = {} + m['light 1'] = light.light1 + m['light 2'] = light.light2 + # + return m lichtdict = mklichtdict () diff --git a/demo/sgi/gl_panel/flying/materials.s b/demo/sgi/gl_panel/flying/materials.s index ae45ca9..b505f0b 100644 --- a/demo/sgi/gl_panel/flying/materials.s +++ b/demo/sgi/gl_panel/flying/materials.s @@ -56,7 +56,7 @@ (h 0.36) (downfunc move-then-resize) ) -(pnl_radio_button (name "m4") +(pnl_radio_button (name "m4") (prop help creator:user-act-help) (label "material 4") (x 6.5) @@ -80,7 +80,7 @@ (h 0.36) (downfunc move-then-resize) ) -(pnl_radio_button (name "m1") +(pnl_radio_button (name "m1") (prop help creator:user-act-help) (label "material 1") (x 6.5) diff --git a/demo/sgi/gl_panel/flying/objdict.py b/demo/sgi/gl_panel/flying/objdict.py index a5d5371..9195093 100644 --- a/demo/sgi/gl_panel/flying/objdict.py +++ b/demo/sgi/gl_panel/flying/objdict.py @@ -23,14 +23,14 @@ objects['table'] = [ZERO, o8] # 'putDict' sets the value of entry 'key' of dictionary 'dict' def putDict(dict, key, val) : - dict[key][0] = val + dict[key][0] = val # -# 'getDict' get the contents of entry i of key 'key' +# 'getDict' get the contents of entry i of key 'key' # of dictionary 'dict' # def getDict(dict, key, i) : - return dict[key][i] + return dict[key][i] # the 'options' dictionary contains the strings of the menu items # that denote the options diff --git a/demo/sgi/gl_panel/flying/objectdef.py b/demo/sgi/gl_panel/flying/objectdef.py index 3e96113..02a9513 100644 --- a/demo/sgi/gl_panel/flying/objectdef.py +++ b/demo/sgi/gl_panel/flying/objectdef.py @@ -7,141 +7,141 @@ FUZZY = 0.00001 # first try - brute force method (ala M.Overmars...) def makespinobject (smooth,rot,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) : - object = [] - dth = 2.0 * pi / float (rot) - for i in range (0, n) : - for j in range (0, rot) : - th = dth * float (j) - # - if smooth = 1: - a1 = th - a2 =th+dth - else : - a1 = th + dth / 2.0 - a2 = th + dth / 2.0 - # - v0 = (x1[i]*sin(th),x1[i]*cos(th),z1[i]) - n0 = (nx1[i]*sin(a1),nx1[i]*cos(a1),nz1[i]) - # - v1 = (x1[i]*sin(th+dth),x1[i]*cos(th+dth),z1[i]) - n1 = (nx1[i]*sin(a2), nx1[i]*cos(a2), nz1[i]) - # - v2 = (x2[i]*sin(th+dth),x2[i]*cos(th+dth),z2[i]) - n2 = (nx2[i]*sin(a2), nx2[i]*cos(a2), nz2[i]) - # - v3 = (x2[i]*sin(th), x2[i]*cos(th), z2[i]) - n3 = (nx2[i]*sin(a1), nx2[i]*cos(a1), nz2[i]) - # - patch = ((v0,n0), (v1,n1), (v2,n2), (v3,n3)) - #patch = ((n0,v0), (n1,v1), (n2,v2), (n3,v3)) - # - if x1[i] < FUZZY : - patch = patch[1:] - # - object.append (patch) - # - return object + object = [] + dth = 2.0 * pi / float (rot) + for i in range (0, n) : + for j in range (0, rot) : + th = dth * float (j) + # + if smooth = 1: + a1 = th + a2 =th+dth + else : + a1 = th + dth / 2.0 + a2 = th + dth / 2.0 + # + v0 = (x1[i]*sin(th),x1[i]*cos(th),z1[i]) + n0 = (nx1[i]*sin(a1),nx1[i]*cos(a1),nz1[i]) + # + v1 = (x1[i]*sin(th+dth),x1[i]*cos(th+dth),z1[i]) + n1 = (nx1[i]*sin(a2), nx1[i]*cos(a2), nz1[i]) + # + v2 = (x2[i]*sin(th+dth),x2[i]*cos(th+dth),z2[i]) + n2 = (nx2[i]*sin(a2), nx2[i]*cos(a2), nz2[i]) + # + v3 = (x2[i]*sin(th), x2[i]*cos(th), z2[i]) + n3 = (nx2[i]*sin(a1), nx2[i]*cos(a1), nz2[i]) + # + patch = ((v0,n0), (v1,n1), (v2,n2), (v3,n3)) + #patch = ((n0,v0), (n1,v1), (n2,v2), (n3,v3)) + # + if x1[i] < FUZZY : + patch = patch[1:] + # + object.append (patch) + # + return object def makesphere (n): - asin = [] - acos = [] - for i in range (0, n-1): - asin.append (sin((pi/float (n))*(1.0+float (i)))) - acos.append(cos((pi/float (n))*(1.0+float (i)))) - # - x1 = [0.0] + asin - z1 = [1.0] + acos - nx1 = [0.0] + asin - nz1 = [1.0] + acos - # - x2 = asin + [0.0] - z2 = acos + [-1.0] - nx2 = asin + [0.0] - nz2 = acos + [-1.0] - # - return makespinobject (1,2*n,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) + asin = [] + acos = [] + for i in range (0, n-1): + asin.append (sin((pi/float (n))*(1.0+float (i)))) + acos.append(cos((pi/float (n))*(1.0+float (i)))) + # + x1 = [0.0] + asin + z1 = [1.0] + acos + nx1 = [0.0] + asin + nz1 = [1.0] + acos + # + x2 = asin + [0.0] + z2 = acos + [-1.0] + nx2 = asin + [0.0] + nz2 = acos + [-1.0] + # + return makespinobject (1,2*n,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) def makecylinder(n) : - x1 = [0.0, 1.0, 1.0] - nx1 = [0.0, 1.0, 0.0] - z1 = [1.0, 1.0, -1.0] - nz1 = [1.0, 0.0, -1.0] - # - z2 = [1.0, -1.0, -1.0] - nz2 = [1.0, 0.0, -1.0] - x2 = [1.0, 1.0, 0.0] - nx2 = [0.0, 1.0, 0.0] - # - return makespinobject(1,2*n,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) + x1 = [0.0, 1.0, 1.0] + nx1 = [0.0, 1.0, 0.0] + z1 = [1.0, 1.0, -1.0] + nz1 = [1.0, 0.0, -1.0] + # + z2 = [1.0, -1.0, -1.0] + nz2 = [1.0, 0.0, -1.0] + x2 = [1.0, 1.0, 0.0] + nx2 = [0.0, 1.0, 0.0] + # + return makespinobject(1,2*n,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) def makecone(n) : - x1 = [0.0, 1.0, 1.0] - nx1 = [2.0/sqrt(5.0), 0.0, 0.0] - z1 = [1.0, -1.0, -1.0] - nz1 = [1.0/sqrt(5.0), -1.0, -1.0] - # - x2 = [1.0, 0.0, 0.0] - nx2 = [2.0/sqrt(5.0), 0.0, 0.0] - nz2 = [1.0/sqrt(5.0), -1.0, -1.0] - z2 = [-1.0, -1.0, -1.0] - # - return makespinobject(1,2*n,2,x1,z1,nx1,nz1,x2,z2,nx2,nz2) + x1 = [0.0, 1.0, 1.0] + nx1 = [2.0/sqrt(5.0), 0.0, 0.0] + z1 = [1.0, -1.0, -1.0] + nz1 = [1.0/sqrt(5.0), -1.0, -1.0] + # + x2 = [1.0, 0.0, 0.0] + nx2 = [2.0/sqrt(5.0), 0.0, 0.0] + nz2 = [1.0/sqrt(5.0), -1.0, -1.0] + z2 = [-1.0, -1.0, -1.0] + # + return makespinobject(1,2*n,2,x1,z1,nx1,nz1,x2,z2,nx2,nz2) def makecube() : - x1 = [0.0, sqrt(2.0), sqrt (2.0)] - nx1 = [0.0, 1.0, 0.0] - z1 = [1.0, 1.0, -1.0] - nz1 = [1.0, 0.0, -1.0] - # - x2 = [sqrt(2.0), sqrt(2.0), 0.0] - nx2 = [0.0, 1.0, 0.0] - z2 = [1.0, -1.0, -1.0] - nz2 = [1.0, 0.0, -1.0] - # - return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) + x1 = [0.0, sqrt(2.0), sqrt (2.0)] + nx1 = [0.0, 1.0, 0.0] + z1 = [1.0, 1.0, -1.0] + nz1 = [1.0, 0.0, -1.0] + # + x2 = [sqrt(2.0), sqrt(2.0), 0.0] + nx2 = [0.0, 1.0, 0.0] + z2 = [1.0, -1.0, -1.0] + nz2 = [1.0, 0.0, -1.0] + # + return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) def makepyramid() : - x1 = [0.0, sqrt(2.0), 0.0] - nx1 = [2.0 / sqrt(5.0), 0.0, 0.0] - z1 = [1.0, -1.0, 0.0] - nz1 = [1.0 / sqrt(5.0), -1.0, 0.0] - # - x2 = [sqrt(2.0), 0.0, 0.0] - nx2 = [2.0 / sqrt(5.0), 0.0, 0.0] - z2 = [-1.0, -1.0, -1.0] - nz2 = [1.0/sqrt(5.0), -1.0, 0.0] - # - return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) + x1 = [0.0, sqrt(2.0), 0.0] + nx1 = [2.0 / sqrt(5.0), 0.0, 0.0] + z1 = [1.0, -1.0, 0.0] + nz1 = [1.0 / sqrt(5.0), -1.0, 0.0] + # + x2 = [sqrt(2.0), 0.0, 0.0] + nx2 = [2.0 / sqrt(5.0), 0.0, 0.0] + z2 = [-1.0, -1.0, -1.0] + nz2 = [1.0/sqrt(5.0), -1.0, 0.0] + # + return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) def makeobjects () : - cube = makecube() - sphere = makesphere (6) - cylinder = makecylinder (6) - cone = makecone (6) - pyramid = makepyramid () - # - odict = {} - odict ['cube'] = cube - odict ['pyramid'] = pyramid - odict ['sphere'] = sphere - odict ['cylinder'] = cylinder - odict ['cone'] = cone - odict ['diamond'] = cube - odict ['disk'] = sphere - # - return odict + cube = makecube() + sphere = makesphere (6) + cylinder = makecylinder (6) + cone = makecone (6) + pyramid = makepyramid () + # + odict = {} + odict ['cube'] = cube + odict ['pyramid'] = pyramid + odict ['sphere'] = sphere + odict ['cylinder'] = cylinder + odict ['cone'] = cone + odict ['diamond'] = cube + odict ['disk'] = sphere + # + return odict renderfuncs = [bgnpolygon, endpolygon] def putFunc (funcs) : - renderfuncs [:] = funcs + renderfuncs [:] = funcs def drawobject (obj) : - # - for patch in obj : - renderfuncs[0] () - vnarray (patch) - renderfuncs[1] () + # + for patch in obj : + renderfuncs[0] () + vnarray (patch) + renderfuncs[1] () diff --git a/demo/sgi/gl_panel/nurbs/nurbs.py b/demo/sgi/gl_panel/nurbs/nurbs.py index 686c3bd..c92cb46 100755 --- a/demo/sgi/gl_panel/nurbs/nurbs.py +++ b/demo/sgi/gl_panel/nurbs/nurbs.py @@ -1,6 +1,6 @@ #! /ufs/guido/bin/sgi/python -# Fancy NURBS demo. Require Z buffer and Panel Library. +# Fancy NURBS demo. Require Z buffer and Panel Library. from gl import * from GL import * @@ -11,186 +11,186 @@ import panel # # flags = trim_f, invis_f, cpvis_f, tpvis_f, axvis_f, freeze_f # -TRIM = 0 -VIS = 1 -CPVIS = 2 -TPVIS = 3 -AXVIS = 4 -FREEZE = 5 +TRIM = 0 +VIS = 1 +CPVIS = 2 +TPVIS = 3 +AXVIS = 4 +FREEZE = 5 flags = [0, 1, 0, 0, 0, 0] def draw_axis () : - cpack (0x0) - zero = (0.0, 0.0, 0.0) - # - one = (1.0, 0.0, 0.0) - smallline (zero, one) - cmov (1.0, 0.0, 0.0) - charstr ('x') - # - one = (0.0, 1.0, 0.0) - smallline (zero, one) - cmov (0.0, 1.0, 0.0) - charstr ('y') - # - one = (0.0, 0.0, 1.0) - smallline (zero, one) - cmov (0.0, 0.0, 1.0) - charstr ('z') + cpack (0x0) + zero = (0.0, 0.0, 0.0) + # + one = (1.0, 0.0, 0.0) + smallline (zero, one) + cmov (1.0, 0.0, 0.0) + charstr ('x') + # + one = (0.0, 1.0, 0.0) + smallline (zero, one) + cmov (0.0, 1.0, 0.0) + charstr ('y') + # + one = (0.0, 0.0, 1.0) + smallline (zero, one) + cmov (0.0, 0.0, 1.0) + charstr ('z') DELTA = 0.1 def cross (p) : - p0 = [p[0], p[1], p[2]] - p1 = [p[0], p[1], p[2]] - for i in range (0, 3) : - p0[i] = p0[i] + DELTA - p1[i] = p1[i] - DELTA - smallline (p0, p1) - p0[i] = p0[i] - DELTA - p1[i] = p1[i] + DELTA + p0 = [p[0], p[1], p[2]] + p1 = [p[0], p[1], p[2]] + for i in range (0, 3) : + p0[i] = p0[i] + DELTA + p1[i] = p1[i] - DELTA + smallline (p0, p1) + p0[i] = p0[i] - DELTA + p1[i] = p1[i] + DELTA def smallline (p0, p1) : - bgnline () - v3f (p0) - v3f (p1) - endline () + bgnline () + v3f (p0) + v3f (p1) + endline () def draw_pts (pnts, color) : - linewidth (2) - cpack (color) - for i in pnts : - cross (i) + linewidth (2) + cpack (color) + for i in pnts : + cross (i) def init_windows(): - foreground() - wid = winopen('nurbs') - wintitle('NURBS Surface') - doublebuffer() - RGBmode() - gconfig() - lsetdepth(0x000, 0x7fffff) - zbuffer( TRUE ) + foreground() + wid = winopen('nurbs') + wintitle('NURBS Surface') + doublebuffer() + RGBmode() + gconfig() + lsetdepth(0x000, 0x7fffff) + zbuffer( TRUE ) def init_view(): - mmode(MPROJECTION) - ortho( -5., 5., -5., 5., -5., 5. ) - # - mmode(MVIEWING) - loadmatrix(idmat) - # - lmbind(MATERIAL, 1) + mmode(MPROJECTION) + ortho( -5., 5., -5., 5., -5., 5. ) + # + mmode(MVIEWING) + loadmatrix(idmat) + # + lmbind(MATERIAL, 1) def set_scene(flags): - # - lmbind(MATERIAL, 0) - RGBcolor(150,150,150) - lmbind(MATERIAL, 1) - clear() - zclear() - # - if not flags[FREEZE] : - rotate( 100, 'y' ) - rotate( 100, 'z' ) + # + lmbind(MATERIAL, 0) + RGBcolor(150,150,150) + lmbind(MATERIAL, 1) + clear() + zclear() + # + if not flags[FREEZE] : + rotate( 100, 'y' ) + rotate( 100, 'z' ) def draw_trim_surface(flags): - pnts = ctlpoints - if flags[VIS] : - bgnsurface() - nurbssurface(surfknots,surfknots,pnts,ORDER,ORDER,N_XYZ) - if flags[TRIM]: - bgntrim() - nurbscurve(trimknots,trimpoints,ORDER-1,N_STW) - endtrim() - endsurface() - # - if flags[CPVIS] : - for i in pnts : - draw_pts (i, RED) - # - if flags[TPVIS] : - tpts = trimpoints - draw_pts (tpts, YELLOW) - # - if flags[AXVIS] : - draw_axis () - # - swapbuffers() + pnts = ctlpoints + if flags[VIS] : + bgnsurface() + nurbssurface(surfknots,surfknots,pnts,ORDER,ORDER,N_XYZ) + if flags[TRIM]: + bgntrim() + nurbscurve(trimknots,trimpoints,ORDER-1,N_STW) + endtrim() + endsurface() + # + if flags[CPVIS] : + for i in pnts : + draw_pts (i, RED) + # + if flags[TPVIS] : + tpts = trimpoints + draw_pts (tpts, YELLOW) + # + if flags[AXVIS] : + draw_axis () + # + swapbuffers() def make_lights(): - lmdef(DEFLMODEL,1,[]) - lmdef(DEFLIGHT,1,[]) - # - # define material #1 - # - a = [] - a = a + [EMISSION, 0.0, 0.0, 0.0] - a = a + [AMBIENT, 0.1, 0.1, 0.1] - a = a + [DIFFUSE, 0.6, 0.3, 0.3] - a = a + [SPECULAR, 0.0, 0.6, 0.0] - a = a + [SHININESS, 2.0] - a = a + [LMNULL] - lmdef(DEFMATERIAL, 1, a) - # - # turn on lighting - # - lmbind(LIGHT0, 1) - lmbind(LMODEL, 1) + lmdef(DEFLMODEL,1,[]) + lmdef(DEFLIGHT,1,[]) + # + # define material #1 + # + a = [] + a = a + [EMISSION, 0.0, 0.0, 0.0] + a = a + [AMBIENT, 0.1, 0.1, 0.1] + a = a + [DIFFUSE, 0.6, 0.3, 0.3] + a = a + [SPECULAR, 0.0, 0.6, 0.0] + a = a + [SHININESS, 2.0] + a = a + [LMNULL] + lmdef(DEFMATERIAL, 1, a) + # + # turn on lighting + # + lmbind(LIGHT0, 1) + lmbind(LMODEL, 1) def main(): - init_windows() - make_lights() - init_view() - # - panel.needredraw() - panels = panel.defpanellist('nurbs.s') - p = panels[0] - # - def cbtrim (a) : - flags[TRIM:TRIM+1] = [int (a.val)] - p.trim.upfunc = cbtrim - # - def cbquit (a) : - import sys - sys.exit (1) - p.quit.upfunc = cbquit - # - def cbmotion (a) : - flags[FREEZE:FREEZE+1] = [int (a.val)] - p.motion.upfunc = cbmotion - # - def cbxyzaxis (a) : - flags[AXVIS:AXVIS+1] = [int (a.val)] - p.xyzaxis.upfunc = cbxyzaxis - # - def cbtrimpnts (a) : - flags[TPVIS:TPVIS+1] = [int (a.val)] - p.trimpnts.upfunc = cbtrimpnts - # - def cbcntlpnts (a) : - flags[CPVIS:CPVIS+1] = [int (a.val)] - p.cntlpnts.upfunc = cbcntlpnts - # - def cbnurb (a) : - flags[VIS:VIS+1] = [int (a.val)] - p.nurb.upfunc = cbnurb - # - set_scene(flags) - setnurbsproperty( N_ERRORCHECKING, 1.0 ) - setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) - draw_trim_surface(flags) - # - while 1: - act = panel.dopanel() - # - wid = panel.userredraw () - if wid : - winset (wid) - reshapeviewport() - set_scene(flags) - draw_trim_surface(flags) - # - set_scene(flags) - draw_trim_surface(flags) + init_windows() + make_lights() + init_view() + # + panel.needredraw() + panels = panel.defpanellist('nurbs.s') + p = panels[0] + # + def cbtrim (a) : + flags[TRIM:TRIM+1] = [int (a.val)] + p.trim.upfunc = cbtrim + # + def cbquit (a) : + import sys + sys.exit (1) + p.quit.upfunc = cbquit + # + def cbmotion (a) : + flags[FREEZE:FREEZE+1] = [int (a.val)] + p.motion.upfunc = cbmotion + # + def cbxyzaxis (a) : + flags[AXVIS:AXVIS+1] = [int (a.val)] + p.xyzaxis.upfunc = cbxyzaxis + # + def cbtrimpnts (a) : + flags[TPVIS:TPVIS+1] = [int (a.val)] + p.trimpnts.upfunc = cbtrimpnts + # + def cbcntlpnts (a) : + flags[CPVIS:CPVIS+1] = [int (a.val)] + p.cntlpnts.upfunc = cbcntlpnts + # + def cbnurb (a) : + flags[VIS:VIS+1] = [int (a.val)] + p.nurb.upfunc = cbnurb + # + set_scene(flags) + setnurbsproperty( N_ERRORCHECKING, 1.0 ) + setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) + draw_trim_surface(flags) + # + while 1: + act = panel.dopanel() + # + wid = panel.userredraw () + if wid : + winset (wid) + reshapeviewport() + set_scene(flags) + draw_trim_surface(flags) + # + set_scene(flags) + draw_trim_surface(flags) main() diff --git a/demo/sgi/gl_panel/nurbs/nurbsdata.py b/demo/sgi/gl_panel/nurbs/nurbsdata.py index ed7e705..9a3f09e 100644 --- a/demo/sgi/gl_panel/nurbs/nurbsdata.py +++ b/demo/sgi/gl_panel/nurbs/nurbsdata.py @@ -25,58 +25,58 @@ surfknots = [-1, -1, -1, -1, 1, 1, 1, 1] # list of list of control points # def make_ctlpoints(): - c = [] - # - ci = [] - ci.append(-2.5, -3.7, 1.0) - ci.append(-1.5, -3.7, 3.0) - ci.append(1.5, -3.7, -2.5) - ci.append(2.5, -3.7, -0.75) - c.append(ci) - # - ci = [] - ci.append(-2.5, -2.0, 3.0) - ci.append(-1.5, -2.0, 4.0) - ci.append(1.5, -2.0, -3.0) - ci.append(2.5, -2.0, 0.0) - c.append(ci) - # - ci = [] - ci.append(-2.5, 2.0, 1.0) - ci.append(-1.5, 2.0, 0.0) - ci.append(1.5, 2.0, -1.0) - ci.append(2.5, 2.0, 2.0) - c.append(ci) - # - ci = [] - ci.append(-2.5, 2.7, 1.25) - ci.append(-1.5, 2.7, 0.1) - ci.append(1.5, 2.7, -0.6) - ci.append(2.5, 2.7, 0.2) - c.append(ci) - # - return c + c = [] + # + ci = [] + ci.append(-2.5, -3.7, 1.0) + ci.append(-1.5, -3.7, 3.0) + ci.append(1.5, -3.7, -2.5) + ci.append(2.5, -3.7, -0.75) + c.append(ci) + # + ci = [] + ci.append(-2.5, -2.0, 3.0) + ci.append(-1.5, -2.0, 4.0) + ci.append(1.5, -2.0, -3.0) + ci.append(2.5, -2.0, 0.0) + c.append(ci) + # + ci = [] + ci.append(-2.5, 2.0, 1.0) + ci.append(-1.5, 2.0, 0.0) + ci.append(1.5, 2.0, -1.0) + ci.append(2.5, 2.0, 2.0) + c.append(ci) + # + ci = [] + ci.append(-2.5, 2.7, 1.25) + ci.append(-1.5, 2.7, 0.1) + ci.append(1.5, 2.7, -0.6) + ci.append(2.5, 2.7, 0.2) + c.append(ci) + # + return c ctlpoints = make_ctlpoints () # # trim knots # -trimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] +trimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] def make_trimpoints(): - c = [] - # - c.append(1.0, 0.0, 1.0) - c.append(1.0, 1.0, 1.0) - c.append(0.0, 2.0, 2.0) - c.append(-1.0, 1.0, 1.0) - c.append(-1.0, 0.0, 1.0) - c.append(-1.0, -1.0, 1.0) - c.append(0.0, -2.0, 2.0) - c.append(1.0, -1.0, 1.0) - c.append(1.0, 0.0, 1.0) - # - return c + c = [] + # + c.append(1.0, 0.0, 1.0) + c.append(1.0, 1.0, 1.0) + c.append(0.0, 2.0, 2.0) + c.append(-1.0, 1.0, 1.0) + c.append(-1.0, 0.0, 1.0) + c.append(-1.0, -1.0, 1.0) + c.append(0.0, -2.0, 2.0) + c.append(1.0, -1.0, 1.0) + c.append(1.0, 0.0, 1.0) + # + return c trimpoints = make_trimpoints() diff --git a/demo/sgi/gl_panel/twoview/block.py b/demo/sgi/gl_panel/twoview/block.py index 9ac518d..a40c8e9 100644 --- a/demo/sgi/gl_panel/twoview/block.py +++ b/demo/sgi/gl_panel/twoview/block.py @@ -7,67 +7,67 @@ from GL import MATERIAL # Arguments are the material indices (0 = don't call lmbind) # def block(m_front, m_back, m_left, m_right, m_top, m_bottom): - # - # Distances defining the sides - # - x_left = -1.0 - x_right = 1.0 - y_top = 1.0 - y_bottom = -1.0 - z_front = 1.0 - z_back = -1.0 - # - # Top surface points: A, B, C, D - # - A = x_right, y_top, z_front - B = x_right, y_top, z_back - C = x_left, y_top, z_back - D = x_left, y_top, z_front - # - # Bottom surface points: E, F, G, H - # - E = x_right, y_bottom, z_front - F = x_right, y_bottom, z_back - G = x_left, y_bottom, z_back - H = x_left, y_bottom, z_front - # - # Draw front face - # - if m_front: lmbind(MATERIAL, m_front) - n3f(0.0, 0.0, 1.0) - face(H, E, A, D) - # - # Draw back face - # - if m_back: lmbind(MATERIAL, m_back) - n3f(0.0, 0.0, -1.0) - face(G, F, B, C) - # - # Draw left face - # - if m_left: lmbind(MATERIAL, m_left) - n3f(-1.0, 0.0, 0.0) - face(G, H, D, C) - # - # Draw right face - # - if m_right: lmbind(MATERIAL, m_right) - n3f(1.0, 0.0, 0.0) - face(F, E, A, B) - # - # Draw top face - # - if m_top: lmbind(MATERIAL, m_top) - n3f(0.0, 1.0, 0.0) - face(A, B, C, D) - # - # Draw bottom face - # - if m_bottom: lmbind(MATERIAL, m_bottom) - n3f(0.0, -1.0, 0.0) - face(E, F, G, H) + # + # Distances defining the sides + # + x_left = -1.0 + x_right = 1.0 + y_top = 1.0 + y_bottom = -1.0 + z_front = 1.0 + z_back = -1.0 + # + # Top surface points: A, B, C, D + # + A = x_right, y_top, z_front + B = x_right, y_top, z_back + C = x_left, y_top, z_back + D = x_left, y_top, z_front + # + # Bottom surface points: E, F, G, H + # + E = x_right, y_bottom, z_front + F = x_right, y_bottom, z_back + G = x_left, y_bottom, z_back + H = x_left, y_bottom, z_front + # + # Draw front face + # + if m_front: lmbind(MATERIAL, m_front) + n3f(0.0, 0.0, 1.0) + face(H, E, A, D) + # + # Draw back face + # + if m_back: lmbind(MATERIAL, m_back) + n3f(0.0, 0.0, -1.0) + face(G, F, B, C) + # + # Draw left face + # + if m_left: lmbind(MATERIAL, m_left) + n3f(-1.0, 0.0, 0.0) + face(G, H, D, C) + # + # Draw right face + # + if m_right: lmbind(MATERIAL, m_right) + n3f(1.0, 0.0, 0.0) + face(F, E, A, B) + # + # Draw top face + # + if m_top: lmbind(MATERIAL, m_top) + n3f(0.0, 1.0, 0.0) + face(A, B, C, D) + # + # Draw bottom face + # + if m_bottom: lmbind(MATERIAL, m_bottom) + n3f(0.0, -1.0, 0.0) + face(E, F, G, H) def face(points): - bgnpolygon() - varray(points) - endpolygon() + bgnpolygon() + varray(points) + endpolygon() diff --git a/demo/sgi/gl_panel/twoview/twoview.py b/demo/sgi/gl_panel/twoview/twoview.py index eea7c75..79c664f 100755 --- a/demo/sgi/gl_panel/twoview/twoview.py +++ b/demo/sgi/gl_panel/twoview/twoview.py @@ -1,7 +1,7 @@ #! /ufs/guido/bin/sgi/python # A demo of GL's viewing transformations, showing two views on one scene. -# Requires the NASA AMES Panel Library. Requires Z buffer. +# Requires the NASA AMES Panel Library. Requires Z buffer. from gl import * from GL import * @@ -13,383 +13,383 @@ far = 1000.0 near = 100.0 def main(): - foreground() - # - keepaspect(1, 1) - prefposition(10, 610, 10, 610) - obswid = winopen('Observer View') - doublebuffer() - RGBmode() - gconfig() - # - keepaspect(1, 1) - prefposition(10, 310, 650, 950) - topwid = winopen('Top View') - doublebuffer() - RGBmode() - gconfig() - # - panels = panel.defpanellist('observer.s') - panels = panels + panel.defpanellist('camera.s') - panels = panels + panel.defpanellist('topview.s') - # - p = panels[0] - q = panels[1] - r = panels[2] - # - p.farclip = q.farclip - p.nearclip = q.nearclip - p.zoom = q.zoom - p.quitbutton = q.quitbutton - # - p.xpos = r.xpos - p.zpos = r.zpos - p.direction = r.direction - # - p.direction.winds = 1.0 # allow full rotation - # - def quit(act): - import sys - sys.exit(0) - p.quitbutton.downfunc = quit - # - p.left.back = p - p.fast_left.back = p - p.right.back = p - p.fast_right.back = p - p.forward.back = p - p.fast_forward.back = p - p.reverse.back = p - p.fast_reverse.back = p - p.up.back = p - p.down.back = p - # - p.left.activefunc = left - p.fast_left.activefunc = fast_left - p.right.activefunc = right - p.fast_right.activefunc = fast_right - p.forward.activefunc = forward - p.fast_forward.activefunc = fast_forward - p.reverse.activefunc = reverse - p.fast_reverse.activefunc = fast_reverse - p.up.activefunc = up - p.down.activefunc = down - # - makeobjects() - # - drawall(p, obswid, topwid) - panel.needredraw() - while 1: - act = panel.dopanel() - if panel.userredraw() or act: - drawall(p, obswid, topwid) + foreground() + # + keepaspect(1, 1) + prefposition(10, 610, 10, 610) + obswid = winopen('Observer View') + doublebuffer() + RGBmode() + gconfig() + # + keepaspect(1, 1) + prefposition(10, 310, 650, 950) + topwid = winopen('Top View') + doublebuffer() + RGBmode() + gconfig() + # + panels = panel.defpanellist('observer.s') + panels = panels + panel.defpanellist('camera.s') + panels = panels + panel.defpanellist('topview.s') + # + p = panels[0] + q = panels[1] + r = panels[2] + # + p.farclip = q.farclip + p.nearclip = q.nearclip + p.zoom = q.zoom + p.quitbutton = q.quitbutton + # + p.xpos = r.xpos + p.zpos = r.zpos + p.direction = r.direction + # + p.direction.winds = 1.0 # allow full rotation + # + def quit(act): + import sys + sys.exit(0) + p.quitbutton.downfunc = quit + # + p.left.back = p + p.fast_left.back = p + p.right.back = p + p.fast_right.back = p + p.forward.back = p + p.fast_forward.back = p + p.reverse.back = p + p.fast_reverse.back = p + p.up.back = p + p.down.back = p + # + p.left.activefunc = left + p.fast_left.activefunc = fast_left + p.right.activefunc = right + p.fast_right.activefunc = fast_right + p.forward.activefunc = forward + p.fast_forward.activefunc = fast_forward + p.reverse.activefunc = reverse + p.fast_reverse.activefunc = fast_reverse + p.up.activefunc = up + p.down.activefunc = down + # + makeobjects() + # + drawall(p, obswid, topwid) + panel.needredraw() + while 1: + act = panel.dopanel() + if panel.userredraw() or act: + drawall(p, obswid, topwid) def left(a): - doturn(a.back, 0.01) + doturn(a.back, 0.01) def fast_left(a): - doturn(a.back, 0.1) + doturn(a.back, 0.1) def right(a): - doturn(a.back, -0.01) + doturn(a.back, -0.01) def fast_right(a): - doturn(a.back, -0.1) + doturn(a.back, -0.1) def doturn(p, angle): - alpha = lookangle(p) + angle - # Reverse the following assignment: - # alpha = pi*1.5 - p.direction.val*2.0*pi - val = (pi*1.5 - alpha) / 2.0 / pi - while val < 0.0: val = val + 1.0 - while val > 1.0: val = val - 1.0 - p.direction.val = val - p.direction.fixact() + alpha = lookangle(p) + angle + # Reverse the following assignment: + # alpha = pi*1.5 - p.direction.val*2.0*pi + val = (pi*1.5 - alpha) / 2.0 / pi + while val < 0.0: val = val + 1.0 + while val > 1.0: val = val - 1.0 + p.direction.val = val + p.direction.fixact() def forward(a): - dostep(a.back, 1.0) + dostep(a.back, 1.0) def fast_forward(a): - dostep(a.back, 10.0) + dostep(a.back, 10.0) def reverse(a): - dostep(a.back, -1.0) + dostep(a.back, -1.0) def fast_reverse(a): - dostep(a.back, -10.0) + dostep(a.back, -10.0) def dostep(p, step): - x, y, z = observerpos(p) - alpha = lookangle(p) - x = x + step*cos(alpha) - z = z - step*sin(alpha) - # Reverse the following assignments: - # x = 2.0 * p.xpos.val * near - near - # z = near - 2.0 * p.zpos.val * near - p.xpos.val = (x + near) / 2.0 / near - p.zpos.val = - (z - near) / 2.0 / near - p.xpos.fixact() - p.zpos.fixact() + x, y, z = observerpos(p) + alpha = lookangle(p) + x = x + step*cos(alpha) + z = z - step*sin(alpha) + # Reverse the following assignments: + # x = 2.0 * p.xpos.val * near - near + # z = near - 2.0 * p.zpos.val * near + p.xpos.val = (x + near) / 2.0 / near + p.zpos.val = - (z - near) / 2.0 / near + p.xpos.fixact() + p.zpos.fixact() def up(a): - doup(a.back, 0.2) + doup(a.back, 0.2) def down(a): - doup(a.back, -0.2) + doup(a.back, -0.2) def doup(p, step): - x, y, z = observerpos(p) - y = y + step - # Reverse: - # y = p.ypos.val * near - p.ypos.val = y/near - p.ypos.fixact() + x, y, z = observerpos(p) + y = y + step + # Reverse: + # y = p.ypos.val * near + p.ypos.val = y/near + p.ypos.fixact() def drawall(p, obswid, topwid): - # - winset(obswid) - obsview(p) - drawscene() - swapbuffers() - # - winset(topwid) - topview(p) - drawscene() - drawobserver(p) - swapbuffers() + # + winset(obswid) + obsview(p) + drawscene() + swapbuffers() + # + winset(topwid) + topview(p) + drawscene() + drawobserver(p) + swapbuffers() def drawobserver(p): - x, y, z = observerpos(p) - alpha = lookangle(p) - fov = 2.0 + 1798.0 * p.zoom.val - beta = fov*pi/3600.0 # Half fov, expressed in radians - # - c3i(0, 255, 0) - # - move(x, y, z) - x1 = x + inf*cos(alpha+beta) - y1 = y - z1 = z - inf*sin(alpha+beta) - draw(x1, y1, z1) - # - move(x, y, z) - x1 = x + inf*cos(alpha-beta) - y1 = y - z1 = z - inf*sin(alpha-beta) - draw(x1, y1, z1) + x, y, z = observerpos(p) + alpha = lookangle(p) + fov = 2.0 + 1798.0 * p.zoom.val + beta = fov*pi/3600.0 # Half fov, expressed in radians + # + c3i(0, 255, 0) + # + move(x, y, z) + x1 = x + inf*cos(alpha+beta) + y1 = y + z1 = z - inf*sin(alpha+beta) + draw(x1, y1, z1) + # + move(x, y, z) + x1 = x + inf*cos(alpha-beta) + y1 = y + z1 = z - inf*sin(alpha-beta) + draw(x1, y1, z1) def observerlookat(p): - x, y, z = observerpos(p) - alpha = lookangle(p) - return x, y, z, x+near*cos(alpha), y, z-near*sin(alpha), 0 + x, y, z = observerpos(p) + alpha = lookangle(p) + return x, y, z, x+near*cos(alpha), y, z-near*sin(alpha), 0 def observerpos(p): - x = 2.0 * p.xpos.val * near - near - y = p.ypos.val * near - z = near - 2.0 * p.zpos.val * near - return x, y, z + x = 2.0 * p.xpos.val * near - near + y = p.ypos.val * near + z = near - 2.0 * p.zpos.val * near + return x, y, z def lookangle(p): - return pi*1.5 - p.direction.val*2.0*pi + return pi*1.5 - p.direction.val*2.0*pi idmat = 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 def topview(p): - mmode(MVIEWING) - ortho(-far, far, -far, far, far, -far) - loadmatrix(idmat) - rotate(900, 'x') + mmode(MVIEWING) + ortho(-far, far, -far, far, far, -far) + loadmatrix(idmat) + rotate(900, 'x') def obsview(p): - fov = 2.0 + 1798.0 * p.zoom.val - nearclip = p.nearclip.val * 10.0 - farclip = p.farclip.val * 10.0*far - aspectratio = 1.0 - mmode(MVIEWING) - perspective(int(fov), aspectratio, nearclip, farclip) - loadmatrix(idmat) - lookat(observerlookat(p)) + fov = 2.0 + 1798.0 * p.zoom.val + nearclip = p.nearclip.val * 10.0 + farclip = p.farclip.val * 10.0*far + aspectratio = 1.0 + mmode(MVIEWING) + perspective(int(fov), aspectratio, nearclip, farclip) + loadmatrix(idmat) + lookat(observerlookat(p)) def drawscene(): - # - # clear window - # - c3i(0, 0, 0) - clear() - # - # turn on z buffering and clear it - # - zbuffer(TRUE) - zclear() - # - # dark blue sky (depending on your gamma value!) - # - c3i(0, 0, 150) - callobj(41) - # - # bright red near and far units circle - # (use rotate since circ() always draws in x-y plane) - # - c3i(255, 0, 0) - pushmatrix() - rotate(900, 'x') - circ(0.0, 0.0, near) - circ(0.0, 0.0, far) - popmatrix() - # - # bright white striping - # - c3i(255, 255, 200) - callobj(42) - # - # building (does its own colors) - # - building() - # - # some other objects - # - dice() + # + # clear window + # + c3i(0, 0, 0) + clear() + # + # turn on z buffering and clear it + # + zbuffer(TRUE) + zclear() + # + # dark blue sky (depending on your gamma value!) + # + c3i(0, 0, 150) + callobj(41) + # + # bright red near and far units circle + # (use rotate since circ() always draws in x-y plane) + # + c3i(255, 0, 0) + pushmatrix() + rotate(900, 'x') + circ(0.0, 0.0, near) + circ(0.0, 0.0, far) + popmatrix() + # + # bright white striping + # + c3i(255, 255, 200) + callobj(42) + # + # building (does its own colors) + # + building() + # + # some other objects + # + dice() def makeobjects(): - # - # sky object - # - makeobj(41) - pmv(-inf, 0.0, -far) - pdr(inf, 0.0, -far) - pdr(inf, inf, -far) - pdr(-inf, inf, -far) - pclos() - closeobj() - # - # road stripes object - # - makeobj(42) - stripes() - closeobj() - # - # lighting model definitions - # - deflight() + # + # sky object + # + makeobj(41) + pmv(-inf, 0.0, -far) + pdr(inf, 0.0, -far) + pdr(inf, inf, -far) + pdr(-inf, inf, -far) + pclos() + closeobj() + # + # road stripes object + # + makeobj(42) + stripes() + closeobj() + # + # lighting model definitions + # + deflight() def stripes(): - # - # left line - # - botrect(-11, -10, far, -far) - # - # right line - # - botrect(10, 11, far, -far) - # - # center lines - # - z = far - while z > -far: - botrect(-0.5, 0.5, z, z - 4.0) - z = z - 10.0 + # + # left line + # + botrect(-11, -10, far, -far) + # + # right line + # + botrect(10, 11, far, -far) + # + # center lines + # + z = far + while z > -far: + botrect(-0.5, 0.5, z, z - 4.0) + z = z - 10.0 def dice(): - from block import block - uselight() - pushmatrix() - translate(0.0, 1.0, -20.0) - rotate(200, 'y') - block(1, 0, 0, 0, 0, 0) - translate(1.0, 0.0, 3.0) - rotate(500, 'y') - block(2, 0, 0, 0, 0, 0) - popmatrix() + from block import block + uselight() + pushmatrix() + translate(0.0, 1.0, -20.0) + rotate(200, 'y') + block(1, 0, 0, 0, 0, 0) + translate(1.0, 0.0, 3.0) + rotate(500, 'y') + block(2, 0, 0, 0, 0, 0) + popmatrix() def deflight(): - # Material for first die (red) - lmdef(DEFMATERIAL, 1, (DIFFUSE, 1.0, 0.0, 0.0)) - # Material for second die (green) - lmdef(DEFMATERIAL, 2, (DIFFUSE, 0.0, 1.0, 0.0)) - # First light source (default: white, from front) - lmdef(DEFLIGHT, 1, ()) - # Second light source (red, from back) - lmdef(DEFLIGHT, 2, (POSITION, 0.0, 1.0, -1.0, 0.0)) - lmdef(DEFLIGHT, 2, (LCOLOR, 1.0, 0.0, 0.0)) - # Lighting model - lmdef(DEFLMODEL, 1, (AMBIENT, 0.0, 0.0, 1.0)) + # Material for first die (red) + lmdef(DEFMATERIAL, 1, (DIFFUSE, 1.0, 0.0, 0.0)) + # Material for second die (green) + lmdef(DEFMATERIAL, 2, (DIFFUSE, 0.0, 1.0, 0.0)) + # First light source (default: white, from front) + lmdef(DEFLIGHT, 1, ()) + # Second light source (red, from back) + lmdef(DEFLIGHT, 2, (POSITION, 0.0, 1.0, -1.0, 0.0)) + lmdef(DEFLIGHT, 2, (LCOLOR, 1.0, 0.0, 0.0)) + # Lighting model + lmdef(DEFLMODEL, 1, (AMBIENT, 0.0, 0.0, 1.0)) def uselight(): - lmbind(LIGHT0, 1) - lmbind(LIGHT1, 2) - lmbind(LMODEL, 1) - # (materials are bound later) + lmbind(LIGHT0, 1) + lmbind(LIGHT1, 2) + lmbind(LMODEL, 1) + # (materials are bound later) def building(): - # - c3i(0, 255, 255) - # - # house bounding coordinates - # - x1 = 20.0 - x1a = 25.0 - x2 = 30.0 - y1 = 0.0 - y2 = 15.0 - y2a = 20.0 - z1 = -40.0 - z2 = -55.0 - # - # door y and z coordinates - # - dy1 = 0.0 - dy2 = 4.0 - dz1 = -45.0 - dz2 = -47.0 - # - # front side (seen from origin) - # - A1 = (x1, y1, z1) - B1 = (x2, y1, z1) - C1 = (x2, y2, z1) - D1 = (x1a, y2a, z1) - E1 = (x1, y2, z1) - # - # back size - # - A2 = (x1, y1, z2) - B2 = (x2, y1, z2) - C2 = (x2, y2, z2) - D2 = (x1a, y2a, z2) - E2 = (x1, y2, z2) - # - # door in the left side - # - P = x1, dy1, dz2 - Q = x1, dy2, dz2 - R = x1, dy2, dz1 - S = x1, dy1, dz1 - # - # draw it - # - concave(TRUE) - c3i(255, 0, 0) - face(A1, B1, C1, D1, E1) - c3i(127, 127, 0) - face(A1, E1, E2, A2, P, Q, R, S) - c3i(0, 255, 0) - face(E1, D1, D2, E2) - c3i(0, 127, 127) - face(D1, C1, C2, D2) - c3i(0, 0, 255) - face(C1, B1, B2, C2) - c3i(127, 0, 127) - face(E2, D2, C2, B2, A2) - concave(FALSE) + # + c3i(0, 255, 255) + # + # house bounding coordinates + # + x1 = 20.0 + x1a = 25.0 + x2 = 30.0 + y1 = 0.0 + y2 = 15.0 + y2a = 20.0 + z1 = -40.0 + z2 = -55.0 + # + # door y and z coordinates + # + dy1 = 0.0 + dy2 = 4.0 + dz1 = -45.0 + dz2 = -47.0 + # + # front side (seen from origin) + # + A1 = (x1, y1, z1) + B1 = (x2, y1, z1) + C1 = (x2, y2, z1) + D1 = (x1a, y2a, z1) + E1 = (x1, y2, z1) + # + # back size + # + A2 = (x1, y1, z2) + B2 = (x2, y1, z2) + C2 = (x2, y2, z2) + D2 = (x1a, y2a, z2) + E2 = (x1, y2, z2) + # + # door in the left side + # + P = x1, dy1, dz2 + Q = x1, dy2, dz2 + R = x1, dy2, dz1 + S = x1, dy1, dz1 + # + # draw it + # + concave(TRUE) + c3i(255, 0, 0) + face(A1, B1, C1, D1, E1) + c3i(127, 127, 0) + face(A1, E1, E2, A2, P, Q, R, S) + c3i(0, 255, 0) + face(E1, D1, D2, E2) + c3i(0, 127, 127) + face(D1, C1, C2, D2) + c3i(0, 0, 255) + face(C1, B1, B2, C2) + c3i(127, 0, 127) + face(E2, D2, C2, B2, A2) + concave(FALSE) def face(points): - bgnpolygon() - varray(points) - endpolygon() + bgnpolygon() + varray(points) + endpolygon() # draw a rectangle at y=0.0 # def botrect(x1, x2, z1, z2): - polf(x1, 0.0, z1, x2, 0.0, z1, x2, 0.0, z2, x1, 0.0, z2) + polf(x1, 0.0, z1, x2, 0.0, z1, x2, 0.0, z2, x1, 0.0, z2) main() diff --git a/demo/stdwin/wdiff.py b/demo/stdwin/wdiff.py index bc005f8..389af63 100755 --- a/demo/stdwin/wdiff.py +++ b/demo/stdwin/wdiff.py @@ -4,17 +4,17 @@ # NB: This uses undocumented window classing modules. # TO DO: -# - faster update after moving/copying one file -# - diff flags (-b, etc.) should be global or maintained per window -# - use a few fixed windows instead of creating new ones all the time -# - ways to specify patterns to skip -# (best by pointing at a file and clicking a special menu entry!) -# - add rcsdiff menu commands -# - add a way to view status of selected files without opening them -# - add a way to diff two files with different names -# - add a way to rename files -# - keep backups of overwritten/deleted files -# - a way to mark specified files as uninteresting for dircmp +# - faster update after moving/copying one file +# - diff flags (-b, etc.) should be global or maintained per window +# - use a few fixed windows instead of creating new ones all the time +# - ways to specify patterns to skip +# (best by pointing at a file and clicking a special menu entry!) +# - add rcsdiff menu commands +# - add a way to view status of selected files without opening them +# - add a way to diff two files with different names +# - add a way to rename files +# - keep backups of overwritten/deleted files +# - a way to mark specified files as uninteresting for dircmp import sys import posix @@ -42,439 +42,439 @@ skiplist = ['RCS', '.Amake', 'tags', '.', '..'] def anydiff(a, b, flags): # Display differences between any two objects - print 'diff', flags, a, b - if path.isdir(a) and path.isdir(b): - w = dirdiff(a, b, flags) - else: - w = filediff(a, b, flags) - addstatmenu(w, [a, b]) - w.original_close = w.close - w.close = close_dirwin - return w + print 'diff', flags, a, b + if path.isdir(a) and path.isdir(b): + w = dirdiff(a, b, flags) + else: + w = filediff(a, b, flags) + addstatmenu(w, [a, b]) + w.original_close = w.close + w.close = close_dirwin + return w def close_dirwin(w): - close_subwindows(w, (), 0) - w.original_close(w) + close_subwindows(w, (), 0) + w.original_close(w) def filediff(a, b, flags): # Display differences between two text files - diffcmd = 'diff' - if flags: diffcmd = diffcmd + mkarg(flags) - diffcmd = diffcmd + mkarg(a) + mkarg(b) - difftext = commands.getoutput(diffcmd) - return textwin.open_readonly(mktitle(a, b), difftext) + diffcmd = 'diff' + if flags: diffcmd = diffcmd + mkarg(flags) + diffcmd = diffcmd + mkarg(a) + mkarg(b) + difftext = commands.getoutput(diffcmd) + return textwin.open_readonly(mktitle(a, b), difftext) def dirdiff(a, b, flags): # Display differences between two directories - data = diffdata(a, b, flags) - w = tablewin.open(mktitle(a, b), data) - w.flags = flags - w.a = a - w.b = b - addviewmenu(w) - addactionmenu(w) - return w + data = diffdata(a, b, flags) + w = tablewin.open(mktitle(a, b), data) + w.flags = flags + w.a = a + w.b = b + addviewmenu(w) + addactionmenu(w) + return w def diffdata(a, b, flags): # Compute directory differences. - # - a_only = [('A only:', header_action), ('', header_action)] - b_only = [('B only:', header_action), ('', header_action)] - ab_diff = [('A <> B:', header_action), ('', header_action)] - ab_same = [('A == B:', header_action), ('', header_action)] - data = [a_only, b_only, ab_diff, ab_same] - # - a_list = dircache.listdir(a)[:] - b_list = dircache.listdir(b)[:] - dircache.annotate(a, a_list) - dircache.annotate(b, b_list) - a_list.sort() - b_list.sort() - # - for x in a_list: - if x in ['./', '../']: - pass - elif x not in b_list: - a_only.append(x, a_only_action) - else: - ax = path.cat(a, x) - bx = path.cat(b, x) - if path.isdir(ax) and path.isdir(bx): - if flags = '-r': - same = dircmp(ax, bx) - else: - same = 0 - else: - try: - same = cmp.cmp(ax, bx) - except posix.error: - same = 0 - if same: - ab_same.append(x, ab_same_action) - else: - ab_diff.append(x, ab_diff_action) - # - for x in b_list: - if x in ['./', '../']: - pass - elif x not in a_list: - b_only.append(x, b_only_action) - # - return data + # + a_only = [('A only:', header_action), ('', header_action)] + b_only = [('B only:', header_action), ('', header_action)] + ab_diff = [('A <> B:', header_action), ('', header_action)] + ab_same = [('A == B:', header_action), ('', header_action)] + data = [a_only, b_only, ab_diff, ab_same] + # + a_list = dircache.listdir(a)[:] + b_list = dircache.listdir(b)[:] + dircache.annotate(a, a_list) + dircache.annotate(b, b_list) + a_list.sort() + b_list.sort() + # + for x in a_list: + if x in ['./', '../']: + pass + elif x not in b_list: + a_only.append(x, a_only_action) + else: + ax = path.cat(a, x) + bx = path.cat(b, x) + if path.isdir(ax) and path.isdir(bx): + if flags = '-r': + same = dircmp(ax, bx) + else: + same = 0 + else: + try: + same = cmp.cmp(ax, bx) + except posix.error: + same = 0 + if same: + ab_same.append(x, ab_same_action) + else: + ab_diff.append(x, ab_diff_action) + # + for x in b_list: + if x in ['./', '../']: + pass + elif x not in a_list: + b_only.append(x, b_only_action) + # + return data # Re-read the directory. # Attempt to find the selected item back. def update(w): - setbusy(w) - icol, irow = w.selection - if 0 <= icol < len(w.data) and 2 <= irow < len(w.data[icol]): - selname = w.data[icol][irow][0] - else: - selname = '' - statcache.forget_dir(w.a) - statcache.forget_dir(w.b) - tablewin.select(w, (-1, -1)) - tablewin.update(w, diffdata(w.a, w.b, w.flags)) - if selname: - for icol in range(len(w.data)): - for irow in range(2, len(w.data[icol])): - if w.data[icol][irow][0] = selname: - tablewin.select(w, (icol, irow)) - break + setbusy(w) + icol, irow = w.selection + if 0 <= icol < len(w.data) and 2 <= irow < len(w.data[icol]): + selname = w.data[icol][irow][0] + else: + selname = '' + statcache.forget_dir(w.a) + statcache.forget_dir(w.b) + tablewin.select(w, (-1, -1)) + tablewin.update(w, diffdata(w.a, w.b, w.flags)) + if selname: + for icol in range(len(w.data)): + for irow in range(2, len(w.data[icol])): + if w.data[icol][irow][0] = selname: + tablewin.select(w, (icol, irow)) + break # Action functions for table items in directory diff windows def header_action(w, string, (icol, irow), (pos, clicks, button, mask)): - tablewin.select(w, (-1, -1)) + tablewin.select(w, (-1, -1)) def a_only_action(w, string, (icol, irow), (pos, clicks, button, mask)): - tablewin.select(w, (icol, irow)) - if clicks = 2: - w2 = anyopen(path.cat(w.a, string)) - if w2: - w2.parent = w + tablewin.select(w, (icol, irow)) + if clicks = 2: + w2 = anyopen(path.cat(w.a, string)) + if w2: + w2.parent = w def b_only_action(w, string, (icol, irow), (pos, clicks, button, mask)): - tablewin.select(w, (icol, irow)) - if clicks = 2: - w2 = anyopen(path.cat(w.b, string)) - if w2: - w2.parent = w + tablewin.select(w, (icol, irow)) + if clicks = 2: + w2 = anyopen(path.cat(w.b, string)) + if w2: + w2.parent = w def ab_diff_action(w, string, (icol, irow), (pos, clicks, button, mask)): - tablewin.select(w, (icol, irow)) - if clicks = 2: - w2 = anydiff(path.cat(w.a, string), path.cat(w.b, string), '') - w2.parent = w + tablewin.select(w, (icol, irow)) + if clicks = 2: + w2 = anydiff(path.cat(w.a, string), path.cat(w.b, string), '') + w2.parent = w def ab_same_action(w, string, sel, detail): - ax = path.cat(w.a, string) - if path.isdir(ax): - ab_diff_action(w, string, sel, detail) - else: - a_only_action(w, string, sel, detail) + ax = path.cat(w.a, string) + if path.isdir(ax): + ab_diff_action(w, string, sel, detail) + else: + a_only_action(w, string, sel, detail) def anyopen(name): # Open any kind of document, ignore errors - try: - w = anywin.open(name) - except (RuntimeError, posix.error): - stdwin.message('Can\'t open ' + name) - return 0 - addstatmenu(w, [name]) - return w + try: + w = anywin.open(name) + except (RuntimeError, posix.error): + stdwin.message('Can\'t open ' + name) + return 0 + addstatmenu(w, [name]) + return w def dircmp(a, b): # Compare whether two directories are the same - # To make this as fast as possible, it uses the statcache - print ' dircmp', a, b - a_list = dircache.listdir(a) - b_list = dircache.listdir(b) - for x in a_list: - if x in skiplist: - pass - elif x not in b_list: - return 0 - else: - ax = path.cat(a, x) - bx = path.cat(b, x) - if statcache.isdir(ax) and statcache.isdir(bx): - if not dircmp(ax, bx): return 0 - else: - try: - if not cmpcache.cmp(ax, bx): return 0 - except posix.error: - return 0 - for x in b_list: - if x in skiplist: - pass - elif x not in a_list: - return 0 - return 1 + # To make this as fast as possible, it uses the statcache + print ' dircmp', a, b + a_list = dircache.listdir(a) + b_list = dircache.listdir(b) + for x in a_list: + if x in skiplist: + pass + elif x not in b_list: + return 0 + else: + ax = path.cat(a, x) + bx = path.cat(b, x) + if statcache.isdir(ax) and statcache.isdir(bx): + if not dircmp(ax, bx): return 0 + else: + try: + if not cmpcache.cmp(ax, bx): return 0 + except posix.error: + return 0 + for x in b_list: + if x in skiplist: + pass + elif x not in a_list: + return 0 + return 1 # View menu (for dir diff windows only) def addviewmenu(w): - w.viewmenu = m = w.menucreate('View') - m.action = [] - add(m, 'diff -r A B', diffr_ab) - add(m, 'diff A B', diff_ab) - add(m, 'diff -b A B', diffb_ab) - add(m, 'diff -c A B', diffc_ab) - add(m, 'gdiff A B', gdiff_ab) - add(m, ('Open A ', 'A'), open_a) - add(m, ('Open B ', 'B'), open_b) - add(m, 'Rescan', rescan) - add(m, 'Rescan -r', rescan_r) + w.viewmenu = m = w.menucreate('View') + m.action = [] + add(m, 'diff -r A B', diffr_ab) + add(m, 'diff A B', diff_ab) + add(m, 'diff -b A B', diffb_ab) + add(m, 'diff -c A B', diffc_ab) + add(m, 'gdiff A B', gdiff_ab) + add(m, ('Open A ', 'A'), open_a) + add(m, ('Open B ', 'B'), open_b) + add(m, 'Rescan', rescan) + add(m, 'Rescan -r', rescan_r) # Action menu (for dir diff windows only) def addactionmenu(w): - w.actionmenu = m = w.menucreate('Action') - m.action = [] - add(m, 'cp A B', cp_ab) - add(m, 'rm B', rm_b) - add(m, '', nop) - add(m, 'cp B A', cp_ba) - add(m, 'rm A', rm_a) + w.actionmenu = m = w.menucreate('Action') + m.action = [] + add(m, 'cp A B', cp_ab) + add(m, 'rm B', rm_b) + add(m, '', nop) + add(m, 'cp B A', cp_ba) + add(m, 'rm A', rm_a) # Main menu (global): def mainmenu(): - m = stdwin.menucreate('Wdiff') - m.action = [] - add(m, ('Quit wdiff', 'Q'), quit_wdiff) - add(m, 'Close subwindows', close_subwindows) - return m + m = stdwin.menucreate('Wdiff') + m.action = [] + add(m, ('Quit wdiff', 'Q'), quit_wdiff) + add(m, 'Close subwindows', close_subwindows) + return m def add(m, text, action): - m.additem(text) - m.action.append(action) + m.additem(text) + m.action.append(action) def quit_wdiff(w, m, item): - if askyesno('Really quit wdiff altogether?', 1): - sys.exit(0) + if askyesno('Really quit wdiff altogether?', 1): + sys.exit(0) def close_subwindows(w, m, item): - while 1: - for w2 in gwin.windows: - if w2.parent = w: - close_subwindows(w2, m, item) - w2.close(w2) - break # inner loop, continue outer loop - else: - break # outer loop + while 1: + for w2 in gwin.windows: + if w2.parent = w: + close_subwindows(w2, m, item) + w2.close(w2) + break # inner loop, continue outer loop + else: + break # outer loop def diffr_ab(w, m, item): - dodiff(w, '-r') + dodiff(w, '-r') def diff_ab(w, m, item): - dodiff(w, '') + dodiff(w, '') def diffb_ab(w, m, item): - dodiff(w, '-b') + dodiff(w, '-b') def diffc_ab(w, m, item): - dodiff(w, '-c') + dodiff(w, '-c') def gdiff_ab(w, m, item): # Call SGI's gdiff utility - x = getselection(w) - if x: - a, b = path.cat(w.a, x), path.cat(w.b, x) - if path.isdir(a) or path.isdir(b): - stdwin.fleep() # This is for files only - else: - diffcmd = 'gdiff' - diffcmd = diffcmd + mkarg(a) + mkarg(b) + ' &' - print diffcmd - sts = posix.system(diffcmd) - if sts: print 'Exit status', sts + x = getselection(w) + if x: + a, b = path.cat(w.a, x), path.cat(w.b, x) + if path.isdir(a) or path.isdir(b): + stdwin.fleep() # This is for files only + else: + diffcmd = 'gdiff' + diffcmd = diffcmd + mkarg(a) + mkarg(b) + ' &' + print diffcmd + sts = posix.system(diffcmd) + if sts: print 'Exit status', sts def dodiff(w, flags): - x = getselection(w) - if x: - w2 = anydiff(path.cat(w.a, x), path.cat(w.b, x), flags) - w2.parent = w + x = getselection(w) + if x: + w2 = anydiff(path.cat(w.a, x), path.cat(w.b, x), flags) + w2.parent = w def open_a(w, m, item): - x = getselection(w) - if x: - w2 = anyopen(path.cat(w.a, x)) - if w2: - w2.parent = w + x = getselection(w) + if x: + w2 = anyopen(path.cat(w.a, x)) + if w2: + w2.parent = w def open_b(w, m, item): - x = getselection(w) - if x: - w2 = anyopen(path.cat(w.b, x)) - if w2: - w2.parent = w + x = getselection(w) + if x: + w2 = anyopen(path.cat(w.b, x)) + if w2: + w2.parent = w def rescan(w, m, item): - w.flags = '' - update(w) + w.flags = '' + update(w) def rescan_r(w, m, item): - w.flags = '-r' - update(w) + w.flags = '-r' + update(w) def rm_a(w, m, item): - x = getselection(w) - if x: - if x[-1:] = '/': x = x[:-1] - x = path.cat(w.a, x) - if path.isdir(x): - if askyesno('Recursively remove A directory ' + x, 1): - runcmd('rm -rf' + mkarg(x)) - else: - runcmd('rm -f' + mkarg(x)) - update(w) + x = getselection(w) + if x: + if x[-1:] = '/': x = x[:-1] + x = path.cat(w.a, x) + if path.isdir(x): + if askyesno('Recursively remove A directory ' + x, 1): + runcmd('rm -rf' + mkarg(x)) + else: + runcmd('rm -f' + mkarg(x)) + update(w) def rm_b(w, m, item): - x = getselection(w) - if x: - if x[-1:] = '/': x = x[:-1] - x = path.cat(w.b, x) - if path.isdir(x): - if askyesno('Recursively remove B directory ' + x, 1): - runcmd('rm -rf' + mkarg(x)) - else: - runcmd('rm -f' + mkarg(x)) - update(w) + x = getselection(w) + if x: + if x[-1:] = '/': x = x[:-1] + x = path.cat(w.b, x) + if path.isdir(x): + if askyesno('Recursively remove B directory ' + x, 1): + runcmd('rm -rf' + mkarg(x)) + else: + runcmd('rm -f' + mkarg(x)) + update(w) def cp_ab(w, m, item): - x = getselection(w) - if x: - if x[-1:] = '/': x = x[:-1] - ax = path.cat(w.a, x) - bx = path.cat(w.b, x) - if path.isdir(ax): - if path.exists(bx): - m = 'Can\'t copy directory to existing target' - stdwin.message(m) - return - runcmd('cp -r' + mkarg(ax) + mkarg(w.b)) - else: - runcmd('cp' + mkarg(ax) + mk2arg(w.b, x)) - update(w) + x = getselection(w) + if x: + if x[-1:] = '/': x = x[:-1] + ax = path.cat(w.a, x) + bx = path.cat(w.b, x) + if path.isdir(ax): + if path.exists(bx): + m = 'Can\'t copy directory to existing target' + stdwin.message(m) + return + runcmd('cp -r' + mkarg(ax) + mkarg(w.b)) + else: + runcmd('cp' + mkarg(ax) + mk2arg(w.b, x)) + update(w) def cp_ba(w, m, item): - x = getselection(w) - if x: - if x[-1:] = '/': x = x[:-1] - ax = path.cat(w.a, x) - bx = path.cat(w.b, x) - if path.isdir(bx): - if path.exists(ax): - m = 'Can\'t copy directory to existing target' - stdwin.message(m) - return - runcmd('cp -r' + mkarg(bx) + mkarg(w.a)) - else: - runcmd('cp' + mk2arg(w.b, x) + mkarg(ax)) - update(w) + x = getselection(w) + if x: + if x[-1:] = '/': x = x[:-1] + ax = path.cat(w.a, x) + bx = path.cat(w.b, x) + if path.isdir(bx): + if path.exists(ax): + m = 'Can\'t copy directory to existing target' + stdwin.message(m) + return + runcmd('cp -r' + mkarg(bx) + mkarg(w.a)) + else: + runcmd('cp' + mk2arg(w.b, x) + mkarg(ax)) + update(w) def nop(args): - pass + pass def getselection(w): - icol, irow = w.selection - if 0 <= icol < len(w.data): - if 0 <= irow < len(w.data[icol]): - return w.data[icol][irow][0] - stdwin.message('no selection') - return '' + icol, irow = w.selection + if 0 <= icol < len(w.data): + if 0 <= irow < len(w.data[icol]): + return w.data[icol][irow][0] + stdwin.message('no selection') + return '' def runcmd(cmd): - print cmd - sts, output = commands.getstatusoutput(cmd) - if sts or output: - if not output: - output = 'Exit status ' + `sts` - stdwin.message(output) + print cmd + sts, output = commands.getstatusoutput(cmd) + if sts or output: + if not output: + output = 'Exit status ' + `sts` + stdwin.message(output) # Status menu (for all kinds of windows) def addstatmenu(w, files): - w.statmenu = m = w.menucreate('Stat') - m.files = files - m.action = [] - for file in files: - m.additem(commands.getstatus(file)) - m.action.append(stataction) + w.statmenu = m = w.menucreate('Stat') + m.files = files + m.action = [] + for file in files: + m.additem(commands.getstatus(file)) + m.action.append(stataction) def stataction(w, m, item): # Menu item action for stat menu - file = m.files[item] - try: - m.setitem(item, commands.getstatus(file)) - except posix.error: - stdwin.message('Can\'t get status for ' + file) + file = m.files[item] + try: + m.setitem(item, commands.getstatus(file)) + except posix.error: + stdwin.message('Can\'t get status for ' + file) # Compute a suitable window title from two paths def mktitle(a, b): - if a = b: return a - i = 1 - while a[-i:] = b[-i:]: i = i+1 - i = i-1 - if not i: - return a + ' ' + b - else: - return '{' + a[:-i] + ',' + b[:-i] + '}' + a[-i:] + if a = b: return a + i = 1 + while a[-i:] = b[-i:]: i = i+1 + i = i-1 + if not i: + return a + ' ' + b + else: + return '{' + a[:-i] + ',' + b[:-i] + '}' + a[-i:] # Ask a confirmation question def askyesno(prompt, default): - try: - return stdwin.askync(prompt, default) - except KeyboardInterrupt: - return 0 + try: + return stdwin.askync(prompt, default) + except KeyboardInterrupt: + return 0 # Display a message "busy" in a window, and mark it for updating def setbusy(w): - left, top = w.getorigin() - width, height = w.getwinsize() - right, bottom = left + width, top + height - d = w.begindrawing() - d.erase((0, 0), (10000, 10000)) - text = 'Busy...' - textwidth = d.textwidth(text) - textheight = d.lineheight() - h, v = left + (width-textwidth)/2, top + (height-textheight)/2 - d.text((h, v), text) - del d - w.change((0, 0), (10000, 10000)) + left, top = w.getorigin() + width, height = w.getwinsize() + right, bottom = left + width, top + height + d = w.begindrawing() + d.erase((0, 0), (10000, 10000)) + text = 'Busy...' + textwidth = d.textwidth(text) + textheight = d.lineheight() + h, v = left + (width-textwidth)/2, top + (height-textheight)/2 + d.text((h, v), text) + del d + w.change((0, 0), (10000, 10000)) # Main function def main(): - print 'wdiff: warning: this version does NOT yet make backups' - argv = sys.argv - flags = '' - if len(argv) >= 2 and argv[1][:1] = '-': - flags = argv[1] - del argv[1] - m = mainmenu() # Create menu earlier than windows - if len(argv) = 2: # 1 argument - w = anyopen(argv[1]) - if not w: return - elif len(argv) = 3: # 2 arguments - w = anydiff(argv[1], argv[2], flags) - w.parent = () - else: - sys.stdout = sys.stderr - print 'usage:', argv[0], '[diff-flags] dir-1 [dir-2]' - sys.exit(2) - del w # It's preserved in gwin.windows - while 1: - try: - gwin.mainloop() - break - except KeyboardInterrupt: - pass # Just continue... + print 'wdiff: warning: this version does NOT yet make backups' + argv = sys.argv + flags = '' + if len(argv) >= 2 and argv[1][:1] = '-': + flags = argv[1] + del argv[1] + m = mainmenu() # Create menu earlier than windows + if len(argv) = 2: # 1 argument + w = anyopen(argv[1]) + if not w: return + elif len(argv) = 3: # 2 arguments + w = anydiff(argv[1], argv[2], flags) + w.parent = () + else: + sys.stdout = sys.stderr + print 'usage:', argv[0], '[diff-flags] dir-1 [dir-2]' + sys.exit(2) + del w # It's preserved in gwin.windows + while 1: + try: + gwin.mainloop() + break + except KeyboardInterrupt: + pass # Just continue... # Start the main function (this is a script) main() diff --git a/doc/Makefile b/doc/Makefile index f2a83bf..b2cf688 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,47 +1,47 @@ # Makefile for Python documentation. -LATEX= latex -DVIPS= dvips -TEXPREVIEW= xdvi +LATEX= latex +DVIPS= dvips +TEXPREVIEW= xdvi -PRINT= lpr +PRINT= lpr -tut: tut.dvi - $(TEXPREVIEW) tut +tut: tut.dvi + $(TEXPREVIEW) tut -tut.dvi tut.ps: tut.toc tut.tex myformat.sty +tut.dvi tut.ps: tut.toc tut.tex myformat.sty -mod: mod.dvi - $(TEXPREVIEW) mod +mod: mod.dvi + $(TEXPREVIEW) mod -mod.dvi mod.ps: mod.toc mod.tex mod1.tex mod2.tex mod3.tex myformat.sty +mod.dvi mod.ps: mod.toc mod.tex mod1.tex mod2.tex mod3.tex myformat.sty -ALL= tut.ps mod.ps +ALL= tut.ps mod.ps -all: $(ALL) +all: $(ALL) -print: $(ALL) - $(PRINT) $(ALL) +print: $(ALL) + $(PRINT) $(ALL) clean: - rm -f *.dvi *.aux *.toc *.log *.ps core [#@,]* *~ + rm -f *.dvi *.aux *.toc *.log *.ps core [#@,]* *~ -.SUFFIXES: # Remove default suffixes +.SUFFIXES: # Remove default suffixes -.SUFFIXES: .tex .aux .toc .dvi .ps +.SUFFIXES: .tex .aux .toc .dvi .ps .tex.aux: - $(LATEX) $* + $(LATEX) $* .tex.toc: - $(LATEX) $* + $(LATEX) $* .tex.dvi: - $(LATEX) $* + $(LATEX) $* .dvi.ps: - $(DVIPS) $* >$*.ps + $(DVIPS) $* >$*.ps .tex.ps: - $(LATEX) $* - $(DVIPS) $* >$*.ps + $(LATEX) $* + $(DVIPS) $* >$*.ps diff --git a/doc/README b/doc/README index 14c3de9..468aad8 100644 --- a/doc/README +++ b/doc/README @@ -4,8 +4,8 @@ started. The following are the important latex source files: - tut.tex A tutorial - mod.tex The library reference + tut.tex A tutorial + mod.tex The library reference They both read the style option file "myformat.sty". @@ -18,7 +18,7 @@ Type "make clean" to get rid of all the intermediate files produced by the latex process, and other junk files. You can just as well ignore the Makefile; all you really need is: - latex tut - latex tut - dvips tut | lpr + latex tut + latex tut + dvips tut | lpr and similar for the "mod" document. diff --git a/doc/SetClass.py b/doc/SetClass.py index 8a5fb9e..ca7ca6b 100644 --- a/doc/SetClass.py +++ b/doc/SetClass.py @@ -1,17 +1,17 @@ class Set(): - def new(self): - self.elements = [] - return self - def add(self, e): - if e not in self.elements: - self.elements.append(e) - def remove(self, e): - if e in self.elements: - for i in range(len(self.elements)): - if self.elements[i] = e: - del self.elements[i] - break - def is_element(self, e): - return e in self.elements - def size(self): - return len(self.elements) + def new(self): + self.elements = [] + return self + def add(self, e): + if e not in self.elements: + self.elements.append(e) + def remove(self, e): + if e in self.elements: + for i in range(len(self.elements)): + if self.elements[i] = e: + del self.elements[i] + break + def is_element(self, e): + return e in self.elements + def size(self): + return len(self.elements) diff --git a/doc/fibo.py b/doc/fibo.py index e8cafa8..83b8e83 100644 --- a/doc/fibo.py +++ b/doc/fibo.py @@ -1,15 +1,15 @@ # Fibonacci numbers demo -def fib(n): # write Fibonacci series up to n - a, b = 0, 1 - while b <= n: - print b, - a, b = b, a+b +def fib(n): # write Fibonacci series up to n + a, b = 0, 1 + while b <= n: + print b, + a, b = b, a+b def fib2(n): # return Fibonacci series up to n - ret = [] - a, b = 0, 1 - while b <= n: - ret.append(b) - a, b = b, a+b - return ret + ret = [] + a, b = 0, 1 + while b <= n: + ret.append(b) + a, b = b, a+b + return ret diff --git a/doc/mod.tex b/doc/mod.tex index c2d2355..cddfed7 100644 --- a/doc/mod.tex +++ b/doc/mod.tex @@ -5,7 +5,7 @@ % A command to force the text after an item to start on a new line \newcommand{\itembreak}{ - \mbox{}\\*[0mm] + \mbox{}\\*[0mm] } % A command to define a function item @@ -17,16 +17,16 @@ \itembreak } -\title{\bf - Python Library Reference \\ - (DRAFT) + itle{\bf + Python Library Reference \\ + (DRAFT) } \author{ - Guido van Rossum \\ - Dept. CST, CWI, Kruislaan 413 \\ - 1098 SJ Amsterdam, The Netherlands \\ - E-mail: {\tt gu...@cwi.nl} + Guido van Rossum \\ + Dept. CST, CWI, Kruislaan 413 \\ + 1098 SJ Amsterdam, The Netherlands \\ + E-mail: {\tt gu...@cwi.nl} } \begin{document} @@ -49,7 +49,7 @@ gives a more formal reference to the language. \pagebreak -\tableofcontents + ableofcontents \pagebreak diff --git a/doc/mod1.tex b/doc/mod1.tex index 2dac554..37abc50 100644 --- a/doc/mod1.tex +++ b/doc/mod1.tex @@ -101,15 +101,15 @@ Operation & Result & Notes \\ {\tt min}({\em s}) & smallest item of {\em s} & \\ {\tt max}({\em s}) & largest item of {\em s} & \\ {\em x} {\tt in} {\em s} & - true if an item of {\em s} is equal to {\em x} & \\ + true if an item of {\em s} is equal to {\em x} & \\ {\em x} {\tt not} {\tt in} {\em s} & - false if an item of {\em s} is equal to {\em x} & \\ + false if an item of {\em s} is equal to {\em x} & \\ {\em s}{\tt +}{\em t} & the concatenation of {\em s} and {\em t} & \\ {\em s}{\tt *}{\em n}, {\em n}*{\em s} & - {\em n} copies of {\em s} concatenated & (1) \\ + {\em n} copies of {\em s} concatenated & (1) \\ {\em s}[{\em i}] & {\em i}'th item of {\em s} & \\ {\em s}[{\em i}:{\em j}] & - slice of {\em s} from {\em i} to {\em j} & (2) \\ + slice of {\em s} from {\em i} to {\em j} & (2) \\ \hline \end{tabular} \end{center} @@ -143,19 +143,19 @@ The following operations are defined on mutable sequence types (where Operation & Result \\ \hline {\em s}[{\em i}] = {\em x} & - item {\em i} of {\em s} is replaced by {\em x} \\ + item {\em i} of {\em s} is replaced by {\em x} \\ {\em s}[{\em i}:{\em j}] = {\em t} & - slice of {\em s} from {\em i} to {\em j} is replaced by {\em t} \\ + slice of {\em s} from {\em i} to {\em j} is replaced by {\em t} \\ {\tt del} {\em s}[{\em i}:{\em j}] & - same as {\em s}[{\em i}:{\em j}] = [] \\ + same as {\em s}[{\em i}:{\em j}] = [] \\ {\em s}.{\tt append}({\em x}) & - same as {\em s}[{\tt len}({\em x}):{\tt len}({\em x})] = [{\em x}] \\ + same as {\em s}[{\tt len}({\em x}):{\tt len}({\em x})] = [{\em x}] \\ {\em s}.{\tt insert}({\em i}, {\em x}) & - same as {\em s}[{\em i}:{\em i}] = [{\em x}] \\ + same as {\em s}[{\em i}:{\em i}] = [{\em x}] \\ {\em s}.{\tt sort}() & - the items of {\em s} are permuted to satisfy \\ - & - $s[i] \leq s[j]$ for $i < j$\\ + the items of {\em s} are permuted to satisfy \\ + & + $s[i] \leq s[j]$ for $i < j$\\ \hline \end{tabular} \end{center} @@ -216,7 +216,7 @@ A small example using a dictionary: ['guido', 'irv', 'jack'] >>> tel.has_key('guido') 1 ->>> +>>> \end{verbatim}\ecode \subsubsection{Other Built-in Types} @@ -372,7 +372,7 @@ For example: ['sys'] >>> dir(sys) ['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout'] ->>> +>>> \end{verbatim}\ecode \funcitem{divmod}{a, b} %.br @@ -398,7 +398,7 @@ For example: (-15, -5) >>> divmod(-100, -7) (14, -2) ->>> +>>> \end{verbatim}\ecode \funcitem{eval}{s} Takes a string as argument and parses and evaluates it as a {\Python} @@ -411,7 +411,7 @@ For example: >>> x = 1 >>> eval('x+1') 2 ->>> +>>> \end{verbatim}\ecode \funcitem{exec}{s} Takes a string as argument and parses and evaluates it as a sequence of @@ -426,7 +426,7 @@ For example: >>> exec('x = x+1\n') >>> x 2 ->>> +>>> \end{verbatim}\ecode \funcitem{float}{x} Converts a number to floating point. @@ -494,7 +494,7 @@ For example: [] >>> range(1, 0) [] ->>> +>>> \end{verbatim}\ecode \funcitem{raw\_input}{s} %.br @@ -508,7 +508,7 @@ For example: >>> raw_input('Type anything: ') Type anything: Mutant Teenage Ninja Turtles 'Mutant Teenage Ninja Turtles' ->>> +>>> \end{verbatim}\ecode \funcitem{reload}{module} Causes an already imported module to be re-parsed and re-initialized. diff --git a/doc/mod2.tex b/doc/mod2.tex index 46f6d62..fca5e8a 100644 --- a/doc/mod2.tex +++ b/doc/mod2.tex @@ -87,12 +87,12 @@ They are: {\tt exp(x)}, {\tt fabs(x)}, {\tt floor(x)}, -%{\tt fmod(...)} XXX not yet +%{\tt fmod(...)} XXX not yet %{\tt frexp(...)} XXX not yet %{\tt ldexp(...)} XXX not yet {\tt log(x)}, {\tt log10(x)}, -%{\tt modf(...)} XXX not yet +%{\tt modf(...)} XXX not yet {\tt pow(x,y)}, {\tt sin(x)}, {\tt sinh(x)}, @@ -193,7 +193,7 @@ For example: '--b--' >>> s[3:4] # The subpattern 'b' ->>> +>>> \end{verbatim}\ecode \subsection{Built-in Module {\tt posix}} @@ -693,16 +693,16 @@ import stdwin from stdwinevents import * def main(): - mywin = stdwin.open('Hello') - # - while 1: - (type, win, detail) = stdwin.getevent() - if type = WE_DRAW: - draw = win.begindrawing() - draw.text((0, 0), 'Hello, world') - del draw - elif type = WE_CLOSE: - break + mywin = stdwin.open('Hello') + # + while 1: + (type, win, detail) = stdwin.getevent() + if type = WE_DRAW: + draw = win.begindrawing() + draw.text((0, 0), 'Hello, world') + del draw + elif type = WE_CLOSE: + break main() \end{verbatim}\ecode @@ -780,7 +780,7 @@ For example: \bcode\begin{verbatim} >>> amoeba.name_lookup('/profile/cap') aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a ->>> +>>> \end{verbatim}\ecode The following methods are defined for capability objects. \begin{description} @@ -879,7 +879,7 @@ implemented in C for efficiency: Amplifies a chunk of samples by a variable factor changing from {\tt f1}/256 to {\tt f2}/256. Negative factors are allowed. -Resulting values that are to large to fit in a byte are clipped. +Resulting values that are to large to fit in a byte are clipped. \funcitem{reverse}{buf} %.br Returns a chunk of samples backwards. @@ -1000,7 +1000,7 @@ is called for the normal, and then {\tt v3f()} is called for the point. \funcitem{vnarray}{} -Similar to +Similar to {\tt nvarray()} but the pairs have the point first and the normal second. \funcitem{nurbssurface}{s\_k[], t\_k[], ctl[][], s\_ord, t\_ord, type} @@ -1042,22 +1042,22 @@ Here is a tiny but complete example GL program in {\Python}: import gl, GL, time def main(): - gl.foreground() - gl.prefposition(500, 900, 500, 900) - w = gl.winopen('CrissCross') - gl.ortho2(0.0, 400.0, 0.0, 400.0) - gl.color(GL.WHITE) - gl.clear() - gl.color(GL.RED) - gl.bgnline() - gl.v2f(0.0, 0.0) - gl.v2f(400.0, 400.0) - gl.endline() - gl.bgnline() - gl.v2f(400.0, 0.0) - gl.v2f(0.0, 400.0) - gl.endline() - time.sleep(5) + gl.foreground() + gl.prefposition(500, 900, 500, 900) + w = gl.winopen('CrissCross') + gl.ortho2(0.0, 400.0, 0.0, 400.0) + gl.color(GL.WHITE) + gl.clear() + gl.color(GL.RED) + gl.bgnline() + gl.v2f(0.0, 0.0) + gl.v2f(400.0, 400.0) + gl.endline() + gl.bgnline() + gl.v2f(400.0, 0.0) + gl.v2f(0.0, 400.0) + gl.endline() + time.sleep(5) main() \end{verbatim}\ecode diff --git a/doc/mod3.tex b/doc/mod3.tex index d1a99b1..d37956c 100644 --- a/doc/mod3.tex +++ b/doc/mod3.tex @@ -19,7 +19,7 @@ The string The string {\tt '0123456789abcdefABCDEF'}. \funcitem{letters} -The concatenation of the strings +The concatenation of the strings {\tt lowercase} and {\tt uppercase} @@ -99,7 +99,7 @@ Removes leading and trailing whitespace from the string Converts lower case letters to upper case and vice versa. \funcitem{upper}{s} Convert letters to upper case. -\funcitem{ljust(s, width), rjust(s, width), center}{s, width} +\funcitem{ljust(s, width), rjust(s, width), center}{s, width} %.br These functions respectively left-justify, right-justify and center a string in a field of given width. @@ -252,7 +252,7 @@ Example: [('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')] >>> args ['a1', 'a2'] ->>> +>>> \end{verbatim}\ecode The exception {\tt getopt.error = 'getopt error'} @@ -305,7 +305,7 @@ Read the file for details. Suggested usage is \bcode\begin{verbatim} >>> from stdwinevents import * ->>> +>>> \end{verbatim}\ecode \subsection{Standard Module {\tt rect}} @@ -342,7 +342,7 @@ This makes it possible to quickly check whether a result is empty: >>> r3 = rect.intersect(r1, r2) >>> if r3 is rect.empty: print 'Empty intersection' Empty intersection ->>> +>>> \end{verbatim}\ecode \funcitem{is\_empty}{r} %.br diff --git a/doc/myformat.sty b/doc/myformat.sty index be70239..192ddb1 100644 --- a/doc/myformat.sty +++ b/doc/myformat.sty @@ -1,34 +1,34 @@ % Style parameters and macros used by all documents here % Page lay-out parameters -\textwidth = 160mm -\textheight = 240mm -\topmargin = -11mm -\oddsidemargin = 0mm -\evensidemargin = 0mm -%\parindent = 0mm + extwidth = 160mm + extheight = 240mm + opmargin = -11mm +\oddsidemargin = 0mm +\evensidemargin = 0mm +%\parindent = 0mm % Frequently used system names -\newcommand{\Python}{Python} % Sometimes I want this italicized +\newcommand{\Python}{Python} % Sometimes I want this italicized \newcommand{\UNIX}{U{\sc nix}} % Variable used by begin code command \newlength{\codewidth} \newcommand{\bcode}{ - % Calculate the text width for the minipage: - \setlength{\codewidth}{\linewidth} - \addtolength{\codewidth}{-\parindent} - % - \vspace{3mm} - \par - \indent - \begin{minipage}[t]{\codewidth} + % Calculate the text width for the minipage: + \setlength{\codewidth}{\linewidth} + \addtolength{\codewidth}{-\parindent} + % + \vspace{3mm} + \par + \indent + \begin{minipage}[t]{\codewidth} } \newcommand{\ecode}{ - \end{minipage} - \vspace{3mm} - \par - \noindent + \end{minipage} + \vspace{3mm} + \par + \noindent } diff --git a/doc/pytry b/doc/pytry index dcc3f84..fb3534d 100755 --- a/doc/pytry +++ b/doc/pytry @@ -4,17 +4,17 @@ trap 'rm -f $TMP; exit 1' 1 2 3 13 14 15 cat $* >$TMP ( - cat $TMP - - sed ' - s/^>>> // - s/^>>>$// - s/^\.\.\. // - s/^\.\.\.$// - ' $TMP | - python - - echo '>>> ' + cat $TMP + + sed ' + s/^>>> // + s/^>>>$// + s/^\.\.\. // + s/^\.\.\.$// + ' $TMP | + python + + echo '>>> ' ) 2>&1 rm $TMP diff --git a/doc/tut.tex b/doc/tut.tex index ad5f56c..e0229b9 100644 --- a/doc/tut.tex +++ b/doc/tut.tex @@ -9,10 +9,10 @@ } \author{ - Guido van Rossum \\ - Dept. CST, CWI, Kruislaan 413 \\ - 1098 SJ Amsterdam, The Netherlands \\ - E-mail: {\tt gu...@cwi.nl} + Guido van Rossum \\ + Dept. CST, CWI, Kruislaan 413 \\ + 1098 SJ Amsterdam, The Netherlands \\ + E-mail: {\tt gu...@cwi.nl} } \begin{document} @@ -154,15 +154,15 @@ installation option, other places instead of are possible; check with your local \Python\ guru or system administrator.% \footnote{ - At CWI, at the time of writing, the interpreter can be found in - the following places: - On the Amoeba Ultrix machines, use the standard path, - {\tt /usr/local/python}. - On the Sun file servers, use - {\tt /ufs/guido/bin/}{\em arch}{\tt /python}, - where {\em arch} can be {\tt sgi} or {\tt sun4}. - On piring, use {\tt /userfs3/amoeba/bin/python}. - (If you can't find a binary advertised here, get in touch with me.) + At CWI, at the time of writing, the interpreter can be found in + the following places: + On the Amoeba Ultrix machines, use the standard path, + {\tt /usr/local/python}. + On the Sun file servers, use + {\tt /ufs/guido/bin/}{\em arch}{\tt /python}, + where {\em arch} can be {\tt sgi} or {\tt sun4}. + On piring, use {\tt /userfs3/amoeba/bin/python}. + (If you can't find a binary advertised here, get in touch with me.) } The interpreter operates somewhat like the \UNIX\ shell: when called with @@ -172,13 +172,13 @@ standard input, it reads and executes a {\em script} from that file.% \footnote{ - There is a difference between ``{\tt python file}'' and - ``{\tt python $<$file}''. In the latter case {\tt input()} and - {\tt raw\_input()} are satisfied from {\em file}, which has - already been read until the end by the parser, so they will read - EOF immediately. In the former case (which is usually what - you want) they are satisfied from whatever file or device is - connected to standard input of the \Python\ interpreter. + There is a difference between ``{\tt python file}'' and + ``{\tt python $<$file}''. In the latter case {\tt input()} and + {\tt raw\_input()} are satisfied from {\em file}, which has + already been read until the end by the parser, so they will read + EOF immediately. In the former case (which is usually what + you want) they are satisfied from whatever file or device is + connected to standard input of the \Python\ interpreter. } If available, the script name and additional arguments thereafter are passed to the script in the variable @@ -232,10 +232,10 @@ When is not set, an installation-dependent default path is used, usually {\tt .:/usr/local/lib/python}.% \footnote{ - Modules are really searched in the list of directories given by - the variable {\tt sys.path} which is initialized from - {\tt PYTHONPATH} or from the installation-dependent default. - See the section on Standard Modules later. + Modules are really searched in the list of directories given by + the variable {\tt sys.path} which is initialized from + {\tt PYTHONPATH} or from the installation-dependent default. + See the section on Standard Modules later. } On BSD'ish \UNIX\ systems, \Python\ scripts can be made directly executable, @@ -262,10 +262,10 @@ however, the basics are easily explained. If supported,% \footnote{ - Perhaps the quickest check to see whether command line editing - is supported is typing Control-P to the first \Python\ prompt - you get. If it beeps, you have command line editing. - If not, you can skip the rest of this section. + Perhaps the quickest check to see whether command line editing + is supported is typing Control-P to the first \Python\ prompt + you get. If it beeps, you have command line editing. + If not, you can skip the rest of this section. } input line editing is active whenever the interpreter prints a primary or secondary prompt. @@ -423,9 +423,9 @@ notation: two subscripts (indices) separated by a colon. >>> word[2:4] 'lp' >>> # Slice indices have useful defaults: ->>> word[:2] # Take first two characters +>>> word[:2] # Take first two characters 'He' ->>> word[2:] # Drop first two characters +>>> word[2:] # Drop first two characters 'lpA' >>> # A useful invariant: s[:i] + s[i:] = s >>> word[:3] + word[3:] @@ -448,12 +448,12 @@ Slice indices (but not simple subscripts) may be negative numbers, to start counting from the right. For example: \bcode\begin{verbatim} ->>> word[-2:] # Take last two characters +>>> word[-2:] # Take last two characters 'pA' ->>> word[:-2] # Drop last two characters +>>> word[:-2] # Drop last two characters 'Hel' >>> # But -0 does not count from the right! ->>> word[-0:] # (since -0 equals 0) +>>> word[-0:] # (since -0 equals 0) 'HelpA' >>> \end{verbatim}\ecode @@ -470,8 +470,8 @@ for example: +---+---+---+---+---+ | H | e | l | p | A | +---+---+---+---+---+ - 0 1 2 3 4 5 --5 -4 -3 -2 -1 + 0 1 2 3 4 5 +-5 -4 -3 -2 -1 \end{verbatim}\ecode The first row of numbers gives the position of the indices 0...5 in the string; the second row gives the corresponding negative indices. @@ -570,8 +570,8 @@ series as follows: >>> # the sum of two elements defines the next >>> a, b = 0, 1 >>> while b < 100: -... print b -... a, b = b, a+b +... print b +... a, b = b, a+b ... 1 1 @@ -616,9 +616,9 @@ The standard comparison operators are written as and {\tt <>}.% \footnote{ - The ambiguity of using {\tt =} - for both assignment and equality is resolved by disallowing - unparenthesized conditions at the right hand side of assignments. + The ambiguity of using {\tt =} + for both assignment and equality is resolved by disallowing + unparenthesized conditions at the right hand side of assignments. } \item The @@ -651,8 +651,8 @@ A trailing comma avoids the newline after the output: \bcode\begin{verbatim} >>> a, b = 0, 1 >>> while b < 1000: -... print b, -... a, b = b, a+b +... print b, +... a, b = b, a+b ... 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 >>> @@ -673,14 +673,14 @@ Perhaps the most well-known statement type is the {\tt if} statement. For example: \bcode\begin{verbatim} >>> if x < 0: -... x = 0 -... print 'Negative changed to zero' +... x = 0 +... print 'Negative changed to zero' ... elif x = 0: -... print 'Zero' +... print 'Zero' ... elif x = 1: -... print 'Single' +... print 'Single' ... else: -... print 'More' +... print 'More' ... \end{verbatim}\ecode There can be zero or more {\tt elif} parts, and the {\tt else} part is @@ -703,7 +703,7 @@ For example (no pun intended): >>> # Measure some strings: >>> a = ['cat', 'window', 'defenestrate'] >>> for x in a: -... print x, len(x) +... print x, len(x) ... cat 3 window 6 @@ -741,7 +741,7 @@ and {\tt len()} as follows: \bcode\begin{verbatim} >>> a = ['Mary', 'had', 'a', 'little', 'boy'] >>> for i in range(len(a)): -... print i, a[i] +... print i, a[i] ... 0 Mary 1 had @@ -763,12 +763,12 @@ This is exemplified by the following loop, which searches for a list item of value 0: \bcode\begin{verbatim} >>> for n in range(2, 10): -... for x in range(2, n): -... if n % x = 0: -... print n, 'equals', x, '*', n/x -... break -... else: -... print n, 'is a prime number' +... for x in range(2, n): +... if n % x = 0: +... print n, 'equals', x, '*', n/x +... break +... else: +... print n, 'is a prime number' ... 2 is a prime number 3 is a prime number @@ -789,7 +789,7 @@ program requires no action. For example: \bcode\begin{verbatim} >>> while 1: -... pass # Busy-wait for keyboard interrupt +... pass # Busy-wait for keyboard interrupt ... \end{verbatim}\ecode @@ -802,11 +802,11 @@ XXX To Be Done. We can create a function that writes the Fibonacci series to an arbitrary boundary: \bcode\begin{verbatim} ->>> def fib(n): # write Fibonacci series up to n -... a, b = 0, 1 -... while b <= n: -... print b, -... a, b = b, a+b +>>> def fib(n): # write Fibonacci series up to n +... a, b = 0, 1 +... while b <= n: +... print b, +... a, b = b, a+b ... >>> # Now call the function we just defined: >>> fib(2000) @@ -837,10 +837,10 @@ the local symbol table of the called function when it is called; thus, arguments are passed using {\em call\ by\ value}.% \footnote{ - Actually, {\em call by object reference} would be a better - description, since if a mutable object is passed, the caller - will see any changes the callee makes to it (e.g., items - inserted into a list). + Actually, {\em call by object reference} would be a better + description, since if a mutable object is passed, the caller + will see any changes the callee makes to it (e.g., items + inserted into a list). } When a function calls another function, a new local symbol table is created for that call. @@ -880,15 +880,15 @@ It is simple to write a function that returns a list of the numbers of the Fibonacci series, instead of printing it: \bcode\begin{verbatim} >>> def fib2(n): # return Fibonacci series up to n -... result = [] -... a, b = 0, 1 -... while b <= n: -... result.append(b) # see below -... a, b = b, a+b -... return result +... result = [] +... a, b = 0, 1 +... while b <= n: +... result.append(b) # see below +... a, b = b, a+b +... return result ... ->>> f100 = fib2(100) # call it ->>> f100 # write the result +>>> f100 = fib2(100) # call it +>>> f100 # write the result [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] >>> \end{verbatim}\ecode @@ -928,8 +928,8 @@ In this case it is equivalent to {\tt ret = ret + [b]}, but more efficient.% \footnote{ - There is a subtle semantic difference if the object - is referenced from more than one place. + There is a subtle semantic difference if the object + is referenced from more than one place. } \end{itemize} The list object type has two more methods: @@ -993,19 +993,19 @@ in the current directory with the following contents: \bcode\begin{verbatim} # Fibonacci numbers module -def fib(n): # write Fibonacci series up to n - a, b = 0, 1 - while b <= n: - print b, - a, b = b, a+b +def fib(n): # write Fibonacci series up to n + a, b = 0, 1 + while b <= n: + print b, + a, b = b, a+b def fib2(n): # return Fibonacci series up to n - ret = [] - a, b = 0, 1 - while b <= n: - ret.append(b) - a, b = b, a+b - return ret + ret = [] + a, b = 0, 1 + while b <= n: + ret.append(b) + a, b = b, a+b + return ret \end{verbatim}\ecode Now enter the \Python\ interpreter and import this module with the following command: @@ -1043,9 +1043,9 @@ They are executed only the {\em first} time the module is imported somewhere.% \footnote{ - In fact function definitions are also `statements' that are - `executed'; the execution enters the function name in the - module's global symbol table. + In fact function definitions are also `statements' that are + `executed'; the execution enters the function name in the + module's global symbol table. } Each module has its own private symbol table, which is used as the @@ -1157,7 +1157,7 @@ kind of complaint you get while you are still learning \Python: >>> while 1 print 'Hello world' Parsing error: file , line 1: while 1 print 'Hello world' - ^ + ^ Unhandled exception: run-time error: syntax error >>> \end{verbatim}\ecode @@ -1178,15 +1178,15 @@ an error when an attempt is made to execute it: >>> 10 * (1/0) Unhandled exception: run-time error: integer division by zero Stack backtrace (innermost last): - File "", line 1 + File "", line 1 >>> 4 + foo*3 Unhandled exception: undefined name: foo Stack backtrace (innermost last): - File "", line 1 + File "", line 1 >>> '2' + 2 Unhandled exception: type error: illegal argument type for built-in operation Stack backtrace (innermost last): - File "", line 1 + File "", line 1 >>> \end{verbatim}\ecode Errors detected during execution are called @@ -1223,9 +1223,9 @@ The detail states the cause of the error in more detail. errors are more serious: these are usually caused by misspelled identifiers.% \footnote{ - The parser does not check whether names used in a program are at - all defined elsewhere in the program, so such checks are - postponed until run-time. The same holds for type checking. + The parser does not check whether names used in a program are at + all defined elsewhere in the program, so such checks are + postponed until run-time. The same holds for type checking. } The detail is the offending identifier. \item @@ -1244,11 +1244,11 @@ some floating point numbers: \bcode\begin{verbatim} >>> numbers = [0.3333, 2.5, 0.0, 10.0] >>> for x in numbers: -... print x, -... try: -... print 1.0 / x -... except RuntimeError: -... print '*** has no inverse ***' +... print x, +... try: +... print 1.0 / x +... except RuntimeError: +... print '*** has no inverse ***' ... 0.3333 3.00030003 2.5 0.4 @@ -1288,7 +1288,7 @@ An except clause may name multiple exceptions as a parenthesized list, e.g.: \bcode\begin{verbatim} ... except (RuntimeError, TypeError, NameError): -... pass +... pass \end{verbatim}\ecode The last except clause may omit the exception name(s), to serve as a wildcard. @@ -1303,9 +1303,9 @@ specify a variable after the exception name (or list) to receive the argument's value, as follows: \bcode\begin{verbatim} >>> try: -... foo() +... foo() ... except NameError, x: -... print 'name', x, 'undefined' +... print 'name', x, 'undefined' ... name foo undefined >>> @@ -1319,21 +1319,21 @@ These are in fact string objects whose {\em object\ identity} (not their value!) identifies the exceptions.% \footnote{ - There should really be a separate exception type; it is pure - laziness that exceptions are identified by strings, and this may - be fixed in the future. + There should really be a separate exception type; it is pure + laziness that exceptions are identified by strings, and this may + be fixed in the future. } The string is printed as the second part of the message for unhandled exceptions. Their names and values are: \bcode\begin{verbatim} -EOFError 'end-of-file read' -KeyboardInterrupt 'keyboard interrupt' -MemoryError 'out of memory' * -NameError 'undefined name' * -RuntimeError 'run-time error' * -SystemError 'system error' * -TypeError 'type error' * +EOFError 'end-of-file read' +KeyboardInterrupt 'keyboard interrupt' +MemoryError 'out of memory' * +NameError 'undefined name' * +RuntimeError 'run-time error' * +SystemError 'system error' * +TypeError 'type error' * \end{verbatim}\ecode The meanings should be clear enough. Those exceptions with a {\tt *} in the third column have an argument. @@ -1344,12 +1344,12 @@ that are called (even indirectly) in the try clause. For example: \bcode\begin{verbatim} >>> def this_fails(): -... x = 1/0 +... x = 1/0 ... >>> try: -... this_fails() +... this_fails() ... except RuntimeError, detail: -... print 'Handling run-time error:', detail +... print 'Handling run-time error:', detail ... Handling run-time error: domain error or zero division >>> @@ -1364,7 +1364,7 @@ For example: >>> raise NameError, 'Hi There!' Unhandled exception: undefined name: Hi There! Stack backtrace (innermost last): - File "", line 1 + File "", line 1 >>> \end{verbatim}\ecode The first argument to {\tt raise} names the exception to be raised. @@ -1378,15 +1378,15 @@ For example: \bcode\begin{verbatim} >>> my_exc = 'nobody likes me!' >>> try: -... raise my_exc, 2*2 +... raise my_exc, 2*2 ... except my_exc, val: -... print 'My exception occured, value:', val +... print 'My exception occured, value:', val ... My exception occured, value: 4 >>> raise my_exc, 1 Unhandled exception: nobody likes me!: 1 Stack backtrace (innermost last): - File "", line 7 + File "", line 7 >>> \end{verbatim}\ecode Many standard modules use this to report errors that may occur in @@ -1399,14 +1399,14 @@ define clean-up actions that must be executed under all circumstances. For example: \bcode\begin{verbatim} >>> try: -... raise KeyboardInterrupt +... raise KeyboardInterrupt ... finally: -... print 'Goodbye, world!' +... print 'Goodbye, world!' ... Goodbye, world! Unhandled exception: keyboard interrupt Stack backtrace (innermost last): - File "", line 2 + File "", line 2 >>> \end{verbatim}\ecode The @@ -1456,11 +1456,11 @@ Also, like Modula-3 but unlike C++, the built-in operators with special syntax (arithmetic operators, subscripting etc.) cannot be redefined for class members.% \footnote{ - They can be redefined for new object types implemented in C in - extensions to the interpreter, however. It would require only a - naming convention and a relatively small change to the - interpreter to allow operator overloading for classes, so - perhaps someday... + They can be redefined for new object types implemented in C in + extensions to the interpreter, however. It would require only a + naming convention and a relatively small change to the + interpreter to allow operator overloading for classes, so + perhaps someday... } \subsubsection{A Simple Example} @@ -1471,22 +1471,22 @@ remove elements, a membership test, and a request for the size of the set. \bcode\begin{verbatim} class Set(): - def new(self): - self.elements = [] - return self - def add(self, e): - if e not in self.elements: - self.elements.append(e) - def remove(self, e): - if e in self.elements: - for i in range(len(self.elements)): - if self.elements[i] = e: - del self.elements[i] - break - def is_element(self, e): - return e in self.elements - def size(self): - return len(self.elements) + def new(self): + self.elements = [] + return self + def add(self, e): + if e not in self.elements: + self.elements.append(e) + def remove(self, e): + if e in self.elements: + for i in range(len(self.elements)): + if self.elements[i] = e: + del self.elements[i] + break + def is_element(self, e): + return e in self.elements + def size(self): + return len(self.elements) \end{verbatim}\ecode Note that the class definition looks like a big compound statement, with all the function definitons indented repective to the @@ -1538,13 +1538,13 @@ XXX This section is not complete yet! \section{XXX P.M.} \begin{itemize} -\item The {\tt del} statement. -\item The {\tt dir()} function. -\item Tuples. -\item Dictionaries. -\item Objects and types in general. -\item Backquotes. -\item And/Or/Not. +\item The {\tt del} statement. +\item The {\tt dir()} function. +\item Tuples. +\item Dictionaries. +\item Objects and types in general. +\item Backquotes. +\item And/Or/Not. \end{itemize} \end{document} diff --git a/lib/Abstract.py b/lib/Abstract.py index 385e6e5..9d9013b 100644 --- a/lib/Abstract.py +++ b/lib/Abstract.py @@ -11,45 +11,45 @@ # define() while split creation methods are called create(). class AbstractParent(): - # - # Upcalls from child to parent - # - def addchild(self, child): unimpl() - def delchild(self, child): unimpl() - # - def need_mouse(self, child): unimpl() - def no_mouse(self, child): unimpl() - # - def need_timer(self, child): unimpl() - def no_timer(self, child): unimpl() - # - # XXX need_kbd, no_kbd; focus??? - # - def begindrawing(self): return unimpl() - def beginmeasuring(self): return unimpl() - # - def change(self, area): unimpl() - def scroll(self, (area, (dh, dv))): unimpl() - def settimer(self, itimer): unimpl() + # + # Upcalls from child to parent + # + def addchild(self, child): unimpl() + def delchild(self, child): unimpl() + # + def need_mouse(self, child): unimpl() + def no_mouse(self, child): unimpl() + # + def need_timer(self, child): unimpl() + def no_timer(self, child): unimpl() + # + # XXX need_kbd, no_kbd; focus??? + # + def begindrawing(self): return unimpl() + def beginmeasuring(self): return unimpl() + # + def change(self, area): unimpl() + def scroll(self, (area, (dh, dv))): unimpl() + def settimer(self, itimer): unimpl() class AbstractChild(): - # - # Downcalls from parent to child - # - def destroy(self): unimpl() - # - def minsize(self, m): return unimpl() - def getbounds(self): return unimpl() - def setbounds(self, bounds): unimpl() - def draw(self, (d, area)): unimpl() - # - # Downcalls only made after certain upcalls - # - def mouse_down(self, detail): unimpl() - def mouse_move(self, detail): unimpl() - def mouse_up(self, detail): unimpl() - # - def timer(self): unimpl() + # + # Downcalls from parent to child + # + def destroy(self): unimpl() + # + def minsize(self, m): return unimpl() + def getbounds(self): return unimpl() + def setbounds(self, bounds): unimpl() + def draw(self, (d, area)): unimpl() + # + # Downcalls only made after certain upcalls + # + def mouse_down(self, detail): unimpl() + def mouse_move(self, detail): unimpl() + def mouse_up(self, detail): unimpl() + # + def timer(self): unimpl() # A "Split" is a child that manages one or more children. # (This terminology is due to DEC SRC, except for CSplits.) @@ -58,4 +58,4 @@ class AbstractChild(): # for others (e.g., all geometry related calls) this is not possible. class AbstractSplit() = AbstractChild(), AbstractParent(): - pass + pass diff --git a/lib/Buttons.py b/lib/Buttons.py index 7c36021..3ad5605 100644 --- a/lib/Buttons.py +++ b/lib/Buttons.py @@ -20,374 +20,374 @@ _MASK = 3 # LabelAppearance provides defaults for all appearance methods. # selected state not visible # disabled --> crossed out -# hilited --> inverted +# hilited --> inverted # class LabelAppearance(): - # - # Initialization - # - def init_appearance(self): - self.bounds = _rect.empty - self.enabled = 1 - self.hilited = 0 - self.selected = 0 - self.text = '' - # - # Size enquiry - # - def minsize(self, m): - try: - self.text = self.text - except NameError: - self.text = '' - return m.textwidth(self.text) + 6, m.lineheight() + 6 - # - def getbounds(self): - return self.bounds - # - # Changing the parameters - # - def settext(self, text): - self.text = text - if self.bounds <> _rect.empty: - self.recalctextpos() - self.redraw() - # - def setbounds(self, bounds): - if self.bounds <> _rect.empty: - self.parent.change(self.bounds) - self.bounds = bounds - if self.bounds <> _rect.empty: - self.recalc() - self.parent.change(bounds) - # - # Changing the state bits - # - def enable(self, flag): - if flag <> self.enabled: - self.enabled = flag - if self.bounds <> _rect.empty: - self.flipenable(self.parent.begindrawing()) - # - def hilite(self, flag): - if flag <> self.hilited: - self.hilited = flag - if self.bounds <> _rect.empty: - self.fliphilite(self.parent.begindrawing()) - # - def select(self, flag): - if flag <> self.selected: - self.selected = flag - if self.bounds <> _rect.empty: - self.redraw() - # - # Recalculate the box bounds and text position. - # This can be overridden by buttons that draw different boxes - # or want their text in a different position. - # - def recalc(self): - if self.bounds <> _rect.empty: - self.recalcbounds() - self.recalctextpos() - # - def recalcbounds(self): - self.hilitebounds = _rect.inset(self.bounds, (3, 3)) - self.crossbounds = self.bounds - # - def recalctextpos(self): - (left, top), (right, bottom) = self.bounds - m = self.parent.beginmeasuring() - h = (left + right - m.textwidth(self.text)) / 2 - v = (top + bottom - m.lineheight()) / 2 - self.textpos = h, v - # - # Generic drawing interface. - # Do not override redraw() or draw() methods; override drawit() c.s. - # - def redraw(self): - if self.bounds <> _rect.empty: - self.draw(self.parent.begindrawing(), self.bounds) - # - def draw(self, (d, area)): - area = _rect.intersect(area, self.bounds) - if area = _rect.empty: - return - d.cliprect(area) - d.erase(self.bounds) - self.drawit(d) - d.noclip() - # - # The drawit() method is fairly generic but may be overridden. - # - def drawit(self, d): - self.drawpict(d) - if self.text: - d.text(self.textpos, self.text) - if not self.enabled: - self.flipenable(d) - if self.hilited: - self.fliphilite(d) - # - # Default drawing detail functions. - # Overriding these is normally sufficient to get different - # appearances. - # - def drawpict(self, d): - pass - # - def flipenable(self, d): - _xorcross(d, self.crossbounds) - # - def fliphilite(self, d): - d.invert(self.hilitebounds) + # + # Initialization + # + def init_appearance(self): + self.bounds = _rect.empty + self.enabled = 1 + self.hilited = 0 + self.selected = 0 + self.text = '' + # + # Size enquiry + # + def minsize(self, m): + try: + self.text = self.text + except NameError: + self.text = '' + return m.textwidth(self.text) + 6, m.lineheight() + 6 + # + def getbounds(self): + return self.bounds + # + # Changing the parameters + # + def settext(self, text): + self.text = text + if self.bounds <> _rect.empty: + self.recalctextpos() + self.redraw() + # + def setbounds(self, bounds): + if self.bounds <> _rect.empty: + self.parent.change(self.bounds) + self.bounds = bounds + if self.bounds <> _rect.empty: + self.recalc() + self.parent.change(bounds) + # + # Changing the state bits + # + def enable(self, flag): + if flag <> self.enabled: + self.enabled = flag + if self.bounds <> _rect.empty: + self.flipenable(self.parent.begindrawing()) + # + def hilite(self, flag): + if flag <> self.hilited: + self.hilited = flag + if self.bounds <> _rect.empty: + self.fliphilite(self.parent.begindrawing()) + # + def select(self, flag): + if flag <> self.selected: + self.selected = flag + if self.bounds <> _rect.empty: + self.redraw() + # + # Recalculate the box bounds and text position. + # This can be overridden by buttons that draw different boxes + # or want their text in a different position. + # + def recalc(self): + if self.bounds <> _rect.empty: + self.recalcbounds() + self.recalctextpos() + # + def recalcbounds(self): + self.hilitebounds = _rect.inset(self.bounds, (3, 3)) + self.crossbounds = self.bounds + # + def recalctextpos(self): + (left, top), (right, bottom) = self.bounds + m = self.parent.beginmeasuring() + h = (left + right - m.textwidth(self.text)) / 2 + v = (top + bottom - m.lineheight()) / 2 + self.textpos = h, v + # + # Generic drawing interface. + # Do not override redraw() or draw() methods; override drawit() c.s. + # + def redraw(self): + if self.bounds <> _rect.empty: + self.draw(self.parent.begindrawing(), self.bounds) + # + def draw(self, (d, area)): + area = _rect.intersect(area, self.bounds) + if area = _rect.empty: + return + d.cliprect(area) + d.erase(self.bounds) + self.drawit(d) + d.noclip() + # + # The drawit() method is fairly generic but may be overridden. + # + def drawit(self, d): + self.drawpict(d) + if self.text: + d.text(self.textpos, self.text) + if not self.enabled: + self.flipenable(d) + if self.hilited: + self.fliphilite(d) + # + # Default drawing detail functions. + # Overriding these is normally sufficient to get different + # appearances. + # + def drawpict(self, d): + pass + # + def flipenable(self, d): + _xorcross(d, self.crossbounds) + # + def fliphilite(self, d): + d.invert(self.hilitebounds) # ButtonAppearance displays a centered string in a box. # selected --> bold border # disabled --> crossed out -# hilited --> inverted +# hilited --> inverted # class ButtonAppearance() = LabelAppearance(): - # - def drawpict(self, d): - d.box(_rect.inset(self.bounds, (1, 1))) - if self.selected: - # Make a thicker box - d.box(self.bounds) - d.box(_rect.inset(self.bounds, (2, 2))) - d.box(_rect.inset(self.bounds, (3, 3))) - # + # + def drawpict(self, d): + d.box(_rect.inset(self.bounds, (1, 1))) + if self.selected: + # Make a thicker box + d.box(self.bounds) + d.box(_rect.inset(self.bounds, (2, 2))) + d.box(_rect.inset(self.bounds, (3, 3))) + # # CheckAppearance displays a small square box and a left-justified string. # selected --> a cross appears in the box # disabled --> whole button crossed out -# hilited --> box is inverted +# hilited --> box is inverted # class CheckAppearance() = LabelAppearance(): - # - def minsize(self, m): - width, height = m.textwidth(self.text) + 6, m.lineheight() + 6 - return width + height + m.textwidth(' '), height - # - def drawpict(self, d): - d.box(self.boxbounds) - if self.selected: _xorcross(d, self.boxbounds) - # - def recalcbounds(self): - LabelAppearance.recalcbounds(self) - (left, top), (right, bottom) = self.bounds - self.size = bottom - top - 4 - self.boxbounds = (left+2, top+2), (left+2+self.size, bottom-2) - self.hilitebounds = self.boxbounds - # - def recalctextpos(self): - m = self.parent.beginmeasuring() - (left, top), (right, bottom) = self.boxbounds - h = right + m.textwidth(' ') - v = top + (self.size - m.lineheight()) / 2 - self.textpos = h, v - # + # + def minsize(self, m): + width, height = m.textwidth(self.text) + 6, m.lineheight() + 6 + return width + height + m.textwidth(' '), height + # + def drawpict(self, d): + d.box(self.boxbounds) + if self.selected: _xorcross(d, self.boxbounds) + # + def recalcbounds(self): + LabelAppearance.recalcbounds(self) + (left, top), (right, bottom) = self.bounds + self.size = bottom - top - 4 + self.boxbounds = (left+2, top+2), (left+2+self.size, bottom-2) + self.hilitebounds = self.boxbounds + # + def recalctextpos(self): + m = self.parent.beginmeasuring() + (left, top), (right, bottom) = self.boxbounds + h = right + m.textwidth(' ') + v = top + (self.size - m.lineheight()) / 2 + self.textpos = h, v + # # RadioAppearance displays a round indicator and a left-justified string. # selected --> a dot appears in the indicator # disabled --> whole button crossed out -# hilited --> indicator is inverted +# hilited --> indicator is inverted # class RadioAppearance() = CheckAppearance(): - # - def drawpict(self, d): - (left, top), (right, bottom) = self.boxbounds - radius = self.size / 2 - h, v = left + radius, top + radius - d.circle((h, v), radius) - if self.selected: - some = radius/3 - d.paint((h-some, v-some), (h+some, v+some)) - # + # + def drawpict(self, d): + (left, top), (right, bottom) = self.boxbounds + radius = self.size / 2 + h, v = left + radius, top + radius + d.circle((h, v), radius) + if self.selected: + some = radius/3 + d.paint((h-some, v-some), (h+some, v+some)) + # # NoReactivity ignores mouse events. # class NoReactivity(): - def init_reactivity(self): pass + def init_reactivity(self): pass # BaseReactivity defines hooks and asks for mouse events, # but provides only dummy mouse event handlers. # The trigger methods call the corresponding hooks set by the user. # Hooks (and triggers) mean the following: -# down_hook called on some mouse-down events -# move_hook called on some mouse-move events -# up_hook called on mouse-up events -# on_hook called for buttons with on/off state, when it goes on -# hook called when a button 'fires' or a radiobutton goes on +# down_hook called on some mouse-down events +# move_hook called on some mouse-move events +# up_hook called on mouse-up events +# on_hook called for buttons with on/off state, when it goes on +# hook called when a button 'fires' or a radiobutton goes on # There are usually extra conditions, e.g., hooks are only called # when the button is enabled, or active, or selected (on). # class BaseReactivity(): - # - def init_reactivity(self): - self.down_hook = self.move_hook = self.up_hook = \ - self.on_hook = self.off_hook = \ - self.hook = self.active = 0 - self.parent.need_mouse(self) - # - def mousetest(self, hv): - return _rect.pointinrect(hv, self.bounds) - # - def mouse_down(self, detail): - pass - # - def mouse_move(self, detail): - pass - # - def mouse_up(self, detail): - pass - # - def down_trigger(self): - if self.down_hook: self.down_hook(self) - # - def move_trigger(self): - if self.move_hook: self.move_hook(self) - # - def up_trigger(self): - if self.up_hook: self.up_hook(self) - # - def on_trigger(self): - if self.on_hook: self.on_hook(self) - # - def off_trigger(self): - if self.off_hook: self.off_hook(self) - # - def trigger(self): - if self.hook: self.hook(self) + # + def init_reactivity(self): + self.down_hook = self.move_hook = self.up_hook = \ + self.on_hook = self.off_hook = \ + self.hook = self.active = 0 + self.parent.need_mouse(self) + # + def mousetest(self, hv): + return _rect.pointinrect(hv, self.bounds) + # + def mouse_down(self, detail): + pass + # + def mouse_move(self, detail): + pass + # + def mouse_up(self, detail): + pass + # + def down_trigger(self): + if self.down_hook: self.down_hook(self) + # + def move_trigger(self): + if self.move_hook: self.move_hook(self) + # + def up_trigger(self): + if self.up_hook: self.up_hook(self) + # + def on_trigger(self): + if self.on_hook: self.on_hook(self) + # + def off_trigger(self): + if self.off_hook: self.off_hook(self) + # + def trigger(self): + if self.hook: self.hook(self) # ToggleReactivity acts like a simple pushbutton. # It toggles its hilite state on mouse down events. # class ToggleReactivity() = BaseReactivity(): - # - def mouse_down(self, detail): - if self.enabled and self.mousetest(detail[_HV]): - self.active = 1 - self.hilite(not self.hilited) - self.down_trigger() - # - def mouse_move(self, detail): - if self.active: - self.move_trigger() - # - def mouse_up(self, detail): - if self.active: - self.up_trigger() - self.active = 0 - # - def down_trigger(self): - if self.hilited: - self.on_trigger() - else: - self.off_trigger() - self.trigger() - # + # + def mouse_down(self, detail): + if self.enabled and self.mousetest(detail[_HV]): + self.active = 1 + self.hilite(not self.hilited) + self.down_trigger() + # + def mouse_move(self, detail): + if self.active: + self.move_trigger() + # + def mouse_up(self, detail): + if self.active: + self.up_trigger() + self.active = 0 + # + def down_trigger(self): + if self.hilited: + self.on_trigger() + else: + self.off_trigger() + self.trigger() + # # TriggerReactivity acts like a fancy pushbutton. # It hilites itself while the mouse is down within its bounds. # class TriggerReactivity() = BaseReactivity(): - # - def mouse_down(self, detail): - if self.enabled and self.mousetest(detail[_HV]): - self.active = 1 - self.hilite(1) - self.down_trigger() - # - def mouse_move(self, detail): - if self.active: - self.hilite(self.mousetest(detail[_HV])) - if self.hilited: - self.move_trigger() - # - def mouse_up(self, detail): - if self.active: - self.hilite(self.mousetest(detail[_HV])) - if self.hilited: - self.up_trigger() - self.trigger() - self.active = 0 - self.hilite(0) - # + # + def mouse_down(self, detail): + if self.enabled and self.mousetest(detail[_HV]): + self.active = 1 + self.hilite(1) + self.down_trigger() + # + def mouse_move(self, detail): + if self.active: + self.hilite(self.mousetest(detail[_HV])) + if self.hilited: + self.move_trigger() + # + def mouse_up(self, detail): + if self.active: + self.hilite(self.mousetest(detail[_HV])) + if self.hilited: + self.up_trigger() + self.trigger() + self.active = 0 + self.hilite(0) + # # CheckReactivity handles mouse events like TriggerReactivity, # It overrides the up_trigger method to flip its selected state. # class CheckReactivity() = TriggerReactivity(): - # - def up_trigger(self): - self.select(not self.selected) - if self.selected: - self.on_trigger() - else: - self.off_trigger() - self.trigger() + # + def up_trigger(self): + self.select(not self.selected) + if self.selected: + self.on_trigger() + else: + self.off_trigger() + self.trigger() # RadioReactivity turns itself on and the other buttons in its group # off when its up_trigger method is called. # class RadioReactivity() = TriggerReactivity(): - # - def init_reactivity(self): - TriggerReactivity.init_reactivity(self) - self.group = [] - # - def up_trigger(self): - for b in self.group: - if b <> self: - if b.selected: - b.select(0) - b.off_trigger() - self.select(1) - self.on_trigger() - self.trigger() + # + def init_reactivity(self): + TriggerReactivity.init_reactivity(self) + self.group = [] + # + def up_trigger(self): + for b in self.group: + if b <> self: + if b.selected: + b.select(0) + b.off_trigger() + self.select(1) + self.on_trigger() + self.trigger() # Auxiliary class for 'define' method. # Call the initializers in the right order. # class Define(): - # - def define(self, parent): - self.parent = parent - parent.addchild(self) - self.init_appearance() - self.init_reactivity() - return self - # - def destroy(self): - self.parent = 0 - # - def definetext(self, (parent, text)): - self = self.define(parent) - self.settext(text) - return self + # + def define(self, parent): + self.parent = parent + parent.addchild(self) + self.init_appearance() + self.init_reactivity() + return self + # + def destroy(self): + self.parent = 0 + # + def definetext(self, (parent, text)): + self = self.define(parent) + self.settext(text) + return self # Subroutine to cross out a rectangle. # def _xorcross(d, bounds): - ((left, top), (right, bottom)) = bounds - # This is s bit funny to make it look better - left = left + 2 - right = right - 2 - top = top + 2 - bottom = bottom - 3 - d.xorline(((left, top), (right, bottom))) - d.xorline((left, bottom), (right, top)) + ((left, top), (right, bottom)) = bounds + # This is s bit funny to make it look better + left = left + 2 + right = right - 2 + top = top + 2 + bottom = bottom - 3 + d.xorline(((left, top), (right, bottom))) + d.xorline((left, bottom), (right, top)) # Ready-made button classes. diff --git a/lib/CSplit.py b/lib/CSplit.py index a28b1c8..03559c1 100644 --- a/lib/CSplit.py +++ b/lib/CSplit.py @@ -1,70 +1,70 @@ # A CSplit is a Clock-shaped split: the children are grouped in a circle. # The numbering is a little different from a real clock: the 12 o'clock -# position is called 0, not 12. This is a little easier since Python -# usually counts from zero. (BTW, there needn't be exactly 12 children.) +# position is called 0, not 12. This is a little easier since Python +# usually counts from zero. (BTW, there needn't be exactly 12 children.) from math import pi, sin, cos from Split import Split class CSplit() = Split(): - # - def minsize(self, m): - # Since things look best if the children are spaced evenly - # along the circle (and often all children have the same - # size anyway) we compute the max child size and assume - # this is each child's size. - width, height = 0, 0 - for child in self.children: - wi, he = child.minsize(m) - width = max(width, wi) - height = max(height, he) - # In approximation, the diameter of the circle we need is - # (diameter of box) * (#children) / pi. - # We approximate pi by 3 (so we slightly overestimate - # our minimal size requirements -- not so bad). - # Because the boxes stick out of the circle we add the - # box size to each dimension. - # Because we really deal with ellipses, do everything - # separate in each dimension. - n = len(self.children) - return width + (width*n + 2)/3, height + (height*n + 2)/3 - # - def getbounds(self): - return self.bounds - # - def setbounds(self, bounds): - self.bounds = bounds - # Place the children. This involves some math. - # Compute center positions for children as if they were - # ellipses with a diameter about 1/N times the - # circumference of the big ellipse. - # (There is some rounding involved to make it look - # reasonable for small and large N alike.) - # XXX One day Python will have automatic conversions... - n = len(self.children) - fn = float(n) - if n = 0: return - (left, top), (right, bottom) = bounds - width, height = right-left, bottom-top - child_width, child_height = width*3/(n+4), height*3/(n+4) - half_width, half_height = \ - float(width-child_width)/2.0, \ - float(height-child_height)/2.0 - center_h, center_v = center = (left+right)/2, (top+bottom)/2 - fch, fcv = float(center_h), float(center_v) - alpha = 2.0 * pi / fn - for i in range(n): - child = self.children[i] - fi = float(i) - fh, fv = \ - fch + half_width*sin(fi*alpha), \ - fcv - half_height*cos(fi*alpha) - left, top = \ - int(fh) - child_width/2, \ - int(fv) - child_height/2 - right, bottom = \ - left + child_width, \ - top + child_height - child.setbounds((left, top), (right, bottom)) - # + # + def minsize(self, m): + # Since things look best if the children are spaced evenly + # along the circle (and often all children have the same + # size anyway) we compute the max child size and assume + # this is each child's size. + width, height = 0, 0 + for child in self.children: + wi, he = child.minsize(m) + width = max(width, wi) + height = max(height, he) + # In approximation, the diameter of the circle we need is + # (diameter of box) * (#children) / pi. + # We approximate pi by 3 (so we slightly overestimate + # our minimal size requirements -- not so bad). + # Because the boxes stick out of the circle we add the + # box size to each dimension. + # Because we really deal with ellipses, do everything + # separate in each dimension. + n = len(self.children) + return width + (width*n + 2)/3, height + (height*n + 2)/3 + # + def getbounds(self): + return self.bounds + # + def setbounds(self, bounds): + self.bounds = bounds + # Place the children. This involves some math. + # Compute center positions for children as if they were + # ellipses with a diameter about 1/N times the + # circumference of the big ellipse. + # (There is some rounding involved to make it look + # reasonable for small and large N alike.) + # XXX One day Python will have automatic conversions... + n = len(self.children) + fn = float(n) + if n = 0: return + (left, top), (right, bottom) = bounds + width, height = right-left, bottom-top + child_width, child_height = width*3/(n+4), height*3/(n+4) + half_width, half_height = \ + float(width-child_width)/2.0, \ + float(height-child_height)/2.0 + center_h, center_v = center = (left+right)/2, (top+bottom)/2 + fch, fcv = float(center_h), float(center_v) + alpha = 2.0 * pi / fn + for i in range(n): + child = self.children[i] + fi = float(i) + fh, fv = \ + fch + half_width*sin(fi*alpha), \ + fcv - half_height*cos(fi*alpha) + left, top = \ + int(fh) - child_width/2, \ + int(fv) - child_height/2 + right, bottom = \ + left + child_width, \ + top + child_height + child.setbounds((left, top), (right, bottom)) + # diff --git a/lib/DEVICE.py b/lib/DEVICE.py index 4f2fadc..00eddfc 100644 --- a/lib/DEVICE.py +++ b/lib/DEVICE.py @@ -1,17 +1,17 @@ #/************************************************************************** -# * * -# * Copyright (C) 1984, Silicon Graphics, Inc. * -# * * -# * These coded instructions, statements, and computer programs contain * -# * unpublished proprietary information of Silicon Graphics, Inc., and * -# * are protected by Federal copyright law. They may not be disclosed * -# * to third parties or copied or duplicated in any form, in whole or * -# * in part, without the prior written consent of Silicon Graphics, Inc. * -# * * +# * * +# * Copyright (C) 1984, Silicon Graphics, Inc. * +# * * +# * These coded instructions, statements, and computer programs contain * +# * unpublished proprietary information of Silicon Graphics, Inc., and * +# * are protected by Federal copyright law. They may not be disclosed * +# * to third parties or copied or duplicated in any form, in whole or * +# * in part, without the prior written consent of Silicon Graphics, Inc. * +# * * # **************************************************************************/ #/* file with device definitions (see /usr/include/device.h) */ -NULLDEV = 0 +NULLDEV = 0 BUTOFFSET = 1 VALOFFSET = 256 TIMOFFSET = 515 @@ -22,402 +22,402 @@ BUTCOUNT = 190 VALCOUNT = 27 TIMCOUNT = 4 XKBDCOUNT = 28 -INCOUNT = 8 +INCOUNT = 8 OUTCOUNT = 8 # # # # -BUT0 = 1 -BUT1 = 2 -BUT2 = 3 -BUT3 = 4 -BUT4 = 5 -BUT5 = 6 -BUT6 = 7 -BUT7 = 8 -BUT8 = 9 -BUT9 = 10 -BUT10 = 11 -BUT11 = 12 -BUT12 = 13 -BUT13 = 14 -BUT14 = 15 -BUT15 = 16 -BUT16 = 17 -BUT17 = 18 -BUT18 = 19 -BUT19 = 20 -BUT20 = 21 -BUT21 = 22 -BUT22 = 23 -BUT23 = 24 -BUT24 = 25 -BUT25 = 26 -BUT26 = 27 -BUT27 = 28 -BUT28 = 29 -BUT29 = 30 -BUT30 = 31 -BUT31 = 32 -BUT32 = 33 -BUT33 = 34 -BUT34 = 35 -BUT35 = 36 -BUT36 = 37 -BUT37 = 38 -BUT38 = 39 -BUT39 = 40 -BUT40 = 41 -BUT41 = 42 -BUT42 = 43 -BUT43 = 44 -BUT44 = 45 -BUT45 = 46 -BUT46 = 47 -BUT47 = 48 -BUT48 = 49 -BUT49 = 50 -BUT50 = 51 -BUT51 = 52 -BUT52 = 53 -BUT53 = 54 -BUT54 = 55 -BUT55 = 56 -BUT56 = 57 -BUT57 = 58 -BUT58 = 59 -BUT59 = 60 -BUT60 = 61 -BUT61 = 62 -BUT62 = 63 -BUT63 = 64 -BUT64 = 65 -BUT65 = 66 -BUT66 = 67 -BUT67 = 68 -BUT68 = 69 -BUT69 = 70 -BUT70 = 71 -BUT71 = 72 -BUT72 = 73 -BUT73 = 74 -BUT74 = 75 -BUT75 = 76 -BUT76 = 77 -BUT77 = 78 -BUT78 = 79 -BUT79 = 80 -BUT80 = 81 -BUT81 = 82 -BUT82 = 83 -MAXKBDBUT = 83 -BUT100 = 101 -BUT101 = 102 -BUT102 = 103 -BUT110 = 111 -BUT111 = 112 -BUT112 = 113 -BUT113 = 114 -BUT114 = 115 -BUT115 = 116 -BUT116 = 117 -BUT117 = 118 -BUT118 = 119 -BUT119 = 120 -BUT120 = 121 -BUT121 = 122 -BUT122 = 123 -BUT123 = 124 -BUT124 = 125 -BUT125 = 126 -BUT126 = 127 -BUT127 = 128 -BUT128 = 129 -BUT129 = 130 -BUT130 = 131 -BUT131 = 132 -BUT132 = 133 -BUT133 = 134 -BUT134 = 135 -BUT135 = 136 -BUT136 = 137 -BUT137 = 138 -BUT138 = 139 -BUT139 = 140 -BUT140 = 141 -BUT141 = 142 -BUT142 = 143 -BUT143 = 144 -BUT144 = 145 -BUT145 = 146 -BUT146 = 147 -BUT147 = 148 -BUT148 = 149 -BUT149 = 150 -BUT150 = 151 -BUT151 = 152 -BUT152 = 153 -BUT153 = 154 -BUT154 = 155 -BUT155 = 156 -BUT156 = 157 -BUT157 = 158 -BUT158 = 159 -BUT159 = 160 -BUT160 = 161 -BUT161 = 162 -BUT162 = 163 -BUT163 = 164 -BUT164 = 165 -BUT165 = 166 -BUT166 = 167 -BUT167 = 168 -BUT168 = 169 -BUT181 = 182 -BUT182 = 183 -BUT183 = 184 -BUT184 = 185 -BUT185 = 186 -BUT186 = 187 -BUT187 = 188 -BUT188 = 189 -BUT189 = 190 -MOUSE1 = 101 -MOUSE2 = 102 -MOUSE3 = 103 -LEFTMOUSE = 103 -MIDDLEMOUSE = 102 -RIGHTMOUSE = 101 -LPENBUT = 104 -BPAD0 = 105 -BPAD1 = 106 -BPAD2 = 107 -BPAD3 = 108 -LPENVALID = 109 -SWBASE = 111 -SW0 = 111 -SW1 = 112 -SW2 = 113 -SW3 = 114 -SW4 = 115 -SW5 = 116 -SW6 = 117 -SW7 = 118 -SW8 = 119 -SW9 = 120 -SW10 = 121 -SW11 = 122 -SW12 = 123 -SW13 = 124 -SW14 = 125 -SW15 = 126 -SW16 = 127 -SW17 = 128 -SW18 = 129 -SW19 = 130 -SW20 = 131 -SW21 = 132 -SW22 = 133 -SW23 = 134 -SW24 = 135 -SW25 = 136 -SW26 = 137 -SW27 = 138 -SW28 = 139 -SW29 = 140 -SW30 = 141 -SW31 = 142 -SBBASE = 182 -SBPICK = 182 -SBBUT1 = 183 -SBBUT2 = 184 -SBBUT3 = 185 -SBBUT4 = 186 -SBBUT5 = 187 -SBBUT6 = 188 -SBBUT7 = 189 -SBBUT8 = 190 -AKEY = 11 -BKEY = 36 -CKEY = 28 -DKEY = 18 -EKEY = 17 -FKEY = 19 -GKEY = 26 -HKEY = 27 -IKEY = 40 -JKEY = 34 -KKEY = 35 -LKEY = 42 -MKEY = 44 -NKEY = 37 -OKEY = 41 -PKEY = 48 -QKEY = 10 -RKEY = 24 -SKEY = 12 -TKEY = 25 -UKEY = 33 -VK