Hi, all - Is it possible to resize the main window on the fly? I want to default to an 800x600 window but give the user an option to resize to 1024. This approach didn''t work: class MyWindow < FXMainWindow def initialize( app ) #... @mainWindowWidth = 800 # Build the overall Application GUI # --------------------------------- super( app, " MyWindow ", :width => @mainWindowWidth, :height => 600, :vSpacing => 0 ) #... winWidth = FXListBox.new( blk1, :opts => LISTBOX_NORMAL ) winWidth.appendItem("800") winWidth.appendItem("1024") winWidth.connect( SEL_COMMAND ) do | sender, sel, data | @mainWindowWidth = data.to_i app.forceRefresh end end end #... if __FILE__ == $0 FXApp.new do | app | FXToolTip.new( app ) gui = MyWindow.new( app ) app.create app.run end end My fallback is to save to a file and load the value on the next start, but is that necessary? Another question, is this discussion list archived and visible anywhere? Lyle, your time is better spent coding than answering the same questions more than once. :))) -- :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081106/67a40b38/attachment.html>
Em Qui, 2008-11-06 ?s 12:01 -0600, Don Wilde escreveu:> Hi, all - > > Is it possible to resize the main window on the fly? I want to default > to an 800x600 window but give the user an option to resize to 1024. > > This approach didn''t work: > > class MyWindow < FXMainWindow > def initialize( app ) > #... > > @mainWindowWidth = 800 > > # Build the overall Application GUI > # --------------------------------- > super( app, > " MyWindow ", > :width => @mainWindowWidth, :height => 600, :vSpacing => > 0 ) > #... > winWidth = FXListBox.new( blk1, :opts => LISTBOX_NORMAL ) > winWidth.appendItem("800") > winWidth.appendItem("1024") > winWidth.connect( SEL_COMMAND ) do | sender, sel, data | > @mainWindowWidth = data.to_i > app.forceRefresh > end > end > end > #...When you say @mainWindowWidth = data.to_i you''re just assigning variable @mainWindowWidth a new value. It has nothing to do with the application''s main window''s width. Instead, try: winWidth.connect( SEL_COMMAND ) do | sender, sel, data | resize(data.to_i, height) end Hope this helps. -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I ------ contatos: email: angico at angico.org skype: an.gi.co ------
On Thu, Nov 6, 2008 at 1:53 PM, angico <angico at angico.org> wrote:> Em Qui, 2008-11-06 ?s 12:01 -0600, Don Wilde escreveu: > > Hi, all - > > > > Is it possible to resize the main window on the fly? I want to default > > to an 800x600 window but give the user an option to resize to 1024. > > > > This approach didn''t work: > > >[snip] When you say @mainWindowWidth = data.to_i you''re just assigning variable> @mainWindowWidth a new value. It has nothing to do with the > application''s main window''s width. > > Instead, try: > > winWidth.connect( SEL_COMMAND ) do | sender, sel, data | > resize(data.to_i, height) > end > > > Hope this helps.Hi, Angico - You definitely put me on the right track. One further refinement necessary, for the record. FXListBox returns a zero-based index into the list, not the text. FXComboBox (according to Lyle) can be inspected with sender.text, but FXListBox is a bit more primitive. My working solution, retaining the variable so I can intelligently size and position things: availWinWidths = Array["800", "1024"] winWidth = FXListBox.new( blk1, :opts => LISTBOX_NORMAL ) availWinWidths.each { | w | winWidth.appendItem( w ) } winWidth.connect( SEL_COMMAND ) do | sender, sel, data | wSel = availWinWidths[ data.to_i ] @mainWindowWidth = wSel.to_i resize(@mainWindowWidth, 600 ) end It works marvelously well. Thank you for the big nudge in the right direction! -- :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081106/04d88080/attachment.html>
Em Qui, 2008-11-06 ?s 20:19 -0600, Don Wilde escreveu:> > Hi, Angico - > > > You definitely put me on the right track. > > One further refinement necessary, for the record. > > FXListBox returns a zero-based index into the list, not the text. > FXComboBox (according to Lyle) can be inspected with sender.text, but > FXListBox is a bit more primitive. > > > My working solution, retaining the variable so I can intelligently > size and position things: > > availWinWidths = Array["800", "1024"] > winWidth = FXListBox.new( blk1, :opts => LISTBOX_NORMAL ) > availWinWidths.each { | w | winWidth.appendItem( w ) } > winWidth.connect( SEL_COMMAND ) do | sender, sel, data | > wSel = availWinWidths[ data.to_i ] > @mainWindowWidth = wSel.to_i > resize(@mainWindowWidth, 600 ) > end > > It works marvelously well. Thank you for the big nudge in the right > direction! >I don''t get the point you insist in using that @mainWindowWidth, when you could just use width. On the other hand, you could simplify the whole above to the following: ### winWidth = FXListBox.new(blk1, :opts => LISTBOX_NORMAL) [800, 1024].each { |w| winWidth.appendItem(w) } winWindth.connect(SEL_COMMAND) do |sender, selector, data| resize(winWidth.getItemText.to_i, height) end ### This could save you some typing and looks (at least to me) more readable. Here "height" is actually a method from FXWindow, which returns the current height of this window''s instance. The same is true for "width", so you wouldn''t need to store the window''s current width in an external variable. Regards, -- angico ------ home page: www.angico.org Gnu/Linux, FLOSS, Espiritismo, e eu por mim mesmo 8^I ------ contatos: email: angico at angico.org skype: an.gi.co ------
[snip]> > > I don''t get the point you insist in using that @mainWindowWidth, when > you could just use width. > > On the other hand, you could simplify the whole above to the following: > > ### > > winWidth = FXListBox.new(blk1, :opts => LISTBOX_NORMAL) > [800, 1024].each { |w| winWidth.appendItem(w) } > winWindth.connect(SEL_COMMAND) do |sender, selector, data| > resize(winWidth.getItemText.to_i, height) > end > > ### > > This could save you some typing and looks (at least to me) more > readable. > > Here "height" is actually a method from FXWindow, which returns the > current height of this window''s instance. The same is true for "width", > so you wouldn''t need to store the window''s current width in an external > variable. >More good advice. I hadn''t thought to ask the Window for its size, and getItemText is much preferable to the external array. It took a few more type conversions to work, but still is much less code than my earlier solution. ### winWidth = FXListBox.new(blk1, :opts => LISTBOX_NORMAL) ["800", "1024"].each { |w| winWidth.appendItem( w ) } winWidth.connect(SEL_COMMAND) do |sender, selector, data| resize(winWidth.getItemText( data.to_i ).to_i, height) end ### Again, thanks for the suggestions! -- :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20081107/7177da7d/attachment-0001.html>