Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otioview UI improvements #254

Merged
merged 2 commits into from May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 36 additions & 20 deletions bin/otioview.py
Expand Up @@ -73,38 +73,39 @@ def __init__(self, adapter_argument_map, *args, **kwargs):

# window options
self.setWindowTitle('OpenTimelineIO Viewer')
self.resize(900, 500)
self.resize(1900, 1200)

# widgets
self.tracks_widget = QtGui.QListWidget(parent=self)
self.tracks_widget = QtGui.QListWidget(
parent=self
)
self.timeline_widget = otioViewWidget.timeline_widget.Timeline(
parent=self
)
self.details_widget = otioViewWidget.details_widget.Details(
parent=self
)

# layout
splitter = QtGui.QSplitter(parent=self)
self.setCentralWidget(splitter)

widg = QtGui.QWidget(parent=self)
layout = QtGui.QVBoxLayout()
widg.setLayout(layout)
layout.addWidget(self.details_widget)
layout.addWidget(self.timeline_widget)
root = QtGui.QWidget(parent=self)
layout = QtGui.QVBoxLayout(root)

splitter = QtGui.QSplitter(parent=root)
splitter.addWidget(self.tracks_widget)
splitter.addWidget(widg)
splitter.setSizes([200, 700])
splitter.addWidget(self.timeline_widget)
splitter.addWidget(self.details_widget)

splitter.setSizes([100, 700, 300])

layout.addWidget(splitter)
self.setCentralWidget(root)

# menu
menubar = self.menuBar()

file_load = QtGui.QAction('load...', menubar)
file_load = QtGui.QAction('Open...', menubar)
file_load.triggered.connect(self._file_load)

file_menu = menubar.addMenu('file')
file_menu = menubar.addMenu('File')
file_menu.addAction(file_load)

# signals
Expand All @@ -127,14 +128,14 @@ def _file_load(self):
path = str(
QtGui.QFileDialog.getOpenFileName(
self,
'load otio',
'Open OpenTimelineIO',
start_folder,
'Otio ({extensions})'.format(extensions=extensions_string)
)[0]
'OTIO ({extensions})'.format(extensions=extensions_string)
)
)

if path:
self.load(path, self.adapter_argument_map)
self.load(path)

def load(self, path):
self._current_file = path
Expand Down Expand Up @@ -163,6 +164,16 @@ def _change_track(self):
if selection:
self.timeline_widget.set_timeline(selection[0].timeline)

def center(self):
frame = self.frameGeometry()
desktop = QtGui.QApplication.desktop()
screen = desktop.screenNumber(
desktop.cursor().pos()
)
centerPoint = desktop.screenGeometry(screen).center()
frame.moveCenter(centerPoint)
self.move(frame.topLeft())


def main():
args = _parsed_args()
Expand All @@ -174,17 +185,22 @@ def main():
argument_map[key] = val
else:
print(
"error: adapter arguments must be in the form foo=bar"
"error: adapter arguments must be in the form key=value"
" got: {}".format(pair)
)
sys.exit(1)

application = QtGui.QApplication(sys.argv)

application.setStyle("plastique")
# application.setStyle("cleanlooks")

window = Main(argument_map)

if args.input is not None:
window.load(args.input)

window.center()
window.show()
window.raise_()
application.exec_()
Expand Down
89 changes: 87 additions & 2 deletions opentimelineview/details_widget.py
Expand Up @@ -23,20 +23,105 @@
#

from PySide import QtGui
from PySide import QtCore

import opentimelineio as otio


class Details(QtGui.QTextEdit):
"""Widget with the json string of the specified OTIO object."""
"""Text widget with the JSON string of the specified OTIO object."""

def __init__(self, *args, **kwargs):
super(Details, self).__init__(*args, **kwargs)
self.setFixedHeight(100)
self.setReadOnly(True)
self.font = QtGui.QFont("Monospace")
self.font.setStyleHint(QtGui.QFont.TypeWriter)
# Qt5: QtGui.QFontDatabase.systemFont(QtGui.QFontDatabase.FixedFont)
self.setFont(self.font)

self.backgroundColor = QtGui.QColor(43, 43, 43)
self.textColor = QtGui.QColor(180, 180, 180)
self.highlightColor = QtGui.QColor(255, 198, 109)
self.keywordColor = QtGui.QColor(204, 120, 50)

self.palette = QtGui.QPalette()
self.palette.setColor(QtGui.QPalette.Base, self.backgroundColor)
self.palette.setColor(QtGui.QPalette.Text, self.textColor)
self.palette.setColor(QtGui.QPalette.BrightText, self.highlightColor)
self.palette.setColor(QtGui.QPalette.Link, self.keywordColor)
self.setPalette(self.palette)

self.highlighter = OTIOSyntaxHighlighter(self.palette, self.document())

def set_item(self, item):
if item is None:
self.setPlainText('')
else:
s = otio.adapters.write_to_string(item, 'otio_json')
self.setPlainText(s)


class OTIOSyntaxHighlighter(QtGui.QSyntaxHighlighter):
def __init__(self, palette, parent=None):
super(OTIOSyntaxHighlighter, self).__init__(parent)

self.punctuation_format = QtGui.QTextCharFormat()
self.punctuation_format.setForeground(palette.link())
self.punctuation_format.setFontWeight(QtGui.QFont.Bold)

self.key_format = QtGui.QTextCharFormat()
# self.key_format.setFontItalic(True)

self.literal_format = QtGui.QTextCharFormat()
self.literal_format.setForeground(palette.brightText())
self.literal_format.setFontWeight(QtGui.QFont.Bold)

self.value_format = QtGui.QTextCharFormat()
self.value_format.setForeground(palette.brightText())
self.value_format.setFontWeight(QtGui.QFont.Bold)

self.schema_format = QtGui.QTextCharFormat()
self.schema_format.setForeground(QtGui.QColor(161, 194, 97))
self.schema_format.setFontWeight(QtGui.QFont.Bold)

def highlightBlock(self, text):
expression = QtCore.QRegExp("(\\{|\\}|\\[|\\]|\\:|\\,)")
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, self.punctuation_format)
index = expression.indexIn(text, index + length)

text.replace("\\\"", " ")

expression = QtCore.QRegExp("\".*\" *\\:")
expression.setMinimal(True)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length - 1, self.key_format)
index = expression.indexIn(text, index + length)

expression = QtCore.QRegExp("\\: *\".*\"")
expression.setMinimal(True)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
firstQuoteIndex = text.indexOf('"', index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, but I am now getting:

Traceback (most recent call last):
  File "/pixar/ws/trees/rnr/storyedit/OpenTimelineIO/opentimelineview/details_widget.py", line 110, in highlightBlock
    firstQuoteIndex = text.indexOf('"', index)

Am I missing something perhaps?

valueLength = length - (firstQuoteIndex - index) - 2
self.setFormat(firstQuoteIndex + 1, valueLength, self.value_format)
index = expression.indexIn(text, index + length)

expression = QtCore.QRegExp("\\: (null|true|false|[0-9\.]+)")
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, self.literal_format)
index = expression.indexIn(text, index + length)

expression = QtCore.QRegExp("\"OTIO_SCHEMA\"\s*:\s*\".*\"")
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, self.schema_format)
index = expression.indexIn(text, index + length)