Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21a3ff9

Browse files
committed
Uniformly replaced init() functions by __init__() constructors.
A few simple things seem to work, I haven't tested it thouroughly though...
1 parent 96b608c commit 21a3ff9

27 files changed

Lines changed: 86 additions & 95 deletions

Demo/sgi/video/DisplayVideoIn.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class DisplayVideoIn:
1111
# Initialize an instance. Arguments:
1212
# vw, vh: size of the video window data to be captured.
1313
# position defaults to 0, 0 but can be set later
14-
def init(self, pktmax, vw, vh, type):
14+
def __init__(self, pktmax, vw, vh, type):
1515
self.pktmax = pktmax
1616
self.realwidth, self.realheight = vw, vh
1717
if type <> 'rgb':
@@ -40,7 +40,6 @@ def init(self, pktmax, vw, vh, type):
4040
self.dataoffset = 0
4141
self.lpos = 0
4242
self.hints = 0
43-
return self
4443

4544
# Change the size of the video being displayed.
4645

@@ -72,7 +71,7 @@ def linewidth(self):
7271
# - data is a piece of data
7372
# The dimensions of data are:
7473
# - pixel depth = 1 byte
75-
# - scan line width = self.width (the vw argument to init())
74+
# - scan line width = self.width (the vw argument to __init__())
7675
# - number of scan lines = self.lpp (PKTMAX / vw)
7776

7877
def getnextpacket(self):

Demo/sgi/video/Dsend.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ def main():
119119
gl.qdevice(DEVICE.WINTHAW)
120120
width, height = gl.getsize()
121121

122-
lvo = LiveVideoOut.LiveVideoOut().init(wid, width, height, vtype)
122+
lvo = LiveVideoOut.LiveVideoOut(wid, width, height, vtype)
123123

124-
lvi = DisplayVideoIn.DisplayVideoIn().init(pktmax, \
125-
width, height, vtype)
124+
lvi = DisplayVideoIn.DisplayVideoIn(pktmax, width, height, vtype)
126125

127126
if xpos or ypos:
128127
lvi.positionvideo(xpos, ypos)

Demo/sgi/video/LiveVideoIn.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LiveVideoIn:
3333
# Note that the data has to be cropped unless vw and vh are
3434
# just right for the video board (vw:vh == 4:3 and vh even).
3535

36-
def init(self, pktmax, vw, vh, type):
36+
def __init__(self, pktmax, vw, vh, type):
3737
if not have_video:
3838
raise RuntimeError, 'no video available'
3939
if vw % 4 != 0:
@@ -72,13 +72,12 @@ def init(self, pktmax, vw, vh, type):
7272
## if not self.justright:
7373
## print 'Want:', self.width, 'x', self.height,
7474
## print '; grab:', self.realwidth, 'x', self.realheight
75-
return self
7675

7776
# Change the size of the video being displayed.
7877

7978
def resizevideo(self, vw, vh):
8079
self.close()
81-
self = self.init(self.pktmax, vw, vh, self.type)
80+
self.__init__(self.pktmax, vw, vh, self.type)
8281

8382
# Remove an instance.
8483
# This turns off continuous capture.
@@ -103,7 +102,7 @@ def linewidth(self):
103102
# - data is a piece of data
104103
# The dimensions of data are:
105104
# - pixel depth = 1 byte
106-
# - scan line width = self.width (the vw argument to init())
105+
# - scan line width = self.width (the vw argument to __init__())
107106
# - number of scan lines = self.lpp (PKTMAX / vw)
108107

109108
def getnextpacket(self):

Demo/sgi/video/LiveVideoOut.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class LiveVideoOut:
1212
# wid: the window id where the video is to be displayed (centered)
1313
# vw, vh: size of the video image to be displayed
1414

15-
def init(self, wid, vw, vh, type):
15+
def __init__(self, wid, vw, vh, type):
1616
##print 'Init', wid, xywh
1717
##print 'video', vw, vw
1818
self.vw = vw
1919
self.vh = vh
20-
self.disp = Displayer().init()
20+
self.disp = Displayer()
2121
if not type in ('rgb', 'rgb8', 'grey', 'mono', 'grey2', \
2222
'grey4'):
2323
raise 'Incorrent live video output type', type
@@ -32,7 +32,6 @@ def init(self, wid, vw, vh, type):
3232
self.disp.initcolormap()
3333
self.reshapewindow()
3434
gl.winset(oldwid)
35-
return self
3635

3736
# Call this in response to every REDRAW event for the window
3837
# or if the window size has changed for other reasons.
@@ -111,7 +110,7 @@ def setmirror(self, mirrored):
111110
class LiveVideoOutSlow(LiveVideoOut):
112111

113112
# Reshapewindow - Realloc buffer.
114-
# (is also called by init() indirectly)
113+
# (is also called by __init__() indirectly)
115114

116115
def reshapewindow(self):
117116
LiveVideoOut.reshapewindow(self)

Demo/sgi/video/OldVcopy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def main():
4141
usage()
4242
[ifile, ofile] = args
4343
print 'open film ', ifile
44-
ifilm = VFile.VinFile().init(ifile)
44+
ifilm = VFile.VinFile(ifile)
4545
print 'open output ', ofile
46-
ofilm = GrabbingVoutFile().init(ofile)
46+
ofilm = GrabbingVoutFile(ofile)
4747

4848
ofilm.setinfo(ifilm.getinfo())
4949

Demo/sgi/video/VCR.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,12 @@ def initline(name):
142142
DEBUG=0
143143

144144
class VCR:
145-
def init(self):
145+
def __init__(self):
146146
self.ifp, self.ofp = initline(DEVICE)
147147
self.busy_cmd = None
148148
self.async = 0
149149
self.cb = None
150150
self.cb_arg = None
151-
return self
152151

153152
def _check(self):
154153
if self.busy_cmd:

Demo/sgi/video/VFile.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class VideoParams:
186186
# Set all parameters to something decent
187187
# (except width and height are set to zero)
188188

189-
def init(self):
189+
def __init__(self):
190190
# Essential parameters
191191
self.frozen = 0 # if set, can't change parameters
192192
self.format = 'grey' # color system used
@@ -203,7 +203,6 @@ def init(self):
203203
self.chrompack = 0 # set if separate chrominance data
204204
self.setderived()
205205
self.decompressor = None
206-
return self
207206

208207
# Freeze the parameters (disallow changes)
209208

@@ -369,11 +368,11 @@ class Displayer(VideoParams):
369368
# Initialize an instance.
370369
# This does not need a current window
371370

372-
def init(self):
371+
def __init__(self):
373372
if no_gl:
374373
raise RuntimeError, \
375374
'no gl module available, so cannot display'
376-
self = VideoParams.init(self)
375+
VideoParams.__init__(self)
377376
# User-settable parameters
378377
self.magnify = 1.0 # frame magnification factor
379378
self.xorigin = 0 # x frame offset
@@ -817,15 +816,18 @@ def writecompressfileheader(fp, cheader, values):
817816

818817
class BasicVinFile(VideoParams):
819818

820-
def init(self, filename):
821-
if filename == '-':
819+
def __init__(self, filename):
820+
if type(filename) != type(''):
821+
fp = filename
822+
filename = '???'
823+
elif filename == '-':
822824
fp = sys.stdin
823825
else:
824826
fp = open(filename, 'r')
825-
return self.initfp(fp, filename)
827+
self.initfp(fp, filename)
826828

827829
def initfp(self, fp, filename):
828-
self = VideoParams.init(self)
830+
VideoParams.__init__(self)
829831
self.fp = fp
830832
self.filename = filename
831833
self.version, values = readfileheader(fp, filename)
@@ -857,7 +859,6 @@ def initfp(self, fp, filename):
857859
except IOError:
858860
self.startpos = -1
859861
self.canseek = 0
860-
return self
861862

862863
def _readv0frameheader(self, fp):
863864
t, ds, cs = readv0frameheader(fp)
@@ -966,9 +967,8 @@ def getfilesize(filename):
966967
class RandomVinFile(BasicVinFile):
967968

968969
def initfp(self, fp, filename):
969-
self = BasicVinFile.initfp(self, fp, filename)
970+
BasicVinFile.initfp(self, fp, filename)
970971
self.index = []
971-
return self
972972

973973
def warmcache(self):
974974
if len(self.index) == 0:
@@ -1073,19 +1073,21 @@ def _getindexframeheader(self, i):
10731073

10741074
class BasicVoutFile(VideoParams):
10751075

1076-
def init(self, filename):
1077-
if filename == '-':
1076+
def __init__(self, filename):
1077+
if type(filename) != type(''):
1078+
fp = filename
1079+
filename = '???'
1080+
elif filename == '-':
10781081
fp = sys.stdout
10791082
else:
10801083
fp = open(filename, 'w')
1081-
return self.initfp(fp, filename)
1084+
self.initfp(fp, filename)
10821085

10831086
def initfp(self, fp, filename):
1084-
self = VideoParams.init(self)
1087+
VideoParams.__init__(self)
10851088
self.fp = fp
10861089
self.filename = filename
10871090
self.version = 3.1 # In case anyone inquries
1088-
return self
10891091

10901092
def flush(self):
10911093
self.fp.flush()
@@ -1153,8 +1155,8 @@ def writeframedata(self, data, cdata):
11531155
class VinFile(RandomVinFile, Displayer):
11541156

11551157
def initfp(self, fp, filename):
1156-
self = Displayer.init(self)
1157-
return RandomVinFile.initfp(self, fp, filename)
1158+
Displayer.__init__(self)
1159+
RandomVinFile.initfp(self, fp, filename)
11581160

11591161
def shownextframe(self):
11601162
t, data, cdata = self.getnextframe()
@@ -1165,9 +1167,9 @@ def shownextframe(self):
11651167
class VoutFile(BasicVoutFile, Displayer):
11661168

11671169
def initfp(self, fp, filename):
1168-
self = Displayer.init(self)
1169-
## self = Grabber.init(self) # XXX not needed
1170-
return BasicVoutFile.initfp(self, fp, filename)
1170+
Displayer.__init__(self)
1171+
## Grabber.__init__(self) # XXX not needed
1172+
BasicVoutFile.initfp(self, fp, filename)
11711173

11721174

11731175
# Simple test program (VinFile only)
@@ -1176,7 +1178,7 @@ def test():
11761178
import time
11771179
if sys.argv[1:]: filename = sys.argv[1]
11781180
else: filename = 'film.video'
1179-
vin = VinFile().init(filename)
1181+
vin = VinFile(filename)
11801182
vin.printinfo()
11811183
gl.foreground()
11821184
gl.prefsize(vin.getsize())

Demo/sgi/video/VGrabber.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class VGrabber(VFile.VideoParams):
1212

13-
# XXX The init() method of VideoParams is just fine, for now
13+
# XXX The constructor of VideoParams is just fine, for now
1414

1515
# Grab a frame.
1616
# Return (data, chromdata) just like getnextframe().

Demo/sgi/video/Vb.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
def main():
4545
## fl.set_graphics_mode(0, 1)
46-
vb = VideoBagOfTricks().init()
46+
vb = VideoBagOfTricks()
4747
while 1:
4848
dummy = fl.do_forms()
4949
[dummy]
@@ -82,7 +82,7 @@ class VideoBagOfTricks:
8282

8383
# Init/close stuff
8484

85-
def init(self):
85+
def __init__(self):
8686
self.window = None
8787
formdef = flp.parse_form('VbForm', 'form')
8888
flp.create_full_form(self, formdef)
@@ -105,7 +105,6 @@ def init(self):
105105
self.optfullsizewindow()
106106
self.showform()
107107
fl.set_event_call_back(self.do_event)
108-
return self
109108

110109
def close(self):
111110
self.close_video()
@@ -610,7 +609,7 @@ def vcr_capture(self):
610609
if not self.vcr:
611610
try:
612611
print 'Connecting to VCR ...'
613-
self.vcr = VCR.VCR().init()
612+
self.vcr = VCR.VCR()
614613
print 'Waiting for VCR to come online ...'
615614
self.vcr.initvcr()
616615
print 'Preparing VCR ...'
@@ -804,7 +803,7 @@ def open_video(self):
804803
x, y = x/2, y/2
805804
elif self.rgb24_size == 3:
806805
x, y = x/4, y/4
807-
vout = VFile.VoutFile().init(self.vfile)
806+
vout = VFile.VoutFile(self.vfile)
808807
vout.setformat(self.vformat)
809808
if self.vformat == 'compress':
810809
cheader = self.init_compressor(x, y)

Demo/sgi/video/Vcopy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def process(infilename, outfilename):
149149
global newwidth, newheight, newpf
150150

151151
try:
152-
vin = VFile.BasicVinFile().init(infilename)
152+
vin = VFile.BasicVinFile(infilename)
153153
except IOError, msg:
154154
sys.stderr.write(infilename + ': I/O error: ' + `msg` + '\n')
155155
return 1
@@ -161,7 +161,7 @@ def process(infilename, outfilename):
161161
return 1
162162

163163
try:
164-
vout = VFile.BasicVoutFile().init(outfilename)
164+
vout = VFile.BasicVoutFile(outfilename)
165165
except IOError, msg:
166166
sys.stderr.write(outfilename + ': I/O error: ' + `msg` + '\n')
167167
return 1

0 commit comments

Comments
 (0)