Commit 9b86e1f5 authored by Guido van Rossum's avatar Guido van Rossum

VFile.py: fix bogus getrandomframe().

Vedit.py, VeditForm.fd: added scroll bar, Trunc, layout rearrangement.
Viewer.py: added random access, qinfo() function.
parent 4e2a4278
...@@ -978,8 +978,8 @@ class RandomVinFile(BasicVinFile): ...@@ -978,8 +978,8 @@ class RandomVinFile(BasicVinFile):
def getrandomframe(self, i): def getrandomframe(self, i):
t, ds, cs = self.getrandomframeheader(i) t, ds, cs = self.getrandomframeheader(i)
data, cdata = self.getnextframedata() data, cdata = self.getnextframedata(ds, cs)
return t, ds, cs return t, data, cdata
def getrandomframeheader(self, i): def getrandomframeheader(self, i):
if i < 0: raise ValueError, 'negative frame index' if i < 0: raise ValueError, 'negative frame index'
......
...@@ -19,6 +19,11 @@ import flp ...@@ -19,6 +19,11 @@ import flp
import Viewer import Viewer
import getopt import getopt
import string import string
import watchcursor
ARROW = 0
WATCH = 1
watchcursor.defwatch(WATCH)
def main(): def main():
...@@ -57,6 +62,14 @@ class Editor: ...@@ -57,6 +62,14 @@ class Editor:
if self.vout: if self.vout:
self.vout.redraw(val) self.vout.redraw(val)
def busy(self):
gl.winset(self.form.window)
gl.setcursor(WATCH, 0, 0)
def ready(self):
gl.winset(self.form.window)
gl.setcursor(ARROW, 0, 0)
def iocheck(self): def iocheck(self):
self.msg('') self.msg('')
...@@ -98,7 +111,18 @@ class Editor: ...@@ -98,7 +111,18 @@ class Editor:
def cb_in_back(self, *args): def cb_in_back(self, *args):
if not self.icheck(): return if not self.icheck(): return
if not self.vin.backup(): self.err('Input buffer exhausted') if not self.vin.backup(): self.err('Begin of input file')
self.ishow()
def cb_in_slider(self, *args):
if not self.icheck(): return
left, pos, right = self.vin.qinfo()
i = int(self.in_slider.get_slider_value())
i = max(i, left)
i = min(i, right)
if i == pos: return
if not self.vin.seek(i):
self.err('Input seek failed')
self.ishow() self.ishow()
def cb_in_rewind(self, *args): def cb_in_rewind(self, *args):
...@@ -128,7 +152,7 @@ class Editor: ...@@ -128,7 +152,7 @@ class Editor:
return return
self.oshow() self.oshow()
if not self.vin.backup(): if not self.vin.backup():
self.err('Input buffer exhausted') self.err('Begin of input file')
return return
self.ishow() self.ishow()
...@@ -154,6 +178,23 @@ class Editor: ...@@ -154,6 +178,23 @@ class Editor:
if not self.vout.backup(): self.err('Output buffer exhausted') if not self.vout.backup(): self.err('Output buffer exhausted')
self.oshow() self.oshow()
def cb_out_slider(self, *args):
if not self.ocheck(): return
i = int(self.out_slider.get_slider_value())
left, pos, right = self.vout.qinfo()
i = int(self.out_slider.get_slider_value())
i = max(i, left)
i = min(i, right)
if i == pos: return
if not self.vout.seek(i):
self.err('Output seek failed')
self.oshow()
def cb_out_trunc(self, *arcs):
if not self.ocheck(): return
self.vout.trunc()
self.oshow()
def cb_out_rewind(self, *args): def cb_out_rewind(self, *args):
if not self.ocheck(): return if not self.ocheck(): return
self.vout.rewind() self.vout.rewind()
...@@ -171,8 +212,7 @@ class Editor: ...@@ -171,8 +212,7 @@ class Editor:
basename = os.path.split(filename)[1] basename = os.path.split(filename)[1]
title = 'in: ' + basename title = 'in: ' + basename
try: try:
vin = Viewer.InputViewer().init(filename, \ vin = Viewer.InputViewer().init(filename, title)
title, self.qsize)
except: except:
self.err('Can\'t open input file', filename) self.err('Can\'t open input file', filename)
return return
...@@ -183,8 +223,10 @@ class Editor: ...@@ -183,8 +223,10 @@ class Editor:
def close_input(self): def close_input(self):
if self.vin: if self.vin:
self.busy()
self.msg('Closing input file...') self.msg('Closing input file...')
self.vin.close() self.vin.close()
self.ready()
self.msg('') self.msg('')
self.vin = None self.vin = None
self.in_file.label = '(none)' self.in_file.label = '(none)'
...@@ -213,8 +255,10 @@ class Editor: ...@@ -213,8 +255,10 @@ class Editor:
def close_output(self): def close_output(self):
if self.vout: if self.vout:
self.busy()
self.msg('Closing output file...') self.msg('Closing output file...')
self.vout.close() self.vout.close()
self.ready()
self.msg('') self.msg('')
self.vout = None self.vout = None
self.out_file.label = '(none)' self.out_file.label = '(none)'
...@@ -238,13 +282,15 @@ class Editor: ...@@ -238,13 +282,15 @@ class Editor:
if v == None: if v == None:
left = right = pos = 0 left = right = pos = 0
else: else:
left, right = v.qsizes() left, pos, right = v.qinfo()
pos = v.tell()
left = pos - left
right = pos + right
getattr(self, io + '_info1').label = `left` getattr(self, io + '_info1').label = `left`
getattr(self, io + '_info2').label = `pos` getattr(self, io + '_info2').label = `pos`
getattr(self, io + '_info3').label = `right` getattr(self, io + '_info3').label = `right`
sl = getattr(self, io + '_slider')
sl.freeze_object()
sl.set_slider_bounds(left, right)
sl.set_slider_value(pos)
sl.unfreeze_object()
try: try:
......
...@@ -7,14 +7,14 @@ Number of forms: 1 ...@@ -7,14 +7,14 @@ Number of forms: 1
=============== FORM =============== =============== FORM ===============
Name: form Name: form
Width: 480.000000 Width: 510.000000
Height: 290.000000 Height: 350.000000
Number of Objects: 23 Number of Objects: 28
-------------------- --------------------
class: 1 class: 1
type: 1 type: 1
box: 0.000000 0.000000 480.000000 290.000000 box: 0.000000 0.000000 510.000000 350.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -26,10 +26,55 @@ name: ...@@ -26,10 +26,55 @@ name:
callback: callback:
argument: argument:
--------------------
class: 1
type: 6
box: 10.000000 130.000000 240.000000 209.999985
boxtype: 6
colors: 47 47
alignment: 4
style: 0
size: 11.000000
lcol: 0
label:
name:
callback:
argument:
--------------------
class: 1
type: 6
box: 260.000000 130.000000 240.000000 209.999985
boxtype: 6
colors: 47 47
alignment: 4
style: 0
size: 11.000000
lcol: 0
label:
name:
callback:
argument:
--------------------
class: 2
type: 0
box: 10.000000 10.000000 430.000000 30.000000
boxtype: 6
colors: 47 47
alignment: 4
style: 0
size: 11.000000
lcol: 0
label: CMIF Video Editor, by Guido van Rossum
name: msg_area
callback:
argument:
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 180.000000 70.000000 120.000000 40.000000 box: 200.000000 90.000000 120.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -44,7 +89,7 @@ argument: 0 ...@@ -44,7 +89,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 90.000000 50.000000 60.000000 60.000000 box: 210.000000 220.000000 30.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -59,14 +104,14 @@ argument: 0 ...@@ -59,14 +104,14 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 10.000000 10.000000 140.000000 30.000000 box: 20.000000 140.000000 220.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
style: 0 style: 0
size: 11.000000 size: 11.000000
lcol: 0 lcol: 0
label: Rewind input label: Rewind
name: name:
callback: cb_in_rewind callback: cb_in_rewind
argument: 0 argument: 0
...@@ -74,14 +119,14 @@ argument: 0 ...@@ -74,14 +119,14 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 330.000000 10.000000 140.000000 30.000000 box: 270.000000 140.000000 100.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
style: 0 style: 0
size: 11.000000 size: 11.000000
lcol: 0 lcol: 0
label: Clear output label: Reset
name: name:
callback: cb_out_rewind callback: cb_out_rewind
argument: 0 argument: 0
...@@ -89,14 +134,14 @@ argument: 0 ...@@ -89,14 +134,14 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 10.000000 210.000000 80.000000 30.000000 box: 20.000000 260.000000 160.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
style: 0 style: 0
size: 11.000000 size: 11.000000
lcol: 0 lcol: 0
label: Input file... label: New input file...
name: name:
callback: cb_in_new callback: cb_in_new
argument: 0 argument: 0
...@@ -104,14 +149,14 @@ argument: 0 ...@@ -104,14 +149,14 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 330.000000 210.000000 80.000000 30.000000 box: 330.000000 260.000000 160.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
style: 0 style: 0
size: 11.000000 size: 11.000000
lcol: 0 lcol: 0
label: Output file... label: New output file...
name: name:
callback: cb_out_new callback: cb_out_new
argument: 0 argument: 0
...@@ -119,7 +164,7 @@ argument: 0 ...@@ -119,7 +164,7 @@ argument: 0
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 10.000000 170.000000 140.000000 30.000000 box: 20.000000 300.000000 220.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -134,7 +179,7 @@ argument: ...@@ -134,7 +179,7 @@ argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 330.000000 170.000000 140.000000 30.000000 box: 270.000000 300.000000 220.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -146,25 +191,10 @@ name: out_file ...@@ -146,25 +191,10 @@ name: out_file
callback: callback:
argument: argument:
--------------------
class: 2
type: 0
box: 10.000000 130.000000 30.000000 30.000000
boxtype: 6
colors: 47 47
alignment: 4
style: 0
size: 8.000000
lcol: 0
label:
name: in_info1
callback:
argument:
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 170.000000 210.000000 140.000000 30.000000 box: 450.000000 10.000000 50.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -179,7 +209,7 @@ argument: 0 ...@@ -179,7 +209,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 330.000000 50.000000 60.000000 60.000000 box: 270.000000 220.000000 30.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -194,7 +224,7 @@ argument: 0 ...@@ -194,7 +224,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 10.000000 50.000000 60.000000 60.000000 box: 20.000000 220.000000 30.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -209,7 +239,7 @@ argument: 0 ...@@ -209,7 +239,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 410.000000 50.000000 60.000000 60.000000 box: 460.000000 220.000000 30.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -224,7 +254,7 @@ argument: 0 ...@@ -224,7 +254,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 4 type: 4
box: 180.000000 20.000000 120.000000 40.000000 box: 200.000000 50.000000 120.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -239,7 +269,7 @@ argument: 0 ...@@ -239,7 +269,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 100.000000 210.000000 50.000000 30.000000 box: 190.000000 260.000000 50.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -254,7 +284,7 @@ argument: 0 ...@@ -254,7 +284,7 @@ argument: 0
-------------------- --------------------
class: 11 class: 11
type: 0 type: 0
box: 420.000000 210.000000 50.000000 30.000000 box: 270.000000 260.000000 50.000000 30.000000
boxtype: 1 boxtype: 1
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -266,25 +296,55 @@ name: ...@@ -266,25 +296,55 @@ name:
callback: cb_out_close callback: cb_out_close
argument: 0 argument: 0
--------------------
class: 21
type: 1
box: 60.000000 220.000000 140.000000 30.000000
boxtype: 2
colors: 47 47
alignment: 1
style: 0
size: 11.000000
lcol: 0
label:
name: in_slider
callback: cb_in_slider
argument: 0
--------------------
class: 21
type: 1
box: 310.000000 220.000000 140.000000 30.000000
boxtype: 2
colors: 47 47
alignment: 1
style: 0
size: 11.000000
lcol: 0
label:
name: out_slider
callback: cb_out_slider
argument: 0
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 10.000000 250.000000 460.000000 30.000000 box: 20.000000 180.000000 30.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
style: 0 style: 0
size: 11.000000 size: 8.000000
lcol: 0 lcol: 0
label: CMIF Video Editor, by Guido van Rossum label:
name: msg_area name: in_info1
callback: callback:
argument: argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 50.000000 130.000000 60.000004 30.000000 box: 100.000000 180.000000 60.000004 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -299,7 +359,7 @@ argument: ...@@ -299,7 +359,7 @@ argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 120.000000 130.000000 30.000000 30.000000 box: 210.000000 180.000000 30.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -314,7 +374,7 @@ argument: ...@@ -314,7 +374,7 @@ argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 330.000000 130.000000 30.000000 30.000000 box: 270.000000 180.000000 30.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -329,7 +389,7 @@ argument: ...@@ -329,7 +389,7 @@ argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 370.000000 130.000000 60.000004 30.000000 box: 350.000000 180.000000 60.000004 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -344,7 +404,7 @@ argument: ...@@ -344,7 +404,7 @@ argument:
-------------------- --------------------
class: 2 class: 2
type: 0 type: 0
box: 440.000000 130.000000 30.000000 30.000000 box: 460.000000 180.000000 30.000000 30.000000
boxtype: 6 boxtype: 6
colors: 47 47 colors: 47 47
alignment: 4 alignment: 4
...@@ -356,5 +416,20 @@ name: out_info3 ...@@ -356,5 +416,20 @@ name: out_info3
callback: callback:
argument: argument:
--------------------
class: 11
type: 0
box: 390.000000 140.000000 100.000000 30.000000
boxtype: 1
colors: 47 47
alignment: 4
style: 0
size: 11.000000
lcol: 0
label: Truncate
name:
callback: cb_out_trunc
argument: 0
============================== ==============================
create_the_forms create_the_forms
...@@ -5,16 +5,17 @@ import os ...@@ -5,16 +5,17 @@ import os
class InputViewer: class InputViewer:
def init(self, filename, title, qsize): def init(self, filename, title, *args):
try: try:
self.vin = VFile.VinFile().init(filename) self.vin = VFile.VinFile().init(filename)
except (EOFError, VFile.Error): except (EOFError, VFile.Error):
raise IOError, 'bad video input file' raise IOError, 'bad video input file'
self.vin.warmcache()
if not title: if not title:
title = os.path.split(filename)[1] title = os.path.split(filename)[1]
self.filename = filename self.filename = filename
self.title = title self.title = title
self.qsize = qsize self.qsize = len(self.vin.index)
gl.foreground() gl.foreground()
gl.prefsize(self.vin.width, self.vin.height) gl.prefsize(self.vin.width, self.vin.height)
self.wid = -1 self.wid = -1
...@@ -39,27 +40,7 @@ class InputViewer: ...@@ -39,27 +40,7 @@ class InputViewer:
gl.winset(self.wid) gl.winset(self.wid)
gl.clear() gl.clear()
self.vin.initcolormap() self.vin.initcolormap()
self.queue = []
self.qindex = 0 self.qindex = 0
self.lost = 0
self.lastt = 0
self.eofread = 0
# Internal
def fillq(self):
if self.qindex < len(self.queue) or self.eofread: return
try:
t, d, cd = self.vin.getnextframe()
except EOFError:
self.eofread = 1
return
dt = t - self.lastt
self.lastt = t
self.queue.append(dt, d, cd)
while len(self.queue) > self.qsize:
del self.queue[0]
self.qindex = self.qindex - 1
self.lost = self.lost + 1
def show(self): def show(self):
if self.wid < 0: if self.wid < 0:
...@@ -68,12 +49,11 @@ class InputViewer: ...@@ -68,12 +49,11 @@ class InputViewer:
self.wid = gl.winopen(self.title) self.wid = gl.winopen(self.title)
gl.clear() gl.clear()
self.vin.initcolormap() self.vin.initcolormap()
self.fillq()
gl.winset(self.wid) gl.winset(self.wid)
if self.qindex >= len(self.queue): if self.qindex >= self.qsize:
self.vin.clear() self.vin.clear()
return return
dt, d, cd = self.queue[self.qindex] dt, d, cd = self.vin.getrandomframe(self.qindex)
self.vin.showframe(d, cd) self.vin.showframe(d, cd)
def redraw(self, wid): def redraw(self, wid):
...@@ -84,13 +64,16 @@ class InputViewer: ...@@ -84,13 +64,16 @@ class InputViewer:
self.show() self.show()
def get(self): def get(self):
if self.qindex >= len(self.queue): if self.qindex >= self.qsize:
self.fillq()
if self.eofread:
return None return None
item = self.queue[self.qindex] if self.qindex > 0:
prevt, ds, cs = \
self.vin.getrandomframeheader(self.qindex-1)
else:
prevt = 0
t, data, cdata = self.vin.getrandomframe(self.qindex)
self.qindex = self.qindex + 1 self.qindex = self.qindex + 1
return item return t-prevt, data, cdata
def backup(self): def backup(self):
if self.qindex == 0: if self.qindex == 0:
...@@ -98,11 +81,20 @@ class InputViewer: ...@@ -98,11 +81,20 @@ class InputViewer:
self.qindex = self.qindex - 1 self.qindex = self.qindex - 1
return 1 return 1
def seek(self, i):
if not 0 <= i <= self.qsize:
return 0
self.qindex = i
return 1
def tell(self): def tell(self):
return self.lost + self.qindex return self.qindex
def qsizes(self): def qsizes(self):
return self.qindex, len(self.queue) - self.qindex return self.qindex, self.qsize - self.qindex
def qinfo(self):
return 0, self.qindex, self.qsize
class OutputViewer: class OutputViewer:
...@@ -206,12 +198,33 @@ class OutputViewer: ...@@ -206,12 +198,33 @@ class OutputViewer:
while len(self.queue) > self.qsize: while len(self.queue) > self.qsize:
self.flushq() self.flushq()
def seek(self, i):
i = i - self.written
if not 0 <= i <= len(self.queue) + len(self.spares):
return 0
while i < len(self.queue):
if not self.backup():
return 0
while i > len(self.queue):
if not self.forward():
return 0
return 1
def trunc(self):
del self.spares[:]
def tell(self): def tell(self):
return self.written + len(self.queue) return self.written + len(self.queue)
def qsizes(self): def qsizes(self):
return len(self.queue), len(self.spares) return len(self.queue), len(self.spares)
def qinfo(self):
first = self.written
pos = first + len(self.queue)
last = pos + len(self.spares)
return first, pos, last
def test(): def test():
import sys import sys
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment