Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Hiero: python3 compatibility #2365

Merged
merged 4 commits into from
Dec 6, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openpype/hosts/hiero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def add_implementation_envs(env, _app):
# Add requirements to HIERO_PLUGIN_PATH
pype_root = os.environ["OPENPYPE_REPOS_ROOT"]
new_hiero_paths = [
os.path.join(pype_root, "openpype", "hosts", "hiero", "startup")
os.path.join(pype_root, "openpype", "hosts", "hiero", "api", "startup")
]
old_hiero_path = env.get("HIERO_PLUGIN_PATH") or ""
for path in old_hiero_path.split(os.pathsep):
Expand Down
2 changes: 2 additions & 0 deletions openpype/hosts/hiero/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .lib import (
pype_tag_name,
flatten,
get_track_items,
get_current_project,
get_current_sequence,
Expand Down Expand Up @@ -75,6 +76,7 @@

# Lib functions
"pype_tag_name",
"flatten",
"get_track_items",
"get_current_project",
"get_current_sequence",
Expand Down
35 changes: 29 additions & 6 deletions openpype/hosts/hiero/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import avalon.io
from openpype.api import (Logger, Anatomy, get_anatomy_settings)
from . import tags
from compiler.ast import flatten

try:
from PySide.QtCore import QFile, QTextStream
Expand All @@ -38,6 +37,13 @@
AVALON_CONFIG = os.getenv("AVALON_CONFIG", "pype")


def flatten(input_list):
for item in input_list:
if isinstance(item, (list, tuple)):
yield from flatten(item)
else:
yield item

def get_current_project(remove_untitled=False):
projects = flatten(hiero.core.projects())
if not remove_untitled:
Expand Down Expand Up @@ -250,7 +256,7 @@ def set_track_item_pype_tag(track_item, data=None):
Returns:
hiero.core.Tag
"""
data = data or dict()
data = data or {}

# basic Tag's attribute
tag_data = {
Expand Down Expand Up @@ -284,7 +290,7 @@ def get_track_item_pype_data(track_item):
Returns:
dict: data found on pype tag
"""
data = dict()
data = {}
# get pype data tag from track item
tag = get_track_item_pype_tag(track_item)

Expand All @@ -299,8 +305,20 @@ def get_track_item_pype_data(track_item):

try:
# capture exceptions which are related to strings only
value = ast.literal_eval(v)
except (ValueError, SyntaxError):
if re.match(r"^[\d]+$", v):
value = int(v)
elif re.match(r"^True$", v):
value = True
elif re.match(r"^False$", v):
value = False
elif re.match(r"^None$", v):
value = None
elif re.match(r"^[\w\d_]+$", v):
value = v
else:
value = ast.literal_eval(v)
except (ValueError, SyntaxError) as msg:
log.warning(msg)
value = v

data.update({key: value})
Expand Down Expand Up @@ -729,9 +747,14 @@ def get_selected_track_items(sequence=None):
def set_selected_track_items(track_items_list, sequence=None):
_sequence = sequence or get_current_sequence()

# make sure only trackItems are in list selection
only_track_items = [
i for i in track_items_list
if isinstance(i, hiero.core.TrackItem)]

# Getting selection
timeline_editor = hiero.ui.getTimelineEditor(_sequence)
return timeline_editor.setSelection(track_items_list)
return timeline_editor.setSelection(only_track_items)


def _read_doc_from_path(path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import re
import sys
import ast
from compiler.ast import flatten
import opentimelineio as otio
from . import utils
import hiero.core
Expand All @@ -29,6 +28,14 @@
self.include_tags = True


def flatten(l):
for i in l:
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(i, (list, tuple)):
yield from flatten(i)
else:
yield i


def get_current_hiero_project(remove_untitled=False):
projects = flatten(hiero.core.projects())
if not remove_untitled:
Expand Down Expand Up @@ -74,13 +81,11 @@ def create_time_effects(otio_clip, track_item):
otio_effect = otio.schema.LinearTimeWarp()
otio_effect.name = "Speed"
otio_effect.time_scalar = speed
otio_effect.metadata = {}

# freeze frame effect
if speed == 0.:
otio_effect = otio.schema.FreezeFrame()
otio_effect.name = "FreezeFrame"
otio_effect.metadata = {}

if otio_effect:
# add otio effect to clip effects
Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/hiero/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def populate_widgets(self, data, content_layout=None):

content_layout = content_layout or self.content_layout[-1]
# fix order of process by defined order value
ordered_keys = data.keys()
ordered_keys = list(data.keys())
for k, v in data.items():
try:
# try removing a key from index which should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
### Magic Widget Finding Methods - This stuff crawls all the PySide widgets, looking for an answer
def findWidget(w):
global foundryWidgets
if 'Foundry' in w.metaObject().className():
if "Foundry" in w.metaObject().className():
foundryWidgets += [w]

for c in w.children():
Expand Down Expand Up @@ -49,7 +49,7 @@ def activeSpreadsheetTreeView():
Does some PySide widget Magic to detect the Active Spreadsheet TreeView.
"""
spreadsheetViews = getFoundryWidgetsWithClassName(
filter='SpreadsheetTreeView')
filter="SpreadsheetTreeView")
for spreadSheet in spreadsheetViews:
if spreadSheet.hasFocus():
activeSpreadSheet = spreadSheet
Expand Down Expand Up @@ -77,36 +77,36 @@ def exportCSVFromActiveSpreadsheetView(self):
spreadsheetTreeView = activeSpreadsheetTreeView()

if not spreadsheetTreeView:
return 'Unable to detect the active TreeView.'
return "Unable to detect the active TreeView."
seq = hiero.ui.activeView().sequence()
if not seq:
print 'Unable to detect the active Sequence from the activeView.'
print("Unable to detect the active Sequence from the activeView.")
return

# The data model of the QTreeView
model = spreadsheetTreeView.model()

csvSavePath = os.path.join(QDir.homePath(), 'Desktop',
seq.name() + '.csv')
csvSavePath = os.path.join(QDir.homePath(), "Desktop",
Copy link

Choose a reason for hiding this comment

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

'QDir' may be undefined, or defined from star imports: PySide.QtCore, PySide.QtGui, PySide2.QtCore, PySide2.QtGui, PySide2.QtWidgets

seq.name() + ".csv")
savePath, filter = QFileDialog.getSaveFileName(
None,
caption="Export Spreadsheet to .CSV as...",
dir=csvSavePath,
filter="*.csv")
print 'Saving To: ' + str(savePath)
print("Saving To: {}".format(savePath))

# Saving was cancelled...
if len(savePath) == 0:
return

# Get the Visible Header Columns from the QTreeView

#csvHeader = ['Event', 'Status', 'Shot Name', 'Reel', 'Track', 'Speed', 'Src In', 'Src Out','Src Duration', 'Dst In', 'Dst Out', 'Dst Duration', 'Clip', 'Clip Media']
#csvHeader = ["Event", "Status", "Shot Name", "Reel", "Track", "Speed", "Src In", "Src Out","Src Duration", "Dst In", "Dst Out", "Dst Duration", "Clip", "Clip Media"]
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved

# Get a CSV writer object
f = open(savePath, 'w')
f = open(savePath, "w")
csvWriter = csv.writer(
f, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
f, delimiter=',', quotechar="|", quoting=csv.QUOTE_MINIMAL)

# This is a list of the Column titles
csvHeader = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "Daniel Flehner Heen"
Expand All @@ -9,7 +8,7 @@
from hiero.core import util

import opentimelineio as otio
from openpype.hosts.hiero.otio import hiero_export
from openpype.hosts.hiero.api.otio import hiero_export

class OTIOExportTask(hiero.core.TaskBase):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = "Daniel Flehner Heen"
__credits__ = ["Jakub Jezek", "Daniel Flehner Heen"]

import hiero.ui
import OTIOExportTask
from .OTIOExportTask import (
OTIOExportTask,
OTIOExportPreset
)

try:
# Hiero >= 11.x
Expand All @@ -20,14 +22,14 @@

FormLayout = QFormLayout # lint:ok

from openpype.hosts.hiero.otio import hiero_export
from openpype.hosts.hiero.api.otio import hiero_export

class OTIOExportUI(hiero.ui.TaskUIBase):
def __init__(self, preset):
"""Initialize"""
hiero.ui.TaskUIBase.__init__(
self,
OTIOExportTask.OTIOExportTask,
OTIOExportTask,
preset,
"OTIO Exporter"
)
Expand Down Expand Up @@ -67,6 +69,6 @@ def populateUI(self, widget, exportTemplate):


hiero.ui.taskUIRegistry.registerTaskUI(
OTIOExportTask.OTIOExportPreset,
OTIOExportPreset,
OTIOExportUI
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .OTIOExportTask import OTIOExportTask
from .OTIOExportUI import OTIOExportUI

__all__ = [
"OTIOExportTask",
"OTIOExportUI"
]
Loading