ruby-processing: Perform action on exit?
in
Processing with Other Languages
•
3 years ago
I'm working on a DRb-based, Internet-enabled ruby-processing server, intended to be run with "rp5 live" (so you can live code with others). My current problem is that I can't seem to execute code to disconnect from the server when the Processing::App subclass quits. I've tried overriding stop() and close(); neither seems to get called. I've even tried key_pressed(event) and disconnecting if event.key_code == 27 (Escape), but that then seems to prevent Escape from closing the window (as it normally does).
Is there a recommended way to run code on exit? A kludge I can use?
Here's my current code:
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'drb-processing', 'client'))
- require 'logger'
- class Sketch < Processing::App
- def setup
- $client = DRbProcessing::Client.new(self)
- $client.logger = Logger.new(STDOUT)
- $client.connect ARGV[0]
- end
- def draw
- end
- def key_pressed(key)
- $client.disconnect if key.key_code == 27 #Escape
- end
- end
- sketch = Sketch.new(:width => 640, :height => 480, :title => '', :full_screen => false)
Many thanks for any help anyone can offer!
1