FXRuby: how to open a second window?


(Laurent Julliard) #1
This is a very, very basic question....

I’m using FXRuby (Thanks Lyle for the good work) and my toy application
creates a mainWindow with a Menu bar. On of this Menu item is in charge
of opening a second window (not a dialog box or something-box but a real
second window) and I couldn’t find how to do that…

My problem is basically that FXWindow.new expect a FXComposite object as
its first argument. I thought passing the root window of the running
application as the first argument to FXWindow.new would do (since
FXRootWindow inherits from FXComposite) but it fails miserably…

An example of how to open a second plain window in a FOX application
would be really welcome. I couldn;t find such an example in those
included with FXRuby.

I already feel stupid just thinking about the obvious answers that you
will all soon be posted :-/

Laurent


(Lyle Johnson) #2

I’m using FXRuby (Thanks Lyle for the good work) and my toy application
creates a mainWindow with a Menu bar. On of this Menu item is in charge
of opening a second window (not a dialog box or something-box but a real
second window) and I couldn’t find how to do that…

I’m not sure if I understand the question, but if you’re just wanting to
display a second main window you could do this:

 menuItem = FXMenuCommand.new(aMenu, "Show another main window")
 menuItem.connect(SEL_COMMAND) {
   mainWindow2 = FXMainWindow.new(app, "Main Window #2")
   mainWindow2.create
   mainWindow2.show
 }

In addition to dialog boxes (which you already know about), yet another
kind of top-level window is a popup, which is what we use for tooltips,
menu panes, etc.

My problem is basically that FXWindow.new expect a FXComposite object as
its first argument. I thought passing the root window of the running
application as the first argument to FXWindow.new would do (since
FXRootWindow inherits from FXComposite) but it fails miserably…

Yes. Although FXWindow is technically not an abstract class (i.e. you
can instantiate one of them), it’s really meant to serve as a base
class for more interesting kinds of windows :wink:

I already feel stupid just thinking about the obvious answers that you
will all soon be posted :-/

If it wasn’t obvious it wasn’t a stupid question. It doesn’t come up a
lot (or hasn’t yet, at any rate), but FOX does allow for multiple
top-level windows.

Hope this helps,

Lyle


(Laurent Julliard) #3

Lyle Johnson wrote:

I’m using FXRuby (Thanks Lyle for the good work) and my toy
application creates a mainWindow with a Menu bar. On of this Menu item
is in charge of opening a second window (not a dialog box or
something-box but a real second window) and I couldn’t find how to do
that…

I’m not sure if I understand the question, but if you’re just wanting to
display a second main window you could do this:

menuItem = FXMenuCommand.new(aMenu, "Show another main window")
menuItem.connect(SEL_COMMAND) {
  mainWindow2 = FXMainWindow.new(app, "Main Window #2")
  mainWindow2.create
  mainWindow2.show
}

Thanks for the suggestion. Jeroen told me that this is not supported in
FOX 1.0.x but will be in 1.2.0. I however tried to your approach with
FOX 1.0.11. I can create the second window ok but the problem is that
there is no way by which I can make the second window active. The focus
stays on the first one even when I use an explicit setFocus()

In addition to dialog boxes (which you already know about), yet another
kind of top-level window is a popup, which is what we use for tooltips,
menu panes, etc.

A Dialog box leads to a similar problem: if I attach it to the
application (which I understand should make it non-modal - the API doc
says so) then I can’t select the second window (dialog box) with the
mouse. And if I make it modal (execute) then it becomes the active
window but it doesn’t serve my purpose because I can no longer work
within my first window until I close the dialog box. And I want both of
them on screen at the same time.

So I’m really stuck here and I can;t believe there isn’t a way to have 2
windows open at the same time and simply go from one to the other with a
simple mouse click. If sbdy could give me a 10 lines sample code showing
two selectable windows at the same time may be that would help me a lot.

My last hope was to create a new type of window derived from FXTopWindow
as suggested
by Jeroen but for some reason this class doesn’t seem to exist in
FXRuby. Any
idea why Lyle?

Laurent


(Lyle Johnson) #4

My last hope was to create a new type of window derived from
FXTopWindow as suggested by Jeroen but for some reason this class

doesn't seem to exist in

FXRuby. Any idea why Lyle?

The class exists (as an abstract base class) but because it's
constructor was marked as "protected" in the SWIG interface file it
didn't get wrapped. So for all practical purposes you can't subclass
FXTopWindow in the current release of FXRuby. I think I can work around
this for the next release and I'll try to get that out ASAP.