Skip to content

Commit

Permalink
support py3
Browse files Browse the repository at this point in the history
  • Loading branch information
1xinghuan committed May 7, 2021
1 parent 6b1a7b9 commit c072e1f
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/core/cel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ def _resolveTempList(templ):
'/root/world/lgt_rim',
]

print resolveCELString(s, all)
print(resolveCELString(s, all))

6 changes: 3 additions & 3 deletions lib/python/usdNodeGraph/core/node/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def setParamDefault(cls, nodeType, paramName, value):

@classmethod
def getAllNodeClassNames(cls):
return cls._nodeTypes.keys()
return list(cls._nodeTypes.keys())

@classmethod
def getAllNodeClass(cls):
return cls._nodeTypes.values()
return list(cls._nodeTypes.values())

@classmethod
def setParameterDefault(cls, parameterName, value):
Expand Down Expand Up @@ -129,7 +129,7 @@ def _initParameters(self):
'fillColor': Color4fParameter(name='fillColor', parent=self, builtIn=True, hints={'showEditor': 'False', 'tab': 'None'}, defaultValue=self.convertColorToFloat(self.fillNormalColor)),
'borderColor': Color4fParameter(name='borderColor', parent=self, builtIn=True, hints={'showEditor': 'False', 'tab': 'None'}, defaultValue=self.convertColorToFloat(self.borderNormalColor)),
}
self._parametersName = self._parameters.keys()
self._parametersName = list(self._parameters.keys())
self._parametersName.sort()

def _initDefaults(self):
Expand Down
11 changes: 6 additions & 5 deletions lib/python/usdNodeGraph/core/node/usdNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from usdNodeGraph.utils.const import consts
from usdNodeGraph.core.state.core import GraphState
from usdNodeGraph.ui.utils.log import LogWindow
from usdNodeGraph.utils.pyversion import *

ATTR_CHECK_OP = consts(
EXACT='exact',
Expand Down Expand Up @@ -84,7 +85,7 @@ def getMetadataValue(self, key, default=None):
return value

def getMetadataKeys(self):
return self._metadata.keys()
return list(self._metadata.keys())

def getMetadatas(self):
return self._metadata
Expand All @@ -107,7 +108,7 @@ def execute(self, stage, prim):
self._beforeExecute(stage, prim)
try:
stage, prim = self._execute(stage, prim)
except Exception as e:
except(Exception) as e:
traceback.print_exc()
LogWindow.error('Node Execute Error: {}\n{}'.format(self.name(), e))
self._afterExecute(stage, prim)
Expand Down Expand Up @@ -151,7 +152,7 @@ def getPrimPath(self):
return self._primPaths

def getExecuteParams(self):
parameters = self._parameters.values()
parameters = list(self._parameters.values())
params = [
param for param in parameters if (
(param.isOverride() or param.hasMetadatas())
Expand Down Expand Up @@ -215,11 +216,11 @@ def registerNode(cls, nodeObjectClass):

@classmethod
def getIgnorePrimInfoKeys(cls):
return cls._metadataNodeMap.keys()
return list(cls._metadataNodeMap.keys())

@classmethod
def getNodes(cls):
return cls._metadataNodeMap.values()
return list(cls._metadataNodeMap.values())

@classmethod
def getMetadataNodeClass(cls, key):
Expand Down
8 changes: 4 additions & 4 deletions lib/python/usdNodeGraph/core/parameter/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def registerParameterWidget(cls, typeName, parameterWidget):

@classmethod
def getParameterTypes(cls):
return cls._parametersMap.keys()
return list(cls._parametersMap.keys())

@classmethod
def getParameter(cls, typeName):
Expand Down Expand Up @@ -77,7 +77,7 @@ def convertTimeSamplesToPy(cls, timeSamples):

@classmethod
def getIntervalValue(cls, timeSamples, time):
keys = timeSamples.keys()
keys = list(timeSamples.keys())
keys.sort()
if time <= keys[0]:
return timeSamples[keys[0]]
Expand Down Expand Up @@ -260,7 +260,7 @@ def hasMetadata(self, key):
return key in self._metadata

def getMetadataKyes(self):
return self._metadata.keys()
return list(self._metadata.keys())

def getMetadataValue(self, key, default=None):
strValue = self._metadata.get(key, default)
Expand Down Expand Up @@ -332,7 +332,7 @@ def removeKey(self, time, emitSignal=True):
time = float(time)
if self.hasKey() and time in self._overrideTimeSamples.keys():
self._overrideTimeSamples.pop(time)
if len(self._overrideTimeSamples.keys()) == 0:
if len(list(self._overrideTimeSamples.keys())) == 0:
self._overrideTimeSamples = None
if emitSignal:
self.valueChanged.emit(self)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/core/parse/_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def fixedWritexml(self, writer, indent="", addindent="", newl=""):
writer.write(indent+"<" + self.tagName)

attrs = self._get_attributes()
a_names = attrs.keys()
a_names = list(attrs.keys())
a_names.sort()

for a_name in a_names:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/module/sqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def to_unicode(qstring):

# for pycharm auto complete
if False:
from PyQt5 import QtSvg, QtCharts, QtOpenGL, QtWidgets, QtCore, QtGui
from PySide2 import QtSvg, QtCharts, QtOpenGL, QtWidgets, QtCore, QtGui

2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/ui/graph/nodeItem/nodeItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ def _updateLabelText(self):
pyString = ' '.join(expString.split(' ')[1:]).replace(']', '')
try:
result = eval(pyString, globals(), Node._expressionMap)
except Exception, e:
except(Exception) as e:
result = e
label = label.replace(expString, str(result))

Expand Down
22 changes: 15 additions & 7 deletions lib/python/usdNodeGraph/ui/graph/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _formatSwitchClicked(self):
def _getContextMenus(self):
actions = []
groupDict = Node.getNodesByGroup()
groups = groupDict.keys()
groups = list(groupDict.keys())
groups.sort()
for group in groups:
nodeActions = []
Expand Down Expand Up @@ -738,7 +738,7 @@ def _getIntoPrim(self, primSpec, upNode):
self._getIntoPrim(child, node)

def _getPrimAttributes(self, primSpec, upNode):
attrs = primSpec.attributes.keys()
attrs = list(primSpec.attributes.keys())
if len(attrs) == 0:
return upNode

Expand All @@ -757,7 +757,7 @@ def _getPrimAttributes(self, primSpec, upNode):
return upNode

def _getPrimRelationships(self, primSpec, upNode):
attrs = primSpec.relationships.keys()
attrs = list(primSpec.relationships.keys())
if len(attrs) == 0:
return upNode

Expand Down Expand Up @@ -819,7 +819,7 @@ def _afterNodeNameChanged(self, node):
def _getUniqueName(self, name):
# nodes = self.allNodes()
# names = [n.name() for n in nodes]
names = self._allNodes.values()
names = list(self._allNodes.values())

match = re.match(NODE_NAME_PATTERN, name)
if match:
Expand Down Expand Up @@ -848,12 +848,20 @@ def _getUniqueName(self, name):
return name, suffix, index

def _executeLayerNodes(self, stage, nodes):
nodes.sort(lambda n1,n2: cmp(n1.pos().y(),n2.pos().y()))
from functools import cmp_to_key
nodes.sort(key=cmp_to_key(self._node_cmp))
for node in nodes:
stage, _ = node.execute(stage, None)

return stage

def _node_cmp(self, n1, n2):
if n1.pos().y() > n2.pos().y():
return 1
if n1.pos().y() < n2.pos().y():
return -1
return 0

def _executeNode(self, node, stage, prim):
stage, prim = node.execute(stage, prim)
if node.Class() == 'VariantSwitch':
Expand Down Expand Up @@ -1071,7 +1079,7 @@ def updateSelectedNodesPipe(self):
pipe.updatePath()

def allNodes(self):
return self._allNodes.keys()
return list(self._allNodes.keys())
# nodes = [item for item in self.items() if isinstance(item, NodeItem)]
# return nodes

Expand Down Expand Up @@ -1276,7 +1284,7 @@ def _exportToFile(self, exportFile):
QtWidgets.QMessageBox.warning(None, 'Warning', 'This layer can\'t be exported!')
return
stage = self._executeAllToStage()
print exportFile
print(exportFile)
stage.GetRootLayer().Export(exportFile)

def exportToFile(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/ui/nodeGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _createSignal(self):
def _getNodeActions(self):
actions = []
groupDict = Node.getNodesByGroup()
groups = groupDict.keys()
groups = list(groupDict.keys())
groups.sort()
for group in groups:
nodeActions = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def updateView(self):

self.clearContents()

keys = self.metadatas.keys()
keys = list(self.metadatas.keys())
keys.sort()

self.setRowCount(len(keys))
Expand Down
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/ui/parameter/param_panel/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def _numChanged(self):

def _removeExtraWidgets(self):
num = int(self.widgetNumEdit.text())
indexs = range(len(self._widgets))
indexs = list(range(len(self._widgets)))
indexs.sort(reverse=True)
for i in indexs:
if i + 1 > num:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .basic import ParameterWidget, VecWidget, VecParameterWidget
from usdNodeGraph.module.sqt import *
from usdNodeGraph.utils.pyversion import *


class StringParameterWidget(VecWidget, VecParameterWidget):
Expand Down
2 changes: 1 addition & 1 deletion lib/python/usdNodeGraph/ui/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def loadPlugins():
# Load each plugin in alphabetical order by name. For each plugin, load all
# of its containers in alphabetical order by type name.
allContainers = []
for plugin in sorted(plugins.keys(), key=lambda plugin: plugin.name):
for plugin in sorted(list(plugins.keys()), key=lambda plugin: plugin.name):
plugin.Load()
pluginContainerTypes = sorted(
plugins[plugin], key=lambda containerType: containerType.typeName)
Expand Down
13 changes: 13 additions & 0 deletions lib/python/usdNodeGraph/utils/pyversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys

PY_MAIN_VERSION = sys.version_info[0]

if PY_MAIN_VERSION == 3:
from imp import reload
basestring = str
unicode = str
long = int
else:
reload = reload
basestring = basestring

1 change: 1 addition & 0 deletions lib/python/usdNodeGraph/utils/res/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
from usdNodeGraph.module.sqt import *
from usdNodeGraph.utils.pyversion import *


RES_FOLDER = '/'.join(__file__.replace('\\', '/').split('/')[:-3]) + '/resource'
Expand Down
13 changes: 1 addition & 12 deletions lib/python/usdNodeGraph/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
import os
from os.path import join as opj
from usdNodeGraph.module.sqt import QtCore, to_unicode
import sys

PY_MAIN_VERSION = sys.version_info[0]

if PY_MAIN_VERSION == 3:
from imp import reload
basestring = str
unicode = str
long = int
else:
reload = reload
basestring = basestring
from .pyversion import *


User_Setting = QtCore.QSettings(
Expand Down

0 comments on commit c072e1f

Please sign in to comment.