[Maya-Python] Re: PyQt in Maya examples

2009-10-26 Thread David Moulder
Here it is, This version has fixed our threading errors that occurred
where maya wouldn't close correctly and leave 1 mayapy thread open.

-Dave

###

from PyQt4 import QtCore, QtGui
import maya.utils as utils
import sys
import time
import threading
import maya.cmds as cmds

pumpedThread = None
app = None
gPump = True

def get_app():
global app
return app

def set_app(i_app):
global app
testAppInstance = QtCore.QCoreApplication.instance()
if testAppInstance:
app = testAppInstance
else:
app = i_app

def get_pt():
global pumpedThread
return pumpedThread

def set_pt(i_pt):
global pumpedThread
pumpedThread = i_pt

def pumpQt():
global app
global gPump
processorEv = threading.Event()
def processor():
app.processEvents()
processorEv.set()
while gPump:
utils.executeDeferred( processor )
processorEv.wait()
processorEv.clear()
time.sleep(0.01)

def killProcess():
global gPump
gPump = False

def killPumpThread():
if get_app():
get_app().closeAllWindows()
if get_pt():
while get_pt().isAlive():
killProcess()
set_pt(None)
set_app(None)


def initializePumpThread():
global gPump
gPump = True
if get_pt() == None:
set_app(QtGui.QApplication(sys.argv))
set_pt(threading.Thread( target = pumpQt, args = () ))
get_pt().start()

On Fri, Oct 23, 2009 at 8:41 PM, Sylvain Berger sylvain.ber...@gmail.comwrote:

 Where can I find your version of pumpThread?

 Thanks


 On Tue, Sep 29, 2009 at 5:24 AM, David Moulder 
 da...@thirstydevil.co.ukwrote:

 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default one
 from the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
 def __init__(self, parent=None):
 super(ExampleUI, self).__init__(parent)
 # Set some basic properties on the UI
 self.setWindowTitle('ExampleUI')
 self.setObjectName(ExampleUI)
 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

 # Add a Layout and set it to the UI
 self.mainLayout = QtGui.QVBoxLayout(self)
 self.setLayout(self.mainLayout)

 # Add a Button and set some properties.  Also add it to a layout.
 self.RefreshButton = QtGui.QPushButton()
 self.RefreshButton.setText(Refresh)
 self.mainLayout.addWidget(self.RefreshButton)

 # Add a list and set it to the layout
 self.SelectionList = QtGui.QListWidget()
 self.SelectionList.setMinimumSize(250,250)
 self.mainLayout.addWidget(self.SelectionList)

 # Connect the Refresh Button to a function to populate the list
 using SIGNAL's
 self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

 def _RefreshButtonFunc(self):
 '''
 Fill the list based on a maya selection
 '''
 oSel = pm.selected()
 if oSel:
 self.SelectionList.clear()
 [self.SelectionList.addItem(s.name()) for s in oSel]
 else:
 self.SelectionList.clear()

 @staticmethod
 def Display():
 '''
 calls the window.  Typical PumpThread call
 Use's a modified pumpThread that properly set's up the thread.
 '''
 # We need a global to stop python gc the UI
 global mainWindow

 # We need pumpThread to make the UI responsive
 pumpThread.initializePumpThread()
 app = pumpThread.get_app()
 if app:
 # We can set the app to use a nice style
 app.setStyle('Plastique')
 mainWindow = ExampleUI()
 mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave



 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:


 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.








 --
 A pit would not be complete without a Freeman coming out of it.
 The Vortigaunt


 


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



[Maya-Python] Re: PyQt in Maya examples

2009-10-26 Thread John Creson

Thanks David!

On Mon, Oct 26, 2009 at 9:13 AM, Sylvain Berger
sylvain.ber...@gmail.com wrote:
 Thanks a lot David!

 On Mon, Oct 26, 2009 at 5:23 AM, David Moulder da...@thirstydevil.co.uk
 wrote:

 Here it is, This version has fixed our threading errors that occurred
 where maya wouldn't close correctly and leave 1 mayapy thread open.

 -Dave

 ###

 from PyQt4 import QtCore, QtGui
 import maya.utils as utils
 import sys
 import time
 import threading
 import maya.cmds as cmds

 pumpedThread = None
 app = None
 gPump = True

 def get_app():
     global app
     return app

 def set_app(i_app):
     global app
     testAppInstance = QtCore.QCoreApplication.instance()
     if testAppInstance:
         app = testAppInstance
     else:
         app = i_app

 def get_pt():
     global pumpedThread
     return pumpedThread

 def set_pt(i_pt):
     global pumpedThread
     pumpedThread = i_pt

 def pumpQt():
     global app
     global gPump
     processorEv = threading.Event()
     def processor():
         app.processEvents()
         processorEv.set()
     while gPump:
         utils.executeDeferred( processor )
         processorEv.wait()
         processorEv.clear()
         time.sleep(0.01)

 def killProcess():
     global gPump
     gPump = False

 def killPumpThread():
     if get_app():
         get_app().closeAllWindows()
     if get_pt():
         while get_pt().isAlive():
             killProcess()
         set_pt(None)
         set_app(None)


 def initializePumpThread():
     global gPump
     gPump = True
     if get_pt() == None:
     set_app(QtGui.QApplication(sys.argv))
     set_pt(threading.Thread( target = pumpQt, args = () ))
     get_pt().start()

 On Fri, Oct 23, 2009 at 8:41 PM, Sylvain Berger sylvain.ber...@gmail.com
 wrote:

 Where can I find your version of pumpThread?

 Thanks

 On Tue, Sep 29, 2009 at 5:24 AM, David Moulder da...@thirstydevil.co.uk
 wrote:

 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default one
 from the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
     def __init__(self, parent=None):
     super(ExampleUI, self).__init__(parent)
     # Set some basic properties on the UI
     self.setWindowTitle('ExampleUI')
     self.setObjectName(ExampleUI)
     self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

     # Add a Layout and set it to the UI
     self.mainLayout = QtGui.QVBoxLayout(self)
     self.setLayout(self.mainLayout)

     # Add a Button and set some properties.  Also add it to a
 layout.
     self.RefreshButton = QtGui.QPushButton()
     self.RefreshButton.setText(Refresh)
     self.mainLayout.addWidget(self.RefreshButton)

     # Add a list and set it to the layout
     self.SelectionList = QtGui.QListWidget()
     self.SelectionList.setMinimumSize(250,250)
     self.mainLayout.addWidget(self.SelectionList)

     # Connect the Refresh Button to a function to populate the list
 using SIGNAL's
     self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

     def _RefreshButtonFunc(self):
     '''
     Fill the list based on a maya selection
     '''
     oSel = pm.selected()
     if oSel:
     self.SelectionList.clear()
     [self.SelectionList.addItem(s.name()) for s in oSel]
     else:
     self.SelectionList.clear()

     @staticmethod
     def Display():
     '''
     calls the window.  Typical PumpThread call
     Use's a modified pumpThread that properly set's up the thread.
     '''
     # We need a global to stop python gc the UI
     global mainWindow

     # We need pumpThread to make the UI responsive
     pumpThread.initializePumpThread()
     app = pumpThread.get_app()
     if app:
     # We can set the app to use a nice style
     app.setStyle('Plastique')
     mainWindow = ExampleUI()
     mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave


 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:

 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.








 --
 A pit would not be complete without a Freeman coming out of it.
 The Vortigaunt








 --
 A pit would not be complete without a Freeman coming out of it.
 The Vortigaunt

 



[Maya-Python] Re: PyQt in Maya examples

2009-10-23 Thread Sylvain Berger
Where can I find your version of pumpThread?

Thanks

On Tue, Sep 29, 2009 at 5:24 AM, David Moulder da...@thirstydevil.co.ukwrote:

 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default one
 from the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
 def __init__(self, parent=None):
 super(ExampleUI, self).__init__(parent)
 # Set some basic properties on the UI
 self.setWindowTitle('ExampleUI')
 self.setObjectName(ExampleUI)
 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

 # Add a Layout and set it to the UI
 self.mainLayout = QtGui.QVBoxLayout(self)
 self.setLayout(self.mainLayout)

 # Add a Button and set some properties.  Also add it to a layout.
 self.RefreshButton = QtGui.QPushButton()
 self.RefreshButton.setText(Refresh)
 self.mainLayout.addWidget(self.RefreshButton)

 # Add a list and set it to the layout
 self.SelectionList = QtGui.QListWidget()
 self.SelectionList.setMinimumSize(250,250)
 self.mainLayout.addWidget(self.SelectionList)

 # Connect the Refresh Button to a function to populate the list
 using SIGNAL's
 self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

 def _RefreshButtonFunc(self):
 '''
 Fill the list based on a maya selection
 '''
 oSel = pm.selected()
 if oSel:
 self.SelectionList.clear()
 [self.SelectionList.addItem(s.name()) for s in oSel]
 else:
 self.SelectionList.clear()

 @staticmethod
 def Display():
 '''
 calls the window.  Typical PumpThread call
 Use's a modified pumpThread that properly set's up the thread.
 '''
 # We need a global to stop python gc the UI
 global mainWindow

 # We need pumpThread to make the UI responsive
 pumpThread.initializePumpThread()
 app = pumpThread.get_app()
 if app:
 # We can set the app to use a nice style
 app.setStyle('Plastique')
 mainWindow = ExampleUI()
 mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave



 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:


 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.




 



-- 
A pit would not be complete without a Freeman coming out of it.
The Vortigaunt

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



[Maya-Python] Re: PyQt in Maya examples

2009-09-29 Thread David Moulder
Ok,  Here's and basic example with PyQT and a QListWidget...
Please note.  This use's a modified pumpThread module.  The default one from
the maya dev kit has given us lots of problems.
Thanks to some very clever people on this list we now have a working
pumpThread module that is heavily tested here at work.

from PyQt4 import QtCore, QtGui
import pymel as pm
import pumpThread

class ExampleUI(QtGui.QDialog):
def __init__(self, parent=None):
super(ExampleUI, self).__init__(parent)
# Set some basic properties on the UI
self.setWindowTitle('ExampleUI')
self.setObjectName(ExampleUI)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

# Add a Layout and set it to the UI
self.mainLayout = QtGui.QVBoxLayout(self)
self.setLayout(self.mainLayout)

# Add a Button and set some properties.  Also add it to a layout.
self.RefreshButton = QtGui.QPushButton()
self.RefreshButton.setText(Refresh)
self.mainLayout.addWidget(self.RefreshButton)

# Add a list and set it to the layout
self.SelectionList = QtGui.QListWidget()
self.SelectionList.setMinimumSize(250,250)
self.mainLayout.addWidget(self.SelectionList)

# Connect the Refresh Button to a function to populate the list
using SIGNAL's
self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
self._RefreshButtonFunc)

def _RefreshButtonFunc(self):
'''
Fill the list based on a maya selection
'''
oSel = pm.selected()
if oSel:
self.SelectionList.clear()
[self.SelectionList.addItem(s.name()) for s in oSel]
else:
self.SelectionList.clear()

@staticmethod
def Display():
'''
calls the window.  Typical PumpThread call
Use's a modified pumpThread that properly set's up the thread.
'''
# We need a global to stop python gc the UI
global mainWindow

# We need pumpThread to make the UI responsive
pumpThread.initializePumpThread()
app = pumpThread.get_app()
if app:
# We can set the app to use a nice style
app.setStyle('Plastique')
mainWindow = ExampleUI()
mainWindow.show()

ExampleUI.Display()

I'll post our final pumpThread later today.

-Dave


On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:


 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.

 


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



[Maya-Python] Re: PyQt in Maya examples

2009-09-29 Thread floyd1510

Thanks Dave for the example.

The problem is that I couldn't get the example running. Following is
what I executed in Maya :

import example
example.ExampleUI()

This outputs the following :

# Result: example.ExampleUI object at 0x2268B6A8 #

Then on running  :

ExampleUI.Display() , I get an error saying ExampleUI is not defined.

Any idea where am I going wrong. Thanks for the help,

Cheers,
Vikram.



This gives an error saying that ExampleUI is not defined. What am I
doing wrong

On Sep 29, 7:24 pm, David Moulder da...@thirstydevil.co.uk wrote:
 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default one from
 the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
     def __init__(self, parent=None):
         super(ExampleUI, self).__init__(parent)
         # Set some basic properties on the UI
         self.setWindowTitle('ExampleUI')
         self.setObjectName(ExampleUI)
         self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

     # Add a Layout and set it to the UI
         self.mainLayout = QtGui.QVBoxLayout(self)
         self.setLayout(self.mainLayout)

         # Add a Button and set some properties.  Also add it to a layout.
         self.RefreshButton = QtGui.QPushButton()
         self.RefreshButton.setText(Refresh)
         self.mainLayout.addWidget(self.RefreshButton)

         # Add a list and set it to the layout
         self.SelectionList = QtGui.QListWidget()
         self.SelectionList.setMinimumSize(250,250)
         self.mainLayout.addWidget(self.SelectionList)

         # Connect the Refresh Button to a function to populate the list
 using SIGNAL's
         self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

     def _RefreshButtonFunc(self):
         '''
         Fill the list based on a maya selection
         '''
         oSel = pm.selected()
         if oSel:
             self.SelectionList.clear()
             [self.SelectionList.addItem(s.name()) for s in oSel]
         else:
             self.SelectionList.clear()

     @staticmethod
     def Display():
         '''
         calls the window.  Typical PumpThread call
         Use's a modified pumpThread that properly set's up the thread.
         '''
         # We need a global to stop python gc the UI
         global mainWindow

         # We need pumpThread to make the UI responsive
         pumpThread.initializePumpThread()
         app = pumpThread.get_app()
         if app:
             # We can set the app to use a nice style
             app.setStyle('Plastique')
             mainWindow = ExampleUI()
             mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave

 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com wrote:

  Hello all,

  I have got PyQt up and running in Maya 2009. I was wondering if
  someone could guide me to a few examples, like adding a list of
  objects from maya into the QT listview or adding items dynamically to
  a combo box etc.

  I appreciate the help.

  Cheers,
  Vikram.


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



[Maya-Python] Re: PyQt in Maya examples

2009-09-29 Thread Chad Dombrova

try:

example.ExampleUI.Display()

ExampleUI is inside the example module, so you have to prefix it with  
the module name

-chad


On Sep 29, 2009, at 9:53 PM, floyd1510 wrote:


 Thanks Dave for the example.

 The problem is that I couldn't get the example running. Following is
 what I executed in Maya :

 import example
 example.ExampleUI()

 This outputs the following :

 # Result: example.ExampleUI object at 0x2268B6A8 #

 Then on running  :

 ExampleUI.Display() , I get an error saying ExampleUI is not defined.

 Any idea where am I going wrong. Thanks for the help,

 Cheers,
 Vikram.



 This gives an error saying that ExampleUI is not defined. What am I
 doing wrong

 On Sep 29, 7:24 pm, David Moulder da...@thirstydevil.co.uk wrote:
 Ok,  Here's and basic example with PyQT and a QListWidget...
 Please note.  This use's a modified pumpThread module.  The default  
 one from
 the maya dev kit has given us lots of problems.
 Thanks to some very clever people on this list we now have a working
 pumpThread module that is heavily tested here at work.

 from PyQt4 import QtCore, QtGui
 import pymel as pm
 import pumpThread

 class ExampleUI(QtGui.QDialog):
 def __init__(self, parent=None):
 super(ExampleUI, self).__init__(parent)
 # Set some basic properties on the UI
 self.setWindowTitle('ExampleUI')
 self.setObjectName(ExampleUI)
 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

 # Add a Layout and set it to the UI
 self.mainLayout = QtGui.QVBoxLayout(self)
 self.setLayout(self.mainLayout)

 # Add a Button and set some properties.  Also add it to a  
 layout.
 self.RefreshButton = QtGui.QPushButton()
 self.RefreshButton.setText(Refresh)
 self.mainLayout.addWidget(self.RefreshButton)

 # Add a list and set it to the layout
 self.SelectionList = QtGui.QListWidget()
 self.SelectionList.setMinimumSize(250,250)
 self.mainLayout.addWidget(self.SelectionList)

 # Connect the Refresh Button to a function to populate the  
 list
 using SIGNAL's
 self.connect(self.RefreshButton, QtCore.SIGNAL(clicked()),
 self._RefreshButtonFunc)

 def _RefreshButtonFunc(self):
 '''
 Fill the list based on a maya selection
 '''
 oSel = pm.selected()
 if oSel:
 self.SelectionList.clear()
 [self.SelectionList.addItem(s.name()) for s in oSel]
 else:
 self.SelectionList.clear()

 @staticmethod
 def Display():
 '''
 calls the window.  Typical PumpThread call
 Use's a modified pumpThread that properly set's up the  
 thread.
 '''
 # We need a global to stop python gc the UI
 global mainWindow

 # We need pumpThread to make the UI responsive
 pumpThread.initializePumpThread()
 app = pumpThread.get_app()
 if app:
 # We can set the app to use a nice style
 app.setStyle('Plastique')
 mainWindow = ExampleUI()
 mainWindow.show()

 ExampleUI.Display()

 I'll post our final pumpThread later today.

 -Dave

 On Tue, Sep 29, 2009 at 6:42 AM, floyd1510 vshingr...@gmail.com  
 wrote:

 Hello all,

 I have got PyQt up and running in Maya 2009. I was wondering if
 someone could guide me to a few examples, like adding a list of
 objects from maya into the QT listview or adding items dynamically  
 to
 a combo box etc.

 I appreciate the help.

 Cheers,
 Vikram.


 


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