comp.lang.ada
 help / color / mirror / Atom feed
* Launching Popup Windows in Gnoga
@ 2014-10-20 12:56 Jeremiah
  2014-10-20 13:38 ` David Botton
  2014-10-20 15:22 ` David Botton
  0 siblings, 2 replies; 16+ messages in thread
From: Jeremiah @ 2014-10-20 12:56 UTC (permalink / raw)


I've been slowly working through the tutorials as I have time.  More recently I have been playing with the material from the Popup window.  Spending some more time of my own with it in my own programs has brought up some questions.  Keep in mind, I am initially working in a Singleton environment (my needs lie there for my first project coming up).  I do plan on multi_connect later as well, but I want to focus on learning the environment under Singleton, since that applies more to what I need to do at this time.

1.  In the tutorial (I think it is Tutorial 6), the program calls Launch to launch the window and the delays some time to allow it to come up before adding elements to it (views, buttons, etc.).  This seems ok at first but when I try it on various windows boxes, sometimes the delays are too short and sometimes they are fine.  I could always increase the delay time, but from a user perspective this could be annoying and I can never really control how long it takes to spawn a window.  If I miss the timing, the window comes up blank (elements aren't added??).  Is there a better way to catch when it is ok to add elements to the window so they appear?  I am guessing an event, but the couple I have tried so far didn't quite do it yet.  The delay method, while quick and effective for a tutorial, isn't quite solid enough for a desktop application that I am planning.

2.  Is there a way to relaunch a window?  If I call Launch more than once, I get an error indicating the item is already created.  I don't need to recreate the window, but simply show it again.  This would be helpful if I want to maintain a data state associated to the window.  Currently, once the event that spawned my window is over, I lose all state.  I can work around this by passing in objects, but I was wanting to see if the window was relaunchable / reshowable so I could easily control when/how its GUI elements were destroyed.

3.  This is related to #2, but is there a way to create elements well enough so I can do things like attach other elements or callbacks to them but separately control when they show on the screen?  This is more a "trying" to understand how it works thing, but also with some of the timing considerations mentioned above, being able to control when I "setup" an element vs. when I view it would be very nice (at least in windows where I have to deal with various OS / Program delays that I cannot control.

This is more for the author if he sees this, but anyone can comment:
4.  Will there eventually be some more documentation on what each method and parameter are for?  I don't mind exploring/playing and I understand Gnoga isn't even officially released, but I know in the future, being better able to understand how each component works would be useful.  I am assuming I have more trouble because I don't do web development, so the concepts are either foreign to me or different from what I am used to in a normal windows GUI environment.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 12:56 Launching Popup Windows in Gnoga Jeremiah
@ 2014-10-20 13:38 ` David Botton
  2014-10-20 15:22 ` David Botton
  1 sibling, 0 replies; 16+ messages in thread
From: David Botton @ 2014-10-20 13:38 UTC (permalink / raw)


On Monday, October 20, 2014 8:56:09 AM UTC-4, Jeremiah wrote:
>I am initially working in a Singleton environment

The Singleton environment is exactly the right one for Desktop apps and there is no shame in using it :) It is there for a reason.

> 1.  the program calls Launch to launch the window and the delays some time to allow it to come up before adding elements to it (views, buttons, etc.). 

Using delay is not ideal, I have been meaning to revisit that before 1.0.  I'll try and do that today.

> 2.   I don't need to recreate the window, but simply show it again.

It is a limitation of browsers, they do not allow showing and hiding windows. Once a browser window is closed the browser has already cleared all its data, no way to recover. So you would need to create a new Gnoga object and launch that.

Alternatives:

1) You could use an iFrame (if loading html from a third party) which is like any other Element_Type and Hidden (true) and Hidden (false) can be called on it.

2) You could create a view_type

In both the above you do something like:

My_Dialog.Position (Absolute);

My_Dialog.Left (Main_Window.Width / 2 - My_Dialog.Width);
-- Center Dialog on Horizontal
My_Dialog.Top (Main_Window.Height /2 - My_Dialog.Height);
-- Center Dialog on Vertical


Then you can use these: (take a look at Gnoga.Gui.Element for the different methods of "hiding" and "showing")

My_Dialog.Hidden (true);
My_Dialog.Hidden (false);

It is in the TO_DO list to create a Dialog_Type that will handle this in the near future.

> 3.  This is related to #2, but is there a way to create elements well enough so I can do things like attach other elements or callbacks to them but separately control when they show on the screen?

You can create a view set it hidden, set up all the children inside of it then just show it when ready.

> 4.  Will there eventually be some more documentation on what each method and parameter are for?

The specs are full with tons of info already, but I do plan on more comprehensive documentation short and long term.

David Botton

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 12:56 Launching Popup Windows in Gnoga Jeremiah
  2014-10-20 13:38 ` David Botton
@ 2014-10-20 15:22 ` David Botton
  2014-10-20 22:01   ` Jeremiah
  1 sibling, 1 reply; 16+ messages in thread
From: David Botton @ 2014-10-20 15:22 UTC (permalink / raw)


I have pushed in to git changes to tutorial 6 that show how to more gracefully handle waiting for a popup.

It is not really possible to set an event on the popup since doing so would end up in a race condition in most situations. Also there is no "standard" between browsers to handle it properly.

In a multi_connect app if the popup is also a gnoga window it would be trivial to just have the two sync up in pure Ada using tasks or POs.

For the Singleton the following insures that you can both access the contents and also that the window has been created and displayed by the browser:

      while
        App.My_Popup2.Document.Ready_State /= Gnoga.Gui.Document.Complete or
        App.My_Popup2.Width = 0
      loop
         delay 0.25;
      end loop;

Also you will notice in Tutorial 6 that Launch now throws an exception if popups are blocked Gnoga.Gui.Window.Popup_Blocked

David Botton

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 15:22 ` David Botton
@ 2014-10-20 22:01   ` Jeremiah
  2014-10-20 22:30     ` David Botton
  0 siblings, 1 reply; 16+ messages in thread
From: Jeremiah @ 2014-10-20 22:01 UTC (permalink / raw)


On Monday, October 20, 2014 11:22:12 AM UTC-4, David Botton wrote:
> Also you will notice in Tutorial 6 that Launch now throws an exception if popups are blocked Gnoga.Gui.Window.Popup_Blocked

Thanks for the update.  I tried it out, but the popup portion seems to be hosing it.  Even with popup blocking turned completely off, I still get the exception.  

On IE I get:
Dispatch Error
CONSTRAINT_ERROR - bad input for 'Value: "undefined"

On FF I get:
Dispatch Error
GNOGA.GUI.WINDOW.POPUP_BLOCKED - gnoga-gui-window.adb:556

This is with the current version as of 5pm EST.

The window still pops up, but the view isn't attached so it is an empty popup (in both IE and FF).

This is my test code.  It has some logic holes, but was just tossing some stuff up to test what you mentioned above


************************************************
with Gnoga.Application.Singleton;
with Gnoga.Gui.Window;
with Gnoga.Gui.View;
with Gnoga.Gui.Base;
with Gnoga.Gui.Element.Common;
with Gnoga.Gui.Document;  use type Gnoga.Gui.Document.Ready_State_Type;

with Ada.Text_IO;  use Ada.Text_IO;

procedure Main is
   Main_Window  : Gnoga.Gui.Window.Window_Type;
   Main_View    : Gnoga.Gui.View.View_Type;
   Main_Button  : Gnoga.Gui.Element.Common.Button_Type;

   Popup_View   : Gnoga.Gui.View.View_Type;
   Popup_Button : Gnoga.Gui.Element.Common.Button_Type;
   
   procedure On_Popup_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is
   begin
      Main_View.Put_Line("Popup Clicked!");
   end On_Popup_Button_Click;


   procedure On_Main_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is
      Popup_Window : Gnoga.Gui.Window.Window_Type;
   begin
      Main_View.Put_Line("Main Clicked!");
      Popup_Window.Launch (Parent => Main_Window,
                           URL      => "",
                           Width    => 500,
                           Height   => 500,
                           Left     => 50,
                           Top      => 50,
                           Location => False,
                           Menu     => False,
                           Status   => False,
                           Tool_Bar => False,
                           Title    => False);
      while
        Popup_Window.Document.Ready_State /= Gnoga.Gui.Document.Complete or
        Popup_Window.Width = 0
      loop
         delay 0.25;
      end loop;
      
      Popup_View.Create(Popup_Window);
      Popup_Button.Create(Popup_View,"Click Me Too!");
      Popup_Button.On_Click_Handler(On_Popup_Button_Click'Unrestricted_Access);
      
   end On_Main_Button_Click;

   

begin
   Gnoga.Application.Title("Hello World");

   Put_Line("Hello World");

   --Gnoga.Application.Open_URL_Windows;
   Gnoga.Application.Singleton.Initialize(Main_Window => Main_Window);

   Main_View.Create(Parent => Main_Window);

   Main_View.Put_Line("Hello World");
   Main_Button.Create(Main_View,"Click Me");

   Main_Button.On_Click_Handler(On_Main_Button_Click'Unrestricted_Access);

   Gnoga.Application.Singleton.Message_Loop;
   Put_Line("Application finished");

end Main;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 22:01   ` Jeremiah
@ 2014-10-20 22:30     ` David Botton
  2014-10-20 23:07       ` Jeremiah
  0 siblings, 1 reply; 16+ messages in thread
From: David Botton @ 2014-10-20 22:30 UTC (permalink / raw)


>    procedure On_Main_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is
>       Popup_Window : Gnoga.Gui.Window.Window_Type;
>    begin

Your issue is not with popups, but an Ada issue.

Popup_Window will finalize at the end of the procedure On_Main_Button_Click, even though the popup will remain on the screen, reference to it has disappeared both in Gnoga and on the browser.

Try this instead:

   procedure On_Main_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is 
      Popup_Window : Gnoga.Gui.Window.Window_Access :=
         new Gnoga.Gui.Window.Window_Type; 
   begin 

That will create a dynamic object that will persist after the procedure terminates. However keep in mind that you now have a small memory leak if you never end up calling Popup_Window.Free.

For a short lived utility app that may be acceptable.

Another example:

   Popup_Window : Gnoga.Gui.Window.Window_Access := null;

   procedure On_Main_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is 
   begin     
     if Popup_Window /= null then
       Popup_Window.Close;
       Popup_Window.Free;
     end if;
     Popup_Winow := new Gnoga.Gui.Window.Window_Type;
...

David Botton


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 22:30     ` David Botton
@ 2014-10-20 23:07       ` Jeremiah
  2014-10-21  0:21         ` David Botton
  0 siblings, 1 reply; 16+ messages in thread
From: Jeremiah @ 2014-10-20 23:07 UTC (permalink / raw)


On Monday, October 20, 2014 6:30:12 PM UTC-4, David Botton wrote:
> Your issue is not with popups, but an Ada issue.
> 
> 
> 
> Popup_Window will finalize at the end of the procedure On_Main_Button_Click, even though the popup will remain on the screen, reference to it has disappeared both in Gnoga and on the browser.
> 
> 
> 
> Try this instead:
> 
> 
> 
>    procedure On_Main_Button_Click( Obj : in out Gnoga.Gui.Base.Base_Type'Class) is 
> 
>       Popup_Window : Gnoga.Gui.Window.Window_Access :=
> 
>          new Gnoga.Gui.Window.Window_Type; 
> 
>    begin 

Even with that change, the issue I mentioned above exists (The Constraint error on IE and the popup blocked exception on FF).  

However, my original post was kinda touching on your response.  I definitely want to avoid memory leaks if possible (I can work around this similar to your second solution).  However, I also need to handle the user clicking on the button multiple times.  I definitely can't hold onto the reference and relaunch the window the next time the button is pressed (at least if I understand your response to the relaunch question correctly).  Doing the close/free and allocating a new one gets around that for the window itself, but I don't know if that has implications on my view object if it is shared amongst multiple window objects.

As another thought, I'm also still not 100% sure if I would have a race condition or synchronization issue if the button was pressed twice (2 popups at the same time).  I know when I program GUI's in windows exactly what thread the actions happen in.  In Gnoga, I'm still looking through to determine if each on on_click is executed in separate threads/tasks or the same as the Main().  I thought about disabling the button to prevent two popups at once, but I wouldn't have an event to remove the disable with later on (especially if they opted to simply close the popup window without clicking my buttons).


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-20 23:07       ` Jeremiah
@ 2014-10-21  0:21         ` David Botton
  2014-10-21  0:27           ` David Botton
  2014-10-21  2:03           ` Jeremiah
  0 siblings, 2 replies; 16+ messages in thread
From: David Botton @ 2014-10-21  0:21 UTC (permalink / raw)


> Even with that change, the issue I mentioned above exists (The Constraint error on IE and the popup blocked exception on FF). 

Ok, I can confirm both situations. I'll look in to it. (Sorry have a high fever, so been slow today)

> As another thought, I'm also still not 100% sure if I would have a race condition or synchronization issue if the button was pressed twice (2 popups at the same time).

I was just trying to illustrate the idea of freeing an object. I would not put that it production. I should have been more clear.

In Gnoga every event is a new task. It is a completely concurrent system. The Main thread runs AWS, each connection is its own thread, etc. You can block in any task at any time and not cause damage to the system, etc.

David Botton


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21  0:21         ` David Botton
@ 2014-10-21  0:27           ` David Botton
  2014-10-21  1:27             ` David Botton
  2014-10-21  2:03           ` Jeremiah
  1 sibling, 1 reply; 16+ messages in thread
From: David Botton @ 2014-10-21  0:27 UTC (permalink / raw)


> Even with that change, the issue I mentioned above exists (The Constraint error on IE and the popup blocked exception on FF). 

I didn't have a windows setup until recently so did very little testing on IE. Apparently IE returns high precision X,Y for mouse clicks, so I will need to deal with that. I'll have a fix for that in soon.

Interestingly IE has no respect for the cross site pop ups and lets you close those.

David Botton

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21  0:27           ` David Botton
@ 2014-10-21  1:27             ` David Botton
  2014-10-21  2:06               ` jeremiah.breeden
  2014-10-21 11:24               ` David Botton
  0 siblings, 2 replies; 16+ messages in thread
From: David Botton @ 2014-10-21  1:27 UTC (permalink / raw)


I've checked in the fix for IE for the mouse pointer issue and a fix for FireFox popups. It may be a limitation of IE to not allow access to the popup's document object (in which case you may be out of lock with popups on IE unless you do a multi_connect app and setup an second on_connect handler for it).

I also noticed that IE doesn't like the proxy server setup I am using on gnoga.com, I'll make sure to spend some time on this at some point soon.

David Botton




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21  0:21         ` David Botton
  2014-10-21  0:27           ` David Botton
@ 2014-10-21  2:03           ` Jeremiah
  1 sibling, 0 replies; 16+ messages in thread
From: Jeremiah @ 2014-10-21  2:03 UTC (permalink / raw)


On Monday, October 20, 2014 8:21:34 PM UTC-4, David Botton wrote:
> > Even with that change, the issue I mentioned above exists (The Constraint error on IE and the popup blocked exception on FF). 
> 
> 
> 
> Ok, I can confirm both situations. I'll look in to it. (Sorry have a high fever, so been slow today)

Get some rest!  No need to worry about this stuff till you feel better.  I was actually feeling a bit guilty for not spending more time flushing out more details for you anyways.  I've only been able to spend time at nights playing with it and kids make that a challenge.

> > As another thought, I'm also still not 100% sure if I would have a race condition or synchronization issue if the button was pressed twice (2 popups at the same time).
> 
> 
> 
> I was just trying to illustrate the idea of freeing an object. I would not put that it production. I should have been more clear.
> 
> 
> 
> In Gnoga every event is a new task. It is a completely concurrent system. The Main thread runs AWS, each connection is its own thread, etc. You can block in any task at any time and not cause damage to the system, etc.

Don't worry, I realized it was just for illustration.  I was just mentioning that because I had guessed this was the case, but was unsure.  I'm thinking ahead so I want to understand how some things work under the hood.  

I know I probably come off as a pretty big newbie (well I haven't programmed Ada in like 7-8 years and it was Ada83...so maybe I am a quite bit of a newbie), but I was definitely already thinking about how to manage it dynamically.  I was honestly being a bit too lazy with my example (trying to get the post in before the kids got home).

Some background:  My main experience when it deals with GUI development is windows, specifically MFC...so pretty old stuff.  In that environment, almost everything GUI related happens in the same thread so you don't have to deal with race conditions or synchronization unless it is with a background thread that you spawn.  All the GUI interactions happen in the main thread using a post message model where all GUI actions place a message on a queue and when the main thread isn't busy, it handles the next message on the queue.   On the one hand, it makes any code used for events like On_Click thread safe with each other.  However, it isn't very powerful and has a lot of limitations.  I like the Gnoga method better.  It's a bit more challenging when you are used to a single threaded model but it really just takes a different way of thinking, so I'll have to take some time and adapt.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21  1:27             ` David Botton
@ 2014-10-21  2:06               ` jeremiah.breeden
  2014-10-21 11:24               ` David Botton
  1 sibling, 0 replies; 16+ messages in thread
From: jeremiah.breeden @ 2014-10-21  2:06 UTC (permalink / raw)


On Monday, October 20, 2014 9:27:51 PM UTC-4, David Botton wrote:
> I've checked in the fix for IE for the mouse pointer issue and a fix for FireFox popups. It may be a limitation of IE to not allow access to the popup's document object (in which case you may be out of lock with popups on IE unless you do a multi_connect app and setup an second on_connect handler for it).  
> 
> 
> 
> I also noticed that IE doesn't like the proxy server setup I am using on gnoga.com, I'll make sure to spend some time on this at some point soon.
> 
> 
> 
> David Botton

I'll try and check it out tomorrow.  To be honest, I don't know much about IE.  I don't actually use it except to test things as I primarily stick with Firefox.  The main reason I've been posting results from it was because I wanted you to have as much info as possible and also to verify that it wasn't simply a FF setup issue.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21  1:27             ` David Botton
  2014-10-21  2:06               ` jeremiah.breeden
@ 2014-10-21 11:24               ` David Botton
  2014-10-22  1:56                 ` Jeremiah
  1 sibling, 1 reply; 16+ messages in thread
From: David Botton @ 2014-10-21 11:24 UTC (permalink / raw)


> I also noticed that IE doesn't like the proxy server setup I am using on gnoga.com, I'll make sure to spend some time on this at some point soon.

Fixed and checked in.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-21 11:24               ` David Botton
@ 2014-10-22  1:56                 ` Jeremiah
  2014-10-22  2:09                   ` David Botton
  0 siblings, 1 reply; 16+ messages in thread
From: Jeremiah @ 2014-10-22  1:56 UTC (permalink / raw)


On Tuesday, October 21, 2014 7:24:51 AM UTC-4, David Botton wrote:
> > I also noticed that IE doesn't like the proxy server setup I am using on gnoga.com, I'll make sure to spend some time on this at some point soon.
> 
> 
> 
> Fixed and checked in.

Thanks.  Just tried it tonight.  Fixed the popup error in FF.  I noted your comment for IE and it definitely still is broken.  I may have to look at multi-connect as an option.  I'll see what I can figure out.   I did notice that in Firefox the check:

Popup_Window.Document.Ready_State /= Gnoga.Gui.Document.Complete

Never goes to Complete and the while loop suggested loops forever.  I'm guessing an event that sets it to complete doesn't fire?  When I comment that part of the while loop requirement, it exits the while loop.

Given the issues with IE (I don't know what my users will have on their computers), is there any info you could point me to on how to make custom Alert like boxes and what event options I have with those?  I still plan on looking at multi-connect but figured I could explore that on the side to see if it will be feasible.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-22  1:56                 ` Jeremiah
@ 2014-10-22  2:09                   ` David Botton
  2014-10-22  2:57                     ` Jeremiah
  0 siblings, 1 reply; 16+ messages in thread
From: David Botton @ 2014-10-22  2:09 UTC (permalink / raw)


1) Window_Type.Alert

2) Use floating Views as I mentioned in an earlier post

3) Use the jQueryUI Dialog that I will have in the next day or so ready.

I will try and debug further the IE issue, but Popups are a very low priority since they are generally nasty stuff to be avoided. I really debated adding at all.

David Botton

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-22  2:09                   ` David Botton
@ 2014-10-22  2:57                     ` Jeremiah
  2014-10-22 15:24                       ` David Botton
  0 siblings, 1 reply; 16+ messages in thread
From: Jeremiah @ 2014-10-22  2:57 UTC (permalink / raw)


On Tuesday, October 21, 2014 10:09:22 PM UTC-4, David Botton wrote:
> 1) Window_Type.Alert
> 
> 
> 
> 2) Use floating Views as I mentioned in an earlier post
> 
> 
> 
> 3) Use the jQueryUI Dialog that I will have in the next day or so ready.
> 
> 
> 
> I will try and debug further the IE issue, but Popups are a very low priority since they are generally nasty stuff to be avoided. I really debated adding at all.
> 
> 
> 
> David Botton
Thanks a bunch!  I apologize if I got annoying with this stuff.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Launching Popup Windows in Gnoga
  2014-10-22  2:57                     ` Jeremiah
@ 2014-10-22 15:24                       ` David Botton
  0 siblings, 0 replies; 16+ messages in thread
From: David Botton @ 2014-10-22 15:24 UTC (permalink / raw)


Not annoying, however I think that using the gnoga mailing list may be better for detailed debugging type stuff.

Join here:
https://lists.sourceforge.net/lists/listinfo/gnoga-list

David Botton

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-10-22 15:24 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20 12:56 Launching Popup Windows in Gnoga Jeremiah
2014-10-20 13:38 ` David Botton
2014-10-20 15:22 ` David Botton
2014-10-20 22:01   ` Jeremiah
2014-10-20 22:30     ` David Botton
2014-10-20 23:07       ` Jeremiah
2014-10-21  0:21         ` David Botton
2014-10-21  0:27           ` David Botton
2014-10-21  1:27             ` David Botton
2014-10-21  2:06               ` jeremiah.breeden
2014-10-21 11:24               ` David Botton
2014-10-22  1:56                 ` Jeremiah
2014-10-22  2:09                   ` David Botton
2014-10-22  2:57                     ` Jeremiah
2014-10-22 15:24                       ` David Botton
2014-10-21  2:03           ` Jeremiah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox