Skip to content

Commit

Permalink
Merge pull request #23 from dreamworksanimation/dev
Browse files Browse the repository at this point in the history
Release version 0.12.0
  • Loading branch information
mds-dwa authored Aug 4, 2021
2 parents 9c1433f + 202c5d2 commit 3af50d3
Show file tree
Hide file tree
Showing 15 changed files with 1,091 additions and 534 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,6 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# VSCode
.vscode/
11 changes: 9 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@ and this will depend on your setup.py install settings.

### Mac (OSX)

#### Installation
1. Launch Terminal
2. ```cd``` to the downloaded usdmanager folder (you should see a setup.py file in here).
3. Customize usdmanager/config.json if needed.
4. Run ```python setup.py install``` (may need to prepend the command with ```sudo``` and/or add the ```--user``` flag)
5. Depending on where you installed it (e.g. /Users/username/Library/Python/3.7/bin), update your $PATH to include the relevant bin directory by editing /etc/paths or ~/.zshrc.

#### Known Issues
- User preferences may not preserve between sessions.
- Since this is not installed as an entirely self-contained package, the application name (and icon) will by Python, not USD Manager.

### Windows

#### Installation
1. Launch Command Prompt
2. ```cd``` to the downloaded usdmanager folder (you should see a setup.py file in here).
3. Run ```python setup.py install``` (may need the ```--user``` flag)
3. Customize usdmanager/config.json if needed.
4. Run ```python setup.py install``` (may need the ```--user``` flag)

If setup.py complains about missing setuptools, you can install it via pip. If you installed a new enough python-2 version, pip should already be handled for you, but you may still need to add it to your PATH. pip should already live somewhere like this (C:\Python27\Scripts\pip.exe), and you can permanently add it to your environment with: ```setx PATH "%PATH%;C:\Python27\Scripts"```

Expand Down
919 changes: 598 additions & 321 deletions usdmanager/__init__.py
100755 → 100644

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions usdmanager/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
Constant values
"""
# USD file extensions.
USD_EXTS = ("usd", "usda", "usdc", "usdz")
# Expandable with custom file formats.
# First in each tuple is preferred extension for that format (e.g. in Save dialog).
USD_AMBIGUOUS_EXTS = ("usd",) # Can be ASCII or crate.
USD_ASCII_EXTS = ("usda",) # Can ONLY be ASCII.
USD_CRATE_EXTS = ("usdc",) # Can ONLY be Crate.
USD_ZIP_EXTS = ("usdz",)
USD_EXTS = USD_AMBIGUOUS_EXTS + USD_ASCII_EXTS + USD_CRATE_EXTS + USD_ZIP_EXTS


# File filters for the File > Open... and File > Save As... dialogs.
FILE_FILTER = (
"USD Files (*.{})".format(" *.".join(USD_EXTS)),
"USD - ASCII (*.usd *.usda)",
"USD - Crate (*.usd *.usdc)",
"USD - Zip (*.usdz)",
"USD - ASCII (*.{})".format(" *.".join(USD_AMBIGUOUS_EXTS + USD_ASCII_EXTS)),
"USD - Crate (*.{})".format(" *.".join(USD_AMBIGUOUS_EXTS + USD_CRATE_EXTS)),
"USD - Zip (*.{})".format(" *.".join(USD_ZIP_EXTS)),
"All Files (*)"
)

Expand Down
19 changes: 18 additions & 1 deletion usdmanager/find_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
from Qt.QtCore import Slot
from Qt.QtWidgets import QStatusBar
from Qt.QtGui import QIcon
from Qt.QtGui import QIcon, QTextDocument

from .utils import loadUiType

Expand Down Expand Up @@ -61,6 +61,23 @@ def connectSignals(self):
"""
self.findLineEdit.textChanged.connect(self.updateButtons)

def searchFlags(self):
""" Get find flags based on checked options.
:Returns:
Find flags
:Rtype:
`QTextDocument.FindFlags`
"""
flags = QTextDocument.FindFlags()
if self.caseSensitiveCheck.isChecked():
flags |= QTextDocument.FindCaseSensitively
if self.wholeWordsCheck.isChecked():
flags |= QTextDocument.FindWholeWords
if self.searchBackwardsCheck.isChecked():
flags |= QTextDocument.FindBackward
return flags

@Slot(str)
def updateButtons(self, text):
"""
Expand Down
14 changes: 11 additions & 3 deletions usdmanager/find_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>443</width>
<height>230</height>
<height>242</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -53,10 +53,18 @@
</layout>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="replaceLineEdit"/>
<widget class="QLineEdit" name="replaceLineEdit">
<property name="placeholderText">
<string>Replace</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="findLineEdit"/>
<widget class="QLineEdit" name="findLineEdit">
<property name="placeholderText">
<string>Find</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="replaceLabel">
Expand Down
73 changes: 20 additions & 53 deletions usdmanager/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
from .utils import findModules


# Used to clear out highlighting from the Find command.
DONT_MATCH_PHRASE = "USDMNGRDONTMATCH"

# Enabled when running in a theme with a dark background color.
DARK_THEME = False

Expand Down Expand Up @@ -106,7 +103,7 @@ def findHighlighters():
# Find all available "MasterHighlighter" subclasses within the highlighters module.
classes = []
for module in findModules("highlighters"):
for name, cls in inspect.getmembers(module, lambda x: inspect.isclass(x) and issubclass(x, MasterHighlighter)):
for _, cls in inspect.getmembers(module, lambda x: inspect.isclass(x) and issubclass(x, MasterHighlighter)):
classes.append(cls)
return classes

Expand Down Expand Up @@ -155,7 +152,7 @@ def __init__(self, parent, enableSyntaxHighlighting=False, programs=None):
# Undo syntax highlighting on at least some of our links so the assigned colors show.
self.ruleLink = createRule("*")
self.highlightingRules.append(self.ruleLink)
self.setLinkPattern(programs or {})
self.setLinkPattern(programs or {}, dirty=False)

# Some general single-line rules that apply to many file formats.
# Numeric literals
Expand Down Expand Up @@ -194,14 +191,6 @@ def __init__(self, parent, enableSyntaxHighlighting=False, programs=None):
if self.ruleLink not in self.highlightingRules:
self.highlightingRules.append(self.ruleLink)

# Find phrase.
frmt = QtGui.QTextCharFormat()
frmt.setBackground(QtCore.Qt.yellow)
pattern = QtCore.QRegExp(DONT_MATCH_PHRASE, QtCore.Qt.CaseInsensitive, QtCore.QRegExp.FixedString)
self.findRule = (pattern, frmt)
self.blankRules.append(self.findRule)
self.highlightingRules.append(self.findRule)

self.setSyntaxHighlighting(enableSyntaxHighlighting)

def getRules(self):
Expand Down Expand Up @@ -240,48 +229,20 @@ def dirty(self):
"""
self.dirtied.emit()

def setFindPhrase(self, phrase):
""" Set the "find" phrase when searching for text.
:Parameters:
phrase : `str`
Text in find bar to search for.
"""
if phrase == "":
phrase = DONT_MATCH_PHRASE

if phrase != self.findPhrase:
if phrase == DONT_MATCH_PHRASE:
self.findRule = (self.findRule[0], QtGui.QTextCharFormat())
else:
self.findRule[1].setBackground(QtCore.Qt.yellow)
self.findRule[0].setPattern(phrase)
self.findPhrase = phrase
self.dirty()

def setFindCase(self, case):
""" Set the case sensitivity when searching for text.
:Parameters:
case : `bool`
Find is case-sensitive if True.
"""
case = QtCore.Qt.CaseSensitive if case else QtCore.Qt.CaseInsensitive
if case != self.findRule[0].caseSensitivity():
self.findRule[0].setCaseSensitivity(case)
self.dirty()

def setLinkPattern(self, programs):
def setLinkPattern(self, programs, dirty=True):
""" Set the rules to search for files based on file extensions, quotes, etc.
:Parameters:
programs : `dict`
extension: program pairs of strings.
dirty : `bool`
If we should trigger a rehighlight or not.
"""
# This is slightly different than the main program's RegEx because Qt doesn't support all the same things.
# TODO: Not allowing a backslash here might break Windows file paths if/when we try to support that.
self.ruleLink[0].setPattern(r'(?:[^\'"@()\t\n\r\f\v\\]*\.)(?:' + '|'.join(programs.keys()) + r')(?=(?:[\'")@]|\\\"))')
self.dirty()
if dirty:
self.dirty()

def setSyntaxHighlighting(self, enable, force=True):
""" Enable/Disable syntax highlighting.
Expand Down Expand Up @@ -334,6 +295,12 @@ def highlightBlock(self, text):
# TODO: Do we need to reset the block state or anything else here?
return

# Reduce name lookups for speed, since this is one of the slowest parts of the app.
setFormat = self.setFormat
currentBlockState = self.currentBlockState
setCurrentBlockState = self.setCurrentBlockState
previousBlockState = self.previousBlockState

for pattern, frmt in self.master.rules:
i = pattern.indexIn(text)
while i >= 0:
Expand All @@ -344,12 +311,12 @@ def highlightBlock(self, text):
i = pos1
else:
length = pattern.matchedLength()
self.setFormat(i, length, frmt)
setFormat(i, length, frmt)
i = pattern.indexIn(text, i + length)

self.setCurrentBlockState(0)
setCurrentBlockState(0)
for state, (startExpr, endExpr, frmt) in enumerate(self.master.multilineRules, 1):
if self.previousBlockState() == state:
if previousBlockState() == state:
# We're already inside a match for this rule. See if there's an ending match.
startIndex = 0
add = 0
Expand All @@ -371,15 +338,15 @@ def highlightBlock(self, text):
# We found the end of the multiline rule.
length = endIndex - startIndex + add + endExpr.matchedLength()
# Since we're at the end of this rule, reset the state so other multiline rules can try to match.
self.setCurrentBlockState(0)
setCurrentBlockState(0)
else:
# Still inside the multiline rule.
length = len(text) - startIndex + add
self.setCurrentBlockState(state)
setCurrentBlockState(state)

# Highlight the portion of this line that's inside the multiline rule.
# TODO: This doesn't actually ensure we hit the closing expression before highlighting.
self.setFormat(startIndex, length, frmt)
setFormat(startIndex, length, frmt)

# Look for the next match.
startIndex = startExpr.indexIn(text, startIndex + length)
Expand All @@ -390,7 +357,7 @@ def highlightBlock(self, text):
else:
add = startExpr.matchedLength()

if self.currentBlockState() == state:
if currentBlockState() == state:
break

self.dirty = False
2 changes: 1 addition & 1 deletion usdmanager/highlighters/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def getRules(self):
[
# Keywords
r"\b(?:and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|"
r"import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\b",
r"import|in|is|lambda|nonlocal|not|or|pass|raise|return|try|while|with|yield)\b",
QtGui.QColor("#4b7029"),
QtGui.QColor("#4b7029"),
QtGui.QFont.Bold
Expand Down
Loading

0 comments on commit 3af50d3

Please sign in to comment.