Re: [Maya-Python] PyQt Model/View not showing in Maya

2016-09-19 Thread Alok Gandhi
Instead of commenting out, you can check for existence of an application
instance.

def run():
app = QtGui.QApplication.instance()
createNew = app is None

if createNew:
app = QtGui.QApplication(sys.argv)

win = BasicDialog()
win.show()
if createNew:
sys.exit(app.exec_())
if __name__ == '__main__':
run()



On Tue, Sep 20, 2016 at 8:30 AM, Justin Israel 
wrote:

>
>
> On Tue, Sep 20, 2016 at 12:20 PM likage  wrote:
>
>> @Justin, thanks for getting back to me.
>> So, I did a rewrite, however as long as I did not comment out both the
>> 'app = QtGui.QApplication(sys.argv)' and 'app.exec_()', running the code
>> would still cause my Maya to hang... Any ideas?
>>
>
> if "if __name__" stuff should not be executed when you import into maya.
> It would only happen when you run the tool standalone. I dont see a reason
> why maya should hang, if what you are doing in Maya is just creating an
> instance of your BasicDialog and calling show()
>
>
>>
>> But still, I would like to have some insights if the code that I have
>> written is the correct way to go?
>>
>
> Are you working with an older Maya (such as pre 2014?). As of current,
> Maya ships with PySide. You shouldn't need to create QString or QStringList
> (if I remember right). They should be able to handle python strings and
> lists?
>
>
>
>>
>>
>> # PyQt4 Modules
>> from PyQt4 import QtGui, QtCore
>> import sys
>> import maya.cmds as cmds
>>
>>
>> class BasicDialog(QtGui.QWidget):
>> def __init__(self):
>> QtGui.QWidget.__init__(self)
>> self.initData()
>> self.initUI()
>>
>> def initData(self):
>> data = QtCore.QStringList()
>> #data = []
>>
>> geos = cmds.ls(type = "mesh")
>> sel = cmds.listRelatives(geos, parent = True)
>> for item in sel:
>> data.append(QtCore.QString(str(item)))
>>
>> # Model
>>
>> self.ui_model = QtGui.QStringListModel(data)
>>
>> def initUI(self):
>> listView = QtGui.QListView()
>> listView.setModel(self.ui_model)
>>
>> layout = QtGui.QVBoxLayout()
>> layout.addWidget(listView)
>> self.setLayout(layout)
>>
>>
>> if __name__ == "__main__":
>> #app = QtGui.QApplication(sys.argv)
>> win = BasicDialog()
>> win.show()
>> #app.exec_()
>>
>>
>> Also, another question I have is, is using 'data = []' the same as 'data
>> = QtCore.QStringList()'? In my case, which would be better? Seeing that
>> both seems to be giving me the same results..
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/4894d625-0e32-4fa8-8a0a-
>> 4398c14c7776%40googlegroups.com
>> 
>> .
>> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/CAPGFgA1aizs_uhCPvNPeisy%
> 2Bhd191mFs0KY60Vqbonm_uG7urQ%40mail.gmail.com
> 
> .
>
> 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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMQg3T8%2BMWk7TYW8Mg7Xfagckb4fv%2BVPrv70FdbA5QuG_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] PyQt Model/View not showing in Maya

2016-09-19 Thread Justin Israel
On Tue, Sep 20, 2016 at 12:20 PM likage  wrote:

> @Justin, thanks for getting back to me.
> So, I did a rewrite, however as long as I did not comment out both the
> 'app = QtGui.QApplication(sys.argv)' and 'app.exec_()', running the code
> would still cause my Maya to hang... Any ideas?
>

if "if __name__" stuff should not be executed when you import into maya. It
would only happen when you run the tool standalone. I dont see a reason why
maya should hang, if what you are doing in Maya is just creating an
instance of your BasicDialog and calling show()


>
> But still, I would like to have some insights if the code that I have
> written is the correct way to go?
>

Are you working with an older Maya (such as pre 2014?). As of current, Maya
ships with PySide. You shouldn't need to create QString or QStringList (if
I remember right). They should be able to handle python strings and lists?



>
>
> # PyQt4 Modules
> from PyQt4 import QtGui, QtCore
> import sys
> import maya.cmds as cmds
>
>
> class BasicDialog(QtGui.QWidget):
> def __init__(self):
> QtGui.QWidget.__init__(self)
> self.initData()
> self.initUI()
>
> def initData(self):
> data = QtCore.QStringList()
> #data = []
>
> geos = cmds.ls(type = "mesh")
> sel = cmds.listRelatives(geos, parent = True)
> for item in sel:
> data.append(QtCore.QString(str(item)))
>
> # Model
>
> self.ui_model = QtGui.QStringListModel(data)
>
> def initUI(self):
> listView = QtGui.QListView()
> listView.setModel(self.ui_model)
>
> layout = QtGui.QVBoxLayout()
> layout.addWidget(listView)
> self.setLayout(layout)
>
>
> if __name__ == "__main__":
> #app = QtGui.QApplication(sys.argv)
> win = BasicDialog()
> win.show()
> #app.exec_()
>
>
> Also, another question I have is, is using 'data = []' the same as 'data =
> QtCore.QStringList()'? In my case, which would be better? Seeing that both
> seems to be giving me the same results..
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/4894d625-0e32-4fa8-8a0a-4398c14c7776%40googlegroups.com
> 
> .
> 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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1aizs_uhCPvNPeisy%2Bhd191mFs0KY60Vqbonm_uG7urQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Maya-Python] PyQt Model/View not showing in Maya

2016-09-19 Thread likage
Hi all, I have just started learning on pyqt4 model/view and I had thought 
of trying out a very simple code to populate maya items into a QListView. 
As I run the following code in an editor (without those maya 
modules/lines), I am able to see QListView being called and populated with 
the information.

As soon as I tried running the code in Maya, the session keeps crashing on 
me unless I comment out the lines on 'app' and 'sys.exit'
But even so, if those lines are commented out, while it does pops up a 
window, nothing was populated within.

Can someone kindly advise?

# PyQt4 Modules
from PyQt4 import QtGui, QtCore, uic
import sip
import sys
import maya.cmds as cmds
import maya.OpenMayaUI as mui

def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)

def main():
dialog = BasicDialog()
dialog.show()


class BasicDialog(QtGui.QDialog):
def __init__(self, parent=getMayaWindow()):
super(BasicDialog, self).__init__(parent)
#app = QtGui.QApplication(sys.argv)
#app.setStyle("cleanLooks")

# Data
data = QtCore.QStringList() 
#data << "one" << "two" << "three" << "four" << "five"   

geos = cmds.ls(type = "mesh")
sel = cmds.listRelatives(geos, parent = True)
for item in sel:
data.append(QtCore.QString(str(item)))

# Model
model = QtGui.QStringListModel(data)

listView = QtGui.QListView()
listView.show()
listView.setModel(model)

#sys.exit(app.exec_())
main()


-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/b37a7724-68d9-4ae8-811f-0d7233b7daf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.