Hi all, I''m trying to get text on to the screen in response to pressing a button. This code doesn''t work, and I don''t know why. My puts command says that the window is shown, but it''s not displayed. Also, it seems to me that there should be an easier way to get text on a screen in response to pressing a button. Any hints? Thanks! Marlene require ''fox16'' include Fox class Lookup < FXMainWindow def initialize(app) super(app, "Lookup window", :width=>400, :height=>600, :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) hearButton = FXButton.new(bframe, "Do you hear me?") yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X) yesLabel = FXLabel.new(yesWindow,"Yes") yesWindow.hide puts "window shown?" + yesWindow.shown?.to_s hearButton.connect(SEL_COMMAND) do |sender,sel, data| yesWindow.create yesWindow.show puts "pushed hear button" puts "window shown?" + yesWindow.shown?.to_s end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 FXApp.new do |app| Lookup.new(app) app.create app.run end end
fxruby-users-bounces at rubyforge.org wrote:> Hi all, > > I''m trying to get text on to the screen in response to pressing a > button. This code doesn''t work, and I don''t know why. My puts command > says that the window is shown, but it''s not displayed. > > Also, it seems to me that there should be an easier way to get text > on a screen in response to pressing a button. Any hints? Thanks! > > Marlene > > require ''fox16'' > include Fox > > class Lookup < FXMainWindow > def initialize(app) > super(app, "Lookup window", :width=>400, :height=>600, > :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) > bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) > hearButton = FXButton.new(bframe, "Do you hear me?") > yesWindow = FXHorizontalFrame.new(self, :opts => > FRAME_GROOVE|LAYOUT_FILL_X) > yesLabel = FXLabel.new(yesWindow,"Yes") > yesWindow.hide > puts "window shown?" + yesWindow.shown?.to_s > hearButton.connect(SEL_COMMAND) do |sender,sel, data| > yesWindow.create > yesWindow.show > puts "pushed hear button" > puts "window shown?" + yesWindow.shown?.to_s > end > end > > def create > super > show(PLACEMENT_SCREEN) > end > > end > > if __FILE__ == $0 > FXApp.new do |app| > Lookup.new(app) > app.create > app.run > end > end > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-usersHi, You needed a call to self.recalc... Best regards, Philippe Lang ------------ require ''fox16'' include Fox class Lookup < FXMainWindow def initialize(app) super(app, "Lookup window", :width=>400, :height=>600, :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) hearButton = FXButton.new(bframe, "Do you hear me?") yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X) yesLabel = FXLabel.new(yesWindow,"Yes") yesWindow.hide puts "window shown?" + yesWindow.shown?.to_s hearButton.connect(SEL_COMMAND) do |sender,sel, data| #yesWindow.create NOT NEEDED self.recalc yesWindow.show puts "pushed hear button" puts "window shown?" + yesWindow.shown?.to_s end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 FXApp.new do |app| Lookup.new(app) app.create app.run end end
fxruby-users-bounces at rubyforge.org wrote:> Thanks for your help! Why do I need the self.recalc?I have to say I don''t know exactly. I thought a self.repaint or self.update would be sufficient, since your frame is only hidden and then shown. As a first guess, I would have said that you need a recalc when you create controls "dynamically", and need to invalidate the window structure. But your example shows that I''m wrong! For sure, Lyle or Jeroen have the answer!> And do you have > a good source for me to read about this kind of thing so I don''t need > to keep asking "confused beginner" questions?Lyle has written a book: http://www.pragprog.com/titles/fxruby/fxruby Otherwise you have examples here: http://www.fxruby.org/doc/examples.html ... And the API reference: http://www.fxruby.org/doc/api/ Best regards, Philippe Lang
Thanks for your help! Why do I need the self.recalc? And do you have a good source for me to read about this kind of thing so I don''t need to keep asking "confused beginner" questions?
Thanks again for your input. I''ve read through Lyle''s book, which is where I''m trying to learn FXRuby from. It''s a great book, but I don''t see where there''s anything about using self.recalc. While trying to solve this problem, I also tried to create the window in the button block, and it didn''t work. I just now tried adding your self.recalc code, and it still doesn''t show. Clearly I''m missing something that should be obvious! class Lookup < FXMainWindow def initialize(app) super(app, "Lookup window", :width=>400, :height=>600, :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) hearButton = FXButton.new(bframe, "Do you hear me?") hearButton.connect(SEL_COMMAND) do |sender,sel, data| @yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X) yesLabel = FXLabel.new(@yesWindow,"Yes") self.recalc @yesWindow.show puts "pushed hear button" puts "window shown? " + @yesWindow.shown?.to_s end end
fxruby-users-bounces at rubyforge.org wrote:> Thanks again for your input. I''ve read through Lyle''s book, which is > where I''m trying to learn FXRuby from. It''s a great book, but I don''t > see where there''s anything about using self.recalc. > > While trying to solve this problem, I also tried to create the window > in the button block, and it didn''t work. I just now tried adding your > self.recalc code, and it still doesn''t show. Clearly I''m missing > something that should be obvious! > > class Lookup < FXMainWindow > def initialize(app) > super(app, "Lookup window", :width=>400, :height=>600, > :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) > bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) > hearButton = FXButton.new(bframe, "Do you hear me?") > hearButton.connect(SEL_COMMAND) do |sender,sel, data| > @yesWindow = FXHorizontalFrame.new(self, :opts => > FRAME_GROOVE|LAYOUT_FILL_X) > yesLabel = FXLabel.new(@yesWindow,"Yes") > self.recalc > @yesWindow.show > puts "pushed hear button" > puts "window shown? " + @yesWindow.shown?.to_s > end > endWhen you create controls dynamically, don''t forget to call "create", like this: require ''fox16'' include Fox class Lookup < FXMainWindow def initialize(app) super(app, "Lookup window", :width=>400, :height=>600, :opts => DECOR_ALL|LAYOUT_FILL_X|LAYOUT_FILL_Y) bframe = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X) hearButton = FXButton.new(bframe, "Do you hear me?") hearButton.connect(SEL_COMMAND) do |sender,sel, data| @yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X) yesLabel = FXLabel.new(@yesWindow,"Yes") @yesWindow.create self.recalc @yesWindow.show puts "pushed hear button" puts "window shown? " + @yesWindow.shown?.to_s end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 FXApp.new do |app| Lookup.new(app) app.create app.run end End Best regards, Philippe Lang Attik System
That fixed this problem - your help has been invaluable. All of this is still rather confusing. So now I tried to layout the yesWindow on the bottom of the screen with a LAYOUT_BOTTOM when I define the yesWindow, but it still appears immediately under my buttons. Any clues what''s happening there? hearButton.connect(SEL_COMMAND) do |sender,sel, data| @yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_BOTTOM) yesLabel = FXLabel.new(@yesWindow,"Yes") I sure appreciate your time and help on this. Marlene Phillips
On Jun 24, 2009, at 3:05 AM, Marlene Phillips wrote:> All of this is still rather confusing. So now I tried to layout the > yesWindow on the bottom of the screen with a LAYOUT_BOTTOM when I > define > the yesWindow, but it still appears immediately under my buttons. Any > clues what''s happening there?Replace LAYOUT_BOTTOM with LAYOUT_SIDE_BOTTOM: @yesWindow = FXHorizontalFrame.new(self, :opts => FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_SIDE_BOTTOM) Hope this helps, Lyle
Again, thanks Lyle for this help, it solved the problem. Is there somewhere I can find more details on what each of these hints in the API means? For example, I''m afraid I don''t know the distinction between "Stick on bottom" (LAYOUT_BOTTOM) and "Pack on bottom" (LAYOUT_SIDE_BOTTOM). And even though I now know that I need to pack the window on the bottom, when I try to read the documentation and see something like "Stick on bottom" I don''t know that I should be looking for anything else. I''d love any info on a reference to deciphering some of the terser explanations here. Thanks!
On Jun 24, 2009, at 3:26 PM, Marlene Phillips wrote:> Again, thanks Lyle for this help, it solved the problem. Is there > somewhere I can find more details on what each of these hints in the > API > means? For example, I''m afraid I don''t know the distinction between > "Stick on bottom" (LAYOUT_BOTTOM) and "Pack on bottom" > (LAYOUT_SIDE_BOTTOM). And even though I now know that > I need to pack the window on the bottom, when I try to read the > documentation and see something like "Stick on bottom" I don''t know > that > I should be looking for anything else. I''d love any info on a > reference to deciphering some of > the terser explanations here.To tell you the truth, it''s unclear to me (from a cursory examination of the FOX source code) exactly what is the distinction between LAYOUT_BOTTOM and LAYOUT_SIDE_BOTTOM (and other similar pairs of layout hints). There is perhaps some better explanation at the FOX home page: http://www.fox-toolkit.org/ but that web site is not responding at this time. Maybe Jeroen will chime in with some illuminating words... -- Lyle