#997 WindowMode.modeless?

lbertrand Mon 1 Mar 2010

For an example, I would like to show multiple windows, so I try to use the mode WindowMode.modeless but I have an exception raised (true for any value of the enum)...

This example:

using fwt
using gfx

class Windows
{
  static Void main()
  {
    Window
    {
      size = Size(200, 200)
      title = "WindowMode.modeless Test"
      mode = WindowMode.modeless
    }.open
  }
}

throws the following exception:

sys::ConstErr: fwt::Window
  fan.sys.Func$Indirect1.checkInCtor (Func.java:147)
  GDCWindows_0::Windows.main (/C:/Documents and Settings/bertranl/Desktop/Fantom/GDC.Examples/GDC.Windows.fan:9)
  fan.sys.FanObj.with (FanObj.java:155)
  fan.sys.FanObj.with (FanObj.java:146)
  GDCWindows_0::Windows.main (/C:/Documents and Settings/bertranl/Desktop/Fantom/GDC.Examples/GDC.Windows.fan:9)
  java.lang.reflect.Method.invoke (Unknown)
  fan.sys.Method.invoke (Method.java:536)
  fan.sys.Method$MethodFunc.callList (Method.java:182)
  fan.sys.Method.callList (Method.java:147)
  fanx.tools.Fan.callMain (Fan.java:135)
  fanx.tools.Fan.executeFile (Fan.java:88)
  fanx.tools.Fan.execute (Fan.java:34)
  fanx.tools.Fan.run (Fan.java:235)
  fanx.tools.Fan.main (Fan.java:273)

If I comment out the line mode = WindowMode.modeless the window is displayed correclty...

I must be missing something very obvious but as my background is really far from desktop development (a long time I haven't done Swing code), I have no clue... It must be possible to display multiple windows on the screen.

brian Mon 1 Mar 2010

The problem is actually very tricky. The constructor for Window is:

new make(Window? parent := null, |This|? f := null)

So that code is essentially calling:

Window(null, null).with { .... }

Which explains why you get the ConstErr. If you change it to the following then it will work:

Window(null)
{
  size = Size(200, 200)

Not sure how to easily fix that gotcha.

lbertrand Mon 1 Mar 2010

Many thanks...All is working - missed the constructor taking a first parameter of the parent window...

Next question is how do I display more than 1 window on the desktop? As soon as open is called it shows the window but do not return the hand to the script so will not show the next window...

Script:

using fwt
using gfx

class Windows
{
  static Void main()
  {
    Window(null)
    {
      size = Size(200, 200)
      title = "Window 1"
      mode = WindowMode.modeless
    }.open

    Window(null)
    {
      size = Size(200, 200)
      title = "Window 2"
      mode = WindowMode.modeless
    }.open
  }
}

I am sure I have been able to see some application being able to display multiple windows on the desktop without them having to be inside a window container... Is there a way to do it...

brian Mon 1 Mar 2010

Once you open the first window, the thread will block in the SWT event loop.

So additional windows will have to be launched on the event loop. Maybe use Desktop.callAsync

lbertrand Mon 1 Mar 2010

I tried but failed...

If I open all the windows using the Desktop.callAsync, it fails as the Main UI thread is not running...

So I need at least to open the 1st window in the script but then cannot call the Desktop.callAsync as the main thread is blocked in the SWT event loop...

I really don't see how to do this! Is there a way to initialize the Main UI loop without blocking the main thread, like a FWT object that do not display anything, so I can then use the Desktop.callAsync to open all my windows

andy Mon 1 Mar 2010

You would normally do that from the Window.onOpened callback from the primary window - but doesn't appear we expose that method (assuming SWT supports that concept).

brian Mon 1 Mar 2010

If you an actor in your application, then I'd have to your actor use callAsync.

Otherwise if you don't have any UI element which kick this off, you can do off one of the other window state change callbacks using a once method so it is just done at initialization time.

qualidafial Thu 4 Mar 2010

How about offering a field blockOnOpen (it could default to true), and exposing the event loop through the fwt::Desktop class?

I think SWT had the right idea when they exposed the event loop as a low-level API. It can be completely optional, but if necessary it's very helpful to be able to plug into it.

Login or Signup to reply.