Skip to content

Commit

Permalink
Merge pull request OpenShot#3021 from ferdnyc/pyqt-openfile-fixes
Browse files Browse the repository at this point in the history
Massive unused/unnecessary variable sweep-up, and more
  • Loading branch information
ferdnyc authored Nov 19, 2019
2 parents 02d58d9 + 2618b3d commit c9af3a7
Show file tree
Hide file tree
Showing 25 changed files with 334 additions and 302 deletions.
35 changes: 20 additions & 15 deletions src/classes/exporters/edl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ def export_edl():
recommended_path = os.path.join(info.HOME_PATH, "%s.edl" % _("Untitled Project"))
else:
recommended_path = recommended_path.replace(".osp", ".edl")
file_path, file_type = QFileDialog.getSaveFileName(get_app().window, _("Export EDL..."), recommended_path,
_("Edit Decision Lists (*.edl)"))
if file_path:
# Append .edl if needed
if ".edl" not in file_path:
file_path = "%s.edl" % file_path
file_path = QFileDialog.getSaveFileName(app.window, _("Export EDL..."), recommended_path,
_("Edit Decision Lists (*.edl)"))[0]
if not file_path:
return

# Append .edl if needed
if not file_path.endswith(".edl"):
file_path = "%s.edl" % file_path

# Get filename with no extension
parent_path, file_name_with_ext = os.path.split(file_path)
file_name, ext = os.path.splitext(file_name_with_ext)
file_name_with_ext = os.path.basename(file_path)
file_name = os.path.splitext(file_name_with_ext)[0]

all_tracks = get_app().project.get("layers")
track_count = len(all_tracks)
Expand All @@ -83,7 +85,7 @@ def export_edl():
continue

# Generate EDL File (1 per track - limitation of EDL format)
# TODO: Improve and move this into it's own class
# TODO: Improve and move this into its own class
with open("%s-%s.edl" % (file_path.replace(".edl", ""), track_name), 'w', encoding="utf8") as f:
# Add Header
f.write("TITLE: %s - %s\n" % (file_name, track_name))
Expand All @@ -105,8 +107,9 @@ def export_edl():

# Write blank clip
f.write(edl_string % (
edit_index, "BL"[:9], "V"[:6], "C", clip_start_time, clip_end_time, timeline_start_time,
timeline_end_time))
edit_index, "BL"[:9], "V"[:6], "C",
clip_start_time, clip_end_time,
timeline_start_time, timeline_end_time))

# Format clip start/end and timeline start/end values (i.e. 00:00:00:00)
clip_start_time = secondsToTimecode(clip.data.get('start'), fps_num, fps_den)
Expand All @@ -119,13 +122,15 @@ def export_edl():
if has_video:
# Video Track
f.write(edl_string % (
edit_index, "AX"[:9], "V"[:6], "C", clip_start_time, clip_end_time, timeline_start_time,
timeline_end_time))
edit_index, "AX"[:9], "V"[:6], "C",
clip_start_time, clip_end_time,
timeline_start_time, timeline_end_time))
if has_audio:
# Audio Track
f.write(edl_string % (
edit_index, "AX"[:9], "A"[:6], "C", clip_start_time, clip_end_time, timeline_start_time,
timeline_end_time))
edit_index, "AX"[:9], "A"[:6], "C",
clip_start_time, clip_end_time,
timeline_start_time, timeline_end_time))
f.write("* FROM CLIP NAME: %s\n" % clip.data.get('title'))

# Add opacity data (if any)
Expand Down
28 changes: 15 additions & 13 deletions src/classes/exporters/final_cut_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,18 @@ def export_xml():
recommended_path = os.path.join(info.HOME_PATH, "%s.xml" % _("Untitled Project"))
else:
recommended_path = recommended_path.replace(".osp", ".xml")
file_path, file_type = QFileDialog.getSaveFileName(app.window, _("Export XML..."), recommended_path,
_("Final Cut Pro (*.xml)"))
if file_path:
# Append .xml if needed
if ".xml" not in file_path:
file_path = "%s.xml" % file_path
file_path = QFileDialog.getSaveFileName(app.window, _("Export XML..."), recommended_path,
_("Final Cut Pro (*.xml)"))[0]
if not file_path:
# User canceled dialog
return

# Get filename with no extension
parent_path, file_name_with_ext = os.path.split(file_path)
file_name, ext = os.path.splitext(file_name_with_ext)
# Append .xml if needed
if not file_path.endswith(".xml"):
file_path = "%s.xml" % file_path

# Get filename with no path
file_name = os.path.basename(file_path)

# Determine max frame (based on clips)
duration = 0.0
Expand All @@ -113,7 +115,7 @@ def export_xml():
xmldoc = minidom.parse(os.path.join(info.RESOURCES_PATH, 'export-project-template.xml'))

# Set Project Details
xmldoc.getElementsByTagName("name")[0].childNodes[0].nodeValue = file_name_with_ext
xmldoc.getElementsByTagName("name")[0].childNodes[0].nodeValue = file_name
xmldoc.getElementsByTagName("uuid")[0].childNodes[0].nodeValue = str(uuid1())
xmldoc.getElementsByTagName("duration")[0].childNodes[0].nodeValue = duration
xmldoc.getElementsByTagName("width")[0].childNodes[0].nodeValue = app.project.get("width")
Expand All @@ -136,8 +138,7 @@ def export_xml():
log.error('No track object found with number: %s' % track.get("number"))
continue

# Track name
track_name = track.get("label") or "TRACK %s" % track_count
# Track details
track_locked = track.get("lock", False)
clips_on_track = Clip.filter(layer=track.get("number"))
if not clips_on_track:
Expand Down Expand Up @@ -228,4 +229,5 @@ def export_xml():
file.write(bytes(xmldoc.toxml(), 'UTF-8'))
file.close()
except IOError as inst:
log.error("Error writing XML export")
log.error("Error writing XML export: {}".format(str(inst)))

16 changes: 8 additions & 8 deletions src/classes/importers/edl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def create_clip(context, track):
_ = app._tr

# Get FPS info
fps_num = get_app().project.get("fps").get("num", 24)
fps_den = get_app().project.get("fps").get("den", 1)
fps_num = app.project.get("fps").get("num", 24)
fps_den = app.project.get("fps").get("den", 1)
fps_float = float(fps_num / fps_den)

# Get clip path (and prompt user if path not found)
Expand Down Expand Up @@ -191,15 +191,15 @@ def import_edl():
if not recommended_path:
recommended_path = info.HOME_PATH
else:
recommended_path = os.path.split(recommended_path)[0]
file_path, file_type = QFileDialog.getOpenFileName(get_app().window, _("Import EDL..."), recommended_path,
_("Edit Decision Lists (*.edl)"), _("Edit Decision Lists (*.edl)"))
recommended_path = os.path.dirname(recommended_path)
file_path = QFileDialog.getOpenFileName(app.window, _("Import EDL..."), recommended_path,
_("Edit Decision Lists (*.edl)"), _("Edit Decision Lists (*.edl)"))[0]
if os.path.exists(file_path):
context = {}
current_clip_index = ""

# Get # of tracks
all_tracks = get_app().project.get("layers")
all_tracks = app.project.get("layers")
track_number = list(reversed(sorted(all_tracks, key=itemgetter('number'))))[0].get("number") + 1000000

# Create new track above existing layer(s)
Expand Down Expand Up @@ -278,5 +278,5 @@ def import_edl():
create_clip(context, track)

# Update the preview and reselect current frame in properties
get_app().window.refreshFrameSignal.emit()
get_app().window.propertyTableView.select_frame(get_app().window.preview_thread.player.Position())
app.window.refreshFrameSignal.emit()
app.window.propertyTableView.select_frame(app.window.preview_thread.player.Position())
Loading

0 comments on commit c9af3a7

Please sign in to comment.