Hi, all. I''m trying to create a "timed" dialog, i.e., a dialog that remains visible for a specified amount of time or until a user clicks any of its buttons (OK, Cancel, etc). I''ve tried to extend this dialog from FXDialogBox, but I just can''t get out of its modal loop. So I thought of extending FXTopWindow, but it claims to be an "abstract base class" and I don''t know exactly how to extend it. Can anybody, please, help me on this topic? Thanks in advance, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I Coopera??o ? muito melhor que competi??o! ------ contatos: email: angico at angico.org skype: an.gi.co ------
On Wednesday 19 November 2008, angico wrote:> Hi, all. > > I''m trying to create a "timed" dialog, i.e., a dialog that remains > visible for a specified amount of time or until a user clicks any of its > buttons (OK, Cancel, etc). > > I''ve tried to extend this dialog from FXDialogBox, but I just can''t get > out of its modal loop. So I thought of extending FXTopWindow, but it > claims to be an "abstract base class" and I don''t know exactly how to > extend it.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 -- +----------------------------------------------------------------------------+ | Copyright (C) 23:10 11/19/2008 Jeroen van der Zijp. All Rights Reserved. | +----------------------------------------------------------------------------+
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. -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I Coopera??o ? muito melhor que competi??o! ------ contatos: email: angico at angico.org skype: an.gi.co ------
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
Em Qui, 2008-11-20 ?s 08:46 -0600, Jeroen van der Zijp escreveu:> > 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, > > > - JeroenGreat!!! It works!!! Thank you very much. Despite of this very nice hint, I''d like you could give me some clues on subclassing the abstract FXTopWindow, for the case I have a specific use for it. Thanks, again, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I Coopera??o ? muito melhor que competi??o! ------ contatos: email: angico at angico.org skype: an.gi.co ------