本文整理匯總了Python中classes.query.Clip.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Clip.get方法的具體用法?Python Clip.get怎麽用?Python Clip.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類classes.query.Clip
的用法示例。
在下文中一共展示了Clip.get方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getMenu
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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
示例2: test_get_clip
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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)
示例3: transformTriggered
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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())
示例4: updateProperty
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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()
示例5: test_update_clip
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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")
示例6: test_delete_clip
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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)
示例7: update_item_timeout
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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())
示例8: refreshTriggered
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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)
示例9: mouseMoveEvent
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
def mouseMoveEvent(self, event):
# Get data model and selection
model = self.clip_properties_model.model
row = self.indexAt(event.pos()).row()
column = self.indexAt(event.pos()).column()
if model.item(row, 0):
self.selected_label = model.item(row, 0)
self.selected_item = model.item(row, 1)
# Is the user dragging on the value column
if self.selected_label and self.selected_item:
frame_number = self.clip_properties_model.frame_number
# Get the position of the cursor and % value
value_column_x = self.columnViewportPosition(1)
value_column_y = value_column_x + self.columnWidth(1)
cursor_value = event.x() - value_column_x
cursor_value_percent = cursor_value / self.columnWidth(1)
property = self.selected_label.data()
property_key = property[0]
property_name = property[1]["name"]
property_type = property[1]["type"]
property_max = property[1]["max"]
property_min = property[1]["min"]
property_value = property[1]["value"]
readonly = property[1]["readonly"]
item_id, item_type = self.selected_item.data()
# Bail if readonly
if readonly:
return
# Get the original data of this item (prior to any updates, for the undo/redo system)
if not self.original_data:
# Ignore undo/redo history temporarily (to avoid a huge pile of undo/redo history)
get_app().updates.ignore_history = True
# Find this clip
c = None
if item_type == "clip":
# Get clip object
c = Clip.get(id=item_id)
elif item_type == "transition":
# Get transition object
c = Transition.get(id=item_id)
elif item_type == "effect":
# Get effect object
c = Effect.get(id=item_id)
if c:
if property_key in c.data:
# Grab the original data for this item/property
self.original_data = c.data
# Calculate percentage value
if property_type in ["float", "int"]:
min_max_range = float(property_max) - float(property_min)
# Determine if range is unreasonably long (such as position, start, end, etc.... which can be huge #'s)
if min_max_range > 1000.0:
# Get the current value
self.new_value = QLocale().system().toDouble(self.selected_item.text())[0]
# Huge range - increment / decrement slowly
if self.previous_x == -1:
# init previous_x for the first time
self.previous_x = event.x()
# calculate # of pixels dragged
drag_diff = self.previous_x - event.x()
if drag_diff > 0:
# Move to the left by a small amount
self.new_value -= 0.50
elif drag_diff < 0:
# Move to the right by a small amount
self.new_value += 0.50
# update previous x
self.previous_x = event.x()
else:
# Small range - use cursor % to calculate new value
self.new_value = property_min + (min_max_range * cursor_value_percent)
# Clamp value between min and max (just incase user drags too big)
self.new_value = max(property_min, self.new_value)
self.new_value = min(property_max, self.new_value)
# Update value of this property
self.clip_properties_model.value_updated(self.selected_item, -1, self.new_value)
# Repaint
self.viewport().update()
示例10: value_updated
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
def value_updated(self, item, interpolation=-1, value=None):
""" 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"]
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
else:
# Use numeric 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(c.data)
# Check the type of property (some are keyframe, and some are not)
if 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"] == closest_point_x:
# Only update interpolation type
found_point = True
clip_updated = True
point["interpolation"] = interpolation
log.info("updating interpolation mode point: co.X = %s to %s" % (point["co"]["X"], interpolation))
break
# Delete point (if needed)
if point_to_delete:
clip_updated = True
log.info("Found point to delete at X=%s" % point_to_delete["co"]["X"])
c.data[property_key]["Points"].remove(point_to_delete)
# Create new point (if needed)
elif not found_point and new_value != None:
clip_updated = True
log.info("Created new point at X=%s" % self.frame_number)
c.data[property_key]["Points"].append({'co': {'X': self.frame_number, 'Y': new_value}, 'interpolation': 1})
#.........這裏部分代碼省略.........
示例11: color_update
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
def color_update(self, item, new_color, interpolation=-1):
"""Insert/Update a color keyframe for the selected row"""
# Determine what was changed
property = self.model.item(item.row(), 0).data()
property_type = property[1]["type"]
closest_point_x = property[1]["closest_point_x"]
property_key = property[0]
clip_id, item_type = item.data()
if property_type == "color":
# 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(c.data)
# Loop through each keyframe (red, blue, and green)
for color, new_value in [("red", new_color.red()), ("blue", new_color.blue()), ("green", new_color.green())]:
# Keyframe
# Loop through points, find a matching points on this frame
found_point = False
for point in c.data[property_key][color]["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 point
point["co"]["Y"] = new_value
log.info("updating point: co.X = %s to value: %s" % (point["co"]["X"], float(new_value)))
break
elif interpolation > -1 and point["co"]["X"] == closest_point_x:
# Only update interpolation type
found_point = True
clip_updated = True
point["interpolation"] = interpolation
log.info("updating interpolation mode point: co.X = %s to %s" % (point["co"]["X"], interpolation))
break
# Create new point (if needed)
if not found_point:
clip_updated = True
log.info("Created new point at X=%s" % self.frame_number)
c.data[property_key][color]["Points"].append({'co': {'X': self.frame_number, 'Y': new_value}, 'interpolation': 1})
# Reduce # of clip properties we are saving (performance boost)
c.data = {property_key: c.data[property_key]}
# Save changes
if clip_updated:
# Save
c.save()
# Update the preview
get_app().window.preview_thread.refreshFrame()
# Clear selection
self.parent.clearSelection()
示例12: remove_keyframe
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
def remove_keyframe(self, item):
"""Remove an existing keyframe (if any)"""
# Determine what was changed
property = self.model.item(item.row(), 0).data()
property_name = property[1]["name"]
property_type = property[1]["type"]
closest_point_x = property[1]["closest_point_x"]
property_type = property[1]["type"]
property_key = property[0]
clip_id, item_type = item.data()
# 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(c.data)
# Determine type of keyframe (normal or color)
keyframe_list = []
if property_type == "color":
keyframe_list = [c.data[property_key]["red"], c.data[property_key]["blue"], c.data[property_key]["green"]]
else:
keyframe_list = [c.data[property_key]]
# Loop through each keyframe (red, blue, and green)
for keyframe in keyframe_list:
# Keyframe
# Loop through points, find a matching points on this frame
closest_point = None
point_to_delete = None
for point in keyframe["Points"]:
if point["co"]["X"] == self.frame_number:
# Found point, Update value
clip_updated = True
point_to_delete = point
break
if point["co"]["X"] == closest_point_x:
closest_point = point
# If no point found, use closest point x
if not point_to_delete:
point_to_delete = closest_point
# Delete point (if needed)
if point_to_delete:
clip_updated = True
log.info("Found point to delete at X=%s" % point_to_delete["co"]["X"])
keyframe["Points"].remove(point_to_delete)
# Reduce # of clip properties we are saving (performance boost)
c.data = {property_key: c.data[property_key]}
# Save changes
if clip_updated:
# Save
c.save()
# Update the preview
get_app().window.preview_thread.refreshFrame()
# Clear selection
self.parent.clearSelection()
示例13: value_updated
# 需要導入模塊: from classes.query import Clip [as 別名]
# 或者: from classes.query.Clip import get [as 別名]
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
#.........這裏部分代碼省略.........