本文整理汇总了Python中classes.query.Clip类的典型用法代码示例。如果您正苦于以下问题:Python Clip类的具体用法?Python Clip怎么用?Python Clip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Clip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
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)
示例2: getMenu
def getMenu(self):
# Build menu for selection button
menu = QMenu(self)
# Get translation object
_ = get_app()._tr
# Look up item for more info
if self.item_type == "clip":
self.item_name = Clip.get(id=self.item_id).title()
elif self.item_type == "transition":
self.item_name = Transition.get(id=self.item_id).title()
elif self.item_type == "effect":
self.item_name = Effect.get(id=self.item_id).title()
# Add selected clips
for item_id in get_app().window.selected_clips:
clip = Clip.get(id=item_id)
item_name = clip.title()
item_icon = QIcon(QPixmap(clip.data.get('image')))
action = menu.addAction(item_name)
action.setIcon(item_icon)
action.setData({'item_id':item_id, 'item_type':'clip'})
action.triggered.connect(self.Action_Triggered)
# Add effects for these clips (if any)
for effect in clip.data.get('effects'):
item_name = Effect.get(id=effect.get('id')).title()
item_icon = QIcon(QPixmap(os.path.join(info.PATH, "effects", "icons", "%s.png" % effect.get('class_name').lower())))
action = menu.addAction(' > %s' % _(item_name))
action.setIcon(item_icon)
action.setData({'item_id': effect.get('id'), 'item_type': 'effect'})
action.triggered.connect(self.Action_Triggered)
# Add selected transitions
for item_id in get_app().window.selected_transitions:
trans = Transition.get(id=item_id)
item_name = _(trans.title())
item_icon = QIcon(QPixmap(trans.data.get('reader',{}).get('path')))
action = menu.addAction(_(item_name))
action.setIcon(item_icon)
action.setData({'item_id': item_id, 'item_type': 'transition'})
action.triggered.connect(self.Action_Triggered)
# Add selected effects
for item_id in get_app().window.selected_effects:
effect = Effect.get(id=item_id)
item_name = _(effect.title())
item_icon = QIcon(QPixmap(os.path.join(info.PATH, "effects", "icons", "%s.png" % effect.data.get('class_name').lower())))
action = menu.addAction(_(item_name))
action.setIcon(item_icon)
action.setData({'item_id': item_id, 'item_type': 'effect'})
action.triggered.connect(self.Action_Triggered)
# Return the menu object
return menu
示例3: test_add_clip
def test_add_clip(self):
""" Test the Clip.save method by adding multiple clips """
# Import additional classes that need the app defined first
from classes.query import Clip
# Find number of clips in project
num_clips = len(Clip.filter())
# 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()
self.assertTrue(query_clip)
self.assertEqual(len(Clip.filter()), num_clips + 1)
# Save the clip again (which should not change the total # of clips)
query_clip.save()
self.assertEqual(len(Clip.filter()), num_clips + 1)
示例4: test_filter_clip
def test_filter_clip(self):
""" Test the Clip.filter method """
# Import additional classes that need the app defined first
from classes.query import Clip
# Find all clips named file1
clips = Clip.filter(id=TestQueryClass.clip_ids[0])
self.assertTrue(clips)
# Do not find a clip
clips = Clip.filter(id="invalidID")
self.assertEqual(len(clips), 0)
示例5: test_get_clip
def test_get_clip(self):
""" Test the Clip.get method """
# Import additional classes that need the app defined first
from classes.query import Clip
# Find a clip named file1
clip = Clip.get(id=TestQueryClass.clip_ids[1])
self.assertTrue(clip)
# Do not find a clip
clip = Clip.get(id="invalidID")
self.assertEqual(clip, None)
示例6: transformTriggered
def transformTriggered(self, clip_id):
"""Handle the transform signal when it's emitted"""
need_refresh = False
# Disable Transform UI
if self and self.transforming_clip:
# Is this the same clip_id already being transformed?
if not clip_id:
# Clear transform
self.transforming_clip = None
need_refresh = True
# Get new clip for transform
if clip_id:
self.transforming_clip = Clip.get(id=clip_id)
if self.transforming_clip:
self.transforming_clip_object = None
clips = get_app().window.timeline_sync.timeline.Clips()
for clip in clips:
if clip.Id() == self.transforming_clip.id:
self.transforming_clip_object = clip
need_refresh = True
break
# Update the preview and reselct current frame in properties
if need_refresh:
get_app().window.refreshFrameSignal.emit()
get_app().window.propertyTableView.select_frame(get_app().window.preview_thread.player.Position())
示例7: actionRemoveEffect_trigger
def actionRemoveEffect_trigger(self, event):
log.info('actionRemoveEffect_trigger')
# Loop through selected clips
for effect_id in self.selected_effects:
log.info("effect id: %s" % effect_id)
# Find matching file
clips = Clip.filter()
found_effect = None
for c in clips:
found_effect = False
log.info("c.data[effects]: %s" % c.data["effects"])
for effect in c.data["effects"]:
if effect["id"] == effect_id:
found_effect = effect
break
if found_effect:
# Remove found effect from clip data and save clip
c.data["effects"].remove(found_effect)
c.save()
# Clear selected effects
self.removeSelection(effect_id, "effect")
示例8: updateProperty
def updateProperty(self, id, frame_number, property_key, new_value):
"""Update a keyframe property to a new value, adding or updating keyframes as needed"""
found_point = False
clip_updated = False
c = Clip.get(id=id)
if not c:
# No clip found
return
for point in c.data[property_key]["Points"]:
log.info("looping points: co.X = %s" % point["co"]["X"])
if point["co"]["X"] == frame_number:
found_point = True
clip_updated = True
point["interpolation"] = openshot.BEZIER
point["co"]["Y"] = float(new_value)
if not found_point and new_value != None:
clip_updated = True
log.info("Created new point at X=%s" % frame_number)
c.data[property_key]["Points"].append({'co': {'X': frame_number, 'Y': new_value}, 'interpolation': openshot.BEZIER})
# Reduce # of clip properties we are saving (performance boost)
c.data = {property_key: c.data.get(property_key)}
# Save changes
if clip_updated:
# Save
c.save()
# Update the preview
get_app().window.refreshFrameSignal.emit()
示例9: test_update_clip
def test_update_clip(self):
""" Test the Clip.save method """
# Import additional classes that need the app defined first
from classes.query import Clip
# Find a clip named file1
update_id = TestQueryClass.clip_ids[0]
clip = Clip.get(id=update_id)
self.assertTrue(clip)
# Update clip
clip.data["layer"] = 2
clip.data["title"] = "My Title"
clip.save()
# Verify updated data
# Get clip again
clip = Clip.get(id=update_id)
self.assertEqual(clip.data["layer"], 2)
self.assertEqual(clip.data["title"], "My Title")
示例10: actionRemoveClip_trigger
def actionRemoveClip_trigger(self, event):
log.info('actionRemoveClip_trigger')
# Loop through selected clips
for clip_id in self.selected_clips:
# Find matching file
clips = Clip.filter(id=clip_id)
for c in clips:
# Clear selected clips
self.removeSelection(clip_id, "clip")
# Remove clip
c.delete()
示例11: test_delete_clip
def test_delete_clip(self):
""" Test the Clip.delete method """
# Import additional classes that need the app defined first
from classes.query import Clip
# Find a clip named file1
delete_id = TestQueryClass.clip_ids[4]
clip = Clip.get(id=delete_id)
self.assertTrue(clip)
# Delete clip
clip.delete()
# Verify deleted data
deleted_clip = Clip.get(id=delete_id)
self.assertFalse(deleted_clip)
# Delete clip again (should do nothing)
clip.delete()
# Verify deleted data
deleted_clip = Clip.get(id=delete_id)
self.assertFalse(deleted_clip)
示例12: update_item_timeout
def update_item_timeout(self):
# Get the next item id, and type
self.item_id = self.next_item_id
self.item_type = self.next_item_type
self.item_name = None
self.item_icon = None
# Stop timer
self.update_timer.stop()
# Get translation object
_ = get_app()._tr
# Look up item for more info
if self.item_type == "clip":
clip = Clip.get(id=self.item_id)
self.item_name = clip.title()
self.item_icon = QIcon(QPixmap(clip.data.get('image')))
elif self.item_type == "transition":
trans = Transition.get(id=self.item_id)
self.item_name = _(trans.title())
self.item_icon = QIcon(QPixmap(trans.data.get('reader', {}).get('path')))
elif self.item_type == "effect":
effect = Effect.get(id=self.item_id)
self.item_name = _(effect.title())
self.item_icon = QIcon(QPixmap(os.path.join(info.PATH, "effects", "icons", "%s.png" % effect.data.get('class_name').lower())))
# Truncate long text
if self.item_name and len(self.item_name) > 25:
self.item_name = "%s..." % self.item_name[:22]
# Set label
if self.item_id:
self.lblSelection.setText("<strong>%s</strong>" % _("Selection:"))
self.btnSelectionName.setText(self.item_name)
self.btnSelectionName.setVisible(True)
if self.item_icon:
self.btnSelectionName.setIcon(self.item_icon)
else:
self.lblSelection.setText("<strong>%s</strong>" % _("No Selection"))
self.btnSelectionName.setVisible(False)
# Set the menu on the button
self.btnSelectionName.setMenu(self.getMenu())
示例13: actionRemove_from_Project_trigger
def actionRemove_from_Project_trigger(self, event):
log.info("actionRemove_from_Project_trigger")
# Loop through selected files
for file_id in self.selected_files:
# Find matching file
f = File.get(id=file_id)
if f:
# Remove file
f.delete()
# Find matching clips (if any)
clips = Clip.filter(file_id=file_id)
for c in clips:
# Remove clip
c.delete()
# Clear selected files
self.selected_files = []
示例14: value_updated
def value_updated(self, item, interpolation=-1, value=None, interpolation_details=[]):
""" Table cell change event - also handles context menu to update interpolation value """
if self.ignore_update_signal:
return
# Get translation method
_ = get_app()._tr
# Determine what was changed
property = self.model.item(item.row(), 0).data()
property_name = property[1]["name"]
closest_point_x = property[1]["closest_point_x"]
previous_point_x = property[1]["previous_point_x"]
property_type = property[1]["type"]
property_key = property[0]
clip_id, item_type = item.data()
# Get value (if any)
if item.text():
# Set and format value based on property type
if value != None:
# Override value
new_value = value
elif property_type == "string":
# Use string value
new_value = item.text()
elif property_type == "bool":
# Use boolean value
if item.text() == _("False"):
new_value = False
else:
new_value = True
elif property_type == "int":
# Use int value
new_value = QLocale().system().toInt(item.text())[0]
else:
# Use decimal value
new_value = QLocale().system().toFloat(item.text())[0]
else:
new_value = None
log.info("%s for %s changed to %s at frame %s with interpolation: %s at closest x: %s" % (property_key, clip_id, new_value, self.frame_number, interpolation, closest_point_x))
# Find this clip
c = None
clip_updated = False
if item_type == "clip":
# Get clip object
c = Clip.get(id=clip_id)
elif item_type == "transition":
# Get transition object
c = Transition.get(id=clip_id)
elif item_type == "effect":
# Get effect object
c = Effect.get(id=clip_id)
if c:
# Update clip attribute
if property_key in c.data:
log.info("value updated: %s" % c.data)
# Check the type of property (some are keyframe, and some are not)
if property_type != "reader" and type(c.data[property_key]) == dict:
# Keyframe
# Loop through points, find a matching points on this frame
found_point = False
point_to_delete = None
for point in c.data[property_key]["Points"]:
log.info("looping points: co.X = %s" % point["co"]["X"])
if interpolation == -1 and point["co"]["X"] == self.frame_number:
# Found point, Update value
found_point = True
clip_updated = True
# Update or delete point
if new_value != None:
point["co"]["Y"] = float(new_value)
log.info("updating point: co.X = %s to value: %s" % (point["co"]["X"], float(new_value)))
else:
point_to_delete = point
break
elif interpolation > -1 and point["co"]["X"] == previous_point_x:
# Only update interpolation type (and the LEFT side of the curve)
found_point = True
clip_updated = True
point["interpolation"] = interpolation
if interpolation == 0:
point["handle_right"] = point.get("handle_right") or {"Y": 0.0, "X": 0.0}
point["handle_right"]["X"] = interpolation_details[0]
point["handle_right"]["Y"] = interpolation_details[1]
log.info("updating interpolation mode point: co.X = %s to %s" % (point["co"]["X"], interpolation))
log.info("use interpolation preset: %s" % str(interpolation_details))
elif interpolation > -1 and point["co"]["X"] == closest_point_x:
# Only update interpolation type (and the RIGHT side of the curve)
found_point = True
#.........这里部分代码省略.........
示例15: refreshTriggered
def refreshTriggered(self):
"""Signal to refresh viewport (i.e. a property might have changed that effects the preview)"""
# Update reference to clip
if self and self.transforming_clip:
self.transforming_clip = Clip.get(id=self.transforming_clip.id)