Skip to content

Commit

Permalink
修改了_command.commands模块的实现, 修复了不会包装ui命令的bug。
Browse files Browse the repository at this point in the history
而相应的对_command.build_new_func模块进行相关的修改。
  • Loading branch information
苍之幻灵 committed Apr 24, 2022
1 parent 2c36e2a commit 062c198
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/CPMel/_command/build_new_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ def new_func_list_from_module(module):
# except KeyError as ex:
# warnings.warn("注册新CPMel命令失败!{}\n".format(ex))

for n, f in commands.commands:
for n, f in commands.commands.items():
try:
module[n] = new_func_from_command(f)
except KeyError as ex:
warnings.warn("注册新CPMel命令失败!{}\n".format(ex))
for n, f in commands.list_commands:
for n, f in commands.list_commands.items():
try:
module[n] = new_func_from_list_command(f)
except KeyError as ex:
warnings.warn("注册新CPMel命令失败!{}\n".format(ex))
for n, f in commands.ui_commands:
for n, f in commands.ui_commands.items():
try:
module[n] = new_func_from_ui_command(f)
except KeyError as ex:
warnings.warn("注册新CPMel命令失败!{}\n".format(ex))
for n, f in commands.other_commands:
for n, f in commands.other_commands.items():
try:
module[n] = new_func_from_command(f)
except KeyError as ex:
Expand Down
106 changes: 62 additions & 44 deletions src/CPMel/_command/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,74 @@
from __future__ import unicode_literals, print_function
import maya.cmds as mc

window = {'Windows': ['colorEditor', 'confirmDialog', 'createEditor', 'defaultNavigation', 'editor', 'editorTemplate',
'fontDialog', 'layoutDialog', 'minimizeApp', 'progressWindow', 'promptDialog',
'refreshEditorTemplates', 'scriptEditorInfo', 'showSelectionInTitle', 'showWindow',
'toggleWindowVisibility', 'window', 'windowPref', 'workspaceControlState', 'workspacePanel'],
'Misc_UI': ['annotate', 'autoPlace', 'buttonManip', 'callbacks', 'disableIncorrectNameWarning', 'grabColor',
'headsUpDisplay', 'headsUpMessage', 'hotkey', 'hotkeyCheck', 'hotkeyCtx', 'hotkeySet',
'inViewMessage', 'linearPrecision', 'loadPrefObjects', 'loadUI', 'mayaDpiSetting', 'multiTouch',
'nameCommand', 'overrideModifier', 'saveAllShelves', 'savePrefObjects', 'savePrefs', 'saveShelf',
'scmh', 'setMenuMode', 'setNodeTypeFlag', 'setStartupMessage', 'textManip',
'thumbnailCaptureComponent'],
'Menus': ['artBuildPaintMenu', 'attrEnumOptionMenu', 'attrEnumOptionMenuGrp', 'attributeMenu', 'hotBox',
'menu', 'menuEditor', 'menuItem', 'menuSet', 'menuSetPref', 'optionMenu', 'optionMenuGrp',
'popupMenu', 'radioMenuItemCollection', 'saveMenu'],
'Layouts': ['columnLayout', 'dockControl', 'flowLayout', 'formLayout', 'frameLayout', 'gridLayout', 'layout',
'menuBarLayout', 'paneLayout', 'rowColumnLayout', 'rowLayout', 'scrollLayout', 'shelfLayout',
'shelfTabLayout', 'tabLayout', 'toolBar', 'workspaceControl', 'workspaceLayoutManager'],
'Controls': ['attrColorSliderGrp', 'attrControlGrp', 'attrFieldGrp', 'attrFieldSliderGrp',
'attrNavigationControlGrp', 'button', 'canvas', 'channelBox', 'checkBox', 'checkBoxGrp',
'cmdScrollFieldExecuter', 'cmdScrollFieldReporter', 'cmdShell', 'colorIndexSliderGrp',
'colorInputWidgetGrp', 'colorSliderButtonGrp', 'colorSliderGrp', 'commandLine', 'componentBox',
'control', 'falloffCurve', 'falloffCurveAttr', 'floatField', 'floatFieldGrp', 'floatScrollBar',
'floatSlider', 'floatSlider2', 'floatSliderButtonGrp', 'floatSliderGrp', 'gradientControl',
'gradientControlNoAttr', 'helpLine', 'hudButton', 'hudSlider', 'hudSliderButton',
'iconTextButton', 'iconTextCheckBox', 'iconTextRadioButton', 'iconTextRadioCollection',
'iconTextScrollList', 'iconTextStaticLabel', 'image', 'intField', 'intFieldGrp', 'intScrollBar',
'intSlider', 'intSliderGrp', 'layerButton', 'messageLine', 'nameField', 'nodeTreeLister',
'palettePort', 'picture', 'progressBar', 'radioButton', 'radioButtonGrp', 'radioCollection',
'rangeControl', 'scriptTable', 'scrollField', 'separator', 'shelfButton', 'soundControl',
'swatchDisplayPort', 'switchTable', 'symbolButton', 'symbolCheckBox', 'text', 'textField',
'textFieldButtonGrp', 'textFieldGrp', 'textScrollList', 'timeControl', 'timeField',
'timeFieldGrp', 'timePort', 'toolButton', 'toolCollection', 'treeLister', 'treeView'],
'Panels': ['canCreateCaddyManip', 'componentEditor', 'contentBrowser', 'getPanel', 'hardwareRenderPanel',
'hotkeyEditorPanel', 'hyperGraph', 'hyperPanel', 'hyperShade', 'inViewEditor', 'modelEditor',
'modelPanel', 'nodeEditor', 'nodeOutliner', 'outlinerEditor', 'outlinerPanel', 'panel',
'panelConfiguration', 'panelHistory', 'saveViewportSettings', 'scriptedPanel', 'scriptedPanelType',
'setFocus', 'spreadSheetEditor', 'viewManip', 'visor', 'webBrowser', 'webBrowserPrefs']}
list_commands = ['listInputDevices', 'listAttr', 'listDeviceAttachments', 'listConnections', 'listCameras', 'listRelatives', 'listInputDeviceButtons', 'listInputDeviceAxes', 'listSets', 'listAnimatable', 'listAttrPatterns', 'listNodeTypes', 'listNodesWithIncorrectNames', 'listHistory']
window = {
'Windows': [
'colorEditor', 'confirmDialog', 'createEditor', 'defaultNavigation', 'editor', 'editorTemplate',
'fontDialog', 'layoutDialog', 'minimizeApp', 'progressWindow', 'promptDialog',
'refreshEditorTemplates', 'scriptEditorInfo', 'showSelectionInTitle', 'showWindow',
'toggleWindowVisibility', 'window', 'windowPref', 'workspaceControlState', 'workspacePanel'
],
'Misc_UI': [
'annotate', 'autoPlace', 'buttonManip', 'callbacks', 'disableIncorrectNameWarning', 'grabColor',
'headsUpDisplay', 'headsUpMessage', 'hotkey', 'hotkeyCheck', 'hotkeyCtx', 'hotkeySet',
'inViewMessage', 'linearPrecision', 'loadPrefObjects', 'loadUI', 'mayaDpiSetting', 'multiTouch',
'nameCommand', 'overrideModifier', 'saveAllShelves', 'savePrefObjects', 'savePrefs', 'saveShelf',
'scmh', 'setMenuMode', 'setNodeTypeFlag', 'setStartupMessage', 'textManip',
'thumbnailCaptureComponent'
],
'Menus': [
'artBuildPaintMenu', 'attrEnumOptionMenu', 'attrEnumOptionMenuGrp', 'attributeMenu', 'hotBox',
'menu', 'menuEditor', 'menuItem', 'menuSet', 'menuSetPref', 'optionMenu', 'optionMenuGrp',
'popupMenu', 'radioMenuItemCollection', 'saveMenu'
],
'Layouts': [
'columnLayout', 'dockControl', 'flowLayout', 'formLayout', 'frameLayout', 'gridLayout', 'layout',
'menuBarLayout', 'paneLayout', 'rowColumnLayout', 'rowLayout', 'scrollLayout', 'shelfLayout',
'shelfTabLayout', 'tabLayout', 'toolBar', 'workspaceControl', 'workspaceLayoutManager'
],
'Controls': [
'attrColorSliderGrp', 'attrControlGrp', 'attrFieldGrp', 'attrFieldSliderGrp',
'attrNavigationControlGrp', 'button', 'canvas', 'channelBox', 'checkBox', 'checkBoxGrp',
'cmdScrollFieldExecuter', 'cmdScrollFieldReporter', 'cmdShell', 'colorIndexSliderGrp',
'colorInputWidgetGrp', 'colorSliderButtonGrp', 'colorSliderGrp', 'commandLine', 'componentBox',
'control', 'falloffCurve', 'falloffCurveAttr', 'floatField', 'floatFieldGrp', 'floatScrollBar',
'floatSlider', 'floatSlider2', 'floatSliderButtonGrp', 'floatSliderGrp', 'gradientControl',
'gradientControlNoAttr', 'helpLine', 'hudButton', 'hudSlider', 'hudSliderButton',
'iconTextButton', 'iconTextCheckBox', 'iconTextRadioButton', 'iconTextRadioCollection',
'iconTextScrollList', 'iconTextStaticLabel', 'image', 'intField', 'intFieldGrp', 'intScrollBar',
'intSlider', 'intSliderGrp', 'layerButton', 'messageLine', 'nameField', 'nodeTreeLister',
'palettePort', 'picture', 'progressBar', 'radioButton', 'radioButtonGrp', 'radioCollection',
'rangeControl', 'scriptTable', 'scrollField', 'separator', 'shelfButton', 'soundControl',
'swatchDisplayPort', 'switchTable', 'symbolButton', 'symbolCheckBox', 'text', 'textField',
'textFieldButtonGrp', 'textFieldGrp', 'textScrollList', 'timeControl', 'timeField',
'timeFieldGrp', 'timePort', 'toolButton', 'toolCollection', 'treeLister', 'treeView'
],
'Panels': [
'canCreateCaddyManip', 'componentEditor', 'contentBrowser', 'getPanel', 'hardwareRenderPanel',
'hotkeyEditorPanel', 'hyperGraph', 'hyperPanel', 'hyperShade', 'inViewEditor', 'modelEditor',
'modelPanel', 'nodeEditor', 'nodeOutliner', 'outlinerEditor', 'outlinerPanel', 'panel',
'panelConfiguration', 'panelHistory', 'saveViewportSettings', 'scriptedPanel', 'scriptedPanelType',
'setFocus', 'spreadSheetEditor', 'viewManip', 'visor', 'webBrowser', 'webBrowserPrefs'
]
}
list_commands = ['listInputDevices', 'listAttr', 'listDeviceAttachments', 'listConnections', 'listCameras',
'listRelatives', 'listInputDeviceButtons', 'listInputDeviceAxes', 'listSets', 'listAnimatable',
'listAttrPatterns', 'listNodeTypes', 'listNodesWithIncorrectNames', 'listHistory']


def selected(*args, **kwargs):
return mc.ls(*args, sl=True, **kwargs)


commands = (getattr(mc, i) for i in dir(mc))
commands = [(i.__name__, i) for i in commands if callable(i)]
commands = {i.__name__: i for i in commands if callable(i)}

list_commands = (getattr(mc, i) for i in list_commands)
list_commands = [(i.__name__, i) for i in list_commands if callable(i)]
list_commands = {i.__name__: i for i in list_commands if callable(i)}

ui_commands = {i for v in window.values() for i in v} & set(commands.keys())
ui_commands = {i: commands[i] for i in ui_commands}

ui_commands = {i for v in window.values() for i in v} & set((i for i in commands if callable(i)))
ui_commands = [(i, commands[i]) for i in ui_commands]
other_commands = [
('selected', selected)
]
other_commands = {
'selected': selected
}

0 comments on commit 062c198

Please sign in to comment.