Ralph Douglass
2007-Dec-10 01:48 UTC
[fxruby-users] deleting children and then adding new ones
Hi all! I''m having a small problem, which is probably really easy to deal with, but I''m just missing how to do it, and I haven''t had any luck looking in the docs or the examples. I''m trying to delete the contents of a frame (using removeChild), and then add new contents to that frame. Whenever I do this, it deletes stuff just fine, but then the new thing doesn''t show up. Here is a short example: require ''fox16'' include Fox app = FXApp.new() main = FXMainWindow.new(app, "Window") vf = FXVerticalFrame.new(main) button = FXButton.new(vf, "Old Button") button.connect(SEL_COMMAND) do vf.removeChild(button) FXButton.new(vf, "New Button") end app.create main.show() app.run Click the button... and then there''s nothing at all. Is there some sort of magic incantation I need to call to get the frame to redraw itself or something? I tried a few that looked like they did that from the docs, but no luck Thanks, Ralph -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20071209/1f6841a5/attachment.html
Lyle Johnson
2007-Dec-10 16:23 UTC
[fxruby-users] deleting children and then adding new ones
On 12/9/07, Ralph Douglass <ralph at grayskies.net> wrote:> I''m trying to delete the contents of a frame (using removeChild), and then > add new contents to that frame. Whenever I do this, it deletes stuff just > fine, but then the new thing doesn''t show up. Here is a short example: > > require ''fox16'' > > include Fox > app = FXApp.new() > main = FXMainWindow.new(app, "Window") > vf = FXVerticalFrame.new(main) > button = FXButton.new(vf, "Old Button") > button.connect (SEL_COMMAND) do > vf.removeChild(button) > FXButton.new(vf, "New Button") > end > > app.create > main.show() > app.run > > Click the button... and then there''s nothing at all. > > Is there some sort of magic incantation I need to call to get the frame to > redraw itself or something?Yes, you need to call create() on the button and then recalc() on the button''s parent: buttton.connect(SEL_COMMAND) do vf.removeChild(button) btn = FXButton.new(vf, "New Button") btn.create btn.recalc end Note that I''m not sure it''s a good idea to destroy an object while you''re executing a message handler for it (as in this example). What is it that you''re trying to accomplish by removing the old button and creating a new one? If you''re just wanting to change the button''s label (for example), you can just do: button.connect(SEL_COMMAND) do button.text = "New Button Text" end Hope this helps, Lyle
Ralph Douglass
2007-Dec-10 18:38 UTC
[fxruby-users] deleting children and then adding new ones
I''m working on the ui for a little video game. On the left in a map of the game''s galaxy, and on the right in a panel. When a planet on the left in clicked on, I want the panel on the right to change to display information and options for that planet. When a user clicks on a fleet of ships, I want it to change to display information and options for the fleet. Is there perhaps a better way to do this than destroying the contents of the frame on the right every time? Thanks, Ralph On 12/10/07, Lyle Johnson <lyle at lylejohnson.name> wrote:> > On 12/9/07, Ralph Douglass <ralph at grayskies.net> wrote: > > > I''m trying to delete the contents of a frame (using removeChild), and > then > > add new contents to that frame. Whenever I do this, it deletes stuff > just > > fine, but then the new thing doesn''t show up. Here is a short example: > > > > require ''fox16'' > > > > include Fox > > app = FXApp.new() > > main = FXMainWindow.new(app, "Window") > > vf = FXVerticalFrame.new(main) > > button = FXButton.new(vf, "Old Button") > > button.connect (SEL_COMMAND) do > > vf.removeChild(button) > > FXButton.new(vf, "New Button") > > end > > > > app.create > > main.show() > > app.run > > > > Click the button... and then there''s nothing at all. > > > > Is there some sort of magic incantation I need to call to get the frame > to > > redraw itself or something? > > Yes, you need to call create() on the button and then recalc() on the > button''s parent: > > buttton.connect(SEL_COMMAND) do > vf.removeChild(button) > btn = FXButton.new(vf, "New Button") > btn.create > btn.recalc > end > > Note that I''m not sure it''s a good idea to destroy an object while > you''re executing a message handler for it (as in this example). What > is it that you''re trying to accomplish by removing the old button and > creating a new one? If you''re just wanting to change the button''s > label (for example), you can just do: > > button.connect(SEL_COMMAND) do > button.text = "New Button Text" > end > > Hope this helps, > > Lyle > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- Ralph -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20071210/98b354f4/attachment-0001.html
Lyle Johnson
2007-Dec-10 19:06 UTC
[fxruby-users] deleting children and then adding new ones
On 12/10/07, Ralph Douglass <ralph at grayskies.net> wrote:> I''m working on the ui for a little video game. On the left in a map of the > game''s galaxy, and on the right in a panel. When a planet on the left in > clicked on, I want the panel on the right to change to display information > and options for that planet. When a user clicks on a fleet of ships, I want > it to change to display information and options for the fleet. > > Is there perhaps a better way to do this than destroying the contents of the > frame on the right every time?Is the information associated with a planet always the same set of widgets, just with different values? If so, I''d just update the widgets'' values whenever the user clicks on a new planet, e.g. planet_button.connect(SEL_COMMAND) do planet_name_label.text = planet.name planet_size_label.text = planet.size end Now, I''m assuming that you''re displaying completely different kinds of information when the user clicks on a fleet of ships, so you''d need to do something different in that case. One option would be to implement the right-hand side information panel as a switcher (FXSwitcher), with one page for "planet information", another page for "fleet information", etc. See the shutter.rb example for an idea of how you might do that. Hope this helps, Lyle
Ralph Douglass
2007-Dec-11 03:50 UTC
[fxruby-users] deleting children and then adding new ones
Thanks, the recalc and create worked really well. I saw the example of the FXSwitcher widget on the website, but thought it wasn''t really what I wanted at the time. I''ll give it a second look now. On 12/10/07, Lyle Johnson <lyle at lylejohnson.name> wrote:> > On 12/10/07, Ralph Douglass <ralph at grayskies.net> wrote: > > > I''m working on the ui for a little video game. On the left in a map of > the > > game''s galaxy, and on the right in a panel. When a planet on the left > in > > clicked on, I want the panel on the right to change to display > information > > and options for that planet. When a user clicks on a fleet of ships, I > want > > it to change to display information and options for the fleet. > > > > Is there perhaps a better way to do this than destroying the contents of > the > > frame on the right every time? > > Is the information associated with a planet always the same set of > widgets, just with different values? If so, I''d just update the > widgets'' values whenever the user clicks on a new planet, e.g. > > planet_button.connect(SEL_COMMAND) do > planet_name_label.text = planet.name > planet_size_label.text = planet.size > end > > Now, I''m assuming that you''re displaying completely different kinds of > information when the user clicks on a fleet of ships, so you''d need to > do something different in that case. One option would be to implement > the right-hand side information panel as a switcher (FXSwitcher), with > one page for "planet information", another page for "fleet > information", etc. See the shutter.rb example for an idea of how you > might do that. > > Hope this helps, > > Lyle > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- Ralph -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20071210/13eb7364/attachment.html
Jeroen van der Zijp
2007-Dec-11 04:48 UTC
[fxruby-users] deleting children and then adding new ones
On Monday 10 December 2007, Ralph Douglass wrote:> Thanks, the recalc and create worked really well. I saw the example of the > FXSwitcher widget on the website, but thought it wasn''t really what I wanted > at the time. I''ll give it a second look now.FXSwitcher is probably recommended for something like this; however, it is not forbidden to destroy windows in response to SEL_COMMAND callback from FXButton. But please note, many callback messages are generated in the middle of a user-transaction, and not at the end of one. In such cases, the widget is expected to exist upon return from the callback. We take great pains to ensure that for the SEL_COMMAND callback, no further references to the originating widgets are made. So its true that for *most* widgets, you are allowed to do anything in the SEL_COMMAND, including deleteing the originating widget. But I do suggest not to make a habit of it. - Jeroen -- +----------------------------------------------------------------------------+ | Copyright (C) 22:40 12/ 3/2007 Jeroen van der Zijp. All Rights Reserved. | +----------------------------------------------------------------------------+