Joined: 02 Feb 2004
|Posted: Tue Oct 12, 2004 5:26 pm Post subject: snack python : not implemented features
I was wondering why there are still two subcommands not implemented in python Sound object : Sound.data and Sound.append.
After some time spent on a debugger, I don't have the answer but maybe a TCL guru can help.
The data and append methods in tkSnack.py can be coded like this :
def data(self, binarydata=None, **kw):
"""Loads sound data from, or writes to, a binary string."""
if binarydata: # copy data to sound
self.tk.call((self.name, 'data', binarydata) + self._options(kw))
else: # return sound data
return self.tk.call((self.name, 'data') + self._options(kw))
def append(self, binarydata, **kw):
"""Appends binary string data to the end of the sound."""
self.tk.call((self.name, 'append', binarydata) + self._options(kw))
When loading sound data as for example:
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
root = Tkinter.Tk()
s = tkSnack.Sound()
data = open('ex1.wav', 'rb').read()
It doesn't work because of the TCL function Tcl_GetByteArrayFromObj() (in generic/jkSoundFile.c called by GetHeader() and ReadSound()). This function applies a conversion of the data to a bytearray. This conversion has probably to do with string encodings.
I don't know how to tell TCL not to modify the binary data. One "dirty" solution is to set variable useOldObjAPI to 1 in generic/snack.c or to use older tcl version. The conversion is not performed then and the python script works fine.
I understand now why those features are not implemented