Armin Armbruster
2008-Nov-21 21:59 UTC
[fxruby-users] Dynamic generation of a (sub) layout
Hi, first of all - I''m relatively unexpierienced with GUI programming in general and with FXRuby in particular. I''ve managed to write a little FXRuby app that animates some data I''ve collected. I made really good progress for a while, but now I''m stuck with the following problem. My data is read from file and can have a varying number of elements, depending on the file. I want to be able to turn on and off each of the elements individually by means of check-buttons. I therefore created a frame that contains a matrix of check-buttons, one for each element. This frame therefore has to be recreated every time a new file gets loaded. Below is a simplified version of what I''ve been trying to do. At the moment the layout works fine the first time around (currently I''ve hard-coded to load a specific file at startup, this will change later). However when I try to open another file, the content of @selectUVFrame disappears - nothing is displayed. I''ve inspected the children of @selectUVFrame and they all seem to be there, except I can''t see them. If I leave out the first line ( @selectUVFrame.each_child{|c| @selectUVFrame.removeChild(c)}) the list of children of @selectUVFrame grows, but again I can''t see the new ones (and the layout get''s corrupted, too). I seem to miss some basic understanding here and couldn''t find any hint of what I''m doing wrong. Thanks for any help, Armin @selectUVFrame is of type FXVerticalFrame and is itself a child of another frame. def generateUVSelectors @selectUVFrame.each_child{|c| @selectUVFrame.removeChild(c)} FXButton.new(@selectUVFrame, "&Clear All", nil, nil, 0,).connect(SEL_COMMAND){ @selectedUVs.each{|cb| cb.setCheck(false)} drawScene } FXButton.new(@selectUVFrame, "&Set All", nil, nil, 0).connect(SEL_COMMAND){ @selectedUVs.each{|cb| cb.setCheck(true)} drawScene } selectMatrix = FXMatrix.new(@selectUVFrame, 4, MATRIX_BY_COLUMNS) @selectedUVs = [] uvs.length.times{|i| @selectedUVs << FXCheckButton.new(selectMatrix, i.to_s, nil, 0){ |cb| cb.setCheck(true) } @selectedUVs[-1].connect(SEL_COMMAND, method(:onSelectUV)) } @selectUVFrame.recalc end -- View this message in context: http://www.nabble.com/Dynamic-generation-of-a-%28sub%29-layout-tp20630230p20630230.html Sent from the FXRuby Users mailing list archive at Nabble.com.
Armin Armbruster
2008-Nov-22 04:34 UTC
[fxruby-users] Dynamic generation of a (sub) layout
Hi again, after digging a bit deeper I found the missing link here: http://www.nabble.com/deleting-children-and-then-adding-new-ones-to14247201.html#a14256259 The problem was that I didn''t call create on the newly created buttons. I''ve modified my code as shown below and this seems to work. Note however that I had to add an additional variable @windowIsLive that''s initialized to false at the start and gets set to true after the show command in my window-class''s create function. Is there a more elegant way to handle this (for example by querying the @selectUVFrame''s status)? Thanks, Armin def generateUVSelectors @selectUVFrame.each_child{|c| @selectUVFrame.removeChild(c)} b1 = FXButton.new(@selectUVFrame, "&Clear All", nil, nil, 0,) b1.connect(SEL_COMMAND){ @selectedUVs.each{|cb| cb.setCheck(false)} drawScene } b1.create if @windowIsLive b2 = FXButton.new(@selectUVFrame, "&Set All", nil, nil, 0) b2.connect(SEL_COMMAND){ @selectedUVs.each{|cb| cb.setCheck(true)} drawScene } b2.create if @windowIsLive selectMatrix = FXMatrix.new(@selectUVFrame, 4, MATRIX_BY_COLUMNS) selectMatrix.create if @windowIsLive @selectedUVs = [] uvs.length.times{|i| @selectedUVs << FXCheckButton.new(selectMatrix, i.to_s, nil, 0){ |cb| cb.setCheck(true) } @selectedUVs[-1].connect(SEL_COMMAND, method(:onSelectUV)) @selectedUVs[-1].create if @windowIsLive } @selectUVFrame.recalc end -- View this message in context: http://www.nabble.com/Dynamic-generation-of-a-%28sub%29-layout-tp20630230p20633412.html Sent from the FXRuby Users mailing list archive at Nabble.com.
On Fri, Nov 21, 2008 at 10:34 PM, Armin Armbruster <aarmbruster at ndigital.com> wrote:> Is there a more elegant way to handle this (for example by querying the @selectUVFrame''s status)?@selectUVFrame.created? should return true if it has already been created. Hope this helps, Lyle
On Mon, Nov 24, 2008 at 1:12 PM, <aarmbruster at ndigital.com> wrote:> I''ve been on ruby forum (www.ruby-forum.com) for a few years now and I actually tried to get into FXRuby a few years back... > Only recently did I find the Nabble forums which are obviously much more active, at least when it comes to FXRuby. > Why are there two forums rather than one?Armin, I don''t manage any "forums" associated with FXRuby. There is an fxruby-users mailing list, information about which can be found on this page: http://www.fxruby.org/community.html The fxruby-users mailing list is the *only* one that I monitor regularly (well, that and foxgui-users). I also try to respond when someone asks an FXRuby-related question on the ruby-talk mailing list, but I don''t always catch those. Web sites like nabble.com and ruby-forum.com are mirrors, of a sort, for the fxruby-users mailing list (and other mailing lists), but I don''t have anything to do with those sites. If ruby-forum.com is for some reason out of sync with this mailing list, you must take that up with whoever''s in charge of that web site. Hope this helps, Lyle