Beginner Q: can't get window to show in response to button press

View: New views
3 Messages — Rating Filter:   Alert me  

Beginner Q: can't get window to show in response to button press

by Marlene Phillips :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to get text on to the screen in response to pressing a
button.  My puts command says that the window is shown, but it's not displayed.

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 #returns false
    hearButton.connect(SEL_COMMAND) do |sender,sel, data|
      yesWindow.show #NOT DISPLAYED. WHY?
      puts "pushed hear button"
      puts "window shown?" + yesWindow.shown?.to_s # returns true
    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

Sorry for the repost, I realized my title on the last one was not helpful.




_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Re: Beginner Q: can't get window to show in response to button press

by Lyle Johnson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jun 24, 2009, at 1:22 AM, Marlene Phillips wrote:

> I'm trying to get text on to the screen in response to pressing a
> button.  My puts command says that the window is shown, but it's not  
> displayed.

The problem is that merely calling show() on a widget (in this case,  
the horizontal frame "yesWindow") doesn't mark the parent window's  
layout as dirty, and so it doesn't know that it needs to repaint its  
contents. The easiest way to fix this is to just add a call to  
recalc() after the call to show(), e.g.

        hearButton.connect(SEL_COMMAND) do
                yesWindow.show
                yesWindow.recalc
        end

This topic is discussed in detail in Chapter 7 of the FXRuby book.

Hope this helps,

Lyle

---
"FXRuby: Create Lean and Mean GUIs with Ruby"
Now available from the Pragmatic Bookshelf!
http://www.pragprog.com/titles/fxruby





_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Re: Beginner Q: can't get window to show in response to button press

by Marlene Phillips :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Lyle,  Thanks for both the help and the explanation of what's happening.
I'm learning to do GUI programming just from your book,
which I'm really appreciating. It's so full of information, though, that
I often feel a bit like I'm trying to take a sip from a fire hose!

Marlene
_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users