[fxruby-users] FXTopWindow

Jeroen van der Zijp jeroen at fox-toolkit.org
Thu Nov 20 09:46:46 EST 2008


On Thursday 20 November 2008, angico wrote:
> Em Qua, 2008-11-19 às 23:19 -0600, Jeroen van der Zijp escreveu:
> 
> 
> > To get out of the modal loop, FXDialogBox calls app->stopModal(); this can
> > be most easily accomplished via ID_CANCEL or ID_ACCEPT messages being sent
> > to the dialogbox [they differ mainly in the return code passed along through
> > runModalFor().
> > You can certainly also call accept in response to a timeout.  In fact, handlers
> > for timeout and chores have already been added to FXDialogBox: SEL_TIMEOUT,
> > SEL_COMMAND, and SEL_CHORE with ID_CANCEL or ID_ACCEPT are available.
> > 
> > So basically all that's needed is to set the timer to send the (SEL_TIMEOUT,ID_CANCEL)
> > message to FXDialogBox at the desired time.
> > 
> > Hope this helps,
> > 
> > 
> > 		- Jeroen
> > 
> > 
> 
> Hi, Jeroen
> 
> I have already unsuccessfuly tried to exit an FXDialogBox's modal loop
> all the ways I could think of - and none of them worked.
> 
> The basic idea for my timeout dialog box is:
> 
> -----
> class TimeoutDlg < FXDialogBox
>   def execute
>     time = 10
>     Thread.new(timer)
>     super
>   end
> 
>   def timer
>     # give the user 5 seconds to respond, or accept the default
>     while time > 0 do
>       sleep 0.5
>       time -= 1
>     end
> 
>     # my first trial, based on suggestion from Lyle
>     handle(self, FXSEL(SEL_COMMAND, ID_ACCEPT), 0) # <-- doesn't work!!!
> 
>     # another trial, also based on Lyle's suggestion
>     hide
>     app.stopModal # <-- doesn't work!!!
> 
>     # my last trial, based on your suggestion
>     handle(self, FXSEL(SEL_TIMEOUT, ID_ACCEPT), 0) # <-- doesn't work!!!
>   end
> -------
> 
> So, that's why I'm bound to create my own dialog, extending it from
> FXTopWindow, but I don't know exactly how to do it, because when I
> create the dialog with @dlg = TimeoutDlg, I got the error:
> 
> 
> ./timeoutdlg.rb:14:in `initialize': No matching function for overloaded
> 'new_FXTopWindow' (ArgumentError)
> from ./timeoutdlg.rb:14:in `initialize'
> 
> 
> Well, in my custom "initialize" I'm just using the same arguments to
> FXComposite::initialize, which, according to the documentation, is the
> "grandparent" of FXTopWindow.
> 
> That said, I'd like to ask you two things: 1) WHY doesn't ANY of the
> trials to exit the FXDialogBox's modal loop work? And 2) HOW do I derive
> or subclass from FXTopWindow (if not for this specific use, for any
> other I might think of)?
> 
> I'm using:
> 
> ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]
> FXRuby 1.6.16
> 
> I thank you very much, in advance.

When I said "timer" I did mean FOX timer, i.e. via app->addTimeout().

What you appear to be doing is starting another thread, which waits
for a while and then invokes stopModal().  This indeed won't work,
because the main GUI thread will remain blocked waiting for events
from the user.


Hope this helps,


		- Jeroen


More information about the fxruby-users mailing list