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
<https://gist.github.com/martin-chatterjee/7759bdc0a877424542afc7bc1db06b07> -
hope this is helpful to somebody besides me.

Cheers, Martin


--
       Martin Chatterjee

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

On Sun, Nov 1, 2015 at 12:30 PM, Marcus Ottosson <[email protected]>
wrote:

> 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.
>
> - https://gist.github.com/mottosso/89aaa491179baf86f7e7
>
> On 21 October 2015 at 10:36, Marcus Ottosson <[email protected]>
> wrote:
>
>> 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.
>> ​
>>
>> On 20 October 2015 at 22:04, eRiC Werner <[email protected]> wrote:
>>
>>> @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
>>>
>>>
>>> On Friday, October 16, 2015 at 1:29:53 PM UTC+2, Marcus Ottosson wrote:
>>>>
>>>> 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!
>>>> ​
>>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/python_inside_maya/ff5b65a7-ef3d-4df8-885b-
>>> c150872baa24%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/ff5b65a7-ef3d-4df8-885b-c150872baa24%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> *Marcus Ottosson*
>> [email protected]
>>
>
>
>
> --
> *Marcus Ottosson*
> [email protected]
>
> --
> 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 [email protected].
> 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
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAzHUArJ7tazp_ngj%3Dyie%2BwSCxz-BjT9CyDtD61NRifFA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAC%2B%2B27KuUuvDmYOnCfwOA6QSOynseawcpGi-e3%2BL-D8E6yb-dQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
            • ... Marcus Ottosson
              • ... yury nedelin
              • ... Justin Israel
              • ... Joe Weidenbach
              • ... Marcus Ottosson
              • ... eRiC Werner
              • ... Marcus Ottosson
              • ... Marcus Ottosson
              • ... Marcus Ottosson
              • ... eRiC Werner
              • ... 'Martin Chatterjee' via Python Programming for Autodesk Maya
              • ... Marcus Ottosson
              • ... 'Martin Chatterjee' via Python Programming for Autodesk Maya
              • ... Marcus Ottosson
  • [Maya-Python]... ctjanney

Reply via email to