Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing a secondary window destroys the object so it cannot be re-used #522

Closed
hyperfocusaurus opened this issue Nov 9, 2019 · 9 comments
Labels
bug Something isn't working good first issue Good for newcomers wontfix This will not be worked on
Milestone

Comments

@hyperfocusaurus
Copy link

Describe the bug
Using application.NewWindow to create a secondary window, it's not possible to re-use that window after it has been closed. If the user presses the X button, the window doesn't respond to Show() calls any more.

To Reproduce

  1. Create a main window
  2. Create a secondary window
  3. Close the secondary window
  4. Attempt to re-show the secondary window.

Example code:

func main() {
  application := app.New()
  mainWindow := application.NewWindow("main")
  secondaryWindow := application.NewWindow("secondary")
  mainWindow.SetContent(widget.NewButton("TEST", func () {
    secondaryWindow.Show()
  }))
  mainWindow.ShowAndRun()
}

Given the example program, click the "TEST" button, then close the sub-window, then click the "TEST" button a second time. The sub-window does not come back.

Screenshots
If applicable, add screenshots to help explain your problem.

Device (please complete the following information):

  • OS: Windows
  • Version: 10
  • Go version: 1.13
  • Fyne version: 1.1.2
@andydotxyz andydotxyz added the bug Something isn't working label Nov 9, 2019
@andydotxyz andydotxyz added this to the 1.2 - Mobile support milestone Nov 9, 2019
@andydotxyz andydotxyz added the good first issue Good for newcomers label Nov 9, 2019
@spatocode
Copy link
Contributor

Am not sure why this bug exists, but you should create a new window from the current application, for which there's 1 per process. This should work fine.

func main() {
application := app.New()
mainWindow := application.NewWindow("main")
secondaryWindow := fyne.CurrentApp().NewWindow("secondary")
mainWindow.SetContent(widget.NewButton("TEST", func () {
secondaryWindow.Show()
}))
mainWindow.ShowAndRun()
}

@hyperfocusaurus
Copy link
Author

ah! ok, I didn't realise that.

Thanks for your help :D

@andydotxyz
Copy link
Member

The suggested code is identical - fyne.CurrentApplication() will return the result of previously called app.New().

Though I would like to hear from @cjbrowne to confirm I am pretty sure this is still an open issue, so am reopening.

@andydotxyz andydotxyz reopened this Nov 16, 2019
@hyperfocusaurus
Copy link
Author

I'll do some testing today, I will admit I didn't actually check that the suggested code works.

@spatocode
Copy link
Contributor

Sorry @cjbrowne, the code is really identical(apologies). But, @andydotxyz it seems the suggested piece of code works only on the fyne demo app. Something is not quite right.

@andydotxyz
Copy link
Member

Sorry, I’m not sure if you are reporting a new issue - can you confirm what doesn’t work outside the demo app? Thanks

@spatocode
Copy link
Contributor

spatocode commented Dec 9, 2019

I'm not pretty sure this is a bug. When you create a secondary window outside the button callback, that window object is stored in memory. Now, when you close the window, that window(not the object) is destroyed so the window object in memory may not be reused(show) again. The proper way is to create the secondary window inside the button callback function so that a new window object is created each time the button is clicked.

This should work fine

func main() {
application := app.New()
mainWindow := application.NewWindow("main")
mainWindow.SetContent(widget.NewButton("TEST", func () {
secondaryWindow := application.NewWindow("secondary")
secondaryWindow.Show()
}))
mainWindow.ShowAndRun()
}

@andydotxyz
Copy link
Member

It should not matter how or when you create a new window (inside or outside of a callback).
Your demo code @spatocode is creating a new one every time, which will always work.

I think that @cjbrowne still has a point - a window that is hidden could easily want to be shown again and any state associated will be lost if we continue to delete the window when it is hidden instead of identifying the difference between Hide and Close/Destroy.

@andydotxyz
Copy link
Member

I have looked at this some more and come to the conclusion that a user close-action is showing the intent to not re-use the window. Perhaps this relates to #467? If that were added you could override the default close behaviour somehow.

If you were to manually call Window.Hide() then it could be re-used, but Closing a window is like calling Window.Close() which destroys content.
Unless any objection I think this issue should be closed as won't-fix as the behaviour is correct.

@andydotxyz andydotxyz added the wontfix This will not be worked on label Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants