On Sunday 11 December 2005 23:47, Victor Lazzarini wrote: > I presume in Python the idea will be more or less the > same (deriving a class and overriding its methods). Yes, here is an example: #!/usr/bin/python import sys from Tkinter import * from ScrolledText import ScrolledText import csnd import threading cs = csnd.Csound() w = ScrolledText(width=80, height=24, foreground='white', background='black') w.pack() w.tag_config('warningTag', foreground='white') w.tag_config('warningTag', foreground='white', background='blue') w.tag_config('errorTag', foreground='white', background='red') w.tag_config('redTag', foreground='red') w.tag_config('greenTag', foreground='green') w.tag_config('blueTag', foreground='cyan') w.tag_config('yellowTag', foreground='yellow') def guiThread(): w.mainloop() # create and start a GUI thread th = threading.Thread(None, guiThread) th.start() # pyCallbacks is a subclass of CsoundCallbackWrapper that can # override the methods MessageCallback(), InputValueCallback(), # OutputValueCallback(), and YieldCallback() for defining callbacks class pyCallbacks(csnd.CsoundCallbackWrapper): def MessageCallback(self, attr, msg): s = self.CharPtrToString(msg) if (attr & csnd.CSOUNDMSG_TYPE_MASK) == csnd.CSOUNDMSG_WARNING: w.insert(END, s, 'warningTag') elif (attr & csnd.CSOUNDMSG_TYPE_MASK) == csnd.CSOUNDMSG_ERROR: w.insert(END, s, 'errorTag') elif (attr & csnd.CSOUNDMSG_FG_COLOR_MASK) == csnd.CSOUNDMSG_FG_RED: w.insert(END, s, 'redTag') elif (attr & csnd.CSOUNDMSG_FG_COLOR_MASK) == csnd.CSOUNDMSG_FG_YELLOW: w.insert(END, s, 'yellowTag') elif (attr & csnd.CSOUNDMSG_FG_COLOR_MASK) == csnd.CSOUNDMSG_FG_GREEN: w.insert(END, s, 'greenTag') elif (attr & csnd.CSOUNDMSG_FG_COLOR_MASK) == csnd.CSOUNDMSG_FG_BLUE: w.insert(END, s, 'blueTag') else: w.insert(END, s, 'miscTag') w.see(END) # def YieldCallback(self): # self.MessageCallback(0, ' ======== Yield called ! ========\n') # return 1 # create a callback wrapper object for this instance of Csound # note that this will use the host data pointer of 'cs', so the # host data cannot be used for other purposes cb = pyCallbacks(cs) # enable the callbacks for which there are definitions above #cb.SetYieldCallback() cb.SetMessageCallback() # build an argument list from the command line options args = csnd.CsoundArgVList() args.Append('csound') n = sys.argv.__len__() if n > 1: for i in range(1, n): args.Append(sys.argv[i]) args.Append('-H0') args.Append('-m231') # compile and perform an orchestra to see if the callbacks work if cs.Compile(args.argc(), args.argv()) == 0: while cs.PerformKsmps() == 0: pass # Reset() must be called before 'cs' or 'cb' is possibly # garbage collected, otherwise a crash may occur cs.Reset() # free memory used by the argument list; this is optional, and # would be done automatically when 'args' is garbage collected args.Clear() # wait for the GUI window to be closed th.join() ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net