pymel floatSlider: attaching it into an existing pyQT layout:

358 views
Skip to first unread message

mtherrell

unread,
Nov 5, 2010, 8:02:34 PM11/5/10
to python_inside_maya
i am using pymel 1.0 in maya 2011.
i am using QTDesigner to create my interface base class.

unfortunately, (and surprisingly) QT does not have a float slider. so
i need to make my float slider in my subclass of my qt interface using
pymel. ( prefer not to make an intslider powers of ten bigger than my
desired float range in order to approximate a float slider in QT.)

(i am using pyuic4 to emit my interface as a .py then i subclass
that .py)

1. are there any examples of creating a floatSlider using pymel, and
then laying it out in an already existing qt layout?

2. how do i get the QObject that results from creating a floatSlider
so that I can connect its signals using qt?

3. is it better to use qt signals to connect the floatSlider to my
functions or better to use the mel 'dragCommand' conventional callback
system somehow?

thanks for any help on using pymel floatSlider inside a qt layout..

-mark therrell

mtherrell

unread,
Nov 6, 2010, 3:04:35 PM11/6/10
to python_inside_maya
i should probably restate the problem and be a bit more clear..

my goal is to generate a maya float slider using the pymel
floatSlider() command, in a subclass of an interface created in qt
designer (and then pyuic4.. not using "loadUI").
i want to be able to treat this slider like any other QObject..
placing and attaching it into a QGridLayout in my QT interface, and
connecting its signals to
functions within my subclass. (whether by signals and slots or by the
callback functions of the floatslider() command itself..not sure)

my problem is that i do not know how to get the QObject that
represents the maya floatSlider so that i can do all these things to
it.
the object that is returned by pymel does not seem to allow QObject
functions. (not a QObject?)

am i missing something simple?
i am very new to qt and pymel..
its likely just newb-ism.
just needed a little help.

thanks.

David Moulder

unread,
Nov 6, 2010, 4:48:39 PM11/6/10
to python_in...@googlegroups.com
hmm, should be possible in 2011.

As long as you know the fullName of the parent layout then can you not use the setParent() cmd and then add the floatSlider.
Then get the float slider back as a QObject see the api MQtUtil i think.  I think pymel has toQObject, not documented tho.

I suppose you can then use signal as slots with that QObject.

It's an interesting mix as it's all Qt but the implementation in both are different.

-Dave




--
David Moulder
http://www.google.com/profiles/squish3d
Message has been deleted
Message has been deleted
Message has been deleted

mtherrell

unread,
Nov 8, 2010, 1:45:22 PM11/8/10
to python_inside_maya
thanks David.

in a function of my subclassed qtDesigner ui, i have access to the
QGridLayoutitself and/ or the QTabWidget that has that grid layout
within it.
like this: self.sliderLayout ..

i am trying to get the maya fullname of that widget using
MQtUtil.fullName().

my problem is MQtUtil.fullName().. and its c++ ducumentaion vs. python
documentation.
MQtUtil.fullName() supposedly returns the fullname as an MString or
the control, given it's QObject.

but i do not know how to represent the QObject pointer in python. the
docs say fullName() requires a pointer to the QObject.
even after reading up on how python handles pointers.. i still cannot
get MQtUtil.fullName() to work in python..

any help or examples on how to represent the QObject as a pointer in
python.. ort how to translate the c++ docs into python in general
would be a great help!

thanks
-mt

David Moulder

unread,
Nov 9, 2010, 4:39:45 AM11/9/10
to python_in...@googlegroups.com
I think you'll find this useful... some basic wraps of MQtUtil I did.  I originally got the idea for this from http://nathanhorne.com/?p=183
It's well worth bookmarking these TD's and using Google Reader.  I'm forever stealing and learning from these guys!  


I've not tried to do what your attempting yet but I hope to when I get 5 minutes at work...

-Dave

John Creson

unread,
Nov 9, 2010, 6:18:33 PM11/9/10
to python_in...@googlegroups.com
another bit to try.

give the layout a unique name and set parent to that unique name

or, dumpwidgets and weed through the dump...

for widge in cmds.lsUI(dumpWidgets=True):
if widge.startswith('mywindow'):
print widge

MQtUtil is also a great place to start digging.

> --
> http://groups.google.com/group/python_inside_maya

Message has been deleted

mtherrell

unread,
Nov 10, 2010, 2:14:52 PM11/10/10
to python_inside_maya
BTW, David thanks for the wrappers!
i did not know how to use sip wrap and unwrap in order to send the
pointers to and from QT

guss i need to learn more about sip.
im and old-school maya guy from way back.. and i used pyqt, after
that, in a proprietary pipeline for a long time..
but im very new to combining the two!

cheers and thanks for the help!
-mt

On Nov 9, 3:18 pm, John Creson <johncre...@gmail.com> wrote:
> another bit to try.
>
> give the layout a unique name and set parent to that unique name
>
> or, dumpwidgets and weed through the dump...
>
> for widge in cmds.lsUI(dumpWidgets=True):
>     if widge.startswith('mywindow'):
>        print widge
>
> MQtUtil is also a great place to start digging.
>
> On Tue, Nov 9, 2010 at 4:39 AM, David Moulder <da...@thirstydevil.co.uk> wrote:
> > I think you'll find this useful... some basic wraps of MQtUtil I did.
> >  I originally got the idea for this from http://nathanhorne.com/?p=183
> > It's well worth bookmarking these TD's and using Google Reader.  I'm forever
> > stealing and learning from these guys!
> >http://pastebin.com/rE6uhtm4
> > I've not tried to do what your attempting yet but I hope to when I get 5
> > minutes at work...
> > -Dave
>

Christian Akesson

unread,
Nov 11, 2010, 3:09:41 PM11/11/10
to python_in...@googlegroups.com
Those wrappers are really sweet - thanks for sharing!!
Utilizing what is already there, I added a method to find any element derived from QWidget within the given target UI by passing the string name of the element.
Found that if you have made the window dockable in Maya, you have to pass the string name of the dock control and if not, you can pass the window name string as target....

Previously I used self.findChild(QPushButton(or whatever class), QString('stringName')), but this utility method eliminates the need to keep track of class you are looking for....
Not quite sure how pastebin works (tried to make a revision on what is already there but I think it made a new link - http://pastebin.com/kNSeTMmX). 

/Christian


mtherrell

unread,
Nov 11, 2010, 3:20:27 PM11/11/10
to python_inside_maya
thanks guys for the tips!

what i have learned so far:

it appears that maya itself does not keep track of the widget
hierarchy in my subclassed, qtDesigner generated UI.

David, i tried out your GetFullName wrapper. running this on my
QObject i still get:

# TypeError: in method 'MQtUtil_fullName', argument 1 of type 'QObject
const *' #

note that, <pointer = sip.unwrapinstance(QObject)>, is actually
returning a number of type long.
but, <mui.MQtUtil.fullName(pointer)>, seems to still be choking on it.
that concerns me a bit..
if the pointer is there, why cant the api use it to get me a pathname?

i wrote my own hacky "fullpathname" test function that returns the
full
pathname of a QWidget in question, and gave it the same QObject that i
give your wrapper. and it gives me what i would expect from your
wrapper..
accept your wrapper of course would show that maya understands widget
paths in my UI.. and my function is purely QT.

somthing like this:
def getFullQWidgetPathName(startQWidget):

pathString = ''
path = []
p = startQWidget

while type(p)!= NoneType:
path.append('%s|'%p.objectName())
p = p.parentWidget()

path.reverse()
pathString = pathString.join(path)
return pathString.rstrip('|')

i can see my tool window in maya, its parented underneath the maya
main window, but maya seems to know nothing else about it.
trying to use any maya ui commands to parent or place the floatSlider
using the resulting path string from my hacky test function, produces:

# RuntimeError: floatSlider: Object ‘MayaWindow|tabChangedSignalTest|
centralwidget|tabWidget|qt_tabwidget_stackedwidget|tab_2|
gridLayoutWidget|sliderLayout’ not found. #

(and after much to-do i did make sure that is the actual widget
hierarchy in the pyQT UI. maya does not even see my tools main window
even though it is a child.. and yet it functions properly as a child.
everything in the UI works.. like using signals from a button to
create a sphere and a static-ui slider to move the sphere in x etc...)

so after all that, i sort of feel like maya really does not know
anything about the pyQT widget hierarchies, unless you use the loadUI
command or create the interface itself with maya commands.

however, i did find a way to parent and position a maya float slider
into this purely pyQT UI running in maya.
i downloaded and installed pymel 1.0.2.
included in this update are commands like toQObject(). i use
toQobject() to get the QObject of the float slider i create, then go
on using pyQT to parent and position the slider.
it works. the only problem is that maya still does not know the
floatSlider has been parented. so when you delete the main tool
window, it does not delete the folatslider. you can however delete it
explicitly with deleteUI maya command.

this situation is functional for what i want to do, if not ideal. i
can at least use maya specific widgets along side pyQT specific
widgets. which is great. but i still cant believe that maya knows
nothing about the widget hierarchy of the pyQT ui! and yet maya still
displays it and catches signals from it just fine.

will keep you updated as i learn more.
-thanks again,
Mark therrell

mtherrell

unread,
Nov 11, 2010, 3:43:59 PM11/11/10
to python_inside_maya
folow up question to David.. or anyone else who has successfully used
these wrapper functions.

when you get a good maya pathstring to your widget using the
GetFullname wrapper (that uses <mui.MQtUtil.fullName(pointer)>)

is the ui you are doing this on generated completely with maya
commands or pymel?
or can you also get a path from a widget in a ui generated soley with
qt (in this case qtDesigner then uic..), and then launched in maya?

the later is what i am trying to do.. without success so far.
if the former scenario is the only way for this wrapper to return a
path,
then that makes me think maya really knows nothing about my designer
generated UI other than signals coming from it.

hmmmm.

Christian Akesson

unread,
Nov 11, 2010, 8:30:56 PM11/11/10
to python_in...@googlegroups.com
I've been using a ui designed, then brought into Maya and make attachable through a dock panel.
I do all the signal and behavior hook ups and some extensions to the ui through code in the init...
Full path names and GetQtWidget works for me when I pass the string of the panel name. I also use GetMayaWindow when bringing in the ui....
Also the method I added for finding any UI element with full path name (bool) worked when I tested it.

Just ping if you have any questions, I will share from what I have gathered so far :-)

/Christian


mtherrell

unread,
Nov 11, 2010, 11:11:33 PM11/11/10
to python_inside_maya
thanks Christian.
sounds like that'll really help out.

interestingly, using

pymel.lsUI(type=['floatSlider'],l=1)

will return (among other floatSliders), the full pathname of the
floatslider i have parented into my qt designer ui.
so maya does know about the widget paths in this ui after all......

....but:

qFloatSlider = pymel.toQtObject('myFloatSlider')
pointer = sip.unwrapinstance(qFloatSlider)
mui.MQtUtil.fullName(pointer)

produces:
# TypeError: in method 'MQtUtil_fullName', argument 1 of type 'QObject
const *' #

printing out pointer:
print pointer
1002092800

type(pointer)
long

bemused by the inability of <mui.MQtUtil.fullName(pointer)> to
function as expected.

-mt


On Nov 11, 5:30 pm, Christian Akesson <cakes...@dslextreme.com> wrote:
> I've been using a ui designed, then brought into Maya and make attachable
> through a dock panel.
> I do all the signal and behavior hook ups and some extensions to the ui
> through code in the init...
> Full path names and GetQtWidget works for me when I pass the string of the
> panel name. I also use GetMayaWindow when bringing in the ui....
> Also the method I added for finding any UI element with full path name
> (bool) worked when I tested it.
>
> Just ping if you have any questions, I will share from what I have gathered
> so far :-)
>
> /Christian
>
> ...
>
> read more »

David Moulder

unread,
Nov 12, 2010, 5:08:32 AM11/12/10
to python_in...@googlegroups.com
With regards to the fullname() function.  I've only had problems on 32bit versions of Maya with the wrappers.  Hence the horrible hack at the end with GetQtWidget to search though the entire ui.  I have bugged the issue I was getting with the 32bit version of Maya.  It would be helpful that if you have a simple test where this isn't working to mail me with it for me to try.  It may be a simple wrapper error or it also may be a flakey api and we should BUG it with Autodesk.

I've experimented with several ways to create GUI's in Maya.  I used pymel, cmds and mel before I got into PyQt.  I'm so used to PyQt now that I would always fire up the designer for simple GUI or just do the layout part of a more complex GUI with the designer.  Then completely write a Qt class for the UI and inherit from the returns of uic.loadUiType(UiDesign).

I do have a Blog.  I keep promising myself that I will start to use it but life keeps getting in the way.  I'll make an effort to put a post up this weekend some Qt I think.

-Dave

Reply all
Reply to author
Forward
0 new messages