Skip to content

Commit

Permalink
[MNT] version up to 0.14.0
Browse files Browse the repository at this point in the history
[MNT] add docstrings, cleanup whitespace and formatting, rm unused code
[MNT] previously deprecated setDirtyTab removed
[ENH] python3 compatibility for setup.py
[BUG] ensure app tmp dir exists if manually removed while open
[BUG] set file dialog starting directory to cwd on launch
[BUG] Save As shouldn't append a dot with no extension
[BUG] disable Open button in include panel when nothing selected
  • Loading branch information
mds-dwa committed Jun 17, 2022
1 parent fecff2c commit a386c44
Show file tree
Hide file tree
Showing 8 changed files with 779 additions and 783 deletions.
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@


PACKAGE = "usdmanager"
execfile("{}/version.py".format(PACKAGE))
import sys
if sys.version_info[0] < 3:
execfile("{}/version.py".format(PACKAGE))
else:
exec(open("{}/version.py".format(PACKAGE)).read())
VERSION = __version__


Expand Down
1,467 changes: 701 additions & 766 deletions usdmanager/__init__.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions usdmanager/file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FileDialog(QFileDialog):
"""
def __init__(self, parent=None, caption="", directory="", filters=None, selectedFilter="", showHidden=False):
""" Initialize the dialog.
:Parameters:
parent : `QtCore.QObject`
Parent object
Expand All @@ -40,8 +40,7 @@ def __init__(self, parent=None, caption="", directory="", filters=None, selected
showHidden : `bool`
Show hidden files
"""
super(FileDialog, self).__init__(parent, caption, directory)
self.setNameFilters(filters or FILE_FILTER)
super(FileDialog, self).__init__(parent, caption, directory, ';;'.join(filters or FILE_FILTER))
if selectedFilter:
self.selectNameFilter(selectedFilter)
if showHidden:
Expand Down
8 changes: 6 additions & 2 deletions usdmanager/include_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def __init__(self, path="", filter="", selectedFilter="", parent=None):
self.fileTypeLabelFiller = QtWidgets.QLabel(self)
self.fileTypeComboFiller = QtWidgets.QLabel(self)
self.buttonOpen = QtWidgets.QPushButton(QIcon.fromTheme("document-open"), "Open", self)
self.buttonOpen.setEnabled(False)

# Item settings.
self.buttonHome.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_DirHomeIcon))
self.buttonHome.setIcon(QIcon.fromTheme("folder_home", self.style().standardIcon(QtWidgets.QStyle.SP_DirHomeIcon)))
self.buttonHome.setToolTip("User's home directory")
self.buttonHome.setAutoRaise(True)
self.buttonOriginal.setToolTip("Original directory")
self.lookInCombo.setMinimumSize(50,0)
self.toParentButton.setIcon(self.style().standardIcon(QtWidgets.QStyle.SP_FileDialogToParent))
self.toParentButton.setIcon(QIcon.fromTheme("up", self.style().standardIcon(QtWidgets.QStyle.SP_FileDialogToParent)))
self.toParentButton.setAutoRaise(True)
self.toParentButton.setToolTip("Parent directory")
self.listView.setDragEnabled(True)
Expand Down Expand Up @@ -387,3 +388,6 @@ def fileSelectionChanged(self, one, two):
if indexes:
idx = indexes[0]
self.fileNameEdit.setText(str(idx.data()))
self.buttonOpen.setEnabled(True)
else:
self.buttonOpen.setEnabled(False)
9 changes: 5 additions & 4 deletions usdmanager/parsers/usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
logging.basicConfig()


NT = os.name == "nt"
NT_REGEX = re.compile(r'^[a-zA-Z]:[/\\]')


class UsdAsciiParser(AbstractExtParser):
""" USD ASCII files.
Expand Down Expand Up @@ -137,10 +141,7 @@ def parseMatch(self, match, linkPath, nativeAbsPath, fileInfo):
def pathForLink(path):
"""Need three slashes before drive letter on Windows; this prepends one, so
with the usual two URL slashes we'll get the proper format."""
if os.name == 'nt' and re.match(r'^[a-zA-Z]:[/\\]', fullPath):
return '/' + path
else:
return path
return '/' + path if NT and NT_REGEX.match(fullPath) else path

# Make the HTML link.
if self.exists[fullPath]:
Expand Down
1 change: 0 additions & 1 deletion usdmanager/preferences_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os

from Qt.QtCore import Slot, QRegExp
from Qt.QtGui import QIcon, QRegExpValidator
Expand Down
64 changes: 59 additions & 5 deletions usdmanager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,23 @@ def expandPath(path, parentPath=None, sdf_format_args=None, extractedDir=None):
resolver.ConfigureResolverForAsset(path)
context = resolver.CreateDefaultContextForAsset(path)
with Ar.ResolverContextBinder(context):
anchoredPath = path if parentPath is None else resolver.CreateIdentifier(path)
if parentPath is None:
anchoredPath = path
elif hasattr(resolver, "CreateIdentifier"):
anchoredPath = resolver.CreateIdentifier(path)
else:
anchoredPath = resolver.AnchorRelativePath(parentPath, path)
resolved = resolver.Resolve(anchoredPath)

# https://graphics.pixar.com/usd/docs/Usdz-File-Format-Specification.html#UsdzFileFormatSpecification-USDConstraints-AssetResolution
# If resolving relative to the layer fails in a usdz archive,
# try to resolve based on the archive's default layer path.
if extractedDir and not os.path.exists(resolved):
default_layer = os.path.join(extractedDir, 'defaultLayer.usd')
anchoredPath = resolver.CreateIdentifier(default_layer, path)
if hasattr(resolver, "CreateIdentifier"):
anchoredPath = resolver.CreateIdentifier(default_layer, path)
else:
anchoredPath = resolver.AnchorRelativePath(default_layer, path)
resolved = resolver.Resolve(anchoredPath)
except Exception as e:
logger.warn("Failed to resolve Asset path %s with parent %s: %s", path, parentPath, e)
Expand Down Expand Up @@ -216,12 +224,58 @@ def generateTemporaryUsdFile(usdFileName, tmpDir=None):
:Raises OSError:
If usdcat fails
"""
fd, tmpFileName = tempfile.mkstemp(suffix="." + USD_AMBIGUOUS_EXTS[0], dir=tmpDir)
fd, tmpFileName = mkstemp(suffix="." + USD_AMBIGUOUS_EXTS[0], dir=tmpDir)
os.close(fd)
usdcat(QtCore.QDir.toNativeSeparators(usdFileName), tmpFileName, format="usda")
return tmpFileName


def mkdtemp(dir, **kwargs):
""" Make a temp dir, safely ensuring the parent temp dir still exists.
:Parameters:
dir : `str`
Parent directory
:Returns:
New temp directory
:Rtype:
`str`
"""
try:
destDir = tempfile.mkdtemp(dir=dir, **kwargs)
except OSError:
if dir is not None and not os.path.exists(dir):
# Someone may have manually removed the temp dir while the app was open.
os.mkdir(dir)
return mkdtemp(dir, **kwargs)
else:
raise
return destDir


def mkstemp(dir, **kwargs):
""" Make a temp file, safely ensuring the parent temp dir still exists.
:Parameters:
dir : `str`
Parent directory
:Returns:
New temp file
:Rtype:
`str`
"""
try:
fd, tmpFileName = tempfile.mkstemp(dir=dir, **kwargs)
except OSError:
if dir is not None and not os.path.exists(dir):
# Someone may have manually removed the temp dir while the app was open.
os.mkdir(dir)
return mkstemp(dir, **kwargs)
else:
raise
return fd, tmpFileName


def usdcat(inputFile, outputFile, format=None):
""" Generate a temporary ASCII USD file that the user can edit.
Expand Down Expand Up @@ -304,7 +358,7 @@ def unzip(path, tmpDir=None):
"""
from zipfile import ZipFile

destDir = tempfile.mkdtemp(prefix="usdmanager_usdz_", dir=tmpDir)
destDir = mkdtemp(prefix="usdmanager_usdz_", dir=tmpDir)
logger.debug("Extracting %s to %s", path, destDir)
with ZipFile(QtCore.QDir.toNativeSeparators(path), 'r') as zipRef:
zipRef.extractall(destDir)
Expand Down Expand Up @@ -535,7 +589,7 @@ def loadUiWidget(path, parent=None, source_path=None):
if parent:
#ui.setParent(parent)
for member in dir(ui):
if not member.startswith('__') and member is not 'staticMetaObject':
if not member.startswith('__') and member != 'staticMetaObject':
setattr(parent, member, getattr(ui, member))
return ui

Expand Down
2 changes: 1 addition & 1 deletion usdmanager/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = '0.13.0'
__version__ = '0.14.0'

0 comments on commit a386c44

Please sign in to comment.