G4P trouble trying to hide a window when the operating system close button is pressed


#1

First off, thank you @quark for the great libraries and gui building tools. They have been really helpful recently!

I am working on a project that involves several windows, all of which I need to be reusable while the program is running. On a few of the windows which involve user input I have added a button that can be clicked to “close” (hide) the window. One of the windows that I am using is meant to display an image and just an image, but needs to be able to be hidden and reused in the future.

Below is a simplified code snippet that I generated with the G4P builder tool.

synchronized public void win_draw1(PApplet appc, GWinData data) { //_CODE_:window1:920231:
  appc.background(230);
} //_CODE_:window1:920231:

public void window1OnClose(GWindow window) { //_CODE_:window1:910966:
  println("window1 - window closed at " + millis());
  
  window1.setVisible(false);
  
} //_CODE_:window1:910966:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setMouseOverEnabled(false);
  surface.setTitle("Sketch Window");
  window1 = GWindow.getWindow(this, "Window title", 0, 0, 240, 120, JAVA2D);
  window1.noLoop();
  window1.setActionOnClose(G4P.KEEP_OPEN);
  window1.addDrawHandler(this, "win_draw1");
  window1.addOnCloseHandler(this, "window1OnClose");
  window1.loop();
}

// Variable declarations 
// autogenerated do not edit
GWindow window1;

I would like to be able to hide the window by pressing the built-in exit/close button, but haven’t found a way to do that yet. If it’s not possible, then I will probably resort to adding a button on the window I want to hide.

Am I missing something obvious here about how G4P windows work? Is there a way to detect if the operating system exit button has been clicked?

Thank you,

Grayson


#2

I forgot to mention that while trying the above technique for hiding the window when the close button is pressed I found out that the onClose event handler is not even being called when I have the the window set with KEEP_OPEN. If I have the window set with CLOSE_WINDOW then the window hides correctly, but does not work when it is unhidden again.


#3

it closes, not hides!

on decorated windows [x] can

  • keep open ( ignore )
  • close
  • close all

only
you would have the option HIDE instead CLOSE?
even if that would be added, have to wait next revision,
but i think you have the show hide toggle buttons (? in MAIN? ) already,
so KEEP OPEN seems best way for now,
but could undecorate the utility windows???


#4

Hmm, that makes sense. I tried to make the window visible after closing and it did show an empty window, but it clearly wasn’t working. I will find a workaround to the problem for now. Thank you for your help!


#5

For anyone whos interested:

I ended up putting the gui initilaizer method inside the on close method. This way, when the window is closes it will reinit as a hidden window that can then be used again. This isn’t ideal, but it works for what I’m doing.