Stein-Erik
2010-Apr-26 13:00 UTC
[fxruby-users] Is dynamically changing keyboard accelerators OK?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
Hello!<br>
<br>
While testing keyboard accelerators in FXRuby, I have come across some
unexpected behaviour. Cf the test program below. It has 3 buttons,
clicking on each sets 3 different sets of accelerators on 2 tab items.<br>
<br>
I am testing this to make sure I understand the accelerators
completely. In my real program I am going to let the user change each
tab name on the fly through a dialog box. I don''t think the user should
be allowed to change the accelerator key, though, so I''ll probably end
up with code like<br>
tab_item1.text =
"&1: " + users_own_name_for_the_tab<br>
that keeps the same accelerator key, but changes the rest as the user
wants.<br>
<br>
However, based on the issues found with my test program below, I am not
sure if it is safe to have a program that sets accelerators on the fly
during execution. So my first question: Is it supposed to be safe to
reassign accelerators on the fly, possibly a lot of times?<br>
<br>
Back to the ''unexpected behaviour''. I am able to reproduce it
by doing
the following:<br>
<ul>
<li>Start the test program (see below). No accelerators are set on
either tab item</li>
<li>Activate button A. It sets accelerator &1 on the first tab
item, and &2 on the second. Both Alt-1 and Alt-2 work OK.</li>
<li>Activate button B. It sets accelerator &2 on the first tab
item, and &3 on the second. But Alt-2 doesn''t work, only
Alt-3!<br>
</li>
</ul>
What for me is even stranger, is that all other sequences of button
activations work OK. For instance, if I active button A, and then
activate button C, both accelerators still work OK. If I then activate
button B, both accelerators now work OK! (Which also should confirm
that there is nothing wrong in the test code that activates the B
combination.) So I am only able to get one accelerator to not work -
Alt-2 in the B combination - if the B combination is invoked directly
after the A combination...<br>
<br>
My second question, therefore: What is happening here?<br>
<br>
---------- Start of test program: --------------<br>
<br>
<blockquote><big><tt>require "fox16"<br>
include Fox<br>
<br>
# FXRuby version 1.6.19, precompiled version running on Windows 7<br>
# Ruby versin 1.8.6<br>
<br>
class CTMainWindow < FXMainWindow<br>
<br>
def create<br>
super<br>
show( PLACEMENT_SCREEN )<br>
end<br>
<br>
def check_close( sender, sel, data )<br>
puts "SEL_CLOSE: #{sender}"<br>
return 0<br>
end<br>
<br>
def initialize( app )<br>
super( app, "Hello from CT", :width
=> 300, :height => 200 )<br>
self.connect( SEL_CLOSE, method( :check_close )
)<br>
<br>
full_frame = FXVerticalFrame.new( self, :opts
=> FRAME_RAISED |
LAYOUT_FILL )<br>
<br>
buttonA = FXButton.new( full_frame, "&A:
Set 1, 2",<br>
:opts => BUTTON_NORMAL | LAYOUT_FILL_X
)<br>
buttonB = FXButton.new( full_frame, "&B:
Set 2, 3",<br>
:opts => BUTTON_NORMAL | LAYOUT_FILL_X
)<br>
buttonC = FXButton.new( full_frame, "&C:
Set 4, 1",<br>
:opts => BUTTON_NORMAL | LAYOUT_FILL_X
)<br>
<br>
tabbook = FXTabBook.new( full_frame, :opts =>
LAYOUT_FILL )<br>
tab1 = FXTabItem.new( tabbook, "
No accelerator " )<br>
page1 = FXVerticalFrame.new( tabbook, :opts =>
FRAME_RAISED |
LAYOUT_FILL )<br>
<br>
tab2 = FXTabItem.new( tabbook, "
Also no accelerator " )<br>
page2 = FXVerticalFrame.new( tabbook, :opts =>
FRAME_RAISED |
LAYOUT_FILL )<br>
<br>
buttonA.connect( SEL_COMMAND ) do |sender, sel,
data|<br>
puts " Setting
&1 on first tab, &2 on second tab"<br>
tab1.text = " &1 is
accelerator "<br>
tab2.text = " &2 is
accelerator "<br>
end<br>
<br>
buttonB.connect( SEL_COMMAND ) do |sender, sel,
data|<br>
puts " Setting
&2 on first tab, &3 on second tab"<br>
tab1.text = " &2 is
accelerator "<br>
tab2.text = " &3 is
accelerator "<br>
end<br>
<br>
buttonC.connect( SEL_COMMAND ) do |sender, sel,
data|<br>
puts " Setting
&4 on first tab, &1 on second tab"<br>
tab1.text = " &4 is
accelerator "<br>
tab2.text = " &1 is
accelerator "<br>
end<br>
<br>
self.accelTable.addAccel( <br>
fxparseAccel( "Alt+F4" ), self, FXSEL( SEL_CLOSE, 0 ) )<br>
end<br>
end<br>
<br>
app = FXApp.new<br>
CTMainWindow.new( app )<br>
app.create<br>
app.run<br>
<br>
</tt></big></blockquote>
<br>
----------- End of test program: ---------------<br>
<br>
<br>
Best regards,<br>
Stein-Erik<br>
</body>
</html>