本文整理汇总了Python中classes.query.File.save方法的典型用法代码示例。如果您正苦于以下问题:Python File.save方法的具体用法?Python File.save怎么用?Python File.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classes.query.File
的用法示例。
在下文中一共展示了File.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def test_add_file(self):
""" Test the File.save method by adding multiple files """
# Import additional classes that need the app defined first
from classes.query import File
# Find number of files in project
num_files = len(File.filter())
# Create file
r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)
# Parse JSON
file_data = json.loads(r.Json())
# Insert into project data
query_file = File()
query_file.data = file_data
query_file.data["path"] = os.path.join(PATH, "images", "openshot.png")
query_file.data["media_type"] = "image"
query_file.save()
self.assertTrue(query_file)
self.assertEqual(len(File.filter()), num_files + 1)
# Save the file again (which should not change the total # of files)
query_file.save()
self.assertEqual(len(File.filter()), num_files + 1)
示例2: setUpClass
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def setUpClass(TestQueryClass):
""" Init unit test data """
# Create Qt application
TestQueryClass.app = OpenShotApp(sys.argv, mode="unittest")
TestQueryClass.clip_ids = []
TestQueryClass.file_ids = []
TestQueryClass.transition_ids = []
# Import additional classes that need the app defined first
from classes.query import Clip, File, Transition
# Insert some clips into the project data
for num in range(5):
# Create clip
c = openshot.Clip(os.path.join(info.IMAGES_PATH, "AboutLogo.png"))
# Parse JSON
clip_data = json.loads(c.Json())
# Insert into project data
query_clip = Clip()
query_clip.data = clip_data
query_clip.save()
# Keep track of the ids
TestQueryClass.clip_ids.append(query_clip.id)
# Insert some files into the project data
for num in range(5):
# Create file
r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)
# Parse JSON
file_data = json.loads(r.Json())
# Insert into project data
query_file = File()
query_file.data = file_data
query_file.data["path"] = os.path.join(info.IMAGES_PATH, "AboutLogo.png")
query_file.data["media_type"] = "image"
query_file.save()
# Keep track of the ids
TestQueryClass.file_ids.append(query_file.id)
# Insert some transitions into the project data
for num in range(5):
# Create mask object
transition_object = openshot.Mask()
transitions_data = json.loads(transition_object.Json())
# Insert into project data
query_transition = Transition()
query_transition.data = transitions_data
query_transition.save()
# Keep track of the ids
TestQueryClass.transition_ids.append(query_transition.id)
示例3: add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def add_file(self, filepath):
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip = openshot.Clip(filepath)
# Get the JSON for the clip's internal reader
try:
reader = clip.Reader()
file_data = json.loads(reader.Json())
# Determine media type
if file_data["has_video"] and not self.is_image(file_data):
file_data["media_type"] = "video"
elif file_data["has_video"] and self.is_image(file_data):
file_data["media_type"] = "image"
elif file_data["has_audio"] and not file_data["has_video"]:
file_data["media_type"] = "audio"
# Save new file to the project data
file = File()
file.data = file_data
file.save()
return True
except:
# Handle exception
msg = QMessageBox()
msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
msg.exec_()
return False
示例4: add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def add_file(self, filepath):
""" Add an animation to the project file tree """
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Get the JSON for the clip's internal reader
try:
# Open image sequence in FFmpegReader
reader = openshot.FFmpegReader(filepath)
reader.Open()
# Serialize JSON for the reader
file_data = json.loads(reader.Json())
# Set media type
file_data["media_type"] = "video"
# Save new file to the project data
file = File()
file.data = file_data
file.save()
return True
except:
# Handle exception
msg = QMessageBox()
msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
msg.exec_()
return False
示例5: add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def add_file(self, filepath):
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip = openshot.Clip(filepath)
# Get the JSON for the clip's internal reader
try:
reader = clip.Reader()
file_data = json.loads(reader.Json())
# Determine media type
if file_data["has_video"] and not self.is_image(file_data):
file_data["media_type"] = "video"
elif file_data["has_video"] and self.is_image(file_data):
file_data["media_type"] = "image"
elif file_data["has_audio"] and not file_data["has_video"]:
file_data["media_type"] = "audio"
# Save new file to the project data
file = File()
file.data = file_data
# Is this file an image sequence / animation?
image_seq_details = self.get_image_sequence_details(filepath)
if image_seq_details:
# Update file with correct path
folder_path = image_seq_details["folder_path"]
file_name = image_seq_details["file_path"]
base_name = image_seq_details["base_name"]
fixlen = image_seq_details["fixlen"]
digits = image_seq_details["digits"]
extension = image_seq_details["extension"]
if not fixlen:
zero_pattern = "%d"
else:
zero_pattern = "%%0%sd" % digits
# Generate the regex pattern for this image sequence
pattern = "%s%s.%s" % (base_name, zero_pattern, extension)
# Split folder name
(parentPath, folderName) = os.path.split(folder_path)
if not base_name:
# Give alternate name
file.data["name"] = "%s (%s)" % (folderName, pattern)
# Load image sequence (to determine duration and video_length)
image_seq = openshot.Clip(os.path.join(folder_path, pattern))
# Update file details
file.data["path"] = os.path.join(folder_path, pattern)
file.data["media_type"] = "video"
file.data["duration"] = image_seq.Reader().info.duration
file.data["video_length"] = image_seq.Reader().info.video_length
# Save file
file.save()
return True
except:
# Handle exception
msg = QMessageBox()
msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
msg.exec_()
return False
示例6: read_legacy_project_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import save [as 别名]
def read_legacy_project_file(self, file_path):
"""Attempt to read a legacy version 1.x openshot project file"""
import sys, pickle
from classes.query import File, Track, Clip, Transition
from classes.app import get_app
import openshot
try:
import json
except ImportError:
import simplejson as json
# Get translation method
_ = get_app()._tr
# Append version info
v = openshot.GetVersion()
project_data = {}
project_data["version"] = {"openshot-qt" : info.VERSION,
"libopenshot" : v.ToString()}
# Get FPS from project
from classes.app import get_app
fps = get_app().project.get(["fps"])
fps_float = float(fps["num"]) / float(fps["den"])
# Import legacy openshot classes (from version 1.X)
from classes.legacy.openshot import classes as legacy_classes
from classes.legacy.openshot.classes import project as legacy_project
from classes.legacy.openshot.classes import sequences as legacy_sequences
from classes.legacy.openshot.classes import track as legacy_track
from classes.legacy.openshot.classes import clip as legacy_clip
from classes.legacy.openshot.classes import keyframe as legacy_keyframe
from classes.legacy.openshot.classes import files as legacy_files
from classes.legacy.openshot.classes import transition as legacy_transition
from classes.legacy.openshot.classes import effect as legacy_effect
from classes.legacy.openshot.classes import marker as legacy_marker
sys.modules['openshot.classes'] = legacy_classes
sys.modules['classes.project'] = legacy_project
sys.modules['classes.sequences'] = legacy_sequences
sys.modules['classes.track'] = legacy_track
sys.modules['classes.clip'] = legacy_clip
sys.modules['classes.keyframe'] = legacy_keyframe
sys.modules['classes.files'] = legacy_files
sys.modules['classes.transition'] = legacy_transition
sys.modules['classes.effect'] = legacy_effect
sys.modules['classes.marker'] = legacy_marker
# Keep track of files that failed to load
failed_files = []
with open(file_path.encode('UTF-8'), 'rb') as f:
try:
# Unpickle legacy openshot project file
v1_data = pickle.load(f, fix_imports=True, encoding="UTF-8")
file_lookup = {}
# Loop through files
for item in v1_data.project_folder.items:
# Is this item a File (i.e. ignore folders)
if isinstance(item, legacy_files.OpenShotFile):
# Create file
try:
clip = openshot.Clip(item.name)
reader = clip.Reader()
file_data = json.loads(reader.Json(), strict=False)
# Determine media type
if file_data["has_video"] and not self.is_image(file_data):
file_data["media_type"] = "video"
elif file_data["has_video"] and self.is_image(file_data):
file_data["media_type"] = "image"
elif file_data["has_audio"] and not file_data["has_video"]:
file_data["media_type"] = "audio"
# Save new file to the project data
file = File()
file.data = file_data
file.save()
# Keep track of new ids and old ids
file_lookup[item.unique_id] = file
except:
# Handle exception quietly
msg = ("%s is not a valid video, audio, or image file." % item.name)
log.error(msg)
failed_files.append(item.name)
# Delete all tracks
track_list = copy.deepcopy(Track.filter())
for track in track_list:
track.delete()
# Create new tracks
track_counter = 0
for legacy_t in reversed(v1_data.sequences[0].tracks):
t = Track()
t.data = {"number": track_counter, "y": 0, "label": legacy_t.name}
t.save()
#.........这里部分代码省略.........