Not quite :-)
in the attached code I modified the "newbtn" routine as you suggested,
it
compiles OK , but still visits "newbtn"
after Tabbing out of the last data field. Clicking on "newbtn"
processes as
expected.
eg:
newbtn= FXButton.new(btns, "New", :opts => LAYOUT_FILL_X|
BUTTON_NORMAL)
def newbtn.canFocus?;false; end
newbtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
puts "new button pressed"
end # new
BTW the program is self contained so should be runnable.
======================== program ==========#!/usr/bin/env ruby
# /home/brett/Ruby_Stuff/Ruby_Fox_Gen/zestaddr2.rb
# Generated by RubyFXGen.rb Ver 0.9a on :Mon Sep 01 17:20:31 +1000 2008
# plus added code to setup scroller
require ''fox16''
include Fox
class MainWindow < FXMainWindow
def initialize(app) super( app, ''Zest Address Entry'')
self.width = 422
self.height = 250
amain= FXVerticalFrame.new(self,LAYOUT_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
main = FXScrollWindow.new(amain, LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr= FXMatrix.new(main, 2,MATRIX_BY_COLUMNS|LAYOUT_CENTER_X)
# addr
FXLabel.new(addr, "First Name" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld1= FXDataTarget.new("")
fld1a=FXTextField.new(addr,20, fld1, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld1a.connect(SEL_COMMAND) do
puts "fld1 contains #{fld1.value}"
main.setPosition(-10, -10)
end
FXLabel.new(addr, "Surname" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld2= FXDataTarget.new("")
FXTextField.new(addr,20, fld2, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld2.connect(SEL_COMMAND) do
puts "fld2 contains #{fld2.value}"
main.setPosition(-20, -20)
end
FXLabel.new(addr, "Company Name" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld3= FXDataTarget.new("")
FXTextField.new(addr,20, fld3, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
fld3.connect(SEL_COMMAND) do
puts "fld3 contains #{fld3.value}"
main.setPosition(-30, -30)
end
FXLabel.new(addr, "Addr1" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr1= FXDataTarget.new("")
FXTextField.new(addr,20, addr1, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr1.connect(SEL_COMMAND) do
puts "addr1 contains #{addr1.value}"
main.setPosition(-40, -40)
end
FXLabel.new(addr, "Addr2" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr2= FXDataTarget.new("")
FXTextField.new(addr,20, addr2, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr2.connect(SEL_COMMAND) do
puts "addr2 contains #{addr2.value}"
main.setPosition(-50, -50)
end
FXLabel.new(addr, "Addr3" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr3= FXDataTarget.new("")
FXTextField.new(addr,20, addr3, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
addr3.connect(SEL_COMMAND) do
puts "addr3 contains #{addr3.value}"
main.setPosition(-70, -70)
end
FXLabel.new(addr, "PostCode" ,
nil,LABEL_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
postcode= FXDataTarget.new("")
FXTextField.new(addr,20, postcode, FXDataTarget::ID_VALUE,
FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y)
postcode.connect(SEL_COMMAND) do
puts "postcode contains #{postcode.value}"
main.setPosition(-0, -0) ## scroll back to first field ( it does )
fld1a.setFocus ## focus on first field ( it does NOT !
-> first BUTTON "New" )
end
btns= FXHorizontalFrame.new(amain, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN)
# btns
newbtn= FXButton.new(btns, "New", :opts => LAYOUT_FILL_X|
BUTTON_NORMAL)
def newbtn.canFocus?;false; end
newbtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
puts "new button pressed"
end # new
clearbtn= FXButton.new(btns,"Clear", :opts =>
LAYOUT_FILL_X|BUTTON_NORMAL)
clearbtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
end # clear
loadbtn= FXButton.new(btns,"Load", :opts=>
LAYOUT_FILL_X|BUTTON_NORMAL)
loadbtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
end # load
savebtn= FXButton.new(btns,"Save",
:opts=>LAYOUT_FILL_X|BUTTON_NORMAL)
savebtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
end # save
quitbtn= FXButton.new(btns,"Quit",
:opts=>LAYOUT_FILL_X|BUTTON_NORMAL)
quitbtn.connect(SEL_COMMAND) do |sender, sel, checked|
# ## your button press code here ##
exit()
end # quit
# set initial field address
fld1a.setFocus
end # def initilize
def create
super
show(PLACEMENT_SCREEN)
end # create
end # class MainWindow
# ============= main prog ============
# Construct an application
theApp = FXApp.new(''Smithy'',''Max'')
# Construct the main window
theApp.normalFont = FXFont.new(theApp,''Adobe
Courier'',12,FONTWEIGHT_BOLD)
# define default display FONT for this application
MainWindow.new(theApp)
# Create and show the application windows
theApp.create
# Run the application
theApp.run
# ============= end ============
Lyle Johnson-4 wrote:>
> On Wed, Sep 10, 2008 at 8:08 PM, dragoncity <dragoncity at
aanet.com.au>
> wrote:
>
>> PS: I posted this on Fox-users and received a possible solution, but
>> would
>> like to know if the same idea can be done with FXRuby.
>>
>> === eg ===>> One way is to derive FXButton class and override
"canFocus()" method:
>>
>> class MyButton : public FXButton {
>> public:
>> FXbool canFocus() const { return false; }
>> }
>> ========>
> Yes, the same approach should work in FXRuby. In fact, you should in
> theory be able to just override the canFocus? method on a particular
> button instance without having to subclass FXButton, e.g.
>
> no_focus_button = FXButton.new(...)
> def no_focus_button.canFocus?; false; end
>
> Hope this helps,
>
> Lyle
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
>
>
--
View this message in context:
http://www.nabble.com/How-to-control-Button-access---tp19426045p19450261.html
Sent from the FXRuby Users mailing list archive at Nabble.com.