Hi, I tried to think of a good subject, but that was the best I could come up with. Here is my problem (pretty much same as before). I have a program I''ve written, and I want to write a wxRuby front end for it. There are hooks in the program that call methods in the wxRuby part of things, however, nothing happens in the actual program unless I''m triggering events in the wxRuby part by moving the mouse or other such things. I''m really not sure what to do - I think I''m just missing something obvious. I''ve attached the programs, so if anyone can let me know what I''m doing wrong, I''d really appreciate it. To run the programs, run "runserver.rbw" and then run two instances of "simpokerplayer.rb". For simpokerplayer, you have to enter a name to standard in after it starts, to identify the player. The server should then start running a game. However, it only does stuff when you move the mouse over the gui of the server. Thanks in advance, -Kurt -------------- next part -------------- A non-text attachment was scrubbed... Name: simpokerplayer.rb Type: application/octet-stream Size: 441 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040801/b9ded759/simpokerplayer.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: runserver.rbw Type: application/octet-stream Size: 57 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040801/b9ded759/runserver.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: simpokerviewer.rb Type: application/octet-stream Size: 2722 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040801/b9ded759/simpokerviewer.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: simpokerserver.rb Type: application/octet-stream Size: 11477 bytes Desc: not available Url : http://rubyforge.org/pipermail/wxruby-users/attachments/20040801/b9ded759/simpokerserver.obj
Mehr, Assaph (Assaph)
2004-Aug-02 21:59 UTC
[Wxruby-users] nothing happens unless I move the mouse
Hi Kurt, Didn''t have a lot of time to play with your code, but you might want to check how you''re handlling the connect.accept and threads. My understanding is that once you accept you should launch an independent thread. HTH, Assaph -----Original Message----- From: wxruby-users-bounces@rubyforge.org [mailto:wxruby-users-bounces@rubyforge.org] On Behalf Of Kurt Dresner Sent: Monday, 2 August 2004 3:46 AM To: General discussion of wxRuby Subject: [Wxruby-users] nothing happens unless I move the mouse Hi, I tried to think of a good subject, but that was the best I could come up with. Here is my problem (pretty much same as before). I have a program I''ve written, and I want to write a wxRuby front end for it. There are hooks in the program that call methods in the wxRuby part of things, however, nothing happens in the actual program unless I''m triggering events in the wxRuby part by moving the mouse or other such things. I''m really not sure what to do - I think I''m just missing something obvious. I''ve attached the programs, so if anyone can let me know what I''m doing wrong, I''d really appreciate it. To run the programs, run "runserver.rbw" and then run two instances of "simpokerplayer.rb". For simpokerplayer, you have to enter a name to standard in after it starts, to identify the player. The server should then start running a game. However, it only does stuff when you move the mouse over the gui of the server. Thanks in advance, -Kurt
Kurt Dresner wrote:> I have a program I''ve written, and I want to write a wxRuby front end > for it. There are hooks in the program that call methods in the > wxRuby part of things, however, nothing happens in the actual program > unless I''m triggering events in the wxRuby part by moving the mouse or > other such things. I''m really not sure what to do - I think I''m just > missing something obvious.Sorry it took me a while to respond. I needed to actually run the programs and fiddle with them to be able to answer. I had seen this myself at one point, but couldn''t remember the context, and wasn''t certain about the solution. The problem is not exactly obvious, but makes sense once you understand what is happening. And there is an easy fix/workaround. Your server app launches a ruby Thread to handle the socket stuff. The problem is that wxRuby normally effectively sleeps (in C++) while waiting for an event. When no events are coming through, no ruby code is invoked, the ruby thread scheduler never has a chance to work. When you are moving the mouse in the server window, or otherwise generating events, ruby gives time to the socket thread. I suppose one trick would be to set up a timer that fired ten times each second, or something like that. But a simpler approach is to take advantage of wxRuby''s idle processing. I added this line in the SPSFrame constructor: evt_idle {|e| onIdle(e)} And I added this method to the SPSFrame class: def onIdle(e) e.request_more end At least on my system, this idle loop does not consume detectable CPU time when no players are connected. I don''t know if that will be the case on all systems. If it is a problem, the timer approach might work better. Cheers, Kevin
Reasonably Related Threads
- Problems using network code and trying to add a GUI
- Has anybody been able to install CDR-Stats all the way through?
- getGraphicsEvent on X11 and event queuing
- getGraphicsEvent() alternative for cairo graphics device?
- getGraphicsEvent on X11 and event queuing