Dynamically changing widgets in FXRuby

I am attempting to learn FXRuby, and I’m running into a small problem,
and I’m not sure if what I’m trying to do is inappropriate in FOX, or
if it’s an FXRuby thing, or if I’m just missing the big picture.

I am trying to create an application where the actual layout of the widgets
on the screen is not known at “initialize” time but rather is dynamically
updated based on the things that the user does:

If I call the “draw_display” method from within initialize, then the program
draws everything as it should be. But if I select the File/Open menu, which
calls draw_display, it does not draw the FXTreeList on my screen. Can someone
help me understand what I am failing to understand?

I would not have asked this question here, but I ransacked all of the examples
that I could with FXRuby, and none of them seem to do the precise thing I am
trying to do here, which makes me wonder if maybe I’m not supposed to be doing
this kind of thing in FOX…

Graciously,
Jacob

#— snip here —#
require 'fox’
include Fox
class MainWindow < FXMainWindow
def draw_display
@tree = FXTreeList.new(@group1, 0, nil, 0,
(FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y|
LAYOUT_TOP|LAYOUT_RIGHT|TREELIST_SHOWS_LINES|
TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|
TREELIST_EXTENDEDSELECT))
@one = @tree.addItemLast(nil, “One”, nil, nil)
@two = @tree.addItemLast(nil, “Two”, nil, nil)
@three = @tree.addItemLast(nil, “Three”, nil, nil)
1.upto(30) {|x|
@tree.addItemLast(@one, “Item 1-#{x}”, nil, nil)
}
end

def initialize(app)
super(app, “Main Window”, nil, nil, DECOR_ALL, 0, 0, 900, 600)

filemenu = FXMenuPane.new(self)
FXMenuCommand.new(filemenu, "Open\tCtl-O").connect(SEL_COMMAND) {
  draw_display
}
menubar = FXMenubar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
FXMenuTitle.new(menubar, "&File", nil, filemenu)

@splitter = FXSplitter.new(self, (LAYOUT_SIDE_TOP|LAYOUT_FILL_X|
    LAYOUT_FILL_Y|SPLITTER_REVERSED|SPLITTER_TRACKING))
@group1 = FXVerticalFrame.new(@splitter,
    FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y,
    0,0,0,0, 0,0,0,0)

end

def create
super
show(PLACEMENT_SCREEN)
end
end

if FILE == $0
$application = FXApp.new(“Main”, “FoxTest”)
$application.init(ARGV)
MainWindow.new($application)
$application.create
$application.run
end
#— snip here —#

···


jnews@epicsol.org Violations of McQ flagrantly “sponsored” by…

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----

#— snip here —#
require ‘fox’
include Fox
class MainWindow < FXMainWindow
def draw_display
@tree = FXTreeList.new(@group1, 0, nil, 0,
(FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y|
LAYOUT_TOP|LAYOUT_RIGHT|TREELIST_SHOWS_LINES|
TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|
TREELIST_EXTENDEDSELECT))

  @tree.create
@one = @tree.addItemLast(nil, "One", nil, nil)
@two = @tree.addItemLast(nil, "Two", nil, nil)
@three = @tree.addItemLast(nil, "Three", nil, nil)
1.upto(30) {|x|
    @tree.addItemLast(@one, "Item 1-#{x}", nil, nil)
}

end

Try that. Fox widgets need to be explicitly ‘created’ when they are added after the
application.create call. And beware calling your ‘draw_display’ from initialize now. The widget
will be created in the first pass, then throw an error in the second pass (when it tries to create
it again).

Jason Persampieri wrote:

And beware calling your ‘draw_display’ from initialize now. The widget
will be created in the first pass, then throw an error in the second pass (when it tries to create
it again).

Actually, it’s the other way around. If you put the call to @tree.create
in your ‘draw_display’ method and then call draw_display directly from
MainWindow#initialize, the sequence of events is:

  1. MainWindow#initialize instantiates (but does not
    create) a number of widgets, then calls draw_display.

  2. MainWindow#draw_display instantiates the tree list
    (@tree) and tries to call create() on it. This fails
    because you have not yet called FXApp#create.

– Lyle

Example at hand:
#— snip here —#
require ‘fox’
include Fox
class MainWindow < FXMainWindow
def draw_display
@tree = FXTreeList.new([snip])
@tree.create
@one = @tree.addItemLast([snip])
[snip]

Try that. [@tree.create] Fox widgets need to be explicitly ‘created’
when they are added after the application.create call. And beware
calling your ‘draw_display’ from initialize now. The widget will be
created in the first pass, then throw an error in the second pass (when
it tries to create it again).

Yes! Thank you so very much! What I was missing was the ‘create’ method.
Now that I know that is the “magic” function which makes things appear on
the screen and see that there are indeed a couple of examples in FXRuby
that show how this works, but I overlooked them because I did not understand.

But thank you very much for helping me. I now can do what I had hoped to
do in FXRuby, which is create a user interface on the fly based on input
files known only at runtime! =)

-Jacob

···

Jason Persampieri jason@persampieri.net wrote:

jnews@epicsol.org Violations of McQ flagrantly “sponsored” by…

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----