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

[ Bug] sg.WIN_CLOSED event is not generated, after catching mouse down events in same window for read_all_windows calls #6691

Open
6 of 9 tasks
cmayer opened this issue Feb 22, 2024 · 4 comments

Comments

@cmayer
Copy link

cmayer commented Feb 22, 2024

Type of Issue (Enhancement, Error, Bug, Question)

Bug


Operating System

MacOs 10.14.6

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Version information can be obtained by calling sg.main_get_debug_data()
Or you can print each version shown in ()

Python version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 21:00:12) [Clang 16.0.6 ]
port: tkinter
tkinter version: 8.6.13
PySimpleGUI version: 4.60.5
PySimpleGUI filename: /Users/cm/anaconda3/envs/sg/lib/python3.12/site-packages/PySimpleGUI/PySimpleGUI.py

Python version (sg.sys.version)

3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 21:00:12) [Clang 16.0.6 ]

PySimpleGUI Version (sg.__version__)

4.60.5

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

8.6.13


Your Experience In Months or Years (optional)

Years Python programming experience
4 years

Years Programming experience overall
30 years

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
no

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • None of your GUI code was generated by an AI algorithm like GPT
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
  • Tried running the Development Build. Your problem may have already been fixed but not released

Detailed Description

The sg.WIN_CLOSED event is not generated, after catching mouse down events in same window.
If I open a window and if I hit the "window close" icon in the left upper corner (MacOsX), the close event is generated and the window closes and in the event loop is exited.

If I click inside of the window before clicking the close window icon, it will not accept the close window icon any more. If I click on the close icon I get the window, event, value as follows:
<PySimpleGUI.PySimpleGUI.Window object at 0x10a700a10> -GRAPH2-+UP {'-GRAPH2-': (3, 293)}

The coordinate is a coordinate inside of the close window icon.
This only happens after generating a mouse down event in the window.

Code To Duplicate

This pre-formatted code block is all set for you to paste in your bit of code:

import PySimpleGUI as sg
from PIL import Image, ImageDraw, ImageTk
import io

## Indeed, it should be possible to combine the following two create window functions to one general function:
def make_overview_window(h, w):
    layout_overview_window = [[sg.Graph(
        canvas_size=(h, w),
        graph_bottom_left=(0, 0),
        graph_top_right=(h, w),
        key="-GRAPH1-",
        change_submits=True,  # mouse click events
        background_color='white',
        drag_submits=True), ],
        [sg.Text(key='info1', size=(60, 1))]]

    return sg.Window("Main zoom selection window", layout_overview_window, finalize=True)

if __name__ == '__main__':
    # Load JPG images using Pillow
    image1 = Image.open('image1.jpg')
    h0, w0 = image1.size

    print("Size: ", h0, " ", w0)

    # Convert images to bytes
    img_bytes1 = io.BytesIO()
    image1.save(img_bytes1, format='PNG')
    window_overview = make_overview_window(h0, w0)

    # get the graph element for ease of use later
    graph_overview_window = window_overview["-GRAPH1-"]
    graph_overview_window.draw_image(data=img_bytes1.getvalue(), location=(0, h0))

    while True:
        window, event, values = sg.read_all_windows() # timeout=10)

        print(window, event, values)
        if window == window_overview:
            if event == sg.WIN_CLOSED:
                break  # exit

            if event == "-GRAPH1-":  # if there's a "Graph" event, then it's a mouse
                x, y = values["-GRAPH1-"]
                print(event, " ", x, " ", y)

    # Close the window
    window_overview.close()

Screenshot, Sketch, or Drawing


Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.

@cmayer
Copy link
Author

cmayer commented Feb 22, 2024

Forgot to mention:
It works when using
event, values = window_overview.read()

Could be distanly related to
#3771

It is related in the following sense:
sg.read_all_windows()
does not always seem to play with sg.WIN_CLOSED

@cmayer
Copy link
Author

cmayer commented Feb 23, 2024

I did more research. Google found this, github did not.

This seems to be the same as:
#3795

@PySimpleGUI
Copy link
Owner

read_all_windows is an "area of priority" for sure. It's something I'm looking forward to getting back to finishing up. There are several features that aren't quite in there and appears other problems are lurking. Regardless, it's the most efficient way of handling multiple windows and thus an important area.

Thank you for taking the time to not just open/log the bug, but continue to research and provide data. It's really appreciated. Can any of this be Mac specific or is it going to be experienced on all platforms (apologize that I've not spent time investigating this in detail yet but thought I would ask so that when I do I've got a another piece of data).

@cmayer
Copy link
Author

cmayer commented Feb 25, 2024

I tried this on windows and the problem and the effect are identical.
window.read() is working, sg.read_all_windows does not work after clicking into the window.
The identical effect is:
When clicking on the close button (after clicking inside of the window) the event is interpreted as a click event inside of the window, i.e. graph key is the event and values contains coordinates.

Version on windows:
Python version:
3.12.1 | packaged by Anaconda, Inc. | (main, Jan 19 2024, 15:44:08) [MSC v.1916 64 bit (AMD64)]

PySimpleGui version:
4.60.5

GUI version:
8.6.12

Python and Gui version as marginally different from those on my Mac.

@PySimpleGUI PySimpleGUI changed the title [ Bug] sg.WIN_CLOSED event is not generated, after catching mouse down events in same window. [ Bug] sg.WIN_CLOSED event is not generated, after catching mouse down events in same window for read_all_windows calls Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants