Skip to content

Commit

Permalink
Formating
Browse files Browse the repository at this point in the history
  • Loading branch information
sowwic committed Jul 25, 2020
1 parent 751ddb9 commit f85e2e1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ dmypy.json

#Project specific
.vscode/
.dsToolEnv/
.dsInstallerEnv/
installer/
29 changes: 18 additions & 11 deletions dsRenamingTool/aliasesDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,40 +127,42 @@ def getAliasTableData(self):

return newAliasDict

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

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

@QtCore.Slot()
def confirmAndClose(self):
self.saveAliases()
self.close()

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

@QtCore.Slot()
def resetToDefault(self):
self.loadFromDict(self.DEFAULT_SUFFIX_ALIASES)

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

@QtCore.Slot()
def exportAliases(self):
exportPath = QtWidgets.QFileDialog.getSaveFileName(self, "Export aliases", "/home/namingAliases.json", "JSON files (*.json)")[0]
if not exportPath:
return

try:
with open(exportPath, "w") as exportFile:
json.dump(self.getAliasTableData(), exportFile, indent=4, separators=(",", ":"))
LOGGER.info("Exported aliases to: {0}".format(exportPath))
except IOError:
LOGGER.error("Failed to export aliases", exc_info=1)

@QtCore.Slot()
def importAliases(self):
importPath = QtWidgets.QFileDialog.getOpenFileName(self, "Import aliases", "/home/", "JSON files (*.json)")[0]
if not importPath:
Expand All @@ -178,6 +180,11 @@ def importAliases(self):
except Exception:
LOGGER.error("Failed to load aliases from {0}".format(importPath), exc_info=1)

# Events
def showEvent(self, e):
super(AliasDialog, self).showEvent(e)
self.checkOptionVar()


class AliasTable(QtWidgets.QTableWidget):
def __init__(self, rows=0, columns=0, parent=None):
Expand Down
41 changes: 33 additions & 8 deletions dsRenamingTool/mainDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import logging.config
import json
from PySide2 import QtWidgets
from PySide2 import QtCore

from dsRenamingTool import renameFn
from dsRenamingTool import aliasesDialog
from dsRenamingTool import config
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from shiboken2 import getCppPointer
reload(aliasesDialog)


# Setup logging
Expand Down Expand Up @@ -46,16 +48,17 @@ def __init__(self):
self.setObjectName(self.__class__.UI_NAME)

self.setWindowTitle(self.WINDOW_TITLE)
self.setMinimumSize(300, 170)
self.settings = self.loadSettings()
self.updateSizeLimit()

workspaceControlName = "{0}WorkspaceControl".format(self.UI_NAME)
if pm.workspaceControl(workspaceControlName, q=1, ex=1):
workspaceControlPtr = long(pma.MQtUtil.findControl(workspaceControlName))
self.workspaceControlName = "{0}WorkspaceControl".format(self.UI_NAME)
if pm.workspaceControl(self.workspaceControlName, q=1, ex=1):
workspaceControlPtr = long(pma.MQtUtil.findControl(self.workspaceControlName))
widgetPtr = long(getCppPointer(self)[0])

pma.MQtUtil.addWidgetToMayaLayout(widgetPtr, workspaceControlPtr)

# self.setDockableParameters(heightSizingProperty="fixed", height=170)
# UI setup
self.createActions()
self.createWidgets()
Expand Down Expand Up @@ -128,9 +131,10 @@ def createLayouts(self):
mainLayout.addLayout(renameLayout)
mainLayout.addLayout(optionsLayout)
mainLayout.addLayout(self.indexLayout)
mainLayout.addStretch()
mainLayout.addLayout(buttonsLayout)
mainLayout.setSpacing(10)
mainLayout.setContentsMargins(10, 25, 10, 10)
mainLayout.setContentsMargins(5, 25, 5, 5)

def createConnections(self):
self.closeButton.clicked.connect(self.hide)
Expand Down Expand Up @@ -167,18 +171,38 @@ def rename(self):
indexPadding=self.indexPaddingSpinBox.value(),
startIndex=self.startingIndexSpinBox.value())

def updateSizeLimit(self):
if self.isFloating():
self.setMinimumSize(300, 170)
self.setMaximumSize(16777215, 16777215)

try:
self.nativeParentWidget().setMaximumSize(self.maximumSize())
self.nativeParentWidget().setMinimumSize(self.minimumSize())
self.resize(self.minimumSize())
except Exception:
pass

else:
try:
self.nativeParentWidget().setFixedHeight(200)
except BaseException:
pass

def editSuffixAliases(self):
editDialog = aliasesDialog.AliasDialog(parent=self)
editDialog.show()

# Events

def showEvent(self, e):
self.resize(self.minimumSize())
self.updateSizeLimit()

def hideEvent(self, e):
self.saveSettings()

def dockCloseEventTriggered(self):
self.saveSettings()

# Properties
@property
def settings(self):
Expand All @@ -192,7 +216,7 @@ def loadSettings(self):
loaded = pm.optionVar.get("dsRiggingRenamingToolSettings", json.dumps(self.DEFAULT_SETTINGS, sort_keys=True))
return json.loads(loaded)

# @QtCore.Slot()
@QtCore.Slot()
def saveSettings(self):
self.settings = {"indexing": self.indexingCheckBox.isChecked(),
"indexStart": self.startingIndexSpinBox.value(),
Expand All @@ -216,3 +240,4 @@ def saveSettings(self):

uiScript = "import dsRenamingTool\ndsRenamer = dsRenamingTool.Dialog()"
dsRenamer.show(dockable=1, uiScript=uiScript)
dsRenamer.updateSizeLimit()

0 comments on commit f85e2e1

Please sign in to comment.