script editor looses cursor after going to different software and coming back to Maya.

173 views
Skip to first unread message

ynedelin

unread,
Oct 14, 2015, 12:30:26 AM10/14/15
to Python Programming for Autodesk Maya
Behavior I am used to is this:
if I am typing something in Maya Script Editor Command Input (bottom) section and then ALT+TAB into another software like Notepad and then ALT+TAB back into Maya my cursor is back in script editor at the place I left it so I can continue to type stuff.

This how it used to be on window machines in classic theme until windows 8 and that how it works on osx.

I got a new machine with windows 8 and now when I ALT-TAB back to Maya script editor cursor is not back in the script editor's Command Input (bottom) but some other panel is in focus in Maya so now I have to grab the mouse and click in the Command Input aria manually !
This is very annoying.

Anyone has any suggestions ?
is there a way to force cursor into the Command Input section of the Script editor with code?

Thank you

Yury

Justin Israel

unread,
Oct 14, 2015, 3:51:46 AM10/14/15
to Python Programming for Autodesk Maya

I don't know much about this particular problem, since on my OSX machine w/ Maya 2015 it does not lose focus. But you could probably install an event filter on the QApplication, to detect the ApplicationDeactivate and ApplicationActivate events. You could then handle checking if the script editor is up and on top, and if so, give it editing focus again.

Justin



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/516e6c92-4325-42b4-8f01-24f2b164a1f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yury nedelin

unread,
Oct 14, 2015, 10:09:57 AM10/14/15
to python_in...@googlegroups.com

Justin,
Thanks for replying, I will try this approach to put script editor in focus.

There is an added issue of putting  the command input section of the script editor in focus.

Yury

Chris Lesage

unread,
Oct 14, 2015, 2:24:41 PM10/14/15
to python_in...@googlegroups.com
Hey Yury,

If I understand correctly, this is a preference and if I remember it isn't on by default.

Preferences -> Interface -> Command Line: Hold Focus [x]

Does checking this box solve your problem?

Chris

Marcus Ottosson

unread,
Oct 14, 2015, 5:50:02 PM10/14/15
to python_in...@googlegroups.com
That only seems relevant to the command-line text input box, and not the script editor.

I get this too, on Windows, and also find it quite bothersome. If a fix comes up, my mind would produce more endorphins.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

yury nedelin

unread,
Oct 15, 2015, 2:22:34 PM10/15/15
to python_in...@googlegroups.com
Well for now I have a ghetto workflow to avoid the mouse.

I have assigned this mel command to the ALT+1 hot key
selectCurrentExecuterControl

its in scriptEditorPanel.mel

so now I do ALT+TAB ALT+1

It seems none of Maya windows is selected when user ALT+TAB back to Maya so just selecting menu panel of the script editor fixes this. I will try Justin's solution later this week, it might all we need.


Marcus Ottosson

unread,
Oct 16, 2015, 7:29:53 AM10/16/15
to python_in...@googlegroups.com

Intrigued by the possibility eliminating this minor annoyance, I followed Justin’s suggestion and wrote a solution.

Run this, or put it in your userSetup.py, and it will restore focus to the Script Editor, if it is available.

from PySide import QtCore, QtGui

class RestoreScriptEditorFocus(QtCore.QObject):
    def eventFilter(self, obj, event):
        if event.type() != QtCore.QEvent.ApplicationActivate:
            return super(RestoreScriptEditorFocus, self).eventFilter(obj, event)

        script_editor = next(w for w in QtGui.qApp.topLevelWidgets() if w.objectName() == "scriptEditorPanel1Window")
        script_editor.activateWindow()
        return True

f = RestoreScriptEditorFocus()
QtGui.qApp.installEventFilter(f)

It’ll also “restore” focus to it, even if it wasn’t the last thing to have focus at the time of leaving the Maya window. Whether that’s a problem or not is too soon to tell, but I’ll leave the implementation for that to the reader.

Enjoy!



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

yury nedelin

unread,
Oct 16, 2015, 2:22:38 PM10/16/15
to python_in...@googlegroups.com
Thank you Marcus! and Justin!
it works for me and seems ok to select Script editor always as it does.
Yury


Justin Israel

unread,
Oct 16, 2015, 4:06:12 PM10/16/15
to python_in...@googlegroups.com

Joe Weidenbach

unread,
Oct 16, 2015, 6:30:53 PM10/16/15
to python_in...@googlegroups.com
Ok, that's a nice trick Marcus!

Marcus Ottosson

unread,
Oct 17, 2015, 5:12:06 PM10/17/15
to python_in...@googlegroups.com
No problem, glad to help!


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

eRiC Werner

unread,
Oct 20, 2015, 5:04:42 PM10/20/15
to Python Programming for Autodesk Maya
@Marcus Ottosson: Awesome!!!

I was trying to hack a version that remembers if last window was actually the scriptEditor. Using QtCore.QEvent.ApplicationDeactivate you easily get when you leave Maya. But getting the last window seems tricky!

QtGui.qApp.activeWindow() does not get you anything at that point.
QtGui.qApp.topLevelWidgets() is not sorted to have topmost window last or something.
cmds.getPanel(withFocus=True) is only sometimes giving you the 'scriptEditorPanel1' :( [wtf?] and
cmds.getPanel(underPointer=True) is kind of unreliable :/

my playground so far: http://pastebin.com/ibq7ZBVD

I'll try If I'm more happy with brute force scriptEditorPanel activation like that already :]
thanks a bunch!!!
ëRiC

Marcus Ottosson

unread,
Oct 21, 2015, 5:36:45 AM10/21/15
to python_in...@googlegroups.com

Hi Eric, glad you liked it.

Thanks for posting your progress! With that in mind, I gave it another go and came up with this.

from PySide import QtCore, QtGui

class RestoreScriptEditorFocus(QtCore.QObject):

    def __init__(self):
        super(RestoreScriptEditorFocus, self).__init__()
        QtGui.qApp.focusChanged.connect(self.on_focuschanged)
        self.restore = False

    def on_focuschanged(self, old, new):
        self.restore = "cmdScrollFieldExecuter" in old.objectName() if old else False

    def eventFilter(self, obj, event):
        if event.type() == QtCore.QEvent.ApplicationActivate and self.restore:
            script_editor = next(w for w in QtGui.qApp.topLevelWidgets() if w.objectName() == "scriptEditorPanel1Window")
            script_editor.activateWindow()
            return True
        else:
            return super(RestoreScriptEditorFocus, self).eventFilter(obj, event)

f = RestoreScriptEditorFocus()
QtGui.qApp.installEventFilter(f)

In a nutshell, it listens for any change of focus, and records whether or not the change was from the input field of the script editor, apparently called something like “cmdScrollFieldExecuter”. Not sure how consistent this is across versions of Maya.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Nov 1, 2015, 6:30:14 AM11/1/15
to python_in...@googlegroups.com
Fixed issues with a docker Script Editor and also went ahead and made a permanent Gist for it to track revision and facilitate searches via Google.

--
Marcus Ottosson
konstr...@gmail.com

Marcus Ottosson

unread,
Nov 2, 2015, 10:08:30 AM11/2/15
to python_in...@googlegroups.com
That's *docked*, not docker.
--
Marcus Ottosson
konstr...@gmail.com

eRiC Werner

unread,
Nov 11, 2015, 1:35:28 PM11/11/15
to Python Programming for Autodesk Maya
Cool! A friend was just suggested something similar! Works for me! :]
So you don't do anything when docked then?
Well I'm not docking. So I don't care... :] 👍
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com

ctjanney

unread,
Nov 11, 2015, 2:44:17 PM11/11/15
to Python Programming for Autodesk Maya
for me, I keep the script editor in a panel of my layout (saved dev layout).  I found when it's in the panel layout, I can ALT+TAB between apps and still have my cursor at the script editor where I left it.  If it's a floating window, not the case.

-ctj

Marcus Ottosson

unread,
Nov 13, 2015, 4:31:50 AM11/13/15
to python_in...@googlegroups.com

So you don’t do anything when docked then?

I hadn’t experienced the issue when it was docked, so figured it’d be safe to simply do nothing.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/62249a4b-b686-4893-9e9e-f28352b5367e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Martin Chatterjee

unread,
Sep 1, 2016, 9:58:28 AM9/1/16
to python_in...@googlegroups.com
Hey everybody, first post on this list for me - nice to e-meet you all! :)

Marcus, thanks again for having provided this workaround for preserving Script Editor focus. However I just noticed that this does not seem to work anymore in Maya 2017 (on Windows, that is...) 

I just had a quick look and the following change/addition seems to work for me both in 2017 and in older versions (the change is in line 15):  

            # (...)
            try:
                script_editor = next(w for w in QtGui.qApp.topLevelWidgets() if w.objectName() == "scriptEditorPanel1Window" or w.accessibleName() == "Script Editor")
                script_editor.activateWindow()
                return True

Marcus, I also commented on your Gist on GitHub, but I somehow failed at issuing a pull request for my change to you. Is that even possible for Gists? 

Anyway, here's my forked and updated Gist - hope this is helpful to somebody besides me.  

Cheers, Martin
  

--
       Martin Chatterjee

 
[ Freelance Technical Director ]
[   http://www.chatterjee.de   ]

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAzHUArJ7tazp_ngj%3Dyie%2BwSCxz-BjT9CyDtD61NRifFA%40mail.gmail.com.

Marcus Ottosson

unread,
Sep 1, 2016, 10:11:46 AM9/1/16
to python_in...@googlegroups.com
Hi Martin, you are most welcome!

I've updated my gist to reflect the changes made in yours, and added a note about it in the new "News" section of the README. Thanks for sharing!

Best,
Marcus

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com




--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Martin Chatterjee

unread,
Sep 1, 2016, 10:34:05 AM9/1/16
to python_in...@googlegroups.com
Hi Marcus, that was fast!  :)  

However I'm afraid I have messed up my updated Gist... :(  

I just updated my Gist again and verified that this works both in 2017 and 2016 on Windows.

Main Changes:
- import block tries to load PySide2 and falls back to PySide
- qApp now belongs to QWidgets (in PySide2) instead of QtGui (in PySide)


Could you please have another look?  Thanks again and sorry about that...


Cheers, Martin


--
       Martin Chatterjee

 
[ Freelance Technical Director ]
[   http://www.chatterjee.de   ]

On Thu, Sep 1, 2016 at 4:11 PM, Marcus Ottosson <konstr...@gmail.com> wrote:
Hi Martin, you are most welcome!

I've updated my gist to reflect the changes made in yours, and added a note about it in the new "News" section of the README. Thanks for sharing!

Best,
Marcus



--
Marcus Ottosson
konstr...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Marcus Ottosson

unread,
Sep 1, 2016, 10:47:38 AM9/1/16
to python_in...@googlegroups.com
No problem, Martin.

I've made another update; removed a few imports and made it PEP08 compliant in terms of line width as well.

Thanks!

Best,
Marcus

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages