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

project.get(): Accept non-list args (strings) #2853

Merged
merged 3 commits into from
Jul 19, 2019
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
6 changes: 3 additions & 3 deletions src/classes/exporters/edl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def export_edl():
edl_string = "%03d %-9s%-6s%-9s%11s %11s %11s %11s\n"

# 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 = get_app().project.get("fps").get("num", 24)
fps_den = get_app().project.get("fps").get("den", 1)
fps_float = float(fps_num / fps_den)

# Get EDL path
Expand All @@ -67,7 +67,7 @@ def export_edl():
parent_path, file_name_with_ext = os.path.split(file_path)
file_name, ext = os.path.splitext(file_name_with_ext)

all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
track_count = len(all_tracks)
for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
existing_track = Track.get(number=track.get("number"))
Expand Down
14 changes: 7 additions & 7 deletions src/classes/exporters/final_cut_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def export_xml():
_ = 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 = get_app().project.get("fps").get("num", 24)
fps_den = get_app().project.get("fps").get("den", 1)
fps_float = float(fps_num / fps_den)

# Ticks (final cut pro value)
Expand Down Expand Up @@ -116,18 +116,18 @@ def export_xml():
xmldoc.getElementsByTagName("name")[0].childNodes[0].nodeValue = file_name_with_ext
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"])
xmldoc.getElementsByTagName("height")[0].childNodes[0].nodeValue = app.project.get(["height"])
xmldoc.getElementsByTagName("samplerate")[0].childNodes[0].nodeValue = app.project.get(["sample_rate"])
xmldoc.getElementsByTagName("sequence")[0].setAttribute("id", app.project.get(["id"]))
xmldoc.getElementsByTagName("width")[0].childNodes[0].nodeValue = app.project.get("width")
xmldoc.getElementsByTagName("height")[0].childNodes[0].nodeValue = app.project.get("height")
xmldoc.getElementsByTagName("samplerate")[0].childNodes[0].nodeValue = app.project.get("sample_rate")
xmldoc.getElementsByTagName("sequence")[0].setAttribute("id", app.project.get("id"))
for childNode in xmldoc.getElementsByTagName("timebase"):
childNode.childNodes[0].nodeValue = fps_float

# Get parent audio node
parentAudioNode = xmldoc.getElementsByTagName("audio")[0]

# Loop through tracks
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
track_count = 1
for track in sorted(all_tracks, key=itemgetter('number')):
existing_track = Track.get(number=track.get("number"))
Expand Down
6 changes: 3 additions & 3 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 = get_app().project.get("fps").get("num", 24)
fps_den = get_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 @@ -200,7 +200,7 @@ def import_edl():
current_clip_index = ""

# Get # of tracks
all_tracks = get_app().project.get(["layers"])
all_tracks = get_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
6 changes: 3 additions & 3 deletions src/classes/importers/final_cut_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def import_xml():
_ = 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 = get_app().project.get("fps").get("num", 24)
fps_den = get_app().project.get("fps").get("den", 1)
fps_float = float(fps_num / fps_den)

# Get XML path
Expand Down Expand Up @@ -83,7 +83,7 @@ def import_xml():

# Get # of tracks
track_index += 1
all_tracks = get_app().project.get(["layers"])
all_tracks = get_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
7 changes: 3 additions & 4 deletions src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ def get(self, key):
""" Get copied value of a given key in data store """

# Verify key is valid type
if not isinstance(key, list):
log.warning("get() key must be a list. key: {}".format(key))
return None
if not key:
log.warning("Cannot get empty key.")
return None
if not isinstance(key, list):
key = [key]

# Get reference to internal data structure
obj = self._data
Expand Down Expand Up @@ -442,7 +441,7 @@ def read_legacy_project_file(self, file_path):

# Get FPS from project
from classes.app import get_app
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])

# Import legacy openshot classes (from version 1.X)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def filter(**kwargs):
""" Take any arguments given as filters, and find a list of matching objects """

# Get a list of clips
clips = project.get(["clips"])
clips = project.get("clips")
matching_objects = []

# Loop through all clips
Expand Down
12 changes: 6 additions & 6 deletions src/classes/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def __init__(self, window):
s = settings.get_settings()

# Get some settings from the project
fps = project.get(["fps"])
width = project.get(["width"])
height = project.get(["height"])
sample_rate = project.get(["sample_rate"])
channels = project.get(["channels"])
channel_layout = project.get(["channel_layout"])
fps = project.get("fps")
width = project.get("width")
height = project.get("height")
sample_rate = project.get("sample_rate")
channels = project.get("channels")
channel_layout = project.get("channel_layout")

# Create an instance of a libopenshot Timeline object
self.timeline = openshot.Timeline(width, height, openshot.Fraction(fps["num"], fps["den"]), sample_rate, channels,
Expand Down
2 changes: 1 addition & 1 deletion src/classes/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def load_history(self, project):
self.actionHistory.clear()

# Get history from project data
history = project.get(["history"])
history = project.get("history")

# Loop through each, and load serialized data into updateAction objects
# Ignore any load actions or history update actions
Expand Down
6 changes: 3 additions & 3 deletions src/windows/add_to_timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def accept(self):
random_transition = True

# Get frames per second
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])

# Loop through each file (in the current order)
Expand Down Expand Up @@ -401,7 +401,7 @@ def updateTotal(self):
total += duration

# Get frames per second
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")

# Update label
total_parts = time_parts.secondsToTime(total, fps["num"], fps["den"])
Expand Down Expand Up @@ -457,7 +457,7 @@ def __init__(self, files=None, position=0.0):
self.txtTransitionLength.valueChanged.connect(self.updateTotal)

# Find display track number
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
display_count = len(all_tracks)
for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
# Add to dropdown
Expand Down
4 changes: 2 additions & 2 deletions src/windows/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self):
if app.project.current_filepath:
recommended_path = os.path.dirname(app.project.current_filepath)

export_path = get_app().project.get(["export_path"])
export_path = get_app().project.get("export_path")
if export_path and os.path.exists(export_path):
# Use last selected export path
self.txtExportFolder.setText(export_path)
Expand Down Expand Up @@ -354,7 +354,7 @@ def updateFrameRate(self):
self.txtEndFrame.setValue(self.timeline_length_int)

# Calculate differences between editing/preview FPS and export FPS
current_fps = get_app().project.get(["fps"])
current_fps = get_app().project.get("fps")
current_fps_float = float(current_fps["num"]) / float(current_fps["den"])
new_fps_float = float(self.txtFrameRateNum.value()) / float(self.txtFrameRateDen.value())
self.export_fps_factor = new_fps_float / current_fps_float
Expand Down
32 changes: 16 additions & 16 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def actionSaveAs_trigger(self, event):
def actionImportFiles_trigger(self, event):
app = get_app()
_ = app._tr
recommended_path = app.project.get(["import_path"])
recommended_path = app.project.get("import_path")
if not recommended_path or not os.path.exists(recommended_path):
recommended_path = os.path.join(info.HOME_PATH)
files = QFileDialog.getOpenFileNames(self, _("Import File..."), recommended_path)[0]
Expand All @@ -674,7 +674,7 @@ def actionAdd_to_Timeline_trigger(self, event):
files.append(File.get(id=file_id))

# Get current position of playhead
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
pos = (self.preview_thread.player.Position() - 1) / fps_float

Expand Down Expand Up @@ -966,8 +966,8 @@ def actionSaveFrame_trigger(self, event):
recommended_path = os.path.dirname(get_app().project.current_filepath)

# Determine path for saved frame - Project's export path
if get_app().project.get(["export_path"]):
recommended_path = get_app().project.get(["export_path"])
if get_app().project.get("export_path"):
recommended_path = get_app().project.get("export_path")

framePath = "%s/Frame-%05d.png" % (recommended_path, self.preview_thread.current_frame)

Expand Down Expand Up @@ -995,7 +995,7 @@ def actionSaveFrame_trigger(self, event):
self.timeline_sync.timeline.SetCache(new_cache_object)

# Set MaxSize to full project resolution and clear preview cache so we get a full resolution frame
self.timeline_sync.timeline.SetMaxSize(get_app().project.get(["width"]), get_app().project.get(["height"]))
self.timeline_sync.timeline.SetMaxSize(get_app().project.get("width"), get_app().project.get("height"))
self.cache_object.Clear()

# Check if file exists, if it does, get the lastModified time
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def actionAddTrack_trigger(self, event):
log.info("actionAddTrack_trigger")

# Get # of tracks
all_tracks = get_app().project.get(["layers"])
all_tracks = get_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 All @@ -1038,7 +1038,7 @@ def actionAddTrackAbove_trigger(self, event):
log.info("actionAddTrackAbove_trigger")

# Get # of tracks
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
selected_layer_id = self.selected_tracks[0]

# Get selected track data
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def actionAddTrackBelow_trigger(self, event):
log.info("actionAddTrackBelow_trigger")

# Get # of tracks
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
selected_layer_id = self.selected_tracks[0]

# Get selected track data
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def actionAddMarker_trigger(self, event):
player = self.preview_thread.player

# Calculate frames per second
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])

# Calculate position in seconds
Expand All @@ -1189,7 +1189,7 @@ def actionPreviousMarker_trigger(self, event):
log.info("actionPreviousMarker_trigger")

# Calculate current position (in seconds)
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
current_position = (self.preview_thread.current_frame - 1) / fps_float
all_marker_positions = []
Expand Down Expand Up @@ -1242,7 +1242,7 @@ def actionNextMarker_trigger(self, event):
log.info(self.preview_thread.current_frame)

# Calculate current position (in seconds)
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
current_position = (self.preview_thread.current_frame - 1) / fps_float
all_marker_positions = []
Expand Down Expand Up @@ -1326,7 +1326,7 @@ def keyPressEvent(self, event):
player = self.preview_thread.player

# Get framerate
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])
playhead_position = float(self.preview_thread.current_frame - 1) / fps_float

Expand Down Expand Up @@ -1638,7 +1638,7 @@ def actionRemoveTrack_trigger(self, event):
_ = get_app()._tr

track_id = self.selected_tracks[0]
max_track_number = len(get_app().project.get(["layers"]))
max_track_number = len(get_app().project.get("layers"))

# Get details of selected track
selected_track = Track.get(id=track_id)
Expand Down Expand Up @@ -1703,7 +1703,7 @@ def actionRenameTrack_trigger(self, event):
selected_track = Track.get(id=track_id)

# Find display track number
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
display_count = len(all_tracks)
for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
if track.get("id") == track_id:
Expand Down Expand Up @@ -1965,7 +1965,7 @@ def SetWindowTitle(self, profile=None):
_ = get_app()._tr

if not profile:
profile = get_app().project.get(["profile"])
profile = get_app().project.get("profile")

# Determine if the project needs saving (has any unsaved changes)
save_indicator = ""
Expand Down Expand Up @@ -2216,7 +2216,7 @@ def setup_toolbars(self):
self.timelineToolbar.addSeparator()

# Get project's initial zoom value
initial_scale = get_app().project.get(["scale"]) or 15
initial_scale = get_app().project.get("scale") or 15
# Round non-exponential scale down to next lowest power of 2
initial_zoom = secondsToZoom(initial_scale)

Expand Down
6 changes: 3 additions & 3 deletions src/windows/models/properties_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def update_frame(self, frame_number, reload_model=True):
break

# Get FPS from project
fps = get_app().project.get(["fps"])
fps = get_app().project.get("fps")
fps_float = float(fps["num"]) / float(fps["den"])

# Requested time
Expand Down Expand Up @@ -654,7 +654,7 @@ def update_model(self, filter=""):
col.setText(fileName)
elif type == "int" and label == "Track":
# Find track display name
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
display_count = len(all_tracks)
display_label = None
for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
Expand Down Expand Up @@ -733,7 +733,7 @@ def update_model(self, filter=""):
col.setText("")
elif type == "int" and label == "Track":
# Find track display name
all_tracks = get_app().project.get(["layers"])
all_tracks = get_app().project.get("layers")
display_count = len(all_tracks)
display_label = None
for track in reversed(sorted(all_tracks, key=itemgetter('number'))):
Expand Down
12 changes: 6 additions & 6 deletions src/windows/preview_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def LoadFile(self, path=None):
project = get_app().project

# Get some settings from the project
fps = project.get(["fps"])
width = project.get(["width"])
height = project.get(["height"])
sample_rate = project.get(["sample_rate"])
channels = project.get(["channels"])
channel_layout = project.get(["channel_layout"])
fps = project.get("fps")
width = project.get("width")
height = project.get("height")
sample_rate = project.get("sample_rate")
channels = project.get("channels")
channel_layout = project.get("channel_layout")

# Create an instance of a libopenshot Timeline object
self.clip_reader = openshot.Timeline(width, height, openshot.Fraction(fps["num"], fps["den"]), sample_rate, channels, channel_layout)
Expand Down
2 changes: 1 addition & 1 deletion src/windows/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def dropdown_index_changed(self, widget, index):
self.lblOther.setText("DAR: %s/%s, SAR: %s/%s, Interlaced: %s" % (profile.info.display_ratio.num, profile.info.display_ratio.den, profile.info.pixel_ratio.num, profile.info.pixel_ratio.den, profile.info.interlaced_frame))

# Get current FPS (prior to changing)
current_fps = get_app().project.get(["fps"])
current_fps = get_app().project.get("fps")
current_fps_float = float(current_fps["num"]) / float(current_fps["den"])
new_fps_float = float(profile.info.fps.num) / float(profile.info.fps.den)
fps_factor = new_fps_float / current_fps_float
Expand Down
Loading