[fxruby-users] No accelTable for an FXTabItem?

Philippe Lang philippe.lang at attiksystem.ch
Fri Feb 16 07:21:50 EST 2007


Hi,

Here is a small test application made up of an FXMainWindow, where you
can find an FXTabBook and three items inside.

I can add "keyboard accelerators" in the main window. It works just
fine.

But I'm unable to do the same in the FXTabItem class. If I call
"accelTable.addAccel" in the MyTabItem class, the error I get is:

------------------------------
test.rb:17:in `initialize': undefined method `addAccel' for nil:NilClass
(NoMeth
odError)
        from test.rb:33:in `new'
        from test.rb:33:in `initialize'
        from test.rb:53:in `new'
        from test.rb:53
------------------------------

Apparently, accelTable is not initialized in the FXTabItem class.

FXTabItem is derived from FXWindow and should have an accelTable
attribute, right?

Does anyone see the problem then?

I'm using the FXRuby 1.6.6 gem under Ruby 1.8.5, under Windows XP.

Regards,

Philippe Lang



========================================================
require 'fox16'

include Fox

class MyTabItem < FXTabItem
    include Responder
    ID_SAVE = FXTabItem::ID_LAST
  
    def initialize(p, text, ic=nil, opts=TAB_TOP_NORMAL, x=0, y=0,
width=0, height=0, padLeft=DEFAULT_PAD, padRight=DEFAULT_PAD,
padTop=DEFAULT_PAD, padBottom=DEFAULT_PAD)
        super(p, text, ic, opts, x, y, width, height, padLeft, padRight,
padTop, padBottom)
        
        FXHorizontalFrame.new(p,
FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y)
        
        FXMAPFUNC(SEL_COMMAND, MyTabItem::ID_SAVE, 'onSave')
        
        # Bug appears if you uncomment the following line:
        #accelTable.addAccel(fxparseAccel("Ctrl-S"), self,
FXSEL(SEL_COMMAND, MyTabItem::ID_SAVE))
    end
    
    def onSave(sender, selector, data)
        puts "save in MyTabItem"
    end
end

class MyWindow < FXMainWindow
    include Responder
    ID_SAVE = FXMainWindow::ID_LAST
    
    def initialize(app)
        super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 200, 100)
        
        tabbook = FXTabBook.new(self, nil, 0,
LAYOUT_FILL_X|LAYOUT_FILL_Y)
        tabitem1 = MyTabItem.new(tabbook, "tab 1")
        tabitem2 = MyTabItem.new(tabbook, "tab 2")
        tabitem3 = MyTabItem.new(tabbook, "tab 3")
        
        FXMAPFUNC(SEL_COMMAND, MyWindow::ID_SAVE, 'onSave')
        accelTable.addAccel(fxparseAccel("Ctrl-S"), self,
FXSEL(SEL_COMMAND, MyWindow::ID_SAVE))
    end
    
    def onSave(sender, selector, data)
        puts "save in MyWindow"
    end
  
    def create
        super
        show(PLACEMENT_SCREEN)
    end
end

if __FILE__ == $0
  application = FXApp.new("Fox", "FXRuby Test")
  MyWindow.new(application)
  application.create
  application.run
end
========================================================



More information about the fxruby-users mailing list