Preloading the wx libraries

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I have a Nokia N810, running Linux, and wxruby works quite well on it,
except application startup which takes quite some time.

I have thought about preloading the wx libraries in some kind of
launcher, which then brings up the forms on some signal.

I tried calling MyApplication.new.main_loop multiple times (exited the
main loop in between), which complained about the constant THE_APP
already being defined. Undefining this and trying again gave me a
segfault. I also tried handling this in the on_init method, but it
didn’t work so well when it wasn’t allowed to return :wink:

Do someone have any suggestions about how to create this type of
launcher?

Best regards,
Magnus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkh8uS0ACgkQFsdVGDM22G6KigCbB57hPWZY+UFdnPfqIhCxsu3J
VlYAn1sxXgSydAnmywJ8lUQAWtdHttKr
=BLZH
-----END PGP SIGNATURE-----

mouth drops I never knew wxRuby was being used, or could even be used
on
something like that little thing. 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. 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.

Sorry, that’s about as much as I can help you with.

L8ers,

Hi

Mario S. 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

-----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 :slight_smile:

I’ll play around a bit and see what happens.
Thanks!

/Magnus

Alex F. wrote:

Generally, this is part of the design of the Wx library, not just wxRuby
case it helps you. It creates a server app upon which a client can
while command = gets
socket.close
def on_init
p command
end

IRBApp.new().main_loop


wxruby-users mailing list
[email protected]
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-----