AREPL-vscode icon indicating copy to clipboard operation
AREPL-vscode copied to clipboard

inject screen setup when user is using turtle to put window in better spot

Open Almenon opened this issue 7 years ago • 8 comments

Currently the window pops up right in your face and is very annoying.

By injecting screen setup code I could put the window in a better spot.

check to make sure they are not already using turtle.setup() beforehand.

Please comment or +1 if you like this feature

Almenon avatar Feb 08 '18 16:02 Almenon

matplotlib:

f.canvas.manager.window.wm_geometry("+1200+0") #right-hand side

turtle:

turtle.setup(500,500,-1,0) # top right-hand side

Almenon avatar Feb 10 '18 19:02 Almenon

from tkinter import Tk, Label
root = Tk()

root.lower() # prevent screen from appearing on top

to_read = "Stuff" 
w = Label(root, text=to_read)
w.pack()
root.mainloop()

annoying thing is despite appearing in back it still steals focus from main app....

Also turtle doesn't steal focus when in cmd or repl, only when executing file or in arepl - why is that? :/

Almenon avatar Mar 17 '19 00:03 Almenon

oh i see - arepl is run as a file (python pythonEvaluator.py) so that's why it steals focus like running a python file. Maybe there is some launch option for not stealing focus?

Almenon avatar Mar 17 '19 00:03 Almenon

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html

Almenon avatar Mar 17 '19 00:03 Almenon

https://askubuntu.com/questions/25644/which-window-has-current-focus

https://stackoverflow.com/a/47161643/11133619

Almenon avatar Mar 17 '19 00:03 Almenon

import ctypes

#   store some stuff for win api interaction
set_to_foreground = ctypes.windll.user32.SetForegroundWindow
# ^ deprecated - should use https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-keybd_event instead
keybd_event = ctypes.windll.user32.keybd_event

alt_key = 0x12
tab_key = 0x09
extended_key = 0x0001
key_up = 0x0002

def steal_focus():
    #keybd_event(alt_key, 0, extended_key | 0, 0)
    keybd_event(alt_key, 0, 0, 0)
    keybd_event(tab_key, 0, 0, 0)
    keybd_event(alt_key, 0, key_up | 0, 0)
    keybd_event(tab_key, 0, key_up | 0, 0)
    #set_to_foreground(window.winfo_id())
    #keybd_event(alt_key, 0, extended_key | tab_key, 0)

 
from tkinter import Tk, Label
root = Tk()

# can i call this when i gain focus somehow?
root.after(250, steal_focus)

# none of below crap worked
#root.lower() # prevent screen from appearing on top
#x=root.tk_focusPrev() 
#root.focusmodel("passive")
#root.protocol("WM_TAKE_FOCUS", lambda x:print('focus'))

to_read = "Stuff" 
w = Label(root, text=to_read)
w.pack()
#x=w.tk_focusPrev()
#x=w.focus
#x=w.grab_release()
root.mainloop()


....... so hacky. Was fun to make tho

Almenon avatar Mar 17 '19 01:03 Almenon

should ask tkinter community / python chat why tkinter takes focus when launching from a file and how to prevent that.

Almenon avatar Mar 17 '19 01:03 Almenon

I don't know why I spent so much time on this I forgot this problem was already fixed for turtle with #202 - if python doesn't restart each time then python doesn't steal focus.

Which by the way doesn't make any sense! The first run of arepl is the same restart or not...... :(

Almenon avatar Mar 17 '19 19:03 Almenon