Vladimir Konrad
2008-Jan-11 17:04 UTC
[fxruby-users] Handling Escape key-press in dialog window
Hello! I am trying to do a log-in screen for an application and have a problem with handling ESC key - when you press it, the dialog box closes and the application opens. What I would like is to quit the application if user hits ESC key while the initial log-in window is open. The LoginWindow class looks like: class LoginWindow < FXDialogBox def initialize(owner) super(owner, "gbrs - log in", :opts => DECOR_TITLE | DECOR_BORDER, :width => 300, :height => 250) <paint the log-in window here> # the following code should do it but it does not self.accelTable.removeAccel(fxparseAccel("ESC")) self.accelTable.addAccel(fxparseAccel("ESC"), getApp(), \ FXSEL(SEL_COMMAND, FXApp::ID_QUIT)) end end # end of class Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
Lyle Johnson
2008-Jan-11 17:20 UTC
[fxruby-users] Handling Escape key-press in dialog window
On Jan 11, 2008, at 11:04 AM, Vladimir Konrad wrote:> I am trying to do a log-in screen for an application and have a > problem > with handling ESC key - when you press it, the dialog box closes and > the application opens. What I would like is to quit the application if > user hits ESC key while the initial log-in window is open. > > The LoginWindow class looks like: > > class LoginWindow < FXDialogBox > > def initialize(owner) > > super(owner, "gbrs - log in", :opts => DECOR_TITLE | > DECOR_BORDER, :width => 300, :height => 250) > > <paint the log-in window here> > > # the following code should do it but it does not > > self.accelTable.removeAccel(fxparseAccel("ESC")) > self.accelTable.addAccel(fxparseAccel("ESC"), getApp(), \ > FXSEL(SEL_COMMAND, FXApp::ID_QUIT)) > end > > endThe problem is that the FXDialogBox doesn''t store that mapping for the "Esc" key in its accelerator table, as you''re assuming here. The FXDialogBox is just listening for SEL_KEYPRESS and SEL_KEYRELEASE messages and checking to see if the key being pressed (and released) is the Escape key (KEY_Escape). See what happens if you do something like this: self.connect(SEL_KEYPRESS) do |sender, sel, event| app.exit(0) if event.code == KEY_Escape false end In other words, we''re overriding the default handler for SEL_KEYPRESS to check for the KEY_Escape keypress, and exiting the application if we see it. If we don''t, the handler returns ''false'' to indicate that we didn''t handle whatever key was pressed. Hope this helps, Lyle
Vladimir Konrad
2008-Jan-11 17:34 UTC
[fxruby-users] Handling Escape key-press in dialog window
> See what happens if you do something like this: > > self.connect(SEL_KEYPRESS) do |sender, sel, event| > app.exit(0) if event.code == KEY_Escape > false > endThis was my first approach (and it still does the same - carries on. The self.connect(SEL_KEYPRESS) does not get even called (is this because some other widget has a focus (there are other keyboard handlers in the log-in screen, but they are set-up for KEY_RELEASE)? Also, the log-in dialog box gets created in the main window .create method: # Main window .create method def create super LoginWindow.new(self).execute(PLACEMENT_SCREEN) show(PLACEMENT_SCREEN) end Vlad PS: I bought your book, time permitting I will send some feed-back... Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
Vladimir Konrad
2008-Jan-12 12:22 UTC
[fxruby-users] Handling Escape key-press in dialog window
Lesson 1 - beginners tend to use framework in unexpected ways (My code was structured badly, solved with registering chore on start-up, which opens the log-in screen). Vlad Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
Lyle Johnson
2008-Jan-12 15:01 UTC
[fxruby-users] Handling Escape key-press in dialog window
On Jan 12, 2008, at 6:22 AM, Vladimir Konrad wrote:> Lesson 1 - beginners tend to use framework in unexpected waysIndeed. ;)> (My code was structured badly, solved with registering chore on > start-up, which opens the log-in screen).Does that mean that you''ve solved (or worked around) this issue with the Esc key press?
Vladimir Konrad
2008-Jan-12 17:44 UTC
[fxruby-users] Handling Escape key-press in dialog window
> > (My code was structured badly, solved with registering chore on > > start-up, which opens the log-in screen). > > Does that mean that you''ve solved (or worked around) this issue with > the Esc key press?Yes, at the end there was no need to handle the Escape key press - the FXDialogBox (the log-in screen) closes and returns 0 when Escape is pressed so I test for that and exit as necessary. Vlad PS: Once I get over the beginners hurdles, I would like to create example application for this and would like to have it included in the FXRuby examples. How do I go about that (just send it to you?)? Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
Lyle Johnson
2008-Jan-12 20:16 UTC
[fxruby-users] Handling Escape key-press in dialog window
On Jan 12, 2008, at 11:44 AM, Vladimir Konrad wrote:>>>> PS: Once I get over the beginners hurdles, I would like to create > example application for this and would like to have it included in the > FXRuby examples. How do I go about that (just send it to you?)?Yes, that would be fine. Thanks!