[fxruby-users] Adding / Deleting controls dynamically

Joey Kinsella jkinsella at ancillaryservices.com
Thu Apr 15 13:41:42 EDT 2010


Pretty close...

Try changing the following code:

     dynamic_frame.each_child do |child|
       child.destroy
     end

to:
     dynamic_frame.each_child do |child|
       dynamic_frame.removeChild(child)
     end

Seems to work.

On Thu, Apr 15, 2010 at 3:31 AM, Philippe Lang <philippe.lang at attiksystem.ch
> wrote:

> 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
>
>
>
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
>

--
If you are not the intended recipient, you are hereby notified
that any dissemination, distribution, copying or other use of
this communication is strictly prohibited.  If you have
received this communication in error, please notify us
immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/d37fbac3/attachment-0001.html>


More information about the fxruby-users mailing list