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

Remember last sketch window position #60

Closed
tabreturn opened this issue Jan 27, 2022 · 3 comments
Closed

Remember last sketch window position #60

tabreturn opened this issue Jan 27, 2022 · 3 comments

Comments

@tabreturn
Copy link

With the Processing editor, you can run a sketch, then move the display window about; py5, of course, does this too.

But, with Processing, rerunning the sketch positions it where you last closed the display window; the py5 display window always defaults to the center of the screen.

One can set the window position explicitly with set_location(), but might there be a way for py5 to recall the last coordinates?

@tabreturn
Copy link
Author

I'm thinking that the editor might handle this (Thonny, in this case). So, run_sketch could accept additional x-y coords for the display window ... but then how does py5 send a message 'back' to Thonny with that info ...

@hx2A
Copy link
Collaborator

hx2A commented Jan 28, 2022

So I've been running py5 Sketches for almost 2 years go (I started in March of 2020) and just about every time I've moved the Sketch window to a new location after it opens up. I never thought about this until you asked about it. I agree, it would be nice if the Sketch window would "remember" its last location and open up new windows in the new location. This is how most other applications work. I wonder if this is managed by the OS or by each individual application.

In any case, here is what I know about Sketch window locations.

run_sketch() supports arguments to set the window location because Processing does. If you look at the third example, it is using them to set the window location on display number 1. (note that means the first monitor and not the DISPLAY=:1 variety)

If you look at the Processing code comments they specifically mention this is used to set the window location by the editor. So in the case of Processing, window location is in fact actively managed by the PDE.

I know little about Processing code outside of the core libraries. But I was able to find the --location param mentioned in the Runner class. In the code one finds editor.getSketchLocation() and editor.setSketchLocation(new Point(left, top)) and some other stuff that suggests that the Sketch is sending messages to the PDE, perhaps over a socket. It makes sense that it would do this because the PApplet's stdout and stderr also appear in the PDE window. There needs to be some communication.

More investigation is needed here. Are py5 Sketches currently attempting to report window locations to a socket that nobody is listening to? First we need to find the code in the Sketch that is reporting the window location and how that communication channel works. Then we need to get the Thonny plugin to receive those messages. Currently the run_sketch command line utility does not accept window location parameters but it would be easy for me add that so they get passed along to the run_sketch() call.

@hx2A
Copy link
Collaborator

hx2A commented Feb 21, 2022

All of this work is done and will now remember the screen location of the last Sketch. The run_sketch command line utility does what it needs to do to allow Thonny to provide the same screen location functionality for users.

Processing uses the --external and --location command line arguments to instruct a Sketch to report window positions and to set the initial window location. To use both in py5 via the run_sketch command, do something like this:

run_sketch --py5_options external location=0,0

The window positions will be outputted to stderr and will be preceded with MOVE. The PDE must be intercepting these messages and removing them from stderr before displaying stderr to the user in the output pane. If it is not easy for you to do the same in Thonny let me know; py5 could easily write the window positions to a socket instead.

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