adding text to statusline

70 views
Skip to first unread message

Michał Frątczak

unread,
Mar 22, 2016, 8:55:38 AM3/22/16
to Python Programming for Autodesk Maya
Hello !
Does anybody have example code adding anything to statusline (that one with open,save icons) ?
I will take any suggestions :)

thanks
-michal

PS. maya2015

Marcus Ottosson

unread,
Mar 22, 2016, 10:05:51 AM3/22/16
to python_in...@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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/6bcd74b5-9996-4b50-835f-7fdbe724e0ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



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

f.michal

unread,
Mar 22, 2016, 10:14:42 AM3/22/16
to python_in...@googlegroups.com
W dniu 2016-03-22 o 15:05, Marcus Ottosson pisze:
Thank you Marcus !!

f.michal

unread,
Mar 22, 2016, 10:35:39 AM3/22/16
to python_in...@googlegroups.com
One more thing, how to add this at the end of statusline ?
I have no experience with Qt and blind fiddiling with parameters does nothing...


W dniu 2016-03-22 o 15:05, Marcus Ottosson pisze:

Marcus Ottosson

unread,
Mar 22, 2016, 12:17:06 PM3/22/16
to python_in...@googlegroups.com
You are most welcome.

Adding to the end is easier. Instead of "insertAction", use "addAction".

toolbar.addAction(action)

I've updated the Gist with a full example.


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



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

Michał Frątczak

unread,
Oct 12, 2016, 7:43:15 AM10/12/16
to Python Programming for Autodesk Maya
Sorry for bringing this up from the past.
We move to maya 2017 and obviously this isn't working anymore.
I updated code to PySide2 (after reading Fredrik's blog) but I get notging (even error messages).
Where in 2015 used to be toolBar object, now is 'flowLayout1' widget...
Is anybody willing to update this example for maya2017?

thanks!

Marcus Ottosson

unread,
Oct 12, 2016, 8:19:35 AM10/12/16
to python_in...@googlegroups.com

I’ve had a look at this just now, and it looks like they’ve gone from using a QToolBox to simply appending arbitrary widgets to a QLayout.

I don’t blame them, think it should probably have been made that way from the start, but what it means for us is that there is no adapting this script to work. It’ll need a rewrite.

It’s possible the alternative approach could work on 2017 and lower, which would be ideal.

I would start looking into grabbing hold of the layout, and adding your widget (not action) to it.

Here’s a start.

import os

try:
    from PySide import QtGui
    QtWidgets = QtGui
except ImportError:
    from PySide2 import QtWidgets, QtGui

# Use this to locate your widget; it will return the
# widget currently under your cursor.
# parent = QtWidgets.qApp.widgetAt(QtGui.QCursor.pos()).objectName()
# parent.objectName()

# Use this once you know the name of it, in this case "toolBar1"
# We can find it as a child of the main window.
window = {o.objectName(): o for o in QtWidgets.qApp.topLevelWidgets()}["MayaWindow"]
toolbar = window.findChild(QtWidgets.QToolBar, "toolBar1")

if toolbar:
    layout = toolbar.layout()
else:
    layout = window.findChild(QtWidgets.QLayout, "flowLayout1")

assert layout, "Sorry, couldn't find the toolbar."

# Create a random action
# NOTE: Not including an icon
action = QtWidgets.QPushButton("Hello")

# Add to the end..
# NOTE: Not adding to start
layout.addWidget(action)

# If you need to replace/update it, you can remove it like so.
# action.deleteLater()

# 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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5bc42682-b2ca-45e8-b617-360dd2b3b07e%40googlegroups.com.

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



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

Michał Frątczak

unread,
Oct 12, 2016, 11:33:34 AM10/12/16
to Python Programming for Autodesk Maya
Thanks Marcus!
With your help I was able to update code to working copy.
There's one piece of it making trouble however:
[code]
QtWidgets.qApp.topLevelWidgets()
[/code]

Sometimes qApp is 'None' and I couldn't find a reproducible scenario for this.
If my script is pasted to script editor it works most of the times. When it's imported through userSetup.py - it's always None...
Any clues ?

thanks

Marcus Ottosson

unread,
Oct 12, 2016, 11:41:36 AM10/12/16
to python_in...@googlegroups.com

Ah, that’s interesting.

qApp is the actively running instance of a QApplication; you could alternatively call QtWidgets.QApplication.instance(). Maya is bound to have just one, but it seems that, based on your description, userSetup.py executes before Qt starts running (sometimes?).

I would pass the entire thing, e.g. by wrapping it into a function, through cmds.evalDeferred or Qt.QtCore.QTimer.singleShot, that should give Qt enough time to catch up.

Michał Frątczak

unread,
Oct 13, 2016, 3:40:45 PM10/13/16
to Python Programming for Autodesk Maya
All is working great now, thanks Marcus
Reply all
Reply to author
Forward
0 new messages