[fxruby-users] Adding / Deleting controls dynamically

Philippe Lang philippe.lang at attiksystem.ch
Thu Apr 15 03:31:00 EDT 2010


Hi,

I'm developing a user interface for querying an SQL database, where controls are being added/deleted dynamically, while the user is working.

Everything works just fine when adding controls: you just have to "create" the control, and then call "recalc" for the frame where the control has been added.

At some point, I need to delete everything which was added, and start over. This is where I start having problems.

Here is some test code, where I tried to reproduce the problem. Add a few controls, delete them all, and add one again: you will see it does not appear at the right place, as if the previous "destroyed" controls where still here, somehow.

Does anyone know how to clean all childs of a frame correctly?

Best regards!

-------------------------------------------------------------
#!/usr/bin/ruby

require 'fox16'

include Fox

class MyWindow < FXMainWindow
    
  def initialize(app)

    super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 400, 200)
    
    stack = FXVerticalFrame.new(self, FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
    
    # Frame where controls are being dynamically added / deleted
    dynamic_frame = FXHorizontalFrame.new(stack, FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
    
    # Bottom frame for buttons
    button_frame = FXHorizontalFrame.new(stack, FRAME_NONE|LAYOUT_FILL_X)
    
    # Button that adds a control in the dynamic_frame. Works fine.
    FXButton.new(button_frame, "add").connect(SEL_COMMAND) do |sender, selector, data|
      FXButton.new(dynamic_frame, "button").create
      dynamic_frame.recalc
    end
    
    # Button that deletes all child windows of dynamic_frame. 
    # Works, except that afterwards, new controls are not added at the right place.
    FXButton.new(button_frame, "remove all").connect(SEL_COMMAND) do |sender, selector, data|
      dynamic_frame.each_child do |child|
        child.destroy
      end
      dynamic_frame.recalc
    end

  end

  def create
    super
    show(PLACEMENT_SCREEN)
  end
  
end

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

-------------------------------------------------------------
Attik System              web  : http://www.attiksystem.ch
Philippe Lang             phone: +41 26 422 13 75
rte de la Fonderie 2      gsm  : +41 79 351 49 94
1700 Fribourg             pgp  : http://keyserver.pgp.com 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 476 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/3aabce75/attachment.bin>


More information about the fxruby-users mailing list