diff options
author | Guido van Rossum <guido@python.org> | 1990-10-25 18:51:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1990-10-25 18:51:42 (GMT) |
commit | e1f069ec9831c263ddbf6fd5b997a115212f9262 (patch) | |
tree | 81a4f93ee6d5483c5002767136dcd2c84ed2875f | |
parent | 4de12876a9b41fa0c701f91191d1a588b69fcaf9 (diff) | |
download | cpython-e1f069ec9831c263ddbf6fd5b997a115212f9262.zip cpython-e1f069ec9831c263ddbf6fd5b997a115212f9262.tar.gz cpython-e1f069ec9831c263ddbf6fd5b997a115212f9262.tar.bz2 |
Initial revision
-rw-r--r-- | Lib/lib-stdwin/Histogram.py | 49 | ||||
-rw-r--r-- | Lib/lib-stdwin/Soundogram.py | 37 | ||||
-rwxr-xr-x | Lib/stdwin/Histogram.py | 49 | ||||
-rwxr-xr-x | Lib/stdwin/Soundogram.py | 37 |
4 files changed, 172 insertions, 0 deletions
diff --git a/Lib/lib-stdwin/Histogram.py b/Lib/lib-stdwin/Histogram.py new file mode 100644 index 0000000..a023938 --- /dev/null +++ b/Lib/lib-stdwin/Histogram.py @@ -0,0 +1,49 @@ +# Module 'Histogram' + +from Buttons import * + + +# A Histogram displays a histogram of numeric data. +# It reacts to resize events by resizing itself, +# leaving the same amount of space around the borders. +# +class HistogramAppearance() = LabelAppearance(): + # + def define(self, (win, bounds, ydata, scale)): + self.init_appearance(win, bounds) + self.ydata = ydata + self.scale = scale # (min, max) + self.left_top, (right, bottom) = bounds + width, height = win.getwinsize() + self.right_margin = width - right + self.bottom_margin = height - bottom + return self + # + def setdata(self, (ydata, scale)): + self.ydata = ydata + self.scale = scale # (min, max) + self.win.change(self.bounds) + # + def drawit(self, d): + ydata = self.ydata + (left, top), (right, bottom) = self.bounds + min, max = self.scale + size = max-min + width, height = right-left, bottom-top + for i in range(len(ydata)): + h0 = left + i * width/len(ydata) + h1 = left + (i+1) * width/len(ydata) + v0 = top + height - (self.ydata[i]-min)*height/size + v1 = top + height + d.paint((h0, v0), (h1, v1)) + # + def resize(self): + width, height = self.win.getwinsize() + right = width - self.right_margin + bottom = height - self.bottom_margin + self.setbounds(self.left_top, (right, bottom)) + # + +class HistogramReactivity() = NoReactivity(): pass + +class Histogram() = HistogramAppearance(), HistogramReactivity(): pass diff --git a/Lib/lib-stdwin/Soundogram.py b/Lib/lib-stdwin/Soundogram.py new file mode 100644 index 0000000..a362eb2 --- /dev/null +++ b/Lib/lib-stdwin/Soundogram.py @@ -0,0 +1,37 @@ +# Module 'Soundogram' + +import audio +from minmax import min, max +from Histogram import Histogram + +class Soundogram() = Histogram(): + # + def define(self, (win, chunk)): + width, height = corner = win.getwinsize() + bounds = (0, 0), corner + self.chunk = chunk + self.step = (len(chunk)-1)/(width/2+1) + 1 + ydata = _make_ydata(chunk, self.step) + return Histogram.define(self, (win, bounds, ydata, (0, 128))) + # + def setchunk(self, chunk): + self.chunk = chunk + self.recompute() + # + def recompute(self): + (left, top), (right, bottom) = self.bounds + width = right - left + self.step = (len(chunk)-1)/width + 1 + ydata = _make_ydata(chunk, self.step) + self.setdata(ydata, (0, 128)) + # + + +def _make_ydata(chunk, step): + ydata = [] + for i in range(0, len(chunk), step): + piece = audio.chr2num(chunk[i:i+step]) + mi, ma = min(piece), max(piece) + y = max(abs(mi), abs(ma)) + ydata.append(y) + return ydata diff --git a/Lib/stdwin/Histogram.py b/Lib/stdwin/Histogram.py new file mode 100755 index 0000000..a023938 --- /dev/null +++ b/Lib/stdwin/Histogram.py @@ -0,0 +1,49 @@ +# Module 'Histogram' + +from Buttons import * + + +# A Histogram displays a histogram of numeric data. +# It reacts to resize events by resizing itself, +# leaving the same amount of space around the borders. +# +class HistogramAppearance() = LabelAppearance(): + # + def define(self, (win, bounds, ydata, scale)): + self.init_appearance(win, bounds) + self.ydata = ydata + self.scale = scale # (min, max) + self.left_top, (right, bottom) = bounds + width, height = win.getwinsize() + self.right_margin = width - right + self.bottom_margin = height - bottom + return self + # + def setdata(self, (ydata, scale)): + self.ydata = ydata + self.scale = scale # (min, max) + self.win.change(self.bounds) + # + def drawit(self, d): + ydata = self.ydata + (left, top), (right, bottom) = self.bounds + min, max = self.scale + size = max-min + width, height = right-left, bottom-top + for i in range(len(ydata)): + h0 = left + i * width/len(ydata) + h1 = left + (i+1) * width/len(ydata) + v0 = top + height - (self.ydata[i]-min)*height/size + v1 = top + height + d.paint((h0, v0), (h1, v1)) + # + def resize(self): + width, height = self.win.getwinsize() + right = width - self.right_margin + bottom = height - self.bottom_margin + self.setbounds(self.left_top, (right, bottom)) + # + +class HistogramReactivity() = NoReactivity(): pass + +class Histogram() = HistogramAppearance(), HistogramReactivity(): pass diff --git a/Lib/stdwin/Soundogram.py b/Lib/stdwin/Soundogram.py new file mode 100755 index 0000000..a362eb2 --- /dev/null +++ b/Lib/stdwin/Soundogram.py @@ -0,0 +1,37 @@ +# Module 'Soundogram' + +import audio +from minmax import min, max +from Histogram import Histogram + +class Soundogram() = Histogram(): + # + def define(self, (win, chunk)): + width, height = corner = win.getwinsize() + bounds = (0, 0), corner + self.chunk = chunk + self.step = (len(chunk)-1)/(width/2+1) + 1 + ydata = _make_ydata(chunk, self.step) + return Histogram.define(self, (win, bounds, ydata, (0, 128))) + # + def setchunk(self, chunk): + self.chunk = chunk + self.recompute() + # + def recompute(self): + (left, top), (right, bottom) = self.bounds + width = right - left + self.step = (len(chunk)-1)/width + 1 + ydata = _make_ydata(chunk, self.step) + self.setdata(ydata, (0, 128)) + # + + +def _make_ydata(chunk, step): + ydata = [] + for i in range(0, len(chunk), step): + piece = audio.chr2num(chunk[i:i+step]) + mi, ma = min(piece), max(piece) + y = max(abs(mi), abs(ma)) + ydata.append(y) + return ydata |