44hero-01
4/3/2020 - 7:17 AM

-cmds- <maya UI> easy win build, and partial

# -*- coding: utf-8 -*-

import maya.cmds as cmds

def txtMessages():
    cmds.rowColumnLayout('rwClmLyot_main'
                , numberOfRows = 1
                , rowAttach = ([1, "both", 5], [2, "both", 5])
                , rowAlign = ([1, "center"], [2, "center"])  
                    )
    cmds.text('hello')
    cmds.text('Mr.Oki')
    cmds.text('Mr.Papa')
    
cmds.window()
txtMessages()
cmds.showWindow()

##############################################################################


win = "testWin"
if cmds.window(win, exists=True):
    cmds.deleteUI(win, window=True)
    

cmds.window(win, title='TEST WINDOW',widthHeight=(600,350))

cmds.rowLayout( numberOfColumns=3
        , columnWidth3=[200, 200, 200]
        , columnAttach=([1,'both',5], [2,'both',5], [3,'both',5])
              ) 
cmds.button( label='Command 1', height=26)
cmds.button( label='Command 2', height=26)
cmds.button( label='Command 3', height=26)

cmds.showWindow(win)

##############################################################################


win = "testWin"
if cmds.window(win, exists=True):
    cmds.deleteUI(win, window=True)
    

cmds.window(win, title='TEST WINDOW',widthHeight=(600,350))

cmds.rowLayout( numberOfColumns=2
        , columnWidth2=[200, 200]
        , columnAttach=([1,'both',5], [2,'both',5])
              ) 
cmds.button( label='Command 1', height=26)
cmds.button( label='Command 2', height=26)

cmds.showWindow(win)

##############################################################################


win = "testWin"
if cmds.window(win, exists=True):
    cmds.deleteUI(win, window=True)
    

cmds.window(win, title='TEST WINDOW',widthHeight=(600,350))

#cmds.columnLayout(adjustableColumn = True)
cmds.rowLayout( numberOfColumns=2
        , columnWidth2=[200, 200]
        , columnAttach=([1,'both',5], [2,'both',5])
              ) 
cmds.button( label='Command 1', height=26)
cmds.button( label='Command 2', height=26)
#cmds.setParent("..")

cmds.showWindow(win)


##############################################################################

win = "testWin"
if cmds.window(win, exists = True):
    cmds.deleteUI(win, window = True)
    
cmds.window(win, title='TEST WINDOW',widthHeight=(600,350))
mainForm = cmds.formLayout(numberOfDivisions=100 )
b1 = cmds.button( label='Command 1', height=26)
b2 = cmds.button( label='Command 2', height=26)
b3 = cmds.button( label='Command 3', height=26)
cmds.formLayout(
            mainForm, edit=True, 
            #フォームの境界にボタンのどのエッジを固定するかの指定。オフセット値を5としている。
            attachForm = ( [ b1, 'left', 5 ], 
                           [ b1, 'bottom', 5 ], 
                           [ b2, 'bottom', 5 ], 
                           [ b3, 'bottom', 5 ], 
                           [ b3, 'right', 5 ]), 
            #ボタンをフォームのどの位置に固定するかの指定。b1の右辺を33%の位置に、b3の左辺を67%の位置に。
            attachPosition = ( [ b1, 'right' , 0, 33], 
                               [ b3, 'left' , 0, 67] ), 
            #真ん中のボタンb2が左右のボタンの隣接する辺に固定ための設定。
            attachControl = ( [ b2, 'left', 4,  b1 ], 
                              [ b2, 'right', 4, b3 ] ),
            #すべてのボタンの上辺は固定しない。
            attachNone = ( [ b1, 'top' ], [ b2, 'top' ], [ b3, 'top' ] )
            )
cmds.evalDeferred(lambda *args: cmds.showWindow(win))

####################################################################

win = "testWin"
if cmds.window(win, exists = True):
    cmds.deleteUI(win, window = True)
    
cmds.window(win, title='TEST WINDOW',widthHeight=(600,350))
mainForm = cmds.formLayout(numberOfDivisions=100 )
b1 = cmds.button( label='Command 1', height=26)
b2 = cmds.button( label='Command 2', height=26)
cmds.formLayout(
            mainForm, edit=True, 
            #フォームの境界にボタンのどのエッジを固定するかの指定。オフセット値を5としている。
            attachForm = ( [ b1, 'left', 5 ], 
                           [ b1, 'bottom', 5 ], 
                           [ b2, 'bottom', 5 ], 
                           [ b2, 'right', 5 ]), 
            #ボタンをフォームのどの位置に固定するかの指定。b1の右辺を33%の位置に、b3の左辺を67%の位置に。
            attachPosition = ( [ b1, 'right' , 0, 49], 
                               [ b2, 'left' , 0, 51] ), 
            #すべてのボタンの上辺は固定しない。
            attachNone = ( [ b1, 'top' ], [ b2, 'top' ])
            )
cmds.evalDeferred(lambda *args: cmds.showWindow(win))
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as om
from functools import partial
from maya.common.ui import LayoutManager


class UI(object):
    @classmethod
    def showUI(cls):
        """A function to instantiate the YO direct Connection  UI window
        :return: win
        """
        win = cls()
        win.createUI()
        # print(win)
        return win

    def classNameOutput(self):
        """
        :rtype: str
        :return: self.__class__.__name__
        """
        return self.__class__.__name__

    def __init__(self):
        """Initialize data attributes"""
        self.win = 'YO_directConnection2_ui'
        self.title = 'directConnection2'
        self.bgcRed = [0.9, 0.5, 0.5]  # list of float
        self.bgcGreen = [0.5, 0.9, 0.5]  # list of float
        self.bgcBlue = [0.5, 0.5, 0.9]  # list of float
        self.srcNode = ''  # string
        self.tgtNode = ''  # string
        self.tXYZ = [0, 0, 0]  # list of bool
        self.rXYZ = [0, 0, 0]  # list of bool
        self.sXYZ = [0, 0, 0]  # list of bool
        self.shXYZ = [0, 0, 0]  # list of bool
        self.v = 0  # bool
        self.exeList = [0, 0, 0, 0, 0]  # list of bool
        self.resultMessageCommon = u' が互いに接続されています。'

    # ######################################################################################
    # UI の構築 ################################################################### start
    def createUI(self):
        u""" <UI の構築>
        """
        if cmds.window(self.win, ex = True):
            cmds.deleteUI(self.win)
        cmds.window(self.win, title = self.title
                    , widthHeight = (145, 60)
                    , menuBar = True
                    , sizeable = True
                    )

        # UI 大枠の定義 ############################################################### start
        self.mainForm = cmds.formLayout(nd = 100)  # メインのまとまり

        self.cM_commonMenu()  # 0. 最上段の UI common menu の作成
        self.cB_commonButtons()  # 1. 最下段の UI common ボタンの作成

        # tab 追加を可能とする時は、tabsVisible = True
        self.optionBorder = cmds.tabLayout('mainTabGrp', scrollable = True
                                           , tabsVisible = False, h = 1
                                           , childResizable = True
                                           )
        ######################################################
        cmds.formLayout(self.mainForm, e = True
                        # フォームの境界にボタンのどのエッジを固定するかの指定。オフセット値を5としている。
                        , attachForm = ([self.optionBorder, 'top', 5]
                                        , [self.optionBorder, 'left', 5]
                                        , [self.optionBorder, 'right', 5]
                                        )
                        # 第1引数コントロールの、第2引数エッジを、第4引数コントロールにアタッチする。
                        , attachControl = [self.optionBorder, 'bottom', 5, self.executeBtn]
                        )
        ######################################################
        # UI 大枠の定義 ################################################################# end

        with LayoutManager(cmds.columnLayout('clmLyot_grpA'
                , adjustableColumn = True
                , w = 50
                                             )
                           ) as clmLyot_grpA:
            self.txtMessages()  # 3. メッセージ の作成
            cmds.separator()
            self.cP_commonPanes()  # 4. UI common panes の作成
            cmds.separator()
            self.cC_commonCheckBoxes()  # 5. UI common operation check boxes の作成
            cmds.separator()

        cmds.evalDeferred(lambda *args: cmds.showWindow(self.win))
    # UI の構築 ##################################################################### end
    # ######################################################################################

    # ######################################################################################
    # 0. 最上段の UI common menu ###################################################### start
    # 最上段の UI menu 作成に利用
    def cM_commonMenu(self):
        u""" <最上段の UI menu 作成に利用>
        """
        editMenu = cmds.menu(l = 'Edit')
        editMenuReload = cmds.menuItem(l = 'Reset Settings'
                                       , c = self.cB_uiReload_command, enable = True
                                       )
        editMenuClose = cmds.menuItem(l = 'Close This UI'
                                      , c = self.cB_uiClose_command, enable = True
                                      )
        helpMenu = cmds.menu(l = 'Help')
        helpMenuItem = cmds.menuItem(l = 'Help on %s' % self.title
                                     # , c = self.helpMenuCmd
                                     )

    # Reload 実行 関数
    def cB_uiReload_command(self, *args):
        u""" <Reload 実行 関数>
        """
        cmds.evalDeferred(lambda *args: self.showUI())  # refresh UI <---- ここ重要!!
        print('reload done')

    # Close 実行 関数
    def cB_uiClose_command(self, *args):
        u""" <Close 実行 関数>
        """
        cmds.evalDeferred(lambda *args: cmds.deleteUI(self.win))
        print('close done')
    # 0. 最上段の UI common menu ######################################################## end
    # ######################################################################################

    # ######################################################################################
    # 1. 最下段の UI common button #################################################### start
    # 最下段の UI button 作成のコントロール
    def cB_commonButtons(self):
        u""" <最下段の UI button 作成のコントロール>
        """
        # execute Button
        self.executeBtn = cmds.button('cBtn1', label = 'execute'
                                      , annotation = u'直接接続を実行します。'
                                      , c = self.execute
                                      )

        # Close Button
        self.closeBtn = cmds.button(l = 'Close'
                                    # , h = 40
                                    , enable = True
                                    , c = self.cB_uiClose_command
                                    , vis = True
                                    )
        ######################################################
        cmds.formLayout(self.mainForm, e = True
                        # <attachForm について>
                        # フォームの境界にボタンのどのエッジを固定するかの指定。オフセット値を5としている。
                        , attachForm = ([self.executeBtn, 'left', 5]
                                        , [self.executeBtn, 'bottom', 5]
                                        # , [self.reloadBtn, 'bottom', 5]
                                        , [self.closeBtn, 'bottom', 5]
                                        , [self.closeBtn, 'right', 5]
                                        )
                        , attachPosition = ([self.executeBtn, 'right', 2, 75]
                                            # 50-->75(↑ reloadBtn有りバージョンの時は50)
                                            , [self.closeBtn, 'left', 2, 75]
                                            )
                        # <attachControl について>
                        # 第1引数コントロールの、第2引数エッジを、第4引数コントロールにアタッチする。
                        # , attachControl = ([self.reloadBtn, 'left', 2, self.executeBtn]
                        #                    , [self.reloadBtn, 'right', 2, self.closeBtn]
                        #                    )
                        , attachNone = ([self.executeBtn, 'top']
                                        , [self.closeBtn, 'top']
                                        # , [self.reloadBtn, 'top']
                                        )
                        )
        ######################################################
    # 1. 最下段の UI common button ####################################################   end
    # ######################################################################################

    # ######################################################################################
    # 3. メッセージ の作成 ############################################################# start
    # メッセージ 作成に利用
    def txtMessages(self):
        u""" <メッセージ 作成に利用>
        """
        cmds.text(l = u'T R S Sh V attr, Direct Connection ツール')
        cmds.text(l = u'note:', bgc = self.bgcBlue
                  , annotation = u'当ツールは、\n'
                                 u'対の transform node 選択同士で、'
                                 u'直接 Translate Rotate Scale Shear Visibility  attr を'
                                 u'互いに素早くコネクションするツールです。\n'
                                 u'1番目選択 node が基となり、2番目選択 node へ 直接コネクションされます。\n'
                                 u'コネクションしたい該当する attr のチェックボタンにチェックを入れて実行すると、'
                                 u'接続が実行されます。')
    # 3. メッセージ の作成 ############################################################### end
    # ######################################################################################

if __name__ == '__main__':
    print(u'{}.py: loaded as script file'.format(__name__))
    UI.showUI()  # ui
else:
    print(u'{}.py: loaded as module file'.format(__name__))

print(u'モジュール名:{}'.format(__name__))  # 実行したモジュール名を表示する
from functool import partial

self.executeBtn = cmds.button(l = 'save',  h = 15, c = partial(self.save_exe))
# -*- coding: utf-8 -*-

import maya.cmds as cmds
from functools import partial

win = 'testWin'

def defaultButtonPush(*args):
    print(args)
    print(args[0], args[1])
    print 'Button 1 was pushed.'

def ui():
    global win
    if cmds.window(win, exists = True):
        cmds.deleteUI(win)
    cmds.window(win, width=150 )
    cmds.columnLayout( adjustableColumn=True )
    cmds.button( label='Button 1', command = partial(defaultButtonPush, 2))
    cmds.button( label='Button 2' )
    cmds.button( label='Button 3' )
    cmds.button( label='Button 4' )
    cmds.showWindow(win)
    
ui()
# -*- coding: utf-8 -*-
 
import maya.cmds as cmds

class Test_window(object):
    """A base class for an options window"""
    
    @classmethod
    def showUI(cls):
        """A function to instantiate the options window"""
        win = cls()
        win.create()
        return win    
        
    def __init__(self):
        """Initialize common data attributes"""
        self.win = 'testWin'
 
    def create(self):
        """Draw the window"""
        if cmds.window(self.win, exists = True):
            cmds.deleteUI(self.win)
        cmds.window(self.win, width = 150)
        cmds.columnLayout(adjustableColumn=True )
        cmds.button(label='Button 1', command = defaultButtonPush )
        cmds.button(label='Button 2' )
        cmds.button(label='Button 3' )
        cmds.button(label='Button 4' )
        cmds.evalDeferred(lambda *args: cmds.showWindow(self.win))
        
    def defaultButtonPush(self, *args):
      print 'Button 1 was pushed.'
    
if __name__ == '__main__':
    print(u'{}.py: loaded as script file'.format(__name__))
    Test_window.showUI()  # open UI
else:
    print(u'{}.py: loaded as module file'.format(__name__))
# -*- coding: utf-8 -*-

import maya.cmds as cmds

win = 'testWin'

def defaultButtonPush(*args):
  print 'Button 1 was pushed.'

def ui():
    global win
    if cmds.window(win, exists = True):
        cmds.deleteUI(win)
    cmds.window(win, width=150 )
    cmds.columnLayout( adjustableColumn=True )
    cmds.button( label='Button 1', command = defaultButtonPush )
    cmds.button( label='Button 2' )
    cmds.button( label='Button 3' )
    cmds.button( label='Button 4' )
    cmds.showWindow(win)
    
ui()
# -*- coding: utf-8 -*-
# サンプル win make -def バージョン-

import maya.cmds as cmds

def applyAndCloseBtm(*args):
    applyBtm()
    closeBtm()
def applyBtm(*args):
    urlList = {
        1:'http://toyota.jp', 
        2:'http://www.nissan.co.jp', 
        3:'http://www.honda.co.jp', 
        4:'http://www.subaru.jp', 
    }
    
    siteIndex = cmds.radioButtonGrp(
                                siteUrl, q=True, 
                                select=True 
                                  )
    cmds.launch(webPage=urlList[siteIndex])                              
def closeBtm(*args):
    cmds.deleteUI(win, window=True)

if cmds.window('test_Windowc', exists=True):
    cmds.deleteUI('test_Windowc', window=True)
    

win = cmds.window('test_Windowc', title='TEST WINDOW',widthHeight=(600,350))
mainForm = cmds.formLayout( numberOfDivisions=100 )

b1 = cmds.button( label='Apply and Close', height=26, command=applyAndCloseBtm )
b2 = cmds.button( label='Apply', height=26, command=applyBtm )
b3 = cmds.button( label='Close', height=26, command=closeBtm )

siteUrl = cmds.radioButtonGrp(
                            label='WWW: ',
                            labelArray4=[ 'TOYOTA', 
                                          'NISSAN', 
                                          'HONDA', 
                                          'SUBARU' ], 
                            numberOfRadioButtons=4, 
                            select=1 
                             )

cmds.formLayout(
            mainForm, edit=True, 
            
            attachForm = ( [ b1, 'left', 5 ], 
                           [ b1, 'bottom', 5 ], 
                           [ b2, 'bottom', 5 ], 
                           [ b3, 'bottom', 5 ], 
                           [ b3, 'right', 5 ]), 
            
            attachPosition = ( [ b1, 'right' , 0, 33], 
                               [ b3, 'left' , 0, 67],
                               [ siteUrl, 'top', 10, 0] ), 
            
            attachControl = ( [ b2, 'left', 4,  b1 ], 
                              [ b2, 'right', 4, b3 ] ),
            
            attachNone = ( [ b1, 'top' ], [ b2, 'top' ], [ b3, 'top' ] )
            )

cmds.showWindow(win)
# -*- coding: utf-8 -*-
# サンプル win make -class バージョン-

import maya.cmds as cmds

class Test_window(object):
    """A base class for an options window"""
    
    @classmethod
    def showUI(cls):
        """A function to instantiate the options window"""
        win = cls()
        win.create()
        return win    
        
    def __init__(self):
        """Initialize common data attributes"""
        self.win = 'test_Windowc'
 
    def create(self):
        """Draw the window"""
        if cmds.window(self.win, exists=True):
            cmds.deleteUI(self.win, window=True)
        win = cmds.window(self.win, title='TEST WINDOW',widthHeight=(600,350))
        
        # UI 大枠の定義 ############################################################### start
        self.mainForm = cmds.formLayout('mainForm', numberOfDivisions=100 )
        self.commonButtons()
        ######################################################
        cmds.formLayout(
                    self.mainForm, edit=True,
                    
                    #フォームの境界にボタンのどのエッジを固定するかの指定。オフセット値を5としている。
                    attachForm = ( [ self.b1, 'left', 5 ], 
                                   [ self.b1, 'bottom', 5 ],
                                   [ self.b2, 'bottom', 5 ], 
                                   [ self.b3, 'bottom', 5 ], 
                                   [ self.b3, 'right', 5 ]), 
                    
                    #ボタンをフォームのどの位置に固定するかの指定。b1の右辺を33%の位置に、b3の左辺を67%の位置に。
                    attachPosition = ( [ self.b1, 'right' , 0, 33], 
                                       [ self.b3, 'left' , 0, 67], ), 
                    
                    #真ん中のボタンb2が左右のボタンの隣接する辺に固定ための設定。
                    #第1引数コントロールの、第2引数エッジを、第4引数コントロールにアタッチする。
                    attachControl = ( [ self.b2, 'left', 4,  self.b1 ], 
                                      [ self.b2, 'right', 4, self.b3 ] ),
                    
                    #すべてのボタンの上辺は固定しない。
                    attachNone = ( [ self.b1, 'top' ], [ self.b2, 'top' ], [ self.b3, 'top' ] )
                    )
        ######################################################
        # UI 大枠の定義 ################################################################# end
        
        self.optionForm = cmds.formLayout('optionForm',  numberOfDivisions=100 )
        self.siteRarioButtons()
        cmds.formLayout(
                    self.optionForm, edit=True,
                    #ボタンをフォームのどの位置に固定するかの指定。b1の右辺を10%の位置に。
                    attachPosition = [ self.siteUrl, 'top', 1, 0]
                    #第1引数コントロールの、第2引数エッジを、第4引数コントロールにアタッチする。
                    #attachControl = [ self.siteUrl, 'top', 4,  self.mainForm ]
                    )
        
        
        cmds.evalDeferred(lambda *args: cmds.showWindow(self.win))
        
    def commonButtons(self):
        self.b1 = cmds.button(label='Apply and Close', height=26, command = self.applyAndCloseBtm )
        self.b2 = cmds.button(label='Apply', height=26, command = self.applyBtm )
        self.b3 = cmds.button(label='Close', height=26, command = self.closeBtm )
        
    def siteRarioButtons(self):
        self.siteUrl = cmds.radioButtonGrp(
                                    label='WWW: ',
                                    labelArray4=[ 'TOYOTA', 
                                                  'NISSAN', 
                                                  'HONDA', 
                                                  'SUBARU' ], 
                                    numberOfRadioButtons = 4, 
                                    select = 1 
                                    #, height = 1
                                     )
        
    def applyAndCloseBtm(self, *args):
        self.applyBtm()
        self.closeBtm()
    
    def applyBtm(self, *args):
        urlList = {
            1:'http://toyota.jp', 
            2:'http://www.nissan.co.jp', 
            3:'http://www.honda.co.jp', 
            4:'http://www.subaru.jp', 
        }
        
        siteIndex = cmds.radioButtonGrp(
                                    self.siteUrl, q = True, 
                                    select = True 
                                      )
        cmds.launch(webPage = urlList[siteIndex])  
    def closeBtm(self, *args):
        cmds.deleteUI(self, win, window=True)
        
if __name__ == '__main__':
    print(u'{}.py: loaded as script file'.format(__name__))
    Test_window.showUI()  # open UI
else:
    print(u'{}.py: loaded as module file'.format(__name__))