[fxruby-users] Add a tab to a tabbok dynamically?

Philippe Lang philippe.lang at attiksystem.ch
Tue Oct 3 06:52:45 EDT 2006


Hi,

I cannot figure out how to add a tab to a tabbook dynamically, while the program is running.

Does anyone know how to force the tab to appear? I tried calling recalc, repaint, layout or forceRefresh, but no success... Below is a small example.

Thanks!

Philippe

P.S. Windows XP SP2, Ruby 1.8.4, FXRuby-1.6.2-ruby184.exe

-----------------------------

#!/usr/bin/ruby

require 'fox16'

include Fox

class MyWindow < FXMainWindow
    
  def initialize(app)

    super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 600, 350)

    # Menu bar stretched along the top of the main window
    menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
  
    # File menu
    filemenu = FXMenuPane.new(self)
    FXMenuTitle.new(menubar, "&File", nil, filemenu)
    FXMenuCommand.new(filemenu, "&Quit\tCtl-Q\tQuit the application",
        nil, app, FXApp::ID_QUIT)

    # Tab menu
    tabmenu = FXMenuPane.new(self)
    FXMenuTitle.new(menubar, "Tab", nil, tabmenu)
    FXMenuCommand.new(tabmenu, "Add a tab").connect(SEL_COMMAND, method(:onAddTab))

    # Tabbook
    @tabbook = FXTabBook.new(self, nil, 0,
        LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_RIGHT)
    
    # First tab
    FXTabItem.new(@tabbook, "Tab 1", nil)
    FXVerticalFrame.new(@tabbook,
        LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK|FRAME_RAISED)
    
  end
  
  def onAddTab(sender, sel, data)
      puts "A tab is added..."
      FXTabItem.new(@tabbook, "Another tab", nil)
      FXVerticalFrame.new(@tabbook,
          LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_THICK|FRAME_RAISED)
      
      self.recalc
      self.repaint
      self.layout
      self.forceRefresh
      
      @tabbook.recalc
      @tabbook.repaint
      @tabbook.layout
      @tabbook.forceRefresh
  end

  def create
    super
    show(PLACEMENT_SCREEN)
  end

end

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


---------------
Philippe Lang
Attik System

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3125 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20061003/3312b620/attachment.bin 


More information about the fxruby-users mailing list