Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sowwic committed Jul 12, 2020
0 parents commit 8b2318a
Show file tree
Hide file tree
Showing 12 changed files with 657 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
125 changes: 125 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"python.pythonPath": "C:\\Program Files\\Python\\python.exe",
"python.autoComplete.extraPaths": [
"D:/Dima/Documents/maya/scripts",
"D:/Program Files/Autodesk/Maya2020/devkit/other/pymel/extras/completion/py",
"D:/Program Files/Autodesk/Maya2020/plug-ins/xgen/scripts",
"C:/ProgramData/Autodesk/ApplicationPlugins/ngskintools/Contents/scripts",
"D:/Program Files/Prism/PythonLibs/CrossPlatform",
"D:/Repos/dsRenamingTool"
],
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
"--max-line-length 180"
],
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 S0nic014

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# dsRenamingTool
Simple renaming tool with auto indexing and autosuffixing
Binary file added docs/images/aliasesDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/mainDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added dsRenamingTool/__init__.py
Empty file.
167 changes: 167 additions & 0 deletions dsRenamingTool/aliasesDialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import pymel.core as pm
import json
from PySide2 import QtWidgets, QtCore
from dsRenamingTool import dialogBase


class AliasDialog(dialogBase._modalDialog):

DEFAULT_SUFFIX_ALIASES = {
"mesh": "PLY",
"nurbsCurve": "CRV",
"nurbsSurface": "NURB",
"pointLight": "LGT",
"areaLight": "LGT",
"joint": "JNT",
"locator": "LOC",
"camera": "CAM",
}

def __init__(self, parent=None, title="Edit aliases"):
super(AliasDialog, self).__init__(parent=parent)

# Setup UI
self.setWindowTitle(title)
self.setMinimumSize(300, 200)

# Update table
self.updateAliasTable()

def createActions(self):
# Menubar
self.menuBar = QtWidgets.QMenuBar(self)
editMenu = self.menuBar.addMenu("&Edit")

# Actions
self.addAliasesAction = QtWidgets.QAction("Add new alias", self)
self.deleteAliasAction = QtWidgets.QAction("Delete selected", self)
self.resetAliasesAction = QtWidgets.QAction("Reset to defaults", self)

# Populate menubar
editMenu.addAction(self.addAliasesAction)
editMenu.addAction(self.deleteAliasAction)
editMenu.addAction(self.resetAliasesAction)

def createWidgets(self):
# Table
self.aliasesTable = AliasTable()
self.aliasesTable.setColumnCount(2)
self.aliasesTable.setHorizontalHeaderLabels(["Object type", "Suffix"])
tableHeaderView = self.aliasesTable.horizontalHeader()
tableHeaderView.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)

# Dialog buttons
self.confirmButton = QtWidgets.QPushButton("Confirm")
self.saveButton = QtWidgets.QPushButton("Save")
self.cancelButton = QtWidgets.QPushButton("Cancel")

def createLayouts(self):
self.mainLayout = QtWidgets.QVBoxLayout(self)
self.mainLayout.setContentsMargins(10, 25, 10, 10)

# Table layout
tableLayout = QtWidgets.QVBoxLayout()
tableLayout.addWidget(self.aliasesTable)

# Buttons layout
buttonsLayout = QtWidgets.QHBoxLayout()
buttonsLayout.addStretch()
buttonsLayout.addWidget(self.confirmButton)
buttonsLayout.addWidget(self.saveButton)
buttonsLayout.addWidget(self.cancelButton)

# Populate main
self.mainLayout.addLayout(tableLayout)
self.mainLayout.addLayout(buttonsLayout)

def createConnections(self):
# Buttons
self.confirmButton.clicked.connect(self.confirmAndClose)
self.saveButton.clicked.connect(self.saveAliases)
self.cancelButton.clicked.connect(self.close)

# Actions
self.addAliasesAction.triggered.connect(self.aliasesTable.addNewEntry)
self.deleteAliasAction.triggered.connect(self.aliasesTable.deleteSelectedRow)
self.resetAliasesAction.triggered.connect(self.resetToDefault)

def updateAliasTable(self):
self.aliasesTable.setRowCount(0)
self.suffixAliases = json.loads(pm.optionVar.get("dsRenamingToolSuffixAliases", json.dumps(self.DEFAULT_SUFFIX_ALIASES, sort_keys=True)))
for i, k in enumerate(self.suffixAliases.keys()):
self.aliasesTable.insertRow(i)
self.insertItem(i, 0, text=k)
self.insertItem(i, 1, text=self.suffixAliases[k])

def insertItem(self, row, column, text=""):
item = QtWidgets.QTableWidgetItem(text)
self.aliasesTable.setItem(row, column, item)

return item

def getAliasTableData(self):
newAliasDict = {}
for row in range(0, self.aliasesTable.rowCount()):
objType = self.aliasesTable.model().index(row, 0).data()
suffix = self.aliasesTable.model().index(row, 1).data()
if objType:
newAliasDict[str(objType)] = str(suffix)

return newAliasDict

def saveAliases(self):
self.suffixAliases = self.getAliasTableData()
aliasString = json.dumps(self.suffixAliases, sort_keys=True)
pm.optionVar["dsRenamingToolSuffixAliases"] = aliasString

def confirmAndClose(self):
self.saveAliases()
self.close()

def showEvent(self, e):
self.checkOptionVar()

def resetToDefault(self):
self.aliasesTable.setRowCount(0)
for i, k in enumerate(self.DEFAULT_SUFFIX_ALIASES.keys()):
self.aliasesTable.insertRow(i)
self.insertItem(i, 0, text=k)
self.insertItem(i, 1, text=self.DEFAULT_SUFFIX_ALIASES[k])

@classmethod
def checkOptionVar(cls):
pm.optionVar.get("dsRenamingToolSuffixAliases", json.dumps(cls.DEFAULT_SUFFIX_ALIASES, sort_keys=True))


class AliasTable(QtWidgets.QTableWidget):
def __init__(self, rows=0, columns=0, parent=None):
super(AliasTable, self).__init__(rows, columns, parent)

self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showContextMenu)

self.createActions()
self.createConnections()

def createActions(self):
self.addAliasAction = QtWidgets.QAction("Add new alias", self)
self.deleteAliasAction = QtWidgets.QAction("Delete alias", self)

def createConnections(self):
self.addAliasAction.triggered.connect(self.addNewEntry)
self.deleteAliasAction.triggered.connect(self.deleteSelectedRow)

def addNewEntry(self):
newIndex = self.rowCount()
self.insertRow(newIndex)

def deleteSelectedRow(self):
for each in self.selectedItems():
self.removeRow(each.row())

def showContextMenu(self, point):
contextMenu = QtWidgets.QMenu()
contextMenu.addAction(self.addAliasAction)
contextMenu.addAction(self.deleteAliasAction)

contextMenu.exec_(self.mapToGlobal(point))
46 changes: 46 additions & 0 deletions dsRenamingTool/dialogBase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from PySide2 import QtCore
from PySide2 import QtWidgets
from shiboken2 import wrapInstance
import maya.OpenMayaUI as omui


def mayaMainWindow():
"""
Get maya main window as QWidget
:return: Maya main window as QWidget
:rtype: PySide2.QtWidgets.QWidget
"""
mainWindowPtr = omui.MQtUtil.mainWindow()
if mainWindowPtr:
return wrapInstance(long(mainWindowPtr), QtWidgets.QWidget)
else:
mayaMainWindow()


class _modalDialog(QtWidgets.QDialog):

def __init__(self, parent=mayaMainWindow()):
super(_modalDialog, self).__init__(parent)

# Disable question mark for windows
self.setWindowFlags(self.windowFlags() ^ QtCore.Qt.WindowContextHelpButtonHint)
# MacOSX window stay on top
self.setProperty("saveWindowPref", True)

self.createActions()
self.createWidgets()
self.createLayouts()
self.createConnections()

def createActions(self):
pass

def createWidgets(self):
pass

def createLayouts(self):
pass

def createConnections(self):
pass
Loading

0 comments on commit 8b2318a

Please sign in to comment.