Uniformly replaced init() functions by __init__() constructors.

A few simple things seem to work, I haven't tested it thouroughly
though...
This commit is contained in:
Guido van Rossum 1993-12-17 15:11:41 +00:00
parent 96b608cf6d
commit 21a3ff9d5d
27 changed files with 86 additions and 95 deletions

View File

@ -11,7 +11,7 @@ class DisplayVideoIn:
# Initialize an instance. Arguments:
# vw, vh: size of the video window data to be captured.
# position defaults to 0, 0 but can be set later
def init(self, pktmax, vw, vh, type):
def __init__(self, pktmax, vw, vh, type):
self.pktmax = pktmax
self.realwidth, self.realheight = vw, vh
if type <> 'rgb':
@ -40,7 +40,6 @@ class DisplayVideoIn:
self.dataoffset = 0
self.lpos = 0
self.hints = 0
return self
# Change the size of the video being displayed.
@ -72,7 +71,7 @@ class DisplayVideoIn:
# - data is a piece of data
# The dimensions of data are:
# - pixel depth = 1 byte
# - scan line width = self.width (the vw argument to init())
# - scan line width = self.width (the vw argument to __init__())
# - number of scan lines = self.lpp (PKTMAX / vw)
def getnextpacket(self):

View File

@ -119,10 +119,9 @@ def main():
gl.qdevice(DEVICE.WINTHAW)
width, height = gl.getsize()
lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height, vtype)
lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)
lvi = DisplayVideoIn.DisplayVideoIn().init(pktmax, \
width, height, vtype)
lvi = DisplayVideoIn.DisplayVideoIn(pktmax, width, height, vtype)
if xpos or ypos:
lvi.positionvideo(xpos, ypos)

View File

@ -33,7 +33,7 @@ class LiveVideoIn:
# Note that the data has to be cropped unless vw and vh are
# just right for the video board (vw:vh == 4:3 and vh even).
def init(self, pktmax, vw, vh, type):
def __init__(self, pktmax, vw, vh, type):
if not have_video:
raise RuntimeError, 'no video available'
if vw % 4 != 0:
@ -72,13 +72,12 @@ class LiveVideoIn:
## if not self.justright:
## print 'Want:', self.width, 'x', self.height,
## print '; grab:', self.realwidth, 'x', self.realheight
return self
# Change the size of the video being displayed.
def resizevideo(self, vw, vh):
self.close()
self = self.init(self.pktmax, vw, vh, self.type)
self.__init__(self.pktmax, vw, vh, self.type)
# Remove an instance.
# This turns off continuous capture.
@ -103,7 +102,7 @@ class LiveVideoIn:
# - data is a piece of data
# The dimensions of data are:
# - pixel depth = 1 byte
# - scan line width = self.width (the vw argument to init())
# - scan line width = self.width (the vw argument to __init__())
# - number of scan lines = self.lpp (PKTMAX / vw)
def getnextpacket(self):

View File

@ -12,12 +12,12 @@ class LiveVideoOut:
# wid: the window id where the video is to be displayed (centered)
# vw, vh: size of the video image to be displayed
def init(self, wid, vw, vh, type):
def __init__(self, wid, vw, vh, type):
##print 'Init', wid, xywh
##print 'video', vw, vw
self.vw = vw
self.vh = vh
self.disp = Displayer().init()
self.disp = Displayer()
if not type in ('rgb', 'rgb8', 'grey', 'mono', 'grey2', \
'grey4'):
raise 'Incorrent live video output type', type
@ -32,7 +32,6 @@ class LiveVideoOut:
self.disp.initcolormap()
self.reshapewindow()
gl.winset(oldwid)
return self
# Call this in response to every REDRAW event for the window
# or if the window size has changed for other reasons.
@ -111,7 +110,7 @@ class LiveVideoOut:
class LiveVideoOutSlow(LiveVideoOut):
# Reshapewindow - Realloc buffer.
# (is also called by init() indirectly)
# (is also called by __init__() indirectly)
def reshapewindow(self):
LiveVideoOut.reshapewindow(self)

View File

@ -41,9 +41,9 @@ def main():
usage()
[ifile, ofile] = args
print 'open film ', ifile
ifilm = VFile.VinFile().init(ifile)
ifilm = VFile.VinFile(ifile)
print 'open output ', ofile
ofilm = GrabbingVoutFile().init(ofile)
ofilm = GrabbingVoutFile(ofile)
ofilm.setinfo(ifilm.getinfo())

View File

@ -142,13 +142,12 @@ MUTE_AV_OFF = EXP_7 + '\xc7'
DEBUG=0
class VCR:
def init(self):
def __init__(self):
self.ifp, self.ofp = initline(DEVICE)
self.busy_cmd = None
self.async = 0
self.cb = None
self.cb_arg = None
return self
def _check(self):
if self.busy_cmd:

View File

@ -186,7 +186,7 @@ class VideoParams:
# Set all parameters to something decent
# (except width and height are set to zero)
def init(self):
def __init__(self):
# Essential parameters
self.frozen = 0 # if set, can't change parameters
self.format = 'grey' # color system used
@ -203,7 +203,6 @@ class VideoParams:
self.chrompack = 0 # set if separate chrominance data
self.setderived()
self.decompressor = None
return self
# Freeze the parameters (disallow changes)
@ -369,11 +368,11 @@ class Displayer(VideoParams):
# Initialize an instance.
# This does not need a current window
def init(self):
def __init__(self):
if no_gl:
raise RuntimeError, \
'no gl module available, so cannot display'
self = VideoParams.init(self)
VideoParams.__init__(self)
# User-settable parameters
self.magnify = 1.0 # frame magnification factor
self.xorigin = 0 # x frame offset
@ -817,15 +816,18 @@ def writecompressfileheader(fp, cheader, values):
class BasicVinFile(VideoParams):
def init(self, filename):
if filename == '-':
def __init__(self, filename):
if type(filename) != type(''):
fp = filename
filename = '???'
elif filename == '-':
fp = sys.stdin
else:
fp = open(filename, 'r')
return self.initfp(fp, filename)
self.initfp(fp, filename)
def initfp(self, fp, filename):
self = VideoParams.init(self)
VideoParams.__init__(self)
self.fp = fp
self.filename = filename
self.version, values = readfileheader(fp, filename)
@ -857,7 +859,6 @@ class BasicVinFile(VideoParams):
except IOError:
self.startpos = -1
self.canseek = 0
return self
def _readv0frameheader(self, fp):
t, ds, cs = readv0frameheader(fp)
@ -966,9 +967,8 @@ def getfilesize(filename):
class RandomVinFile(BasicVinFile):
def initfp(self, fp, filename):
self = BasicVinFile.initfp(self, fp, filename)
BasicVinFile.initfp(self, fp, filename)
self.index = []
return self
def warmcache(self):
if len(self.index) == 0:
@ -1073,19 +1073,21 @@ class RandomVinFile(BasicVinFile):
class BasicVoutFile(VideoParams):
def init(self, filename):
if filename == '-':
def __init__(self, filename):
if type(filename) != type(''):
fp = filename
filename = '???'
elif filename == '-':
fp = sys.stdout
else:
fp = open(filename, 'w')
return self.initfp(fp, filename)
self.initfp(fp, filename)
def initfp(self, fp, filename):
self = VideoParams.init(self)
VideoParams.__init__(self)
self.fp = fp
self.filename = filename
self.version = 3.1 # In case anyone inquries
return self
def flush(self):
self.fp.flush()
@ -1153,8 +1155,8 @@ class BasicVoutFile(VideoParams):
class VinFile(RandomVinFile, Displayer):
def initfp(self, fp, filename):
self = Displayer.init(self)
return RandomVinFile.initfp(self, fp, filename)
Displayer.__init__(self)
RandomVinFile.initfp(self, fp, filename)
def shownextframe(self):
t, data, cdata = self.getnextframe()
@ -1165,9 +1167,9 @@ class VinFile(RandomVinFile, Displayer):
class VoutFile(BasicVoutFile, Displayer):
def initfp(self, fp, filename):
self = Displayer.init(self)
## self = Grabber.init(self) # XXX not needed
return BasicVoutFile.initfp(self, fp, filename)
Displayer.__init__(self)
## Grabber.__init__(self) # XXX not needed
BasicVoutFile.initfp(self, fp, filename)
# Simple test program (VinFile only)
@ -1176,7 +1178,7 @@ def test():
import time
if sys.argv[1:]: filename = sys.argv[1]
else: filename = 'film.video'
vin = VinFile().init(filename)
vin = VinFile(filename)
vin.printinfo()
gl.foreground()
gl.prefsize(vin.getsize())

View File

@ -10,7 +10,7 @@ from VFile import Error
class VGrabber(VFile.VideoParams):
# XXX The init() method of VideoParams is just fine, for now
# XXX The constructor of VideoParams is just fine, for now
# Grab a frame.
# Return (data, chromdata) just like getnextframe().

View File

@ -43,7 +43,7 @@ watchcursor.defwatch(WATCH)
def main():
## fl.set_graphics_mode(0, 1)
vb = VideoBagOfTricks().init()
vb = VideoBagOfTricks()
while 1:
dummy = fl.do_forms()
[dummy]
@ -82,7 +82,7 @@ class VideoBagOfTricks:
# Init/close stuff
def init(self):
def __init__(self):
self.window = None
formdef = flp.parse_form('VbForm', 'form')
flp.create_full_form(self, formdef)
@ -105,7 +105,6 @@ class VideoBagOfTricks:
self.optfullsizewindow()
self.showform()
fl.set_event_call_back(self.do_event)
return self
def close(self):
self.close_video()
@ -610,7 +609,7 @@ class VideoBagOfTricks:
if not self.vcr:
try:
print 'Connecting to VCR ...'
self.vcr = VCR.VCR().init()
self.vcr = VCR.VCR()
print 'Waiting for VCR to come online ...'
self.vcr.initvcr()
print 'Preparing VCR ...'
@ -804,7 +803,7 @@ class VideoBagOfTricks:
x, y = x/2, y/2
elif self.rgb24_size == 3:
x, y = x/4, y/4
vout = VFile.VoutFile().init(self.vfile)
vout = VFile.VoutFile(self.vfile)
vout.setformat(self.vformat)
if self.vformat == 'compress':
cheader = self.init_compressor(x, y)

View File

@ -149,7 +149,7 @@ def process(infilename, outfilename):
global newwidth, newheight, newpf
try:
vin = VFile.BasicVinFile().init(infilename)
vin = VFile.BasicVinFile(infilename)
except IOError, msg:
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
return 1
@ -161,7 +161,7 @@ def process(infilename, outfilename):
return 1
try:
vout = VFile.BasicVoutFile().init(outfilename)
vout = VFile.BasicVoutFile(outfilename)
except IOError, msg:
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -9,7 +9,7 @@ VERSION_STRING='#!VcrIndex 1.1\n'
PREV_VERSION_STRING='#!VcrIndex 1.0\n'
class VcrIndex:
def init(self, name):
def __init__(self, name):
self.curmovie = None
self.curscene = None
self.modified = 0
@ -18,12 +18,12 @@ class VcrIndex:
self.editable = []
if not name:
self.movies = {}
return self
return
try:
fp = open(name, 'r')
except IOError:
self.movies = {}
return self
return
header = fp.readline()
if header == PREV_VERSION_STRING:
print 'Converting old-format database...'
@ -41,14 +41,13 @@ class VcrIndex:
self.movies[m] = newd
print 'Done.'
return self
return
if header <> VERSION_STRING:
print 'VcrIndex: incorrect version string:', header
self.movies = {}
return self
return
data = fp.read(100000)
self.movies = eval(data)
return self
#
# Save database to given file (or same file as read from if no
# filename given).

View File

@ -32,7 +32,7 @@ def main():
for o, a in opts:
if o == '-q':
qsize = string.atoi(a)
ed = Editor().init(qsize)
ed = Editor(qsize)
if args[0:]:
ed.open_input(args[0])
if args[1:]:
@ -43,7 +43,7 @@ def main():
class Editor:
def init(self, qsize):
def __init__(self, qsize):
self.qsize = qsize
self.vin = None
self.vout = None
@ -53,7 +53,6 @@ class Editor:
flp.create_full_form(self, formdef)
self.form.show_form(FL.PLACE_SIZE, FL.TRUE, 'Vedit')
fl.set_event_call_back(self.do_event)
return self
def do_event(self, dev, val):
if dev == DEVICE.REDRAW:
@ -215,7 +214,7 @@ class Editor:
basename = os.path.split(filename)[1]
title = 'in: ' + basename
try:
vin = Viewer.InputViewer().init(filename, title)
vin = Viewer.InputViewer(filename, title)
except:
self.err('Can\'t open input file', filename)
return
@ -244,7 +243,7 @@ class Editor:
basename = os.path.split(filename)[1]
title = 'out: ' + basename
try:
vout = Viewer.OutputViewer().init(filename, \
vout = Viewer.OutputViewer(filename, \
title, self.qsize)
except:
self.err('Can\'t open output file', filename)

View File

@ -39,7 +39,7 @@ def main():
def process(infilename, outfilename):
try:
vin = VFile.BasicVinFile().init(infilename)
vin = VFile.BasicVinFile(infilename)
except IOError, msg:
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
return 1
@ -51,7 +51,7 @@ def process(infilename, outfilename):
return 1
try:
vout = VFile.BasicVoutFile().init(outfilename)
vout = VFile.BasicVoutFile(outfilename)
except IOError, msg:
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -5,9 +5,9 @@ import os
class InputViewer:
def init(self, filename, title, *args):
def __init__(self, filename, title, *args):
try:
self.vin = VFile.VinFile().init(filename)
self.vin = VFile.VinFile(filename)
except (EOFError, VFile.Error):
raise IOError, 'bad video input file'
self.vin.warmcache()
@ -20,7 +20,6 @@ class InputViewer:
gl.prefsize(self.vin.width, self.vin.height)
self.wid = -1
self.reset()
return self
def close(self):
self.vin.close()
@ -99,9 +98,9 @@ class InputViewer:
class OutputViewer:
def init(self, filename, title, qsize):
def __init__(self, filename, title, qsize):
try:
self.vout = VFile.VoutFile().init(filename)
self.vout = VFile.VoutFile(filename)
except (EOFError, VFile.Error):
raise IOError, 'bad video output file'
if not title:
@ -112,7 +111,6 @@ class OutputViewer:
gl.foreground()
self.wid = -1
self.reset()
return self
def close(self):
while self.queue:
@ -124,7 +122,7 @@ class OutputViewer:
def rewind(self):
info = self.vout.getinfo()
self.vout.close()
self.vout = VFile.VoutFile().init(self.filename)
self.vout = VFile.VoutFile(self.filename)
self.vout.setinfo(info)
self.reset()
@ -228,8 +226,8 @@ class OutputViewer:
def test():
import sys
a = InputViewer().init(sys.argv[1], '')
b = OutputViewer().init(sys.argv[2], '')
a = InputViewer(sys.argv[1], '')
b = OutputViewer(sys.argv[2], '')
b.setinfo(a.getinfo())
while 1:

View File

@ -68,7 +68,7 @@ def main():
def process(filename):
try:
vin = VFile.RandomVinFile().init(filename)
vin = VFile.RandomVinFile(filename)
except IOError, msg:
sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -39,7 +39,7 @@ def main():
def process(infilename, outfilename):
try:
vin = VFile.BasicVinFile().init(infilename)
vin = VFile.BasicVinFile(infilename)
except IOError, msg:
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
return 1
@ -51,7 +51,7 @@ def process(infilename, outfilename):
return 1
try:
vout = VFile.BasicVoutFile().init(outfilename)
vout = VFile.BasicVoutFile(outfilename)
except IOError, msg:
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -144,7 +144,7 @@ def main():
def process(filename):
try:
vin = VFile.VinFile().init(filename)
vin = VFile.VinFile(filename)
except IOError, msg:
sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
return 1
@ -233,7 +233,7 @@ def playonce(vin):
MAXSIZE = 20 # Don't read ahead too much
import thread
import Queue
queue = Queue.Queue().init(MAXSIZE)
queue = Queue.Queue(MAXSIZE)
stop = []
thread.start_new_thread(read_ahead, (vin, queue, stop))
# Get the read-ahead thread going

View File

@ -253,7 +253,7 @@ def record(v, info, filename, audiofilename, mono, grey, greybits, \
# XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
tpf = 1000.0 / fps # Time per field in msec
if filename:
vout = VFile.VoutFile().init(filename)
vout = VFile.VoutFile(filename)
if mono:
format = 'mono'
elif grey and greybits == 8:
@ -273,7 +273,7 @@ def record(v, info, filename, audiofilename, mono, grey, greybits, \
print 'done.'
MAXSIZE = 20 # XXX should be a user option
import Queue
queue = Queue.Queue().init(MAXSIZE)
queue = Queue.Queue(MAXSIZE)
done = thread.allocate_lock()
done.acquire_lock()
convertor = None
@ -376,8 +376,8 @@ def saveframes(vout, queue, done, mono, monotreshold, convertor):
AQSIZE = 8000 # XXX should be a user option
def initaudio(filename, stop, done):
import thread, aiff
afile = aiff.Aiff().init(filename, 'w')
import thread, aifc
afile = aifc.open(filename, 'w')
afile.nchannels = AL.MONO
afile.sampwidth = AL.SAMPLE_8
params = [AL.INPUT_RATE, 0]

View File

@ -309,7 +309,7 @@ def record(v, info, filename, audiofilename, \
# Construct header and write it
#
try:
vout = VFile.VoutFile().init(filename)
vout = VFile.VoutFile(filename)
except IOError, msg:
print filename, ':', msg
sys.exit(1)
@ -389,8 +389,8 @@ def record(v, info, filename, audiofilename, \
AQSIZE = 8*8000 # XXX should be a user option
def initaudio(filename, stop, start, done):
import thread, aiff
afile = aiff.Aiff().init(filename, 'w')
import thread, aifc
afile = aifc.open(filename, 'w')
afile.nchannels = AL.MONO
afile.sampwidth = AL.SAMPLE_8
params = [AL.INPUT_RATE, 0]

View File

@ -68,7 +68,7 @@ def main():
gl.qdevice(DEVICE.WINSHUT)
gl.qdevice(DEVICE.WINQUIT)
lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height, vtype)
lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)
ifdlist = [gl.qgetfd(), s.fileno()]
ofdlist = []

View File

@ -96,9 +96,9 @@ def main():
gl.qdevice(DEVICE.WINTHAW)
width, height = gl.getsize()
lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height, vtype)
lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)
lvi = LiveVideoIn.LiveVideoIn().init(pktmax, width, height, vtype)
lvi = LiveVideoIn.LiveVideoIn(pktmax, width, height, vtype)
s = socket(AF_INET, SOCK_DGRAM)
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)

View File

@ -65,7 +65,7 @@ def main():
def process(infilename, outfilename):
try:
vin = VFile.BasicVinFile().init(infilename)
vin = VFile.BasicVinFile(infilename)
except IOError, msg:
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
return 1
@ -77,7 +77,7 @@ def process(infilename, outfilename):
return 1
try:
vout = VFile.BasicVoutFile().init(outfilename)
vout = VFile.BasicVoutFile(outfilename)
except IOError, msg:
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -39,7 +39,7 @@ def main():
def process(infilename, outfilename):
try:
vin = VFile.BasicVinFile().init(infilename)
vin = VFile.BasicVinFile(infilename)
except IOError, msg:
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
return 1
@ -51,7 +51,7 @@ def process(infilename, outfilename):
return 1
try:
vout = VFile.BasicVoutFile().init(outfilename)
vout = VFile.BasicVoutFile(outfilename)
except IOError, msg:
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
return 1

View File

@ -55,7 +55,7 @@ def main():
videofile = videofile + '.video'
print 'Opening video input file..'
vin = VFile.VinFile().init(videofile)
vin = VFile.VinFile(videofile)
print 'Opening audio input file..'
ain = aifc.open(audiofile, 'r')

View File

@ -126,14 +126,13 @@ def enumerate_converters(fcs):
def instantiate_converter(args):
list = args[2]
cl = RtConverters().init(list)
cl = RtConverters(list)
args.append(cl.convert)
return args
class RtConverters:
def init(self, list):
def __init__(self, list):
self.list = list
return self
def convert(self, img, w, h):
for cv in self.list:

View File

@ -48,7 +48,7 @@ def main():
format = oformat
cfunc = imgconv.getconverter(oformat, format)
vout = VFile.VoutFile().init(outfile)
vout = VFile.VoutFile(outfile)
vout.format = format
vout.width = nxsize
vout.height = ysize

View File

@ -74,7 +74,7 @@ def main():
def process(filename):
try:
vin = VFile.VinFile().init(filename)
vin = VFile.VinFile(filename)
except IOError, msg:
sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
return 1