[wxruby-users] Preloading the wx libraries
Magnus Engström
magnus at aoeu.info
Wed Jul 16 02:55:52 EDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I tried this approach, but I missed the Thread.pass bit, so my threads
wasn't very effective when I wasn't operating on the frames :)
I'll play around a bit and see what happens.
Thanks!
/Magnus
Alex Fenton wrote:
> 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
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkh9m3gACgkQFsdVGDM22G6jzACdGkC6BEYamPeiQYTgD3o/61F/
BuAAn0X1kjRQGFoKdAkkespIylDu+Tsc
=d6R+
-----END PGP SIGNATURE-----
More information about the wxruby-users
mailing list