Thanks for your reply!
I’m new both to Python and to Sublime plugin development.
SuperCollider consists in sclang, a command line executable which waits for commands on STDIN and displays the result in STDOUT.
It’s a blocking.
The idea is to start a new thread with sclang running, and to send commands to sclang, and display what’s on STDOUT in a console inside Sublime Text.
I started with this code :
import sublime, sublime_plugin
import subprocess
class SupercolliderCommand(sublime_plugin.WindowCommand):
def run(self):
# create output panel
panel_name = 'supercollider'
if not hasattr(self, 'output_view'):
self.output_view = self.window.get_output_panel(panel_name)
v = self.output_view
# call supercollider
if not hasattr(self, 'sclang_instance'):
sc_dir = 'C:\\Program Files\\SuperCollider-3.5-rc2\\'
sc_exe = 'sclang'
self.sclang_instance = subprocess.Popen(sc_exe, cwd=sc_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
edit = v.begin_edit()
stdoutdata, stderrdata = self.sclang_instance.communicate()
v.insert(edit, v.size(), stdoutdata + '\n')
v.end_edit(edit)
v.show(v.size()) # scroll down
self.window.run_command("show_panel", {"panel": "output." + panel_name})
It launches sclang but
- there’s a new instance of sclang launched every time I run the command (bad!)
- it blocks sublime text
If I kill the sclang process, I can see that my panel was created and sclang displayed something, so I’m on the right way.
-> I have to find how to launch a separate thread with sclang, and how to communicate with that process.
Cheers!
geoffroy