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

Non main windows cannot be closed properly. #2122

Closed
mzdk100 opened this issue Sep 15, 2023 · 6 comments
Closed

Non main windows cannot be closed properly. #2122

mzdk100 opened this issue Sep 15, 2023 · 6 comments
Labels
bug A crash or error in behavior.

Comments

@mzdk100
Copy link

mzdk100 commented Sep 15, 2023

Describe the bug

Here is a test code I wrote that creates a multi window program, but it has very strange situations:

  1. Let's first run this program and click on show window1 or show window2 in the window.
  2. On Windows, once window1 and window2 are displayed, you cannot click the close button in the upper right corner with the mouse. Clicking on it does not respond, and it can be summarized as the user cannot close this window; For this reason, I added a close button on the window1 interface and actively called the window1.close() function. Fortunately, it can work normally; But window2 is at a loss.
  3. Test results on the Android platform: Once window1 or window2 is displayed, the content on the interface will be cleared and cannot be returned to the main window again.
import toga
class App(toga.App):
    def startup(self):
        window1 = toga.Window(title='Window 1', size=(400, 300))
        button_close_window1 = toga.Button('close', on_press=lambda _: window1.close())
        window1.content = button_close_window1
        window2 = toga.Window(title='Window 2', size=(300, 200))
        label2 = toga.Label('Hello, Toga!')
        window2.content = label2
        main_window = toga.MainWindow(title='MainWindow')
        main_box = toga.Box()
        button_show_window1 = toga.Button('show_window1', on_press=lambda _: window1.show())
        button_show_window2 = toga.Button('show_window2', on_press=lambda _: window2.show())
        main_box.add(button_show_window1)
        main_box.add(button_show_window2)
        main_window.content = main_box
        self.main_window = main_window
        self.windows += window1
        self.windows += window2
        main_window.show()

def main():
    app = App(formal_name='test', app_id='test')
    app.main_loop()
if __name__ == '__main__':
   main()

Steps to reproduce

See above.

Expected behavior

If it works normally, it should be when we click the close button in the upper right corner of window1 and window2 that the current window can be closed and returned to the main window.
On Android, it should close the current page and return to the previous page when pressing the back key, rather than an empty page.

Screenshots

No response

Environment

  • Operating System: window10
  • Python version: 3.10
  • Software versions:
    • Briefcase:
    • Toga:
    • ...

Logs


Additional context

No response

@mzdk100 mzdk100 added the bug A crash or error in behavior. label Sep 15, 2023
@proneon267
Copy link
Contributor

Confirmed that the window not closing behavior when clicked on the close button in the upper right corner with the mouse, is fixed by #2112.

@freakboy3742
Copy link
Member

I believe this is a duplicate of #1872, fixed by #1877. This bug existed in v0.3.1, but I can't reproduce this problem with the current main branch.

However, that only applies to the Windows version of the problem. Android doesn't support opening secondary windows, so anything going on there isn't a bug.

@mzdk100
Copy link
Author

mzdk100 commented Sep 15, 2023

On Windows, use 'on_close=lambda _: True' has been tested and passed, but Android is still not working properly, that is, pressing the back key on the second window cannot return to MainWindow.
I am familiar with Android. In Android, activities can be started in the form of multiple instances, and the activities that are later started are pushed to the top of the activity stack. When the back key is pressed, the top activity will pop up, so this effect can be achieved.

@freakboy3742
Copy link
Member

And I'm saying that is by design. At present, Toga's Android backed does not support creating additional windows after the main window.

Whether there might possibly be an interpretation of "Window" that might make sense, the current implementation does not support it.

@mzdk100
Copy link
Author

mzdk100 commented Sep 15, 2023

But my product needs to achieve the effect I mentioned above, what should I do?

@freakboy3742
Copy link
Member

As it stands, the feature doesn't exist. That means your options are:

  1. Redesign your product so you do t need that feature
  2. Design and implement the feature as a contribution to Toga
  3. Implement the feature in a form specific to your app's needs, rather than as a generic feature
  4. Use a different GUI toolkit.

Any feature in Toga is a wrapper around the native system capabilities; so the approach for step 2 or 3 will use the same techniques that Toga is using currently - that is, the Chaquopy bridge layer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior.
Projects
None yet
Development

No branches or pull requests

3 participants