[wxruby-users] Preloading the wx libraries
Alex Fenton
alex at pressure.to
Tue Jul 15 19:05:48 EDT 2008
Hi
Mario Steele wrote:
> *mouth drops* I never knew wxRuby was being used, or could even be
> used on something like that little thing.
Likewise ... cool
> The problem with that, is you need to initialize Wx::App only once.
> Any attempt to use Wx::App more then once, will cause the error your
> getting.
Generally, this is part of the design of the Wx library, not just wxRuby
- it expects the main_loop to be entered only once, as part of the
library is initialised at this point rather than at library load.
> You could possibly setup a Client/Server system, in which you create a
> dummy library, that replicates the functionality of wxRuby, which
> actually communicates to the Server, to create the windows, and such.
> That would be the only way you would be able to "Pre Load" the wxRuby
> library.
I looked into this approach a while back when I was trying to create an
interactive wxRuby shell which could be used to test out ideas quickly.
I never got it into a fully functional state, but here's the code in
case it helps you. It creates a server app upon which a client can
execute wx code.
alex
##### CLIENT #####
require 'socket'
include Socket::Constants
while command = gets
if command.chomp == "x"
exit!
end
p 'command'
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 5858, '127.0.0.1' )
socket.connect( sockaddr )
socket.write( command )
result = socket.readline
STDOUT.puts ">> #{result}"
socket.close
end
# results = socket.read
##### SERVER #####
require 'wx'
require 'socket'
class IRBApp < Wx::App
def on_init
server = TCPServer.new('127.0.0.1', 5858)
$f = Wx::Frame.new(nil, -1, 'empty')
# $f.show
Wx::Timer.every(100) { Thread.pass }
listener = Thread.new do
while session = server.accept
command = session.gets
p command
begin
result = eval( command )
rescue => result
end
session.puts(result.inspect)
session.close
end
end
listener.abort_on_exception = true
end
end
IRBApp.new().main_loop
More information about the wxruby-users
mailing list