Hello all, Running this on an Intel Mac OSX 10.4.8 ruby 1.8.4 (2005-12-24) [i686-darwin] wxruby2-preview (0.0.37) using zshell I''m having a heck of a time setting up a GUI with a differing number of widgets per row, resulting in a differing number or widgets per column. At first I tried to simply do something like the following: class CharacterInfoPanel < Wx::Panel def initialize(parent) super(parent) sizer = Wx::BoxSizer.new(Wx::VERTICAL) set_sizer(sizer) row = Wx::Panel.new(self,-1) row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) row.set_sizer(row_sizer) row_sizer.add(Wx::StaticText.new(self, -1, "Character Name")) row_sizer.add(Wx::Panel.new(self,-1, Wx::DEFAULT_POSITION, Wx::Size.new (10,1))) row_sizer.add(Wx::StaticText.new(self, -1, "Player Name")) sizer.add(row_sizer) row = Wx::Panel.new(self,-1) row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) row.set_sizer(row_sizer) character_name_text = Wx::TextCtrl.new(self, -1) row_sizer.add(character_name_text) player_name_text = Wx::TextCtrl.new(self, -1) row_sizer.add(player_name_text) sizer.add(row_sizer) end (I know adding the rows is ugly, but I''m not bothering ''ruby-izing'' this until I figure this crap out.) This certainly produces the results I want, however when I quit the application I seem to be getting some rather strange errors. 1) gm_aid.rb:35: [BUG] Bus Error ruby 1.8.4 (2005-12-24) [i686-darwin] zsh: abort ruby gm_aid.rb 2) zsh: illegal hardware instruction ruby gm_aid.rb Okay so then I decided to take a different approach, to see if things would work. I tried this without adding sizers to other sizers like so: class CharacterInfoPanel < Wx::Panel def initialize(parent) super(parent) sizer = Wx::BoxSizer.new(Wx::VERTICAL) set_sizer(sizer) row = Wx::Panel.new(self,-1) row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) row.set_sizer(row_sizer) row_sizer.add(Wx::StaticText.new(self, -1, "Character Name")) row_sizer.add(Wx::Panel.new(self,-1, Wx::DEFAULT_POSITION, Wx::Size.new (10,1))) row_sizer.add(Wx::StaticText.new(self, -1, "Player Name")) sizer.add(row) row = Wx::Panel.new(self,-1) row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) row.set_sizer(row_sizer) character_name_text = Wx::TextCtrl.new(self, -1) row_sizer.add(character_name_text) player_name_text = Wx::TextCtrl.new(self, -1) row_sizer.add(player_name_text) sizer.add(row) end Am I crazy to think this should work? Well, so when I quit the app I get no errors...however, it certainly doesn''t set up my world like I expect. It seems when you do this, whenever you add a row, it simply clobbers the old row. So my static texts aren''t even showing up, just my text controls...in the first row. It does seem to add a second row, but the row is completely blank. So if I were to copy setting up the two rows and paste it a few times, I''d still only wind up with one row with any actual controls in it...and then several blank rows. Anyone have any ideas here? This is driving me up the wall...and down the other side. _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
Chris Thiel
2007-Jan-22 05:18 UTC
[Wxruby-users] Adding sizers to other sizers doesn''t work
On a side note, just upgraded to wxruby2-preview 0.0.38 (i686-darwin8.4.1) and still getting the same behavior. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20070121/1d6119e3/attachment.html
Alex Fenton
2007-Jan-22 08:51 UTC
[Wxruby-users] Adding sizers to other sizers doesn''t work
Hi Chris> I''m having a heck of a time setting up a GUI with a differing number > of widgets per row, resulting in a differing number or widgets per > column.Yep, sizers are flexible but a bit tricky.> At first I tried to simply do something like the following:You''re very close, but you''ve added extra panels into the hierarchy where they''re not needed. If you''re nesting sizers, just add the subordinate (horiz) sizer directly to the parent (vert) one. The sub sizer doesn''t need to be associated with a Wx::Window.> class CharacterInfoPanel < Wx::Panel > def initialize(parent) > super(parent) > sizer = Wx::BoxSizer.new(Wx::VERTICAL) > set_sizer(sizer) > > row = Wx::Panel.new(self,-1)delete this> row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) > row.set_sizer(row_sizer)and this> row_sizer.add(Wx::StaticText.new(self, -1, "Character Name")) > row_sizer.add(Wx:: Panel.new(self,-1, Wx::DEFAULT_POSITION, > Wx::Size.new(10,1))) > row_sizer.add(Wx::StaticText.new(self, -1, "Player Name")) > sizer.add(row_sizer) > > row = Wx::Panel.new(self,-1)and this> row_sizer = Wx:: BoxSizer.new(Wx::HORIZONTAL) > row.set_sizer(row_sizer)and this> character_name_text = Wx::TextCtrl.new(self, -1) > row_sizer.add(character_name_text) > player_name_text = Wx::TextCtrl.new(self, -1) > row_sizer.add(player_name_text) > sizer.add(row_sizer) > endWith those four lines removed it works for me. It doesn''t segfault for me on exit using 0.0.38 - there are some similar other bugs now fixed in SVN head causing crash-on-exit so please do report these. Note that to space out widgets within sizers, you can give a numeric fourth argument to Sizer#add to put pixel spacing around members, or alternately use Sizer#insert_spacer.> (I know adding the rows is ugly, but I''m not bothering ''ruby-izing'' > this until I figure this crap out.)Yep. You might want to take a look at wxSugar which has a specific module for making working with nested sizers less verbose: panel = Wx::Panel.new(self) panel.arrange_horizontally(:padding => 4) do panel.add(Wx::StaticText[:label => ''Character Name'']) panel.add(Wx::StaticText[:label => ''Player Name'']) end panel.arrange_horizontally(:padding => 4) do player_name_txt = panel.add(Wx::TextCtrl) char_name_txt = panel.add(Wx::TextCtrl) end hth alex
Chris Thiel
2007-Jan-25 06:58 UTC
[Wxruby-users] Adding sizers to other sizers doesn''t work
Alex, Thanks a bunch...works like a charm now. WxSugar is rockin'' like Dokken too. So what''s your advice for setting up a GUI with several widgets spanning more than one row or column? Always struggled with this layout in Java, seems as though I''m destined to struggle with it in Ruby as well. Anyhow, thanks for the advice thus far. Chris On 1/22/07, Alex Fenton <alex at pressure.to> wrote:> > Hi Chris > > > > I''m having a heck of a time setting up a GUI with a differing number > > of widgets per row, resulting in a differing number or widgets per > > column. > Yep, sizers are flexible but a bit tricky. > > At first I tried to simply do something like the following: > You''re very close, but you''ve added extra panels into the hierarchy > where they''re not needed. If you''re nesting sizers, just add the > subordinate (horiz) sizer directly to the parent (vert) one. The sub > sizer doesn''t need to be associated with a Wx::Window. > > class CharacterInfoPanel < Wx::Panel > > def initialize(parent) > > super(parent) > > sizer = Wx::BoxSizer.new(Wx::VERTICAL) > > set_sizer(sizer) > > > > row = Wx::Panel.new(self,-1) > delete this > > row_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL) > > row.set_sizer(row_sizer) > and this > > row_sizer.add(Wx::StaticText.new(self, -1, "Character Name")) > > row_sizer.add(Wx:: Panel.new(self,-1, Wx::DEFAULT_POSITION, > > Wx::Size.new(10,1))) > > row_sizer.add(Wx::StaticText.new(self, -1, "Player Name")) > > sizer.add(row_sizer) > > > > row = Wx::Panel.new(self,-1) > and this > > row_sizer = Wx:: BoxSizer.new(Wx::HORIZONTAL) > > row.set_sizer(row_sizer) > and this > > character_name_text = Wx::TextCtrl.new(self, -1) > > row_sizer.add(character_name_text) > > player_name_text = Wx::TextCtrl.new(self, -1) > > row_sizer.add(player_name_text) > > sizer.add(row_sizer) > > end > With those four lines removed it works for me. > > It doesn''t segfault for me on exit using 0.0.38 - there are some similar > other bugs now fixed in SVN head causing crash-on-exit so please do > report these. > > Note that to space out widgets within sizers, you can give a numeric > fourth argument to Sizer#add to put pixel spacing around members, or > alternately use Sizer#insert_spacer. > > (I know adding the rows is ugly, but I''m not bothering ''ruby-izing'' > > this until I figure this crap out.) > Yep. You might want to take a look at wxSugar which has a specific > module for making working with nested sizers less verbose: > > panel = Wx::Panel.new(self) > > panel.arrange_horizontally(:padding => 4) do > panel.add(Wx::StaticText[:label => ''Character Name'']) > panel.add(Wx::StaticText[:label => ''Player Name'']) > end > > panel.arrange_horizontally(:padding => 4) do > player_name_txt = panel.add(Wx::TextCtrl) > char_name_txt = panel.add(Wx::TextCtrl) > end > > hth > alex > > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20070124/a89703c0/attachment-0001.html
Alex Fenton
2007-Jan-25 18:15 UTC
[Wxruby-users] Adding sizers to other sizers doesn''t work
Chris Thiel wrote:> So what''s your advice for setting up a GUI with several widgets > spanning more than one row or column?You can nest sizers containing widgets to any depth you like, and that will let you create most ''spanning'' type layouts. Just With wxSugar: arrange_horizontally do # a single long widget here, spanning two columns end arrange_horizontally do # a half-width widget # another half-width widget end Use the :proportion argument to add to tell widgets to grow and shrink as the container grows and shrinks. See also: http://rubyforge.org/pipermail/wxruby-users/2006-February/001902.html> Always struggled with this layout in Java, seems as though I''m > destined to struggle with it in Ruby as well.I wouldn''t be so pessimistic - this is fairly straightforward once you''ve got the hang of it. There''s also GridBagSizer which isn''t yet available in wxruby, but I expect we can add it to an upcoming release. alex