Skip to content

Commit

Permalink
Merge pull request #11 from dreamworksanimation/dev
Browse files Browse the repository at this point in the history
Release version 0.6.0
  • Loading branch information
mds-dwa authored Jul 9, 2019
2 parents e850562 + 46ecf51 commit c81edfe
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 33 deletions.
81 changes: 56 additions & 25 deletions usdmanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,32 @@ def setupUi(self):
"""
self.baseInstance = utils.loadUiWidget('main_window.ui', self)

# Set usdview stylesheet.
if self.app.opts['dark']:
# You now have access to the widgets defined in the ui file.
self.defaultDocFont = QtGui.QFont()
self.defaultDocFont.setStyleHint(QtGui.QFont.Courier)
self.defaultDocFont.setFamily("Monospace")
self.defaultDocFont.setPointSize(9)
self.defaultDocFont.setBold(False)
self.defaultDocFont.setItalic(False)

self.readSettings()
self.compileLinkRegEx()

# Changing the theme while the app is already running doesn't work well.
# Currently, we set this once, and the user must restart the application to see changes.
userThemeName = self.app.opts['theme'] or self.preferences['theme']
if userThemeName == "dark":
# Set usdview-based stylesheet.
stylesheet = resource_filename(__name__, "usdviewstyle.qss")
with open(stylesheet) as f:
# Qt style sheet accepts only forward slashes as path separators.
sheetString = f.read().replace('RESOURCE_DIR', os.path.dirname(stylesheet).replace("\\", "/"))
self.setStyleSheet(sheetString)

# Do some additional adjustments for any dark theme, even if it's coming from the system settings.
# TODO: Be able to make these adjustments on the fly if the user changes the system theme.
if self.isDarkTheme():
highlighter.DARK_THEME = True

# Change some more stuff that the stylesheet doesn't catch.
p = QtWidgets.QApplication.palette()
Expand All @@ -267,19 +286,6 @@ def setupUi(self):
a.binary {{color:#69F}}
span.badLink {{color:#F33}}
</style></head><body style="white-space:pre">{}</body></html>"""

highlighter.DARK_THEME = True

# You now have access to the widgets defined in the ui file.
self.defaultDocFont = QtGui.QFont()
self.defaultDocFont.setStyleHint(QtGui.QFont.Courier)
self.defaultDocFont.setFamily("Monospace")
self.defaultDocFont.setPointSize(9)
self.defaultDocFont.setBold(False)
self.defaultDocFont.setItalic(False)

self.readSettings()
self.compileLinkRegEx()

searchPaths = QtGui.QIcon.themeSearchPaths()
extraSearchPaths = [x for x in self.app.appConfig.get("themeSearchPaths", []) if x not in searchPaths]
Expand Down Expand Up @@ -646,7 +652,8 @@ def readSettings(self):
'diffTool': self.config.value("diffTool", self.app.appConfig.get("diffTool", "xdiff")),
'autoCompleteAddressBar': self.config.boolValue("autoCompleteAddressBar", True),
'useSpaces': self.config.boolValue("useSpaces", True),
'tabSpaces': int(self.config.value("tabSpaces", 4))
'tabSpaces': int(self.config.value("tabSpaces", 4)),
'theme': self.config.value("theme", None),
}

# Read 'programs' settings object into self.programs.
Expand Down Expand Up @@ -728,6 +735,7 @@ def writeSettings(self):
self.config.setValue("autoCompleteAddressBar", self.preferences['autoCompleteAddressBar'])
self.config.setValue("useSpaces", self.preferences['useSpaces'])
self.config.setValue("tabSpaces", self.preferences['tabSpaces'])
self.config.setValue("theme", self.preferences['theme'])

# Write self.programs to settings object
exts = self.programs.keys()
Expand Down Expand Up @@ -1604,7 +1612,7 @@ def find(self, flags=None, startPos=3, loop=True):
if cursor.hasSelection():
# Found phrase. Set cursor and formatting.
currTextWidget.setTextCursor(cursor)
self.findBar.setStyleSheet("QLineEdit{{background:{}}}".format("inherit" if self.app.opts['dark'] else "none"))
self.findBar.setStyleSheet("QLineEdit{{background:{}}}".format("inherit" if self.isDarkTheme() else "none"))
if loop:
# Didn't just loop through the document, so hide any messages.
self.labelFindPixmap.setVisible(False)
Expand Down Expand Up @@ -1924,6 +1932,7 @@ def editPreferences(self):
self.preferences['font'] = dlg.getPrefFont()
self.preferences['useSpaces'] = dlg.getPrefUseSpaces()
self.preferences['tabSpaces'] = dlg.getPrefTabSpaces()
self.preferences['theme'] = dlg.getPrefTheme()

# Update font and line number visibility in all tabs.
self.tabWidget.setFont(self.preferences['font'])
Expand Down Expand Up @@ -1999,7 +2008,7 @@ def validateFindBar(self, text):
self.buttonHighlightAll.setEnabled(False)
if self.buttonHighlightAll.isChecked():
self.findHighlightAll()
self.findBar.setStyleSheet("QLineEdit{{background:{}}}".format("inherit" if self.app.opts['dark'] else "none"))
self.findBar.setStyleSheet("QLineEdit{{background:{}}}".format("inherit" if self.isDarkTheme() else "none"))
self.labelFindPixmap.setVisible(False)
self.labelFindStatus.setVisible(False)

Expand Down Expand Up @@ -3028,6 +3037,17 @@ def currentTabChanged(self, idx):
if not self.quitting:
self.findHighlightAll()

def isDarkTheme(self):
""" Check if any dark theme is active based on the background lightness.
:Returns:
True if the lightness factor of the window background is less than 0.5.
The 0.5 threshold to determine if it's dark is completely arbitrary.
:Rtype:
`bool`
"""
return self.palette().window().color().lightnessF() < 0.5

def updateButtons(self):
""" Update button states, text fields, and other GUI elements.
"""
Expand Down Expand Up @@ -3733,7 +3753,7 @@ def keyPressEvent(self, e):
# Otherwise, QTextEdit already handles inserting the tab character.
self.insertPlainText(" " * self.tabSpaces)
return
elif e.key() == QtCore.Qt.Key_Backtab and e.modifiers() == QtCore.Qt.ShiftModifier and self.textCursor().hasSelection():
elif e.key() == QtCore.Qt.Key_Backtab and e.modifiers() == QtCore.Qt.ShiftModifier:
self.unindentText()
return
super(TextEdit, self).keyPressEvent(e)
Expand Down Expand Up @@ -3844,7 +3864,7 @@ def indentText(self):
cursor.movePosition(cursor.StartOfBlock)
cursor.beginEditBlock()
# Modify all blocks between selectionStart and selectionEnd
while cursor.position() <= end and not cursor.atEnd():
while cursor.position() < end and not cursor.atEnd():
if self.useSpaces:
if self.tabSpaces:
cursor.insertText(" " * self.tabSpaces)
Expand All @@ -3869,7 +3889,7 @@ def unindentText(self):
cursor.movePosition(cursor.StartOfBlock)
cursor.beginEditBlock()
# Modify all blocks between selectionStart and selectionEnd
while cursor.position() <= end and not cursor.atEnd():
while cursor.position() < end and not cursor.atEnd():
currBlock = cursor.blockNumber()

for i in range(self.tabSpaces):
Expand Down Expand Up @@ -3915,7 +3935,7 @@ def __init__(self, parent=None):
"""
super(BrowserTab, self).__init__(parent)

if self.window().app.opts['dark']:
if self.window().isDarkTheme():
color = QtGui.QColor(35, 35, 35).name()
else:
color = self.style().standardPalette().base().color().darker(105).name()
Expand Down Expand Up @@ -4204,10 +4224,18 @@ def run(self):
description = 'File Browser/Text Editor for quick navigation and\n'
'editing among text-based files that reference other files.\n\n')
parser.add_argument('fileName', nargs='*', help='The file(s) to view.')
parser.add_argument("-dark",

group = parser.add_mutually_exclusive_group()
group.add_argument("-theme",
choices=["light", "dark"],
help="Override the user theme preference. Use the Preferences dialog to save this setting)"
)
# Legacy flag, now equivalent to "-theme dark"
group.add_argument("-dark",
action="store_true",
help="Use usdview-like dark Qt theme"
help=argparse.SUPPRESS
)

parser.add_argument("-info",
action="store_true",
help="Log info messages"
Expand All @@ -4217,11 +4245,14 @@ def run(self):
help="Log debugging messages"
)
results = parser.parse_args()
if results.dark:
results.theme = "dark"
logger.warning('The -dark flag has been deprecated. Please use "-theme dark" instead.')
self.opts = {
'dir': os.getcwd(),
'info': results.info,
'debug': results.debug,
'dark': results.dark
'theme': results.theme,
}

# Initialize the application and settings.
Expand Down
15 changes: 15 additions & 0 deletions usdmanager/preferences_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def setupUi(self, widget):
self.useSpacesSpinBox.setValue(parent.preferences['tabSpaces'])
self.lineEditTextEditor.setText(parent.preferences['textEditor'])
self.lineEditDiffTool.setText(parent.preferences['diffTool'])
self.themeWidget.setChecked(parent.preferences['theme'] == "dark")
self.updateFontLabel()

# ----- Programs tab -----
Expand Down Expand Up @@ -215,6 +216,19 @@ def getPrefTextEditor(self):
"""
return self.lineEditTextEditor.text()

def getPrefTheme(self):
""" Get the selected theme.
We may eventually make this a combo box supporting multiple themes,
so use the string name instead of just a boolean.
:Returns:
Selected theme name, or None if the default
:Rtype:
`str` | None
"""
return "dark" if self.themeWidget.isChecked() else None

def getPrefUseSpaces(self):
"""
:Returns:
Expand Down Expand Up @@ -318,6 +332,7 @@ def restoreDefaults(self, btn):
self.lineEditDiffTool.setText(window.app.appConfig.get("diffTool", "xdiff"))
self.useSpacesCheckBox.setChecked(True)
self.useSpacesSpinBox.setValue(4)
self.themeWidget.setChecked(False)
self.docFont = window.defaultDocFont
self.updateFontLabel()

Expand Down
19 changes: 16 additions & 3 deletions usdmanager/preferences_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>463</width>
<height>519</height>
<height>574</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -162,6 +162,16 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="themeWidget">
<property name="toolTip">
<string>Use the dark UI theme. You must restart the application to see any changes for this setting.</string>
</property>
<property name="text">
<string>Dark theme (restart to see changes)</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
Expand Down Expand Up @@ -254,8 +264,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>417</width>
<height>260</height>
<width>119</width>
<height>72</height>
</rect>
</property>
<layout class="QGridLayout" name="scrollAreaLayout">
Expand Down Expand Up @@ -415,6 +425,9 @@
<tabstop>checkBox_showAllMessages</tabstop>
<tabstop>checkBox_showHiddenFiles</tabstop>
<tabstop>checkBox_autoCompleteAddressBar</tabstop>
<tabstop>useSpacesCheckBox</tabstop>
<tabstop>useSpacesSpinBox</tabstop>
<tabstop>themeWidget</tabstop>
<tabstop>lineEditTextEditor</tabstop>
<tabstop>lineEditDiffTool</tabstop>
<tabstop>buttonFont</tabstop>
Expand Down
6 changes: 2 additions & 4 deletions usdmanager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ def generateTemporaryUsdFile(usdFileName, tmpDir=None):
If usdcat fails
"""
fd, tmpFileName = tempfile.mkstemp(suffix=".usd", dir=tmpDir)
try:
usdcat(usdFileName, tmpFileName, format="usda")
finally:
os.close(fd)
os.close(fd)
usdcat(usdFileName, tmpFileName, format="usda")
return tmpFileName


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.5.0'
__version__ = '0.6.0'

0 comments on commit c81edfe

Please sign in to comment.