List Info

Thread: No accelTable for an FXTabItem?




No accelTable for an FXTabItem?
country flaguser name
Switzerland
2007-02-16 06:21:50
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
========================================================

_______________________________________________
fxruby-users mailing list
fxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/fxruby-users

Re: No accelTable for an FXTabItem?
user name
2007-02-16 07:31:03
On Friday 16 February 2007 06:21, Philippe Lang wrote:
> 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?

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!


		- Jeroen


-- 
+-----------------------------------------------------------
-----------------+
| Copyright (C) 07:20 02/16/2007 Jeroen van der Zijp.   All
Rights Reserved. |
+-----------------------------------------------------------
-----------------+
_______________________________________________
fxruby-users mailing list
fxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/fxruby-users

Re: No accelTable for an FXTabItem?
country flaguser name
Switzerland
2007-02-16 07:50:59
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...

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')
        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"
    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
===========================================
_______________________________________________
fxruby-users mailing list
fxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/fxruby-users

Re: No accelTable for an FXTabItem?
country flaguser name
Switzerland
2007-02-16 09:07:25
fxruby-users-bouncesrubyforge.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
===================================================
_______________________________________________
fxruby-users mailing list
fxruby-usersrubyforge.org
ht
tp://rubyforge.org/mailman/listinfo/fxruby-users

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )