[fxruby-users] No accelTable for an FXTabItem?

Philippe Lang philippe.lang at attiksystem.ch
Fri Feb 16 10:07:25 EST 2007


fxruby-users-bounces at rubyforge.org wrote:
> Jeroen van der Zijp wrote:
> 
>>> Apparently, accelTable is not initialized in the FXTabItem class.
>>> 
>>> FXTabItem is derived from FXWindow and should have an accelTable
>>> attribute, right?
>> 
>> It has a variable for accel table, but no accel table has been added
>> yet.  However, after you add an accel table, you should certainly be
>> able to add accelerator key-combinations to it then!
> 
> Hi,
> 
> I've tried initializing the accel table, the error has disappeared,
> but the tab item does not react to CTRL-S at all. Something to enable
> maybe?  
> 
> One more question: what happens if three tabs have the same hotkey
> configured in their respective accel table? Do they all receive the
> callback, or only the active tab? I'd like to code something similar
> to the second solution, but I'm not sure how to do that...   

Hi again,

I have tried something else, still without success: I have overloaded
the tab frame as well, and configured its accel table. The only callback
that works for me is the one in the "MyWindow" class. 


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

include Fox

class MyFrame < FXHorizontalFrame
    include Responder
    ID_SAVE = FXHorizontalFrame::ID_LAST
    
    def initialize(p, opts=0, x=0, y=0, width=0, height=0,
padLeft=DEFAULT_SPACING, padRight=DEFAULT_SPACING,
padTop=DEFAULT_SPACING, padBottom=DEFAULT_SPACING,
hSpacing=DEFAULT_SPACING, vSpacing=DEFAULT_SPACING)
        super(p, opts, x, y, width, height, padLeft, padRight, padTop,
padBottom, hSpacing, vSpacing)
        
        FXMAPFUNC(SEL_COMMAND, MyFrame::ID_SAVE, 'onSave')
        accelTable = FXAccelTable.new()
        accelTable.addAccel(fxparseAccel("Ctrl-S"), self,
FXSEL(SEL_COMMAND, MyFrame::ID_SAVE))
    end
    
    def onSave(sender, selector, data)
        puts "save in MyFrame"
    end
end

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)
        
        frame = MyFrame.new(p, FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y)
        
        FXMAPFUNC(SEL_COMMAND, MyTabItem::ID_SAVE, 'onSave')
        accelTable = FXAccelTable.new()
        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"
        puts @tabbook.current
    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