Guest User

Untitled

a guest
Feb 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import maya.cmds as mc
  2.  
  3. class ScriptJobUI(object):
  4.    
  5.     def __init__(self):
  6.  
  7.         self.__window = 'SelectEdgeJob'
  8.         self.__currentJobId = None  
  9.  
  10.         # Check to see if the Window exists, Delete Window
  11.         if mc.window(self.__window, query=True, exists=True):
  12.             mc.deleteUI(self.__window)
  13.  
  14.         # Define window attributes
  15.         self.__window = mc.window(self.__window, title='SelectEdgeJob', sizeable=True)
  16.  
  17.         # Create menu bar with help    
  18.         menuBarLayout = mc.menuBarLayout()
  19.         helpMenu = mc.menu( label='help', tearOff=False )
  20.         howToHelp = mc.menuItem( label='How to use', command=loadHelp)
  21.  
  22.         # Main Layout of all menu is a form
  23.         mainFormLayout = mc.formLayout()
  24.         menuSeparator = mc.separator(style='in')
  25.         bottomSeparator = mc.separator(style='in')
  26.  
  27.         # create button to launch function
  28.         startSelectionButton = mc.button(label='Start Selection', command=startScriptJob)
  29.  
  30.         # create button to complete function
  31.         endtSelectionButton = mc.button(label='End Selection', command=endScriptJob)
  32.  
  33.         # Position the controls MainForm
  34.         mc.formLayout(mainFormLayout, edit=True, # attach to the form
  35.             attachForm=[
  36.                 (menuSeparator, 'top',3),
  37.                 (menuSeparator, 'left',3),
  38.                 (menuSeparator, 'right',3),
  39.  
  40.                 (startSelectionButton, 'left',3),                                                      
  41.                 (endtSelectionButton, 'right',3),
  42.  
  43.                 (bottomSeparator, 'left',3),
  44.                 (bottomSeparator, 'right',3),
  45.                 (bottomSeparator, 'bottom',5),
  46.             ],
  47.  
  48.             # Attach controls to positions
  49.             attachPosition=[
  50.                 (startSelectionButton, 'right', 2, 50),
  51.                 (endtSelectionButton, 'left', 2, 50),
  52.             ],
  53.  
  54.             # Attach controls to other controls
  55.             attachControl=[
  56.                 (startSelectionButton, 'top',5,menuSeparator),
  57.                 (endtSelectionButton, 'top',5,menuSeparator),
  58.             ],
  59.         )
  60.  
  61.     def show(self):
  62.         mc.showWindow(self.__window)
  63.  
  64.     def startScriptJob(self, *args):
  65.         self.endScriptJob()  # make sure an old one is dead first
  66.  
  67.         print 'StartJob'
  68.         newJob = mc.scriptJob(event=['SelectionChanged', self.selectionChanged])
  69.         print 'JOBNUMBER:', newJob
  70.  
  71.         self.__currentJobId = newJob
  72.  
  73.     def endScriptJob(self, *args):
  74.         if self.__currentJobId is not None:
  75.             print 'EndJob'
  76.             mc.scriptJob(kill=self.__currentJobId, force=True)
  77.  
  78.     def loadHelp(self, *args):
  79.         pass    
  80.  
  81.     def selectionChanged(self, *args):
  82.         print 'Script Job Executed!'
  83.  
  84.  
  85. ui = ScriptJobUI()
  86. ui.show()
Advertisement
Add Comment
Please, Sign In to add comment