Exemple #1
0
def match_transform(mode='', child_comp=False):
    from . import sisidebar_sub
    pre_sel = cmds.ls(sl=True, l=True)
    selection = cmds.ls(sl=True, l=True, type='transform')
    if not selection:
        return
    cmds.undoInfo(openChunk=True)
    set_maching(nodes=selection, mode=mode ,pre_sel=pre_sel, child_comp=child_comp)
    
    msg = lang.Lang(en=u"<hl>Select Matching Object</hl>",
                            ja=u"<hl>一致対象オブジェクトを選択してください</hl>")
    cmds.inViewMessage( amg=msg.output(), pos='midCenterTop', fade=True )
    #cmds.select(cl=True)
    maching_tool = cmds.scriptCtx( title='Much Transform',
                        totalSelectionSets=3,
                        cumulativeLists=True,
                        expandSelectionList=True,
                        toolCursorType="edit",
                        setNoSelectionPrompt='Select the object you want to matching transform.'
                        )
    #カスタムカーソルを設定
    image_path = os.path.join(os.path.dirname(__file__), 'icon/')
    my_cursor = QCursor(QPixmap(image_path+'picker.png'))
    QApplication.setOverrideCursor(my_cursor)
    #cmds.hudButton('HUDHelloButton', e=True, s=7, b=5, vis=1, l='Button', bw=80, bsh='roundRectangle', rc=match_cancel )
    global hud_but
    if maya_ver != 2017:
        try:
            hud_but = cmds.hudButton('HUD_match_cancel', s=7, b=5, vis=1, l='Cancel', bw=80, bsh='roundRectangle', rc=finish_matching)
            #print 'create'
        except:
            #print 'change'
            hud_but = cmds.hudButton('HUD_match_cancel',e=True, s=7, b=5, vis=1, l='Cancel', bw=80, bsh='roundRectangle', rc=finish_matching)
    jobNum = cmds.scriptJob(ro=True, e=('SelectionChanged', qt.Callback(trs_matching)), protected=True)
    sisidebar_sub.get_matrix()
Exemple #2
0
def scriptCtx(*args, **kwargs):
    if len(args):
        doPassSelf = kwargs.pop('passSelf', False)
    else:
        doPassSelf = False
    for key in ['fcs', 'finalCommandScript', 'tf', 'toolFinish', 'toolStart', 'ts']:
        try:
            cb = kwargs[key]
            if callable(cb):
                kwargs[key] = _factories.makeUICallback(cb, args, doPassSelf)
        except KeyError:
            pass
    res = cmds.scriptCtx(*args, **kwargs)
    return res
Exemple #3
0
    def create_context(self, contextOptions, repeat=False):
        """
        Create a context hooked to the events for this instance
        """
        props = hasattr(self, 'create_property_ui') or None
        vals = hasattr(self, 'values') or None
        if not props == vals:
            raise RuntimeError('Tool classes with custom properties must implement both properties() and values()')

        if props and vals:
            props = self.PROPERTIES
            vals = self.VALUES

        opts = contextOptions.options(self.EVENT_PREFIX, self.START, self.FINISH, self.EXIT, props, vals)
        opts['title'] = self.name
        context_name = cmds.scriptCtx(**opts)
        Tool.REGISTRY[context_name] = self
        self.context_name = context_name
        self.repeat = repeat
        return context_name
Exemple #4
0
def match_transform(mode=''):
    from . import sisidebar_sub
    pre_sel = cmds.ls(sl=True, l=True)
    selection = cmds.ls(sl=True, l=True, type='transform')
    if not selection:
        return
    sisidebar_sub.set_maching(nodes=selection, mode=mode ,pre_sel=pre_sel)
    
    msg = lang.Lang(en=u"<hl>Select Matching Object</hl>",
                            ja=u"<hl>一致対象オブジェクトを選択してください</hl>")
    cmds.inViewMessage( amg=msg.output(), pos='midCenterTop', fade=True )
    #cmds.select(cl=True)
    maching_tool = cmds.scriptCtx( title='Much Transform',
                        totalSelectionSets=3,
                        cumulativeLists=True,
                        expandSelectionList=True,
                        tct="edit",
                        setNoSelectionPrompt='Select the object you want to matching transform.'
                        )
    cmds.setToolTo(maching_tool)
    jobNum = cmds.scriptJob(ro=True, e=('SelectionChanged', qt.Callback(sisidebar_sub.trs_matching)), protected=True)
    sisidebar_sub.get_matrix()
Exemple #5
0
    def __init__(self):
    
        parent = gui.mainWindow()

        # stay on top added for maya2014 osx
        super(Gui, self).__init__(parent, QtCore.Qt.WindowStaysOnTopHint)

        self.toolActive = False

        #self.setWindowFlags( self.windowFlags() )

        #self.setWindowFlags(QtCore.Qt.Window)

        self.setWindowTitle('Markerset Tool')
        self.resize( 500, 600 )
        
        self.markers   = None
        self.markerset = None
        self.prefix    = None
        self.customSets = {}

        self.mainlayout = QtWidgets.QVBoxLayout()
        self.hlayout = QtWidgets.QHBoxLayout()
        self.menuBar = QtWidgets.QMenuBar()
        self.toolbar = QtWidgets.QToolBar()
        self.setStyleSheet( "QToolButton {  background-color: #222; padding: 3px; margin: 3px; border: 1px solid gray; } ");

        self.mainlayout.setMenuBar(self.menuBar)    

        # markerset combo

        self.formLayout = QtWidgets.QFormLayout()
        self.markersetSelector = QtWidgets.QComboBox(self)        
        self.markersetSelector.currentIndexChanged.connect( self.markersetSelect )
        self.formLayout.addRow( "Markerset", self.markersetSelector )        

        # markerset prefix table
        self.prefixSelector = QtWidgets.QTableWidget(self)
        self.prefixSelector.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection);
        self.prefixSelector.itemChanged.connect( self.prefixItemChange )
        self.prefixSelector.currentCellChanged.connect( self.prefixSelected )
        self.prefixSelector.setColumnCount(2)
        self.prefixSelector.setColumnWidth(0, 200)
        self.prefixSelector.setColumnWidth(1, 30)
        self.prefixSelector.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.formLayout.addRow(  self.prefixSelector )

        # display mode combo
        self.displaySelector = QtWidgets.QComboBox(self)
        self.displaySelector.currentIndexChanged.connect( self.setDisplayMode )
        self.displaySelector.addItems( [ '--select--', 'square', 'circle', 'cross', 'circle/cross' ] )
        self.formLayout.addRow( "Display Markers", self.displaySelector )

        # display mode-selected
        self.displaySelector2 = QtWidgets.QComboBox(self)
        self.displaySelector2.currentIndexChanged.connect( self.setSelectedMode )
        self.displaySelector2.addItems( [ '--select--', 'square', 'circle', 'cross', 'circle/cross' ] )
        self.formLayout.addRow( "Display Selected", self.displaySelector2 )

        # source range mode
        self.sourceRangeSelector = QtWidgets.QComboBox(self)
        self.sourceRangeSelector.addItems( [  'gap', 'fill', 'segment', 'spike', 'all', 'selected' ] )
        self.formLayout.addRow( "Source Range", self.sourceRangeSelector )

        # replace mode 
        self.replaceModeSelector = QtWidgets.QComboBox(self)
        self.replaceModeSelector.addItems( [ 'extract', 'swap', 'overwrite' ] )
        self.formLayout.addRow( "Replace Mode", self.replaceModeSelector )

        # buttons
        buttonLayout  = QtWidgets.QHBoxLayout()

        refreshButton = QtWidgets.QToolButton(self)
        refreshButton.setText("Refresh")
        refreshButton.clicked.connect( self.markersetSelect )

        oneTwoButton = QtWidgets.QToolButton(self)
        oneTwoButton.setText("1->2")
        oneTwoButton.clicked.connect( self.onetwo )

        queryButton = QtWidgets.QToolButton(self)
        queryButton.setText("?")
        queryButton.clicked.connect( self.query )
        queryButton.setToolTip("select affected keys")

        highlightButton = QtWidgets.QToolButton(self)
        highlightButton.setText("^")
        highlightButton.clicked.connect( self.highlight )
        highlightButton.setToolTip("Highlight selected")

        toolButton = QtWidgets.QToolButton(self)
        toolButton.setText("*")
        toolButton.clicked.connect( self.tool )
        toolButton.setToolTip("Assignment Tool")

        buttonLayout.addWidget(refreshButton)
        buttonLayout.addWidget(oneTwoButton)
        buttonLayout.addWidget(queryButton)
        buttonLayout.addWidget(highlightButton)
        buttonLayout.addWidget(toolButton)
        #buttonWidget  = QtWidgets.QWidget()
        #buttonWidget.setLayout(buttonLayout)

        self.formLayout.addRow( buttonLayout )

        # colors
        self.colorWidget = QtWidgets.QWidget(self)
        self.colorLayout = QtWidgets.QHBoxLayout(self.colorWidget)
        for c in [14, 15, 22, 27, 28, 29, 30, 31 ] :
            self.colorLayout.addWidget ( colorButton( c , partial( self.cb_color, c ) ) )
        self.colorWidget.setLayout(self.colorLayout)
        self.formLayout.addRow( self.colorWidget )


        # progress
        self.progressBar = QtWidgets.QProgressBar(self)
        self.progressBar.setVisible(False)
        self.formLayout.addRow(self.progressBar)

        self.progressLabel = QtWidgets.QLabel(self)
        self.progressLabel.setVisible(False)
        self.formLayout.addWidget(self.progressLabel)
        self.progressLabel.setSizePolicy( QtWidgets.QSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)  )

        
        # marker select list
        self.markerList = QtWidgets.QTableWidget(1, 4, self)
        self.markerList.itemClicked.connect( self.cb_select )
        self.markerList.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection )

        # marker assign list
        #self.assignList = QtWidgets.QListWidget(self)
        #self.assignList.itemClicked.connect( self.cb_change )


        # markerset menu
        markersetMenu = QtWidgets.QMenu("Markerset", parent=self)
        self.menuBar.addMenu(markersetMenu)

        for text, func in [
                        ( 'Load',                    self.cb_load),
                        ( 'Save',                    self.cb_save),
                        ( 'From Selection',          self.cb_fromSelection),
                        ( 'Set Markerset Directory', self.cb_setMarkersetDir),
                        ( 'Refesh',                  self.loadMarkersets ),
                        ( 'Save Markerset',          self.cb_save )
                        ] :
            
            action = QtWidgets.QAction( text, self )
            action.triggered.connect(func)
            markersetMenu.addAction( action)
            
        # marker menu
        markerMenu = QtWidgets.QMenu("Markers", parent=self)
        self.menuBar.addMenu(markerMenu)
        
        for text, func in [
                        ( 'Draw Line',           self.cb_drawLine ),
                        ( 'Clear Lines',         self.cb_clearMarkerLines),
                        ( 'Select Empty',        self.cb_selectEmpty),
                        ( 'Select Unlabelled',   self.cb_selectUnlabelled) ,
                        ( 'Set Data Rate',       self.cb_setDataRate),
                        ] :
            
            action = QtWidgets.QAction( text, self )
            action.triggered.connect(func)
            markerMenu.addAction( action)



        # toolbar

        for text, func in [ 
                        ( 'sel',        self.cb_selectMarkers ) ,
                        ( 'sel-all',    self.cb_selectAll ),
                        ( 'lines',      self.cb_drawLines ),
                        ( 'active',     self.cb_setActive),
                        ( 'display',    self.cb_display),
                        ] :
            action = QtWidgets.QAction( text, self )
            action.triggered.connect(func)
            self.toolbar.addAction( action )
    

        # layout
        self.hlayout.addWidget( self.markerList, 1 )
        self.hlayout.addLayout( self.formLayout, 0 )

        self.mainlayout.addWidget( self.toolbar,    0 )
        self.mainlayout.addLayout( self.hlayout, 1 ) 

        #self.mainWidget = QtGui.QWidget()
        #self.mainWidget.setLayout( self.mainlayout )
        #self.setCentralWidget(self.mainWidget)

        self.setLayout( self.mainlayout )
        #self.setWindowFlags( self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint )
        #self.setWindowFlags( self.windowFlags() & ~QtCore.Qt.WindowStaysOnBottomHint )


        self.loadMarkersets()
        
        # guess the markerset by finding the set with the most matching markers

        results = []
        for i, setName in enumerate( markerset.markersets.keys() ) :
            mset = markerset.markersets[ setName ]
            for prefix in mset.prefixes() :
                found, missing = mset.test(prefix )
                results.append ( ( i, prefix, len(found) ) )

        if len(results) > 0 :
            maxval = max( results, key = lambda v : v[2] )[0]
            self.markersetSelector.setCurrentIndex(maxval+1)


        self.markersetSelect()

        startCommand  = "import " + localsettings.module + ".labeler as l;l.startTool()"
        finishCommand = "import " + localsettings.module + ".labeler as l;l.selectEvent()"
        self.context =  m.scriptCtx( t='test', ts='python("' + startCommand + '")',
                 tf='python("' + finishCommand + '")', tct='dot',  lc=True, tss=1)